diff --git a/.github/workflows/codeql-build.yml b/.github/workflows/codeql-build.yml new file mode 100644 index 000000000..46f0ee81f --- /dev/null +++ b/.github/workflows/codeql-build.yml @@ -0,0 +1,58 @@ +name: "CodeQL Analysis" + +on: + push: + pull_request: + +env: + SIMULATION: native + ENABLE_UNIT_TESTS: true + OMIT_DEPRECATED: true + BUILDTYPE: release + +jobs: + + CodeQL-Build: + runs-on: ubuntu-18.04 + timeout-minutes: 15 + + steps: + # Checks out a copy of your repository on the ubuntu-latest machine + - name: Checkout bundle + uses: actions/checkout@v2 + with: + repository: nasa/cFS + submodules: true + + - name: Checkout submodule + uses: actions/checkout@v2 + with: + path: osal + + - name: Check versions + run: git submodule + + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: c + queries: +security-extended, security-and-quality + + # Setup the build system + - name: Set up for build + run: | + cp ./cfe/cmake/Makefile.sample Makefile + cp -r ./cfe/cmake/sample_defs sample_defs + make prep + + # Build the code + - name: Build + run: | + make osal + make native/default_cpu1/osal/tests/ + make native/default_cpu1/osal/unit-test-coverage/ + make native/default_cpu1/osal/unit-tests/ + make native/default_cpu1/osal/ut-stubs/ + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml new file mode 100644 index 000000000..0a998eccb --- /dev/null +++ b/.github/workflows/format-check.yml @@ -0,0 +1,53 @@ +name: Format Check + +# Run on main push and pull requests +on: + push: + branches: + - main + pull_request: + +jobs: + + static-analysis: + name: Run format check + runs-on: ubuntu-18.04 + timeout-minutes: 15 + + steps: + + - name: Install format checker + run: | + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main' + sudo apt-get update && sudo apt-get install clang-format-10 + + - name: Checkout bundle + uses: actions/checkout@v2 + with: + repository: nasa/cFS + + - name: Checkout + uses: actions/checkout@v2 + with: + path: repo + + - name: Generate format differences + run: | + cd repo + find . -name "*.[ch]" -exec clang-format-10 -i -style=file {} + + git diff > $GITHUB_WORKSPACE/style_differences.txt + + - name: Archive Static Analysis Artifacts + uses: actions/upload-artifact@v2 + with: + name: style_differences + path: style_differences.txt + + - name: Error on differences + run: | + if [[ -s style_differences.txt ]]; + then + cat style_differences.txt + exit -1 + fi diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 000000000..b81b11aa5 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,55 @@ +name: Static Analysis + +# Run this workflow every time a new commit pushed to your repository +on: + push: + branches: + - main + pull_request: + +jobs: + + static-analysis: + name: Run cppcheck + runs-on: ubuntu-18.04 + timeout-minutes: 15 + + strategy: + fail-fast: false + matrix: + cppcheck: [all, osal] + + steps: + + - name: Install cppcheck + run: sudo apt-get install cppcheck -y + + # Checks out a copy of the cfs bundle + - name: Checkout code + uses: actions/checkout@v2 + with: + submodules: true + + - name: Run bundle cppcheck + if: ${{matrix.cppcheck =='all'}} + run: cppcheck --force --inline-suppr --quiet . 2> ${{matrix.cppcheck}}_cppcheck_err.txt + + # Run strict static analysis for embedded portions of osal + - name: osal strict cppcheck + if: ${{matrix.cppcheck =='osal'}} + run: | + cppcheck --force --inline-suppr --std=c99 --language=c --enable=warning,performance,portability,style --suppress=variableScope --inconclusive ./src/bsp ./src/os 2> ./${{matrix.cppcheck}}_cppcheck_err.txt + + - name: Archive Static Analysis Artifacts + uses: actions/upload-artifact@v2 + with: + name: ${{matrix.cppcheck}}-cppcheck-err + path: ./*cppcheck_err.txt + + - name: Check for errors + run: | + if [[ -s ${{matrix.cppcheck}}_cppcheck_err.txt ]]; + then + cat ${{matrix.cppcheck}}_cppcheck_err.txt + exit -1 + fi diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 17b4806e5..000000000 --- a/.travis.yml +++ /dev/null @@ -1,61 +0,0 @@ -os: linux -dist: bionic -language: c -compiler: - - gcc -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - cmake cppcheck lcov - -_functional_test: &functional_test - script: - # Check versions - - cppcheck --version - - #cppcheck flight software osal/src/bsp, osal/src/os - - cppcheck --force --inline-suppr --std=c99 --language=c --error-exitcode=1 - --enable=warning,performance,portability,style --suppress=variableScope - --inconclusive --quiet src/bsp src/os 2>cppcheck_flight_osal.txt - - | - if [[ -s cppcheck_flight_osal.txt ]]; then - echo "You must fix cppcheck errors before submitting a pull request" - echo "" - cat cppcheck_flight_osal.txt - exit -1 - fi - - # Setup - - mkdir build - - cd build - - # Prep and build - - cmake -DENABLE_UNIT_TESTS=true -DOSAL_SYSTEM_BSPTYPE=generic-linux -DOSAL_CONFIG_DEBUG_PERMISSIVE_MODE=TRUE .. - - make - - # lcov capture pre-execution - - lcov --rc lcov_branch_coverage=1 --capture --initial --directory ./ --output-file coverage_base.info - - # Test - - make test - - # lcov post run analysis - - lcov --rc lcov_branch_coverage=1 --capture --directory ./ --output-file coverage_test.info - - lcov --rc lcov_branch_coverage=1 --add-tracefile coverage_base.info --add-tracefile - coverage_test.info --output-file coverage_total.info - - lcov --rc lcov_branch_coverage=1 --remove coverage_total.info '*unit-test-coverage*' - --output-file coverage_filtered.info - - genhtml coverage_filtered.info --output-directory lcov - -jobs: - include: - - env: BUILDTYPE=release OSAL_OMIT_DEPRECATED=true - <<: *functional_test - - env: BUILDTYPE=release OSAL_OMIT_DEPRECATED=false - <<: *functional_test - - env: BUILDTYPE=debug OSAL_OMIT_DEPRECATED=true - <<: *functional_test - - env: BUILDTYPE=debug OSAL_OMIT_DEPRECATED=false - <<: *functional_test diff --git a/README.md b/README.md index dac9b1f06..01a94dd59 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -Travis-CI: [![Build Status](https://travis-ci.com/nasa/osal.svg)](https://travis-ci.com/nasa/osal) +![Static Analysis](https://github.com/nasa/osal/workflows/Static%20Analysis/badge.svg) +![Format Check](https://github.com/nasa/osal/workflows/Format%20Check/badge.svg) # Core Flight System : Framework : Operating System Abstraction Layer @@ -10,6 +11,138 @@ The autogenerated OSAL user's guide can be viewed at + +### Development Build: 5.1.0-rc1+dev221 + +- Fixes `printf` format to correctly build in RTEMS-5. +- **Deprecates `OS_fsBlocksFree()` and `OS_fsBytesFree()`** in favor of `OS_FileSysStatVolume()`. +- Adds `Security.md` with instructions to report vulnerabilities. +- Add `UtDebug` in `OS_printf` stub. Output the `OS_printf` input as a debug message from stub. +- Documentation: Add note on `UtTest_Add` API. Nesting `UtTest_Add` from within an added test fails without error. +- Unit Test: No more garbage characters written to test report log +- Fix typo in `osapi.h` affecting C++ build. No other functional change +- Unit Test: Rename `UT_ClearForceFail` as `UT_ClearDefaultValue`. Update the comments of `UT_SetDefaultReturnValue` to match the more general function. +- Unit Test: Add test teardown failures to the test summary and changed the printout to use the same style as startup failures. +- Unit Test: Removes no longer applicable `UT_CheckForOpenSockets` since the UT framework resets the state for each unit test. +- Changes the file-create operation to read-write permissions to work on RTEMS +- Unit Test: Fixes incorrect assertions in `network-api-test` to correctly check return values. +- Unit Test: Generalizes queue timeout test to also test message queue functionality to validate settings and permissions to work with mqueues. +- Implements `OS_time_t` with a single 64-bit tick counter rather than a split 32 bit seconds + 32 bit microseconds counter. +- Unit Test: Installs the modules used in unit testing and adds removal of post-test, left-over files. +- See + +### Development Build: 5.1.0-rc1+dev184 + +- Address issues with OSAL global table management: + - use iterators whenever possible + - use an unlock key rather than task ID so OS_TaskExit() doesn't trigger a warning + - general cleanup of lock/unlock impl and remove redundant logic + - unlock global tables during create/delete + - keep threads "attached" in POSIX, so they can be joined when deleted. +- No longer triggers warning with OS_TaskExit() on VxWorks (see #645) +- `OS_TaskDelete()` on POSIX does not return until the task has actually exited (see #642) +- The chmod test is now skipped on VxWorks rather than failing. The `OS_FileChmod_Impl()` function now returns `OS_ERR_NOT_IMPLEMENTED` when run on a file system that does not have permissions, which in turn causes the unit test to be skipped rather than fail. +- Corrects a file handle leak. +- Add parameter check to `OS_SocketSendTo` and adjust coverage test to validate. +- Replace `OS_fsBytesFree` and `OS_fsBlocksFree` with `OS_FileSysStatVolume`. This new API for getting stats on file system. Uses existing `OS_FileSysStatVolume_Impl` call and exposes it in the public API. +- When cleaning up for shutdown, delete resources that have a task/thread first, followed by other resource types. This helps avoid possible dependencies as running threads might be using the other resources. No detectable external impact; internally, the tasks are deleted first during shutdown, which only has an impact if/when tasks are actively using other OSAL resources. +- The mount/unmount *VxWorks* implementation was not adequately checking for and handling the `FS_BASED` pass -through mapping type - which should be mostly a no-op. Create a mount point directory if it does not already exist when using this mapping type for consistency with POSIX. +- Adds a documentation note to `OS_FileSysAddFixedMap()`: The virtual mount point cannot be empty - so `OS_FileSysAddFixedMap(.., "/", "/")` does not work but `OS_FileSysAddFixedMap(.., "/", "/root")` does work and allows one to open files in the root as `"/root/"` from OSAL applications. Mount-point directories do not need to previously exist when using OS_FileSysAddFixedMap +- store `taskTCB` return in a `void *`, then cast to `OS_impl_task_internal_record_t *` to avoid a strict alignment compiler error +- Removes the non-portable `OS_PACK` and `OS_ALIGNED` macros. +- Uses the POSIX dir implementation on VxWorks 6.9. The only incompatibility is the prototype for `mkdir()`which is missing the second argument; this is worked around with a compatibility macro for VxWorks 6.x builds. +- Translate and convert the VxWorks coverage test cases to the portable dir implementation, which benefits VxWorks7, RTEMS, and POSIX. +- Fixes prototypes so they run on RTEMS by replacing uint32 with size_t +- Adds` OS_CHECK_POINTER` macros to `OS_ConvertToArrayIndex` and `OS_TimeBaseGetFreeRun` so they can handle NULL pointers and return the correct error. +- Adds access functions to convert/extract different units from an OS_time_t value - so that other code in CFE/PSP/Apps can be updated to use the access functions and thereby not break when the internal time definition changes. Replaces the `int32` with `OS_time_t` in the "stat" structure used by the file module. Updates the pointer argument to `OS_SetLocalTime()` to be `const`. Prototype change of `OS_SetLocalTime()` should be backward compatible. +- See + +### Development Build: 5.1.0-rc1+dev149 + +- Document UtAssert_Message parameters, also adds "see also" note for helper macros. +- Fix doxygen typo +- Replace `OS_BinSemFlush` with `OS_BinSemGive` to prevent a rare race condition. Change the port numbers to be different from network test for when tests are run in parallel. +- Fix doxygen format errors. Usersguide now builds without warnings. +- Suppress invalid cppcheck warning in `OS_WaitForStateChange` +- Add cppcheck static analysis workflow to osal CI +- See + +### Development Build: 5.1.0-rc1+dev132 + +- Convert the OSAL Configuration Guide from docx and pdf to a markdown file. +- Test Tasks do not run at 100%. Move all definitions and instantiations out of the core-test header file and reuse the already-existing single task definition. +- Break up `osapi-os-*.h` files into units that correspond to the implementation units. Kept old header file names for compatibility. +- Reworks the POSIX global lock implementation. Does not change the POSIX signal mask when locking/unlocking the global. + - Fixes a race condition. + - Adds a condition variable to the global lock structure. improves handling of tasks competing for access to the same object. + - No longer changing signal masks repeatedly/unexpectedly. May be relevant to some BSP/driver developers. +- Checks return of sysconf for error and reports them. Only sets PageSize on success. If sysconf fails it provides a mechanism to avoid error propagation. +- Uses `errno` instead of status return from `clock_getres` with `strerror` reporting. +- Adds support for VxWorks 7 +- See + +### Development Build: 5.1.0-rc1+dev109 + +- Add support for RTEMS 5.1 in the OSAL and provides defines and necessary ifdefs so RTEMS 4.11 can continue to be supported. +- Adds functional test for OS_chmod +- Refactor the table array access across OSAL. Use a token concept in combination with a macro to obtain the table entry instead of indexing arrays directly. All access is then done through this table pointer. Use the full object ID in the timer call back list. Update the timer sync callback prototype. Pass the entire OSAL ID to the sync function, not just the index. This is technically an API change. +- Replaces condition on forever loops to end on shutdown. Loops now exit on shutdown. +- Removes obsolete printf tests that didn't work +- See + + +### Development Build: 5.1.0-rc1+dev91 + +- Rename `UT_SetForceFail` to `UT_SetDefaultReturnValue` since some functions that retain more than 1 value are not necessarily failing +- Add a 5th timer to TimerTest functional to test the one shot (zero-length time interval) case. +- Ensure all APIs use the proper type. Sizes are now size_t; these will now be 64 bits on a 64 bit platform. +- Fix build issue on VxWorks 6.9 by using the 3 argument form of `open()`. Passing `0` as the mode solves the build issue. This parameter is ignored when not creating a file. +- The address calculations now use `unsigned long` instead of `long` to ensure that all rounding and base address adjustments behave the same way in the event that the addresses lie in the upper half of memory (i.e. start with a 1 bit) which would put it in the negative range of a long type. +- See + + +### Development Build: 5.1.0-rc1+dev75 + +- Ensure that the handle is not NULL before invoking dlclose(). In particular the handle will be NULL for static modules. Shutdown after CTRL+C occurs normally (no segfault). +- Add a "flags" parameter to OS_ModuleLoad() to indicate the desired symbol visibility: + - GLOBAL (0, the default, and matches current behavior) + - LOCAL which hides from other modules and prevents other modules from binding to symbols in this module, thereby ensuring/preserving the ability to unload in the future + - CFE should use LOCAL flag for apps, and GLOBAL flags for libraries. +- See + +### Development Build: 5.1.0-rc1+dev68 + +- When `OS_DEBUG` is enabled, this adds a message if mutex give/take actions occur outside the expected sequence. This informs the user (via the debug console) if a lock is taken more than once or if a lock is given by a different task than the one that originally took it: +``` +OS_MutSemTake():216:WARNING: Task 65547 taking mutex 327685 while owned by task 65547 +``` +- Removes all FIXME comments +- Resolves security/filename race issue by opening file and acting on descriptor by adding fstat stub +- Squashed the minor recommended bugs +- UtAssert macros now accept variable string arguments.The `UtAssert_True` wrapper around call is no longer needed to accommodate dynamic string output, thus removing the double assert. UtAssert macros will now be able to offer more information by themselves. +- See + ### Development Build: 5.1.0-rc1+dev60 - Appliy standard formating, whitespace-only changes diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..30252dba3 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,15 @@ +# Security Policy + +## Reporting a Vulnerability + +To report a vulnerability for the OSAL subsystem please [submit an issue](https://github.com/nasa/osal/issues/new/choose). + +For general cFS vulnerabilities please [open a cFS framework issue](https://github.com/nasa/cfs/issues/new/choose) and see our [top-level security policy](https://github.com/nasa/cFS/security/policy). + +In either case please use the "Bug Report" template and provide as much information as possible. Apply appropraite labels for each report. For security related reports, tag the issue with the "security" label. + +## Additional Support + +For additional support, email us at cfs-program@lists.nasa.gov. For help using OSAL and cFS, [subscribe to our mailing list](https://lists.nasa.gov/mailman/listinfo/cfs-community) that includes all the community members/users of the NASA core Flight Software (cFS) product line. The mailing list is used to communicate any information related to the cFS product such as current releases, bug findings and fixes, enhancement requests, community meeting notifications, sending out meeting minutes, etc. + +If you wish to report a cybersecurity incident or concern please contact the NASA Security Operations Center either by phone at 1-877-627-2732 or via email address soc@nasa.gov. diff --git a/default_config.cmake b/default_config.cmake index fe993a457..f71dafbc5 100644 --- a/default_config.cmake +++ b/default_config.cmake @@ -15,6 +15,53 @@ # ########################################################################## +############################################################## +# Argument/Bug-checking options +############################################################## + +# OSAL_CONFIG_BUGCHECK_DISABLE +# ---------------------------------- +# +# Disable/compile-out the "bugcheck" macro +# +# The bugcheck macro is used to validate the inputs to functions and/or +# assert on other conditions that should _always_ be true. If any of these +# conditions ever evaluate as false, it indicates a bug in the code - +# either in the OSAL or the application which invoked OSAL. +# +# If set FALSE (default), then the OSAL bugcheck macro will evaluate its +# boolean conditional and generate an action if that conditional evaulates +# false. (The specific action to take is configured via a different +# directive -- see OSAL_CONFIG_BUGCHECK_STRICT). +# +# These extra bug checks do consume a slight bit of code+data space as +# well as some runtime CPU cycles on every call, depending on the conditions +# being tested. +# +# Once the application has reached a sufficient level of stability and +# confidence is obtained that these bug checks are not possible to be +# triggered, this directive may be set TRUE which disables the bug checks +# completely - rendering these statements as no-ops. +# +set(OSAL_CONFIG_BUGCHECK_DISABLE FALSE) + + +# OSAL_CONFIG_BUGCHECK_STRICT +# ---------------------------------- +# +# Select a strict implementation for the "bugcheck" macro +# +# If set FALSE (default), then the OSAL bugcheck macro will generate a +# debug message and return an error code if the conditional evaluates +# as false. This is a soft error - the application will get the +# error code and keep running. +# +# If set to TRUE, then any failure of any bugcheck macro is considered +# fatal and will trigger an abort(). On many platforms this will +# generate an abnormal application exit with a core file for debugging. +# +set(OSAL_CONFIG_BUGCHECK_STRICT FALSE) + ############################################################## # Code/Feature Selection Options for the OSAL implementation diff --git a/doc/OSAL-Configuration-Guide.md b/doc/OSAL-Configuration-Guide.md new file mode 100644 index 000000000..e32ff65d0 --- /dev/null +++ b/doc/OSAL-Configuration-Guide.md @@ -0,0 +1,869 @@ +# Introduction + +## Scope + +The purpose of this document is to provide guidelines and conventions +for the configuration and deployment of the Operating System Abstraction +Layer (OSAL) to a desired platform or platforms. + +## Background + +The goal OS Abstraction Layer is to promote the creation of portable and +reusable real time embedded system software. Given the necessary OS +abstraction layer implementations, the same embedded software should +compile and run on a number of platforms ranging from spacecraft +computer systems to desktop PCs. + +## Applicable Documents + +| **Document ID** | **Document Title** | +| --- | --- | +| | | + + +## Acronyms + +| **Acronym** | **Description** | +|---|---| +| OS | Operating System | +| API | Application Programming Interface | +| CM | Configuration Management | +| CPU | Central Processing Unit | +| EEPROM | Electrically Erasable Programmable Read-Only Memory | +| HW, H/W | Hardware | +| RAM | Random-Access Memory | +| SW, S/W | Software | +| TBD | To Be Determined | + +## Glossary of Terms + +The following table defines the terms used throughout this document. +These terms are identified as proper nouns and are capitalized. + +| **Term** | **Definition** | +|---|---| +| Application (APP) | A generic term for a computer program in a desktop or embedded system. An Application is generally not part of the operating system. | +| Application Programmer's Interface (API) | A set of routines, protocols, and tools for building software applications | +| Board Support Package (BSP) | A collection of user-provided facilities that interface an OS and the cFE with a specific hardware platform. The BSP is responsible for hardware initialization. | +| Core Flight Executive (cFE) | A runtime environment and a set of services for hosting FSW Applications | +| Cyclic Redundancy Check | A polynomial based method for checking that a data set has remained unchanged from one time period to another. | +| Developer | Anyone who is coding a software Application. | +| Hardware Platform | The target hardware that hosts the Operating System and Application. | +| Interface Control Document | A document that describes the software interface, in detail, to another piece of software or hardware. | +| I/O Data | Any data being written to and read from an I/O port. No structure is placed on the data and no distinction as to the type of I/O device. I/O data is defined separately from memory data because it has a separate API and it's an optional interface of the cFE. | +| Log | A collection of data that an application stores that provides information to diagnose and debug FSW problems. | +| Memory Data | Any data being written to and read from memory. No structure is placed on the data and no distinction as to the type of memory is made. | +| MMU | Memory Management Unit. A piece of hardware that manages virtual memory systems. It automatically translates addresses into physical addresses so that an application can be linked with one set of addresses but actually reside in a different part of memory. | +| Network | A connection between subsystems used for communication purposes. | +| Platform | See "Hardware Platform" above. | +| User | Anyone who interacts with the Software Application or system in its operational state. A user can be a developer, a tester, an operator, or a maintainer. +| Application (APP) | A generic term for a computer program in a desktop or embedded system. An Application is generally not part of the operating system. | +| Application Programmer's Interface (API) | A set of routines, protocols, and tools for building software applications | +| Board Support Package (BSP) | A collection of user-provided facilities that interface an OS and the cFE with a specific hardware platform. The BSP is responsible for hardware initialization. | +| Core Flight Executive (cFE) | A runtime environment and a set of services for hosting FSW Applications | +| Cyclic Redundancy Check | A polynomial based method for checking that a data set has remained unchanged from one time period to another. | +| Developer | Anyone who is coding a software Application. | +| Hardware Platform | The target hardware that hosts the Operating System and Application. | +| Interface Control Document | A document that describes the software interface, in detail, to another piece of software or hardware. | +| I/O Data | Any data being written to and read from an I/O port. No structure is placed on the data and no distinction as to the type of I/O device. I/O data is defined separately from memory data because it has a separate API and it's an optional interface of the cFE. | +| Log | A collection of data that an application stores that provides information to diagnose and debug FSW problems. | +| Memory Data | Any data being written to and read from memory. No structure is placed on the data and no distinction as to the type of memory is made. | +| MMU | Memory Management Unit. A piece of hardware that manages virtual memory systems. It automatically translates addresses into physical addresses so that an application can be linked with one set of addresses but actually reside in a different part of memory. | +| Network | A connection between subsystems used for communication purposes. | +| Platform | See "Hardware Platform" above. | +| User | Anyone who interacts with the Software Application or system in its operational state. A user can be a developer, a tester, an operator, or a maintainer.| + +# How to Configure, Build, and Run the OSAL + + +The OSAL distribution includes a complete development environment with +support for a number of processors and operating systems. The OSAL +development environment has been designed to isolate the portable OS +source code from the OSAL applications, configuration parameters, and +build products. The development environment is an example of how to +configure and build portable software using the OSAL code, but it is by +no means a requirement to use the OSAL. The included platforms for the +OSAL can be used as starting points for other boards and CPUs. + +The following sections provide instructions on how to: + +- Setup the build environment + +- Configure the build directory for an OSAL application + +- Configure a OSAL Application + +- Build the OSAL Application + +- Load the OSAL Application on to the target platform + +- Run the OSAL Application on the target platform + +In the current OSAL release, two build systems are available: the +"classic" build using ordinary makefiles, and a new build utilizing the +"cmake" tool. The "classic" build is mostly carried over from previous +OSAL releases and preserves compatibility with existing +projects/workflows. The "cmake" build offers increased features by +introducing additional scripting and build-time configurability, +allowing direct inclusion into larger projects with less need to modify +files to support a specific target or configuration. + +## Setup the Build Environment + +This section details the steps needed to setup the OSAL source +distribution and prepare the host development environment to build the +OSAL. + +### Setup the OSAL Source Distribution + +Get a copy of the OSAL source distribution directory on your build +machine. The source distribution has the following directories: + +#### OSAL source distribution directories + +| **Directory** | **Description** | +|---|---| +| osal | The top level OSAL source distribution directory. OSAL version 2.10 is being used as an example. | +| osal/src | The src directory contains the OSAL source, and make rules. | +| osal/src/examples | The sample directory contains the sample applications for the osal. | +| osal/src/tests | The tests directory contains a small number of OSAL tests that can run on the targets. | +| osal/src/unit-tests |The unit-tests directory contains a suite of OSAL unit tests. | +| osal/src/bsp | The bsp directory contains the platform specific code for the OSAL as well as code to make the OSAL run on a particular platform. Everything in this directory is used to adapt the OSAL and Applications to a particular hardware platform. This directory also contains the startup code for the example programs. The included platforms are generic enough that they may be easy to port to other platforms and processor architectures. For example: The bsp/mcf5235-rtems board support package was ported to an ARM processor running RTEMS with minimal effort. | +| osal/src/make | The make directory contains common makefiles for building the OSAL and its applications (classic build only) | +| osal/src/os | The os directory is the heart of the OSAL, containing the implementation of the OSAL for each supported operating system. There is a sub-directory for each supported operating system in this directory. The OSAL include files are also contained in this directory (src/os/inc). | +| osal/src/inc | The inc directory contains system wide include files that are used by the OSAL on all platforms. | +| osal/build | The build directory contains the classic framework for building an OSAL application. The files in this directory allow easy customization and configuration for any supported OS or platform for the OSAL. By changing two variables in a file, the OSAL examples and test can be built for any of the supported platforms. | +| osal/doc | The doc directory contains the documentation and release notes for the OSAL. | + + +The osal directory can go just about anywhere on a host development +system. + +#### Example directory structure locations + +| **Host Operating System** | **Example Directory** | **Notes** | +|---|---|---| +| Windows/vxWorks 6 Development Shell | C:\\osalproject\\osal | Building on Windows with the vxWorks 6.x development tools requires using the "vxWorks Development Shell". The system will not build on a standard Cygwin Shell, or a windows DOS prompt. | +| Linux | /home/osaluser/osal| | + +## Configure the OSAL Parameter File + +The file **osconfig.h** has configuration parameters for tailoring the +OSAL parameters. Most parameters set upper bounds on the number of OS +objects that can be created. The OSAL keeps track of allocated OS +objects using fixed size tables. The OSAL source distribution contains a +sample osconfig.h file in the "osal/src/bsp/\/config" directory, +which can either be used as-is or tuned for specific project needs. The +osconfig.h file is required regardless of the build system in use +(classic or cmake). + +#### OSAL configuration parameters + +| **Parameter** | **Description** | +|---|---| +| OS_MAX_TASKS | The maximum number of tasks that can be created in the running OSAL application. | +| OS_MAX_QUEUES | The maximum number of queues that can be created in the running OSAL application. | +| OS_MAX_COUNT_SEMAPHORES | The maximum number of counting semaphores that can be created in the running OSAL application. | +| OS_MAX_BIN_SEMAPHORES | The maximum number of binary semaphores that can be created in the running OSAL application. | +| OS_MAX_MUTEXES | The maximum number of mutexes that can be created in the running OSAL application. | +|OS_MAX_PATH_LEN |The maximum length for an absolute path length in the OSAL File API.| +|OS_MAX_API_NAME|The maximum length for an individual file name in the OSAL File API.| |OS_BUFFER_SIZE|The maximum size of a formatted text message for the OS_printf API.| |OS_BUFFER_MSG_DEPTH|The maximum number of messages buffered by the OS_printf API.| +|OS_UTILITY_TASK_ON |Turns on a utility task that will read the statements to print from the OS_printf function. If this define is commented out OS_printf will print the text under the context of the caller.| +|OS_UTILITYTASK_STACK_SIZE|The size of the stack for the utility task.| |OS_UTILITYTASK_PRIORITY|The priority of the utility task.| +|OSAL_SOCKET_QUEUE |If this is defined, the posix port will use the socket implementation for message queues, rather than the POSIX message queue implementation.| |OS_MAX_MODULES |Used for defining the maximum number of loadable modules that the OS AL can keep track of. This is used for the new Module Load and Symbol API.| +|OS_MAX_SYM_LEN|Used for setting the maximum length of a symbol name in the symbol API .| +|OS_MAX_TIMERS|Used for defining the maximum number of timers in the OSAL.| + + +## Setting up "classic" build + +The following procedures are relevant only when using the classic +makefile build. For the equivalent cmake instructions, see the next +section. + +### Create System Environment Variable + +The OSAL development environment requires one system environment +variable to be set in order to build the example programs. The directory +also contains a shell script "setvars.sh" to set the environment to the +current OSAL directory. + +#### Environment Variables needed by the cFE + +| **Environment Variable** | **Value (in Linux as an example)** | **Notes** | +|---|---|---| +| OSAL_SRC | /home/osaluser/osal | The location of the OS Abstraction Layer source code. This directory can be moved anywhere as long as the environment variable is set accordingly. | + + +#### Example Environment Variable for Different Development Hosts + +| **Host Operating System** | **Example Environment Variables** | **Notes** | +|---|---|---| +| Windows/vxWorks 6 Development Shell | \% set OSAL_SRC=C:/osalproject/osal | 1\. These environment variables can be set in the Windows control panel under system/environment variables. 2\. Note the forward slash directory separators in the DOS environment variables. Because the vxWorks tools are half DOS and half-Unix, they don't seem to like the DOS style backslash.| +| Linux| \$ export OSAL_SRC=/home/osaluser/osal | These settings can be set in the user's .bash_profile | + +### Configure the Build Directory for the OSAL application + +The build directory is where the OSAL is configured and compiled for a +particular processor, board, and OS. The build directory is designed to +hold the OSAL configuration for the selected platform. The **core** +directory is where the core OS code, and bsp code are built. They are +left in the core directory for the applications to link against. The +build directory can have multiple OSAL applications to build for a +particular platform. The OSAL distribution contains directories for +example and test applications. Multiple build directories can be used to +configure the OSAL for different platforms in the same environment, each +with its own unique OSAL configuration. + +### Configure the 'build' Directory + +In order to build the OSAL for one of the supported platforms, the OSAL +build directory must be properly configured. This involves editing a +couple of configuration files and setting up one or more sample +applications that use the OSAL API. + +### Define the CPU, Operating System, and Processor Board + +In the build directory, edit the **'osal-config.mak'** file and set the +options for your target. The default settings in the osal-config.mak are +for running vxWorks6.4 on a generic PowerPC board. + + +#### osal-config.mak Settings + +| **osal-config.mak variable** | **Valid selections** | **Notes** | +|---|---|---| +| OS | vxworks6, rtems, posix | 1\. VxWorks 5.5 is no longer supported. 2\. posix is tested for 32 bit linux 2.6.x | +| BSP | genppc-vxworks6.4, mac-posix, pc-posix, mcf5235-rtems, sis-rtems | Use posix for linux | +| OSAL_M32 | -m32 (or commented out) | See below. | + +Note that not all combinations are valid. See the Platform Specific +Section for more information on each supported cFE target. + +In some cases, developers may find their compiler toolchain producing +"64-bit" images, when "32-bit" images are needed -- for example, when +using "native" GCC on a 64-bit X86 Linux. The OSAL build files support +use of an **OSAL_M32** build variable to insert the appropriate "please +build 32-bit images" compiler parameter into all compilation and linkage +commands. + +In this use case, the setting of the **OSAL_M32** build variable should +be uncommented in the **osal-config.mak** file, and set to the correct +flag for the compiler toolchain in use. The build system will also honor +settings of this variable made in the developer's shell environment or +on the "make" command line.. + +Usage of this flag may require an optional "multilib" (or similar) +package to be installed. Refer to your operating system and toolchain +documentation for details, if adding the appropriate flag causes your +builds to fail due to (for example) missing 32-bit or multilib related +headers or libraries. + +## Setting up the "cmake" build + +This section covers how to set up the host machine for building OSAL +using the cmake build system. Rather than using pre-written makefiles as +the classic build does, the cmake build generates makefiles entirely +from instructions specified in files contained with the source code +itself. This has several advantages: + +- Enhanced script-like capabilities + +- Generally no need to modify files to adapt to a particular target. + +- Easier integration with larger mission projects + +Typically, OSAL is not built by itself, but rather as a library to be +used within a larger application. The OSAL cmake build system allows +both options; building as a standalone entity for testing purposes, or +building as a sub-component within a larger project. The same scripts +are used in both cases, and no modification is required. + +### Prerequisites + +In order to build OSAL using cmake, the "cmake" package must be +installed for the host/development machine. On Linux, this is generally +available via the respective Linux distribution package management +system, i.e. "yum" on RedHat and derivatives, or "apt-get" on Debian and +derivatives. For other operating systems, the cmake tool is available in +source and binary form from . OSAL requires at least +version 2.6.4 of the cmake tool. + +### Variables that must be specified + +The OSAL cmake build is controlled by several user-supplied variables +when the build is first provisioned: + +| **CMake variable** | **Valid selections** | **Notes** | +|---|---|---| +| OSAL_SYSTEM_OSTYPE | Any directory name that exists under osal/src/os |All OS-specific source files in this directory will be built. An optional, OS-specific "build-options.cmake" file will also be included which may add necessary compiler options specific to that OS. | +| OSAL_SYSTEM_BSPTYPE | Any directory name that exists under osal/src/bsp | All BSP-specific source files in this directory will be built. An optional, BSP-specific "build-options.cmake" file will also be included which may add necessary compiler options specific to that BSP. | +| OSAL_INCLUDEDIR | Any directory on the host system (absolute path) | Optional; if specified, this will be included in the compiler include file search path. Typically this is used to specify the location of "osconfig.h" for standalone OSAL builds. | +| ENABLE_UNIT_TESTS | TRUE or FALSE | Optional; defaults to "FALSE" if not specified. If set to TRUE, the included unit test code will also be built in addition to the runtime library. | +| OSAL_USER_C\_FLAGS | Any valid switches for the compiler in use. | Optional; the user may specify any arbitrary compiler switches to use. | + + +It is important to note that the values specified for these variables +are **automatically cached** by the cmake build system. It is only +necessary to specify these values when first provisioning/configuring a +build; these are *not* required when simply building the binaries. + +This caching function removes the need for environment variables to be +set as in the "setvars.sh" file in the classic build. The cmake build +does not require the user to set environment variables; all necessary +context information is automatically stored in the cache when the build +is first provisioned. + +### Setting up a standalone OSAL build + +The OSAL may be built standalone in order to evaluate the library for a +particular target and/or execute the included unit tests. + +In the cmake build system, all generated files are placed in a dedicated +"binary" directory that is separate from the source tree. To provision a +build, the user must first create the binary directory by issuing the +"mkdir" command (on Linux), preferably outside the OSAL source tree. +Then, the "cmake" provisioning tool is invoked to generate the actual +makefiles, supplying values for the required variables: + +``` +$ mkdir build +$ cd build +$ cmake –DOSAL_SYSTEM_OSTYPE=posix –DOSAL_SYSTEM_BSPTYPE=pc-linux \ + –DENABLE_UNIT_TESTS=TRUE –DOSAL_INCLUDEDIR=/path/to/user/config \ + /path/to/osal/source + +``` + + +The cmake provisioning tool generates standard makefiles in the build +directory. To build the OSAL binaries, simply run "make" in the build +directory. + +### Integrating OSAL into a larger build + +Modularity is a key feature of the cmake system. As such, the OSAL cmake +build system can be directly used as a component within a larger +"mission" build, as long as the same variables are supplied via the +parent cmake script: + +``` +SET(OSAL_SYSTEM_OSTYPE “posix”) +SET(OSAL_SYSTEM_BSPTYPE “pc-linux”) +ADD_SUBDIRECTORY(path/to/osal) +``` + +The values for the variables can be obtained by any means, shown here is +just a simplified example of how it can be done for a known target. + +### Cross compiling with Cmake + +To cross compile, cmake uses a separate "toolchain file" that indicates +the specific compiler to use, and any machine-specific compiler options +that may be required. Documentation for the toolchain files is available +on the cmake website at . The toolchain file is +specified when the build is provisioned. No OSAL build scripts need to +be modified in order to cross compile or add extra machine-specific +options. + +## Check over or customize the OSAL BSP directory + +The glue logic that ties an OSAL application to a specific processor +board and platform is in the src/bsp directory. This directory contains +the BSP code, which contains all of the specific rules, glue code, and +startup code to make an OSAL application run on a particular board with +a particular OS. + +The platforms supported in the OSAL distribution should run out of the +box. They provide a starting point for a complete port to a new +processor board. + +This section will be expanded in the future to include information +needed for new OSAL ports. + +## Configure one or more OSAL Applications + +Once the OSAL is configured and ready to build, an OSAL application can +be configured in the build directory. Multiple OSAL applications can be +created in this directory. The application source code can come from the +src/examples directory, or the applications can be contained completely +within the build directory. The OSAL source distribution has a set of +test and example applications in the src/examples and src/tests +directories and a set of corresponding application directories and +makefiles in build directory. + +### Configure a sample application in the build directory + +The following show the files needed for a sample OSAL application in the +build directory. + + +#### Sample OSAL Applications and the associated files + +| **File** | **Description** | +|---|---| +| build/examples/tasking-example | Directory for the included OSAL example Application. | +| build/examples/tasking-example/Makefile | Makefile for the example OSAL app. Because the source is in the src/examples/tasking-example directory, there is no need to include it here. The Makefile will find it using the OSAL_SRC environment variable. The source could be copied here in order to customize it. | +| build/examples/new_osal_app | Directory for a new OSAL application. | +| build/examples/new_osal_app/Makefile | Makefile for a new OSAL application. | +| build/examples/new_osal_app/new_osal_app.c | Source file for the new OSAL application. | +| build/examples/new_osal_app/new_osal_app.h | Header file for the new OSAL application. | + + +The Application Makefiles have a specific format, so it is best to copy +one of the application Makefiles from the build directory, such as +build/examples/tasking-example. + +### Configure the application's main entry point + +The OSAL development environment provides the main entry point/startup +code for the Application. This code is located in the src/\/src +directory. The startup code will call the Application's entry point +which is named: void OS_Application_Startup(void) + +## Build the OSAL core and Applications + +Once the OSAL Core and Applications are set up in a build directory, +everything can be compiled. The OSAL Core or any of the Applications can +be built from individual make files, or they can be built from the +top-level Makefile in the build directory. + +#### Build Commands + +| **Shell command** | **Description** | +|---|---| +| **\$ cd build** | Change to the build directory. | +| **\$ make** | Build the OSAL Core, and all Applications. | +| **\$ make clean** | Clean the OSAL Core, and all Applications. | + + +The following additional make targets apply only to the "classic" build; +the cmake build handles configuration and dependencies automatically. + +| **Shell command** | **Description** | +|---|---| +| **\$ make config** | Copy the osconfig.h for the BSP to the build directory. | +| **\$ cd examples/tasking-example; make** | Build the tasking-example Application only. | +| **\$ make depend** | Recalculate the dependencies on the OSAL Core files and apps. | + +Once the OSAL Applications are built, they are ready to load and execute +on the target. The filename of the executable is dependent on the OS it +is built for. + +#### OSAL Application executable name + +| **Target Operating System** | **Application executable name** | **Notes** | +|---|---|---| +| vxWorks 6.x dynamic link | example1.elf | The vxWorks PowerPC platforms use a dynamically loaded object without the kernel. | +| Linux | example1.bin | | +| Rtems/Coldfire | example1.nxe | This is a static linked executable, linked with the RTEMS kernel and BSP. | +| RTEMS/SIS | example1.nxe | This is a static linked executable, linked with the RTEMS kernel and BSP. | + +## Load and Run the OSAL Applications + +Depending on the Target, it is usually straightforward to run an OSAL +Application on a target platform. On desktop platforms, it is just a +matter of running the executable program. On vxWorks, the example +programs are loadable modules. + +### Load the OSAL Application Executable on the Target + +On desktop targets the cFE Core can be run from the directory where it +was compiled. On embedded targets, the Application has to be loaded into +a remote file system, or booted over the network. On the vxWorks PowerPC +targets, the Application can be loaded into the EEPROM or Flash disk +after the vxWorks kernel is booted. On RTEMS targets, the Application +can be loaded using the CEXP dynamic loader or it can be linked in with +an RTEMS Binary. See the target specific sections for details on each +platform. + +### Setup the Target File Systems + +Because the OSAL runs on many different platforms, it must be able to +deal with different file system types and different paths. The OSAL +accomplishes this by using a file system abstraction. The abstracted +OSAL file system is similar to a UNIX file system, where the root +directory starts with "/" and all disks are mounted on directory trees. +For example: + +- /ram0/apps/ RAM disk 0, apps subdirectory + +- /ram1/data/ RAM disk 1, data subdirectory + +- /hd0/tables/ Hard Disk 0, tables subdirectory + +Using this abstraction, a file "datafile1.dat" on RAM disk 1 might be +accessed from the OSAL by using the path "/ram1/data/datafile1.dat". +Using the host vxWorks tools, the path to the same file would be: +"RAM:0/data/datafile1.dat". If the OSAL is running on a Linux +development workstation, the file might be located at: +"/tmp/ramdev1/data/datafile1.dat". The important part is that the OSAL +Application can access the files using a generic path, allowing the +software to remain portable. + +There are a few ways to map these host file systems to OSAL file +systems: + +- **Map existing target file systems to a OSAL path**. This is one of +the most common ways to map the Non-Volatile disk to the OSAL. The OSAL +relies on the target OS to create/mount a file system and it simply is +given a mapping to the disk to allow the OSAL to access it. + +- **Create EEPROM/Flash/ATA File systems**. The OSAL has the ability +on some targets to format or initialize a EEPROM or ATA disk device. +This is less commonly used. + +- **Create RAM File Systems**. The OSAL can create RAM disks on the +vxWorks targets. The OSAL will create or re-initialize the RAM disk for +the vxWorks targets. + +**RTEMS Note**: The RTEMS OS provides a base file system, called IMFS +that provides the root directory. Because this closely matches what the +OSAL file system abstraction provides, the RTEMS directories and +filenames are a one to one mapping. In other words the path on RTEMS is +the same as the path in the OSAL. + +The following table shows examples of these file system mappings on +various hosts. **Note** the change in the way the POSIX ports are +mapped. Linux will no longer remove or create sub-directories based on +the volume name. The path mapping for the FS_BASED option is now a +simple mapping from an OSAL path to a host path. This makes the OSAL +easier to use on linux platforms: + +#### OSAL File system mapping + +| **Target Operating system** | **cFE File system path** | **Target OS File system path** | **Notes** | +|---|---|---|---| +| vxWorks 6.x | /ram | RAM:0/ | Most vxWorks targets | +| | /cf | CF:0/ or CF:1/ | MCP750| +|| /cf | EEP:0/| RAD750 target | +| Linux | /ram | ./ram0 | Note the "." This will map the RAM disk to the current working directory + the "ram0" subdirectory. | +|| /cf | ./cf | Again, starts with the current working directory. | +| RTEMS | /ram | /ram | RTEMS has 1-1 mapping with the OSAL | +|| /cf | /cf || + +### Start the OSAL Application on the Target + +Starting an OSAL Application is a highly target dependant activity. The +following table gives examples of how to start an Application on various +platforms. For full details see the notes for each section. + +#### How to start an OSAL Application on Various Target Systems: + +| **"Target" operating system** | **How to start the cFE** | +|---|---| +|RTEMS / mcf5235 | Loaded through GDB/BDM using a shell script: "debug.sh" | +| RTEMS / SIS | Loaded through GDB/SIS simulator: \$ sparc-rtems4.10-gdb tasking-example.n (gdb) target sim (gdb) load (gdb) run | +| vxWorks 6.2 / RAD750 | Started from the vxWorks Target Shell commands: Vx\> ld \< tasking-example.elf Vx\> OS_BSPMain | +| Linux | Start directly from the linux shell: \$ ./tasking-example.bin | + + +# Target Specific Instructions + +This section provides details on how to load and run each of the +supported OSAL configurations. + +## Generic PPC / vxWorks 6.4 Platform: + +The Generic PPC applications will work on both the Motorola MCP750 and +the BAE RAD750 running vxWorks 6.4. On this platform, the OSAL +Applications are built as dynamic loadable vxWorks modules, rather than +being linked to the vxWorks kernel/BSP. The OSAL Applications are loaded +into the compact flash disk on the MCP750, so it can be started from a +vxWorks shell or startup script after the kernel comes up. + +### OSAL Configuration for the Generic PPC / VxWorks 6.4 + +#### osal-config.mak Settings + +| **osal-config.mak variable** | **Required selection** | **Notes** | + |---|---|---| +| OS | vxworks6 || +| BSP | genppc-vxworks6.4|| + +### File System Mappings on the MCP750 PPC Board + +The cFE uses the following file system mappings for the MCP750 PPC +Board. The file system mappings are defined in the bsp_voltab.c file in +the src/arch/ppc/genppc/vxworks6.4/bsp directory: + +#### OSAL File System Mappings + +| **OSAL "device"** | **File System Type** | **OSAL Path** | **Host Path** | **Notes** | +|---|---|---|---|---| +| /ramdev0|Real RAM Disk ( vxWorks )|/ram|RAM:0/| +| /eedev0|File System Mapped (FS_BASED)|/cf|eep:0/|This is the Compact Flash drive on the MCP750| +|/ramdev1 -- /ramdev5|Real RAM Disk|N/A|N/A|Unused table entries for applications to create new RAM disks| +| /ssedev0 - /ssrdev2|File System Mapped (FS_BASED)|N/A|/ssr:0/SSR1 - /ssr:0/SSR3|Unused table entries for applications to map Hard Disk device directories to "pseudo" SSR file systems.| + +### How to run the OSAL Applications on the MCP750 or RAD750 + +1\. Load the kernel. The custom vxWorks kernel is loaded into the MCP750 +via TFTP. We use a vxWorks boot image (Rather than the Motorola boot +monitor/loader ) to boot the MCP750 board, TFTP the "real" kernel to +RAM, and execute it. This vxWorks boot image also sets the network +settings for the "real" kernel image. On our OSAL/cFE development +system, we keep the loadable vxWorks kernel image in a TFTP directory on +the development workstation. So the vxWorks kernel image goes in +/tftpboot/cpu1/cfecpu1.st. **( \$ cp +/opt/workspace/mcp750image/default/vxWorks /tftpboot/cpu1/cfecpu1.st )** + +2\. Copy the "example1.elf" ( or other executable name ) loadable module +into the non-volatile disk. On the MCP750, this is done simply by FTPing +the tasking-example.elf file to the target: + +``` +$ ftp 192.168.1.4 + + +ftp\> username: target + +ftp\> password: password + +ftp\> cd "CF:0" + +ftp\> binary + +ftp\> put tasking-example.elf + +``` + +3\. Load the example Application in the vxWorks shell: +``` +vx\> cd "CF:0" + +vx\> ld \< tasking-example.elf +``` + +4\. Run the example Application in the vxWorks shell: +``` +vx\> OS_BSPMain +``` + +(The entry point for the examples and test programs is always +OS_BSPMain) + +## Axiom M5235 BCC / RTEMS 4.10: + +The OSAL supports the Axiom 5235 BCC single board computer with an RTEMS +4.10 board support package. The 4.10.2 version of RTEMS was used (as of +December 2012) along with the RTEMS 4.10 compiler for the m68k/coldfire. +The tests and examples are built as static RTEMS executable programs for +the board and can be loaded using the DBUG monitor or BDM port. When +developing for RTEMS, the libraries and BSP code is usually located in +/opt/rtems-4.10. The OSAL Makefiles use an environment variable +"RTEMS_BSP_BASE" to determine where the RTEMS libraries and BSPs are +installed. This variable is set from the "setvars.sh" file along with an +example of how to set the variable.. + +### OSAL Configuration for the Axiom M5235 BCC / RTEMS 4.10 + +#### osal-config.mak Settings + +| **osal-config.mak variable** | **Required selection** | **Notes** | +|---|---|---| +| OS|rtems|| +| BSP|rtems-mcf5235|| + + +### File System Mappings on the Axiom M5235 BCC / RTEMS 4.10 + +The RTEMS port of the OSAL has a one to one file system mapping. The +OSAL RAM disk will format an RTEMS NVRAM disk with the RFS file +system.The file system mappings are defined in the bsp_voltab.c file in +the src/bsp/mcf5235-rtems/src directory: + +#### OSAL File System Mappings + + |**OSAL "device"**|**File System Type**|**OSAL Path**|**Host Path**| **Notes**| +|---|---|---|---|---| +| /ramdev0|RAM_DISK ( NVRAM/RFS )|/ram|/ram|Mapped to the IMFS root directory| +| /eedev0|File System Mapped (FS_BASED)|/cf|/cf|Mapped to the IMFS root directory| +| /ramdev1 -- /ramdev5|Unused|N/A|N/A|Unused table entries for applications to create new RAM disks. RTEMS does not currently have support for creating new RAM disks.| +| /ssedev0 - /ssrdev2|File System Mapped (FS_BASED)|N/A|N/A|Unused table entries for applications to map Hard Disk device directories to "pseudo" SSR file systems.| + +### How to run the OSAL Applications on the Axiom M5235 BCC with RTEMS 4.10 + +When the example application and test programs are all built as static +executables for the M5235BCC board. The example programs can be loaded +in the following ways: + +Using the BDM port through the GNU debugger. If the board is connected +to the host PC with a BDM debugger cable, then the example programs can +be loaded and run from there. For our environment we use the Gnu +Debugger that was included with the RTEMS 4.10 tools and the +m68k-bdm-gdbserver from the BDM Tools project: + . The gdb-init script and a debug.sh +file are included in the src/bsp/mcf5235-rtems/bsp/rtems-support +directories. The debug.sh script gives the proper command line to load +the application to the board using the GDB debugger and BDM interface. + +## SPARC SIS Simulator / RTEMS 4.10: + +The OSAL supports the SPARC SIS simulator built into GDB with the sis +RTEMS 4.10 board support package. The 4.10.1 version of RTEMS was used +(as of December 2011) along with the RTEMS 4.10 compiler for the sparc. +The tests and examples are built as static RTEMS executable programs for +the simulator. The OSAL Makefiles use an environment variable +"RTEMS_BSP_BASE" to determine where the RTEMS libraries and BSPs are +installed. This variable is set from the "setvars.sh" file along with an +example of how to set the variable. + +### OSAL Configuration for the SPARC SIS Simulator / RTEMS 4.10 + +#### osal-config.mak Settings + + | **osal-config.mak variable** | **Required selection** | **Notes**| +|---|---|---| +| OS|rtems|| +| BSP|sis-rtems|| + +### File System Mappings on the SPARC SIS Simulator / RTEMS 4.10 + +The RTEMS port of the OSAL has a one to one file system mapping. The +OSAL RAM disk will format an RTEMS NVRAM disk with the RFS file system. +The file system mappings are defined in the bsp_voltab.c file in the +src/bsp/sis-rtems/src directory: + +#### OSAL File System Mappings + +| **OSAL "device"**|**File System Type**|**OSAL Path** | **Host Path** | **Notes**| +|---|---|---|---|---| +| /ramdev0 |RAM_DISK ( NVRAM/RFS )|/ram|/ram|Mapped to the IMFS root directory| +| /eedev0|File System Mapped (FS_BASED)|/cf|/cf|Mapped to the IMFS root directory| +| /ramdev1 -- /ramdev5|Unused|N/A|N/A|Unused table entries for applications to create new RAM disks. RTEMS does not currently have support for creating new RAM disks.| +| /ssedev0 - /ssrdev2|File System Mapped (FS_BASED)|N/A|N/A|Unused table entries for applications to map Hard Disk device directories to "pseudo" SSR file systems.| + +### How to run the OSAL Applications on the SPARC SIS Simulator with RTEMS 4.10 + +When the example application and test programs are all built as static +executables for the SIS Simulator built into the sparc-rtems4.10-gdb +executable. + +To run an example or test, simply do the following: +``` +**\$ sparc-rtems4.10-gdb tasking-example.nxe** + +**(gdb) target sim** + +**(gdb) load** + +**(gdb) run** +``` + +When you are finished running/debugging, hit \-c and quit the +debugger. + + +## PC / Linux Platform + +The OSAL can run on linux distributions. Testing is done with CentOS 6.5 +32 bit and Ubuntu 13.10 64 bit. Newer versions of the Linux 2.6 +kernel have POSIX message queues, which can be used for the OSAL Queue +implementation. If the POSIX message queues are not available, then the +OSAL Queues can use UDP sockets. (see the OS_SOCKET_QUEUE configuration +parameter). In general, the older versions of linux (2.4 kernel) are not +supported, but most modern Linux releases such as Ubuntu 12.10 and +later, and Cent OS/Redhat Enterprise Linux 5 and later should work. The +OSAL has also been used on the Raspberry Pi computer with the Raspbian +Debian based linux. The OSAL is primarily run on 32 bit linux +distributions, but it should compile and run as a 32 bit application on +64 bit linux. + +### OSAL Configuration for the PC / Linux Platform + +#### osal-config.mak Settings + +| **Prolog.mak variable** | **Required selection** | **Notes**| +|---|---|---| +| OS|posix|| +| BSP|pc-linux|| + +Additional configuration notes: + +To enable the POSIX message queues, make sure the OS_SOCKET_QUEUE +parameter is not defined in osconfig.h. + +If the OS_SOCKET_QUEUE option is not used, the OSAL will use POSIX +message queues. If POSIX message queues are used, your application may +need to run as root in order to create the queues you need. There are +kernel parameters that can be adjusted in order to avoid running as +root. + +### How to Run the OSAL on the PC / Linux Platform + +1\. To run an OSAL Application, simply execute the binary from a shell +prompt: + +``` +build/examples/tasking-example\]\$ ./tasking-example.bin +``` + +# OSAL Unit Tests + +The OSAL distribution includes a suite of black box unit tests, white +box unit tests (/src/unit-test-coverage), and functional tests +(/src/tests). Tam Ngo at NASA Johnson Space Flight Center developed the +suite of black box unit tests located in the /src/unit_tests directory. +This section describes how to build and run the suite of black box unit +tests using the "classic" build. Note: it is assumed the steps in +Section 2 How to Configure, Build, and Run the OSAL have been followed +to setup the build environment for the "classic" build. The unit tests +run on Linux, but could also be configured to run on other operating +systems (and will in future releases). + +Currently the osprintf tests are not compiled and run, and the ARINC 653 +tests are not used. A future release of the OSAL will contain support +for the ARINC653 operating system API. + +## OSAL Unit Test Configuration for the PC / Linux Platform + +#### osal-config.mak Settings + +| **Prolog.mak variable** | **Required selection** | **Notes**| +|---|---|---| +|OS|posix|Unit tests are for the POSIX port| +| BSP|pc-linux-ut|This is a special BSP for the unit tests| + +## How to Run the OSAL Unit Tests on the PC / Linux Platform + +To build and run the OSAL unit tests, run the following commands from +the "build" directory: + +#### Build Commands + +| **Shell command** | **Description**| +|---|---| +| **\$ cd build**|Change to the build directory.| +| **\$ make clean-unit-tests**| Clean the OSAL Core, and all Applications| +|**\$ make config**|Copy the osconfig.h for the BSP to the build directory| +| **\$ make unit-tests**|Build all of the unit tests.| +| **\$ make gcov**|Run the unit tests, collecting code coverage information.| + +Once the unit tests have run, the log files are available in the +individual unit test binary directories + +#### OSAL Unit Test Directories + + | **Directory**|**Description**| + |---|---| + | build|The top level OSAL build directory.| + | build/unit-tests|The top level unit test build directory.| + | build/unit-tests/oscore-test|Contains the test binary, log, and gcov files for the OSAL core tests| | build/unit-tests/osfile-test|Contains the test binary, log, and gcov files for the OSAL file API tests| + | build/unit-tests/osfilesys-test|Contains the test binary, log, and gcov files for the OSAL file system tests| + | build/unit-tests/osloader-test|Contains the test binary, log, and gcov files for the OSAL loader tests| + |build/unit-tests/ostimer-test|Contains the test binary, log, and gcov files for the OSAL timer tests| + +# Revision History + +| Revision Number | Release Date | Changes to Prior Revision | Approval | +|---|---|---|---| +| 1.0 | 10/17/07 | Initial Release. | A. Cudmore | +| 1.1 | 02/13/08 | Updates for RTEMS, Linux, and Cygwin for 2.11 release | A. Cudmore | +| 1.2 | 09/05/08 | Updates for OSAL 2.12 release | A. Cudmore | +| 1.3 | 03/10/10 | Updates for OSAL 3.1 release | A. Cudmore | +| 1.4 | 05/25/11 | Updates for OSAL 3.3 release | A. Cudmore | +| 1.5 | 12/13/11 | Updates for OSAL 3.4 release -- added support for sis-rtems Removed cFE configuration text | A. Cudmore | +| 1.6 | 12/21/12 | Updates for OSAL 4.0 release -- Removed Cygwin and OS X configurations | A. Cudmore | +| 4.1 | 01/17/14 | Updates for OSAL 4.1 release. Sync document version ID to software version. Add information for building and running unit tests. | A. Cudmore | +| 4.2 | 01/31/16 | Moved osconfig.h description into section 2.2.h Consolidated the \"classic\" build and prerequisites setup into section 2.3. Added new section 2.4 on provisioning a build using cmake. Minor
modifications to subsequent sections only where there was a difference between cmake and classic builds; i.e. the cmake build has no \"make config\" or \"make depend\". Updated title page to replace Code 582 banner with cFS. Added header. | J.Hickey S.Strege | \ No newline at end of file diff --git a/doc/OSAL-Configuration-guide.doc b/doc/OSAL-Configuration-guide.doc deleted file mode 100644 index c191d772d..000000000 Binary files a/doc/OSAL-Configuration-guide.doc and /dev/null differ diff --git a/doc/OSAL-Configuration-guide.pdf b/doc/OSAL-Configuration-guide.pdf deleted file mode 100644 index 16bb4acb4..000000000 Binary files a/doc/OSAL-Configuration-guide.pdf and /dev/null differ diff --git a/osconfig.h.in b/osconfig.h.in index 49ee2768c..a7f947b18 100644 --- a/osconfig.h.in +++ b/osconfig.h.in @@ -20,38 +20,41 @@ /** * \brief Configuration file Operating System Abstraction Layer - * + * * The specific definitions in this file may only be modified - * by setting the respective OSAL configuration options in the CMake - * build. + * by setting the respective OSAL configuration options in the CMake + * build. * * Any direct modifications to the generated copy will - * be overwritten each time CMake executes. + * be overwritten each time CMake executes. * * \note This file was automatically generated by CMake from * @CMAKE_CURRENT_SOURCE_DIR@/default_config.cmake */ - -#ifndef INCLUDE_OSCONFIG_H_ -#define INCLUDE_OSCONFIG_H_ -/* - * OSAL feature selection options from build config +#ifndef OSCONFIG_H +#define OSCONFIG_H + +/* + * OSAL feature selection options from build config */ #cmakedefine OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER -#cmakedefine OSAL_CONFIG_INCLUDE_NETWORK -#cmakedefine OSAL_CONFIG_INCLUDE_STATIC_LOADER +#cmakedefine OSAL_CONFIG_INCLUDE_NETWORK +#cmakedefine OSAL_CONFIG_INCLUDE_STATIC_LOADER #cmakedefine OSAL_CONFIG_INCLUDE_SHELL -#cmakedefine OSAL_CONFIG_DEBUG_PRINTF -#cmakedefine OSAL_CONFIG_DEBUG_PERMISSIVE_MODE +#cmakedefine OSAL_CONFIG_DEBUG_PRINTF +#cmakedefine OSAL_CONFIG_DEBUG_PERMISSIVE_MODE -/* +#cmakedefine OSAL_CONFIG_BUGCHECK_DISABLE +#cmakedefine OSAL_CONFIG_BUGCHECK_STRICT + +/* * OSAL resource limits from build config * * (These are prefixed with OS_ for compatibility * with existing code referencing these symbols) */ - + /** * \brief The maximum number of to support * @@ -140,8 +143,8 @@ /** * \brief The maximum length of OSAL file names - * - * This limit applies specifically to the file name portion, not the + * + * This limit applies specifically to the file name portion, not the * directory portion, of a path name. * * Based on the OSAL_CONFIG_MAX_FILE_NAME configuration option @@ -175,14 +178,14 @@ * \brief The maximum size of the socket address structure * * This is part of the Socket API, and should be set large enough to hold - * the largest address type in use on the target system. + * the largest address type in use on the target system. * * Based on the OSAL_CONFIG_SOCKADDR_MAX_LEN configuration option */ #define OS_SOCKADDR_MAX_LEN @OSAL_CONFIG_SOCKADDR_MAX_LEN@ /** - * \brief The maximum size of output produced by a single OS_printf() + * \brief The maximum size of output produced by a single OS_printf() * * Based on the OSAL_CONFIG_PRINTF_BUFFER_SIZE configuration option */ @@ -234,7 +237,7 @@ #define OS_QUEUE_MAX_DEPTH @OSAL_CONFIG_QUEUE_MAX_DEPTH@ /** - * \brief The name of the temporary file used to store shell commands + * \brief The name of the temporary file used to store shell commands * * This configuration is only applicable if shell support is enabled, and * only necessary/relevant on some OS implementations. @@ -251,14 +254,14 @@ * * Based on the OSAL_CONFIG_PRINTF_CONSOLE_NAME configuration option */ -#define OS_PRINTF_CONSOLE_NAME "@OSAL_CONFIG_PRINTF_CONSOLE_NAME@" +#define OS_PRINTF_CONSOLE_NAME "@OSAL_CONFIG_PRINTF_CONSOLE_NAME@" -/* +/* * OSAL fixed resource limits * * The resource limits here are not user-configurable, but - * may be changed in a future revision of OSAL, so it is - * still present in osconfig.h along with the others. + * may be changed in a future revision of OSAL, so it is + * still present in osconfig.h along with the others. */ /** @@ -269,11 +272,19 @@ #define OS_MAX_CONSOLES 1 /** - * \brief The system-specific file extension used on loadable module files + * \brief The system-specific file extension used on loadable module files * * Fixed value based on system selection, not user configurable. */ #define OS_MODULE_FILE_EXTENSION "@CMAKE_SHARED_LIBRARY_SUFFIX@" +/* +** Length of a Device and Volume name +*/ +#define OS_FS_DEV_NAME_LEN 32 /**< Device name length */ +#define OS_FS_PHYS_NAME_LEN 64 /**< Physical drive name length */ +#define OS_FS_VOL_NAME_LEN 32 /**< Volume name length */ + + +#endif /* OSCONFIG_H */ -#endif /* INCLUDE_OSCONFIG_H_ */ diff --git a/src/bsp/generic-linux/src/bsp_console.c b/src/bsp/generic-linux/src/bsp_console.c index 766640952..29b09b19a 100644 --- a/src/bsp/generic-linux/src/bsp_console.c +++ b/src/bsp/generic-linux/src/bsp_console.c @@ -25,6 +25,8 @@ * OSAL BSP debug console abstraction */ +#include +#include #include #include #include @@ -72,7 +74,7 @@ static void OS_BSP_ExecTput(const char *cap, const char *param) OS_BSP_ConsoleOutput_Impl See full description in header ------------------------------------------------------------------*/ -void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +void OS_BSP_ConsoleOutput_Impl(const char *Str, size_t DataLen) { ssize_t WriteLen; diff --git a/src/bsp/generic-linux/src/bsp_start.c b/src/bsp/generic-linux/src/bsp_start.c index 0254ec8e0..71b6afeb3 100644 --- a/src/bsp/generic-linux/src/bsp_start.c +++ b/src/bsp/generic-linux/src/bsp_start.c @@ -28,6 +28,7 @@ * 2005/07/26 A. Cudmore | Initial version for linux */ +#include #include #include #include @@ -69,7 +70,7 @@ void OS_BSP_Initialize(void) { if (fgets(buffer, sizeof(buffer), fp) != NULL) { - OS_BSP_Global.MaxQueueDepth = strtoul(buffer, NULL, 10); + OS_BSP_Global.MaxQueueDepth = OSAL_BLOCKCOUNT_C(strtoul(buffer, NULL, 10)); BSP_DEBUG("Maximum user msg queue depth = %u\n", (unsigned int)OS_BSP_Global.MaxQueueDepth); } fclose(fp); diff --git a/src/bsp/generic-linux/src/generic_linux_bsp_internal.h b/src/bsp/generic-linux/src/generic_linux_bsp_internal.h index 60b0a0174..85ab8145e 100644 --- a/src/bsp/generic-linux/src/generic_linux_bsp_internal.h +++ b/src/bsp/generic-linux/src/generic_linux_bsp_internal.h @@ -28,7 +28,9 @@ #ifndef GENERIC_LINUX_BSP_INTERNAL_H_ #define GENERIC_LINUX_BSP_INTERNAL_H_ -#include "osapi.h" +#include "osapi-common.h" +#include "osapi-bsp.h" +#include "osapi-error.h" #include "bsp-impl.h" /* @@ -44,4 +46,4 @@ typedef struct */ extern OS_BSP_GenericLinuxGlobalData_t OS_BSP_GenericLinuxGlobal; -#endif /* GENERIC_LINUX_BSP_INTERNAL_H_ */ +#endif /* GENERIC_LINUX_BSP_INTERNAL_H */ diff --git a/src/bsp/generic-vxworks/src/bsp_console.c b/src/bsp/generic-vxworks/src/bsp_console.c index b96ffe13b..660d8319b 100644 --- a/src/bsp/generic-vxworks/src/bsp_console.c +++ b/src/bsp/generic-vxworks/src/bsp_console.c @@ -40,7 +40,7 @@ OS_BSP_ConsoleOutput_Impl See full description in header ------------------------------------------------------------------*/ -void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +void OS_BSP_ConsoleOutput_Impl(const char *Str, size_t DataLen) { while (DataLen > 0) { diff --git a/src/bsp/generic-vxworks/src/generic_vxworks_bsp_internal.h b/src/bsp/generic-vxworks/src/generic_vxworks_bsp_internal.h index 6734dde78..640603c4a 100644 --- a/src/bsp/generic-vxworks/src/generic_vxworks_bsp_internal.h +++ b/src/bsp/generic-vxworks/src/generic_vxworks_bsp_internal.h @@ -31,7 +31,6 @@ /* ** OSAL includes */ -#include "osapi.h" #include "bsp-impl.h" -#endif /* GENERIC_VXWORKS_BSP_INTERNAL_H_ */ +#endif /* GENERIC_VXWORKS_BSP_INTERNAL_H */ diff --git a/src/bsp/pc-rtems/CMakeLists.txt b/src/bsp/pc-rtems/CMakeLists.txt index 9b5a0af99..c6f6a1b29 100644 --- a/src/bsp/pc-rtems/CMakeLists.txt +++ b/src/bsp/pc-rtems/CMakeLists.txt @@ -9,6 +9,13 @@ add_library(osal_pc-rtems_impl OBJECT src/bsp_console.c ) +# This definition is needed for the gethostname call +# By defining this, it avoids the need to use the -std=gnu99 +# instead of the preferred -std=c99 GCC switch +target_compile_definitions(osal_pc-rtems_impl PUBLIC + _BSD_SOURCE +) + # This BSP only works with "rtems" OS layer. # Confirming this reduces risk of accidental misconfiguration set(OSAL_EXPECTED_OSTYPE "rtems" PARENT_SCOPE) diff --git a/src/bsp/pc-rtems/src/bsp_console.c b/src/bsp/pc-rtems/src/bsp_console.c index 9a954c20e..85e521736 100644 --- a/src/bsp/pc-rtems/src/bsp_console.c +++ b/src/bsp/pc-rtems/src/bsp_console.c @@ -41,7 +41,7 @@ OS_BSP_ConsoleOutput_Impl See full description in header ------------------------------------------------------------------*/ -void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +void OS_BSP_ConsoleOutput_Impl(const char *Str, size_t DataLen) { /* writes the raw data directly to STDOUT_FILENO (unbuffered) */ write(STDOUT_FILENO, Str, DataLen); diff --git a/src/bsp/pc-rtems/src/bsp_start.c b/src/bsp/pc-rtems/src/bsp_start.c index 2bbad651b..cb2e43542 100644 --- a/src/bsp/pc-rtems/src/bsp_start.c +++ b/src/bsp/pc-rtems/src/bsp_start.c @@ -83,10 +83,10 @@ void OS_BSP_Setup(void) cmdlinestr = bsp_cmdline(); printf("\n\n*** RTEMS Info ***\n"); - printf("%s", _Copyright_Notice); - printf("%s\n\n", _RTEMS_version); - printf(" Stack size=%d\n", (int)Configuration.stack_space_size); - printf(" Workspace size=%d\n", (int)Configuration.work_space_size); + printf("%s", OSAL_BSP_COPYRIGHT_NOTICE); + printf("%s\n\n", rtems_get_version_string()); + printf(" Stack size=%d\n", (int)rtems_configuration_get_stack_space_size()); + printf(" Workspace size=%d\n", (int)rtems_configuration_get_work_space_size()); if (cmdlinestr != NULL) { printf(" Bootloader Command Line: %s\n", cmdlinestr); @@ -370,13 +370,17 @@ rtems_task Init(rtems_task_argument ignored) * 16 internal semaphores * */ -#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 8) -#define CONFIGURE_MAXIMUM_TIMERS (OS_MAX_TIMERS + 2) -#define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 16) -#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES (OS_MAX_QUEUES + 4) +#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 8) +#define CONFIGURE_MAXIMUM_TIMERS (OS_MAX_TIMERS + 2) +#define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 16) +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES (OS_MAX_QUEUES + 4) +#define CONFIGURE_MAXIMUM_DRIVERS 10 +#define CONFIGURE_MAXIMUM_POSIX_KEYS 4 +#ifdef _RTEMS_5_ +#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) +#else #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) -#define CONFIGURE_MAXIMUM_DRIVERS 10 -#define CONFIGURE_MAXIMUM_POSIX_KEYS 4 +#endif #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER diff --git a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h index 8d3690596..67f7ff1cb 100644 --- a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h +++ b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h @@ -25,13 +25,12 @@ * Header file for internal data to the PC-RTEMS BSP */ -#ifndef _PCRTEMS_BSP_INTERNAL_H_ -#define _PCRTEMS_BSP_INTERNAL_H_ +#ifndef PCRTEMS_BSP_INTERNAL_H +#define PCRTEMS_BSP_INTERNAL_H /* ** OSAL includes */ -#include "osapi.h" #include "bsp-impl.h" /* @@ -40,6 +39,15 @@ #define RTEMS_MAX_USER_OPTIONS 4 #define RTEMS_MAX_CMDLINE 256 +/* + * Handle the differences between RTEMS 5 and 4.11 copyright notice + */ +#ifdef _RTEMS_5_ +#define OSAL_BSP_COPYRIGHT_NOTICE rtems_get_copyright_notice() +#else +#define OSAL_BSP_COPYRIGHT_NOTICE _Copyright_Notice +#endif + /* * The location which the general purpose file system will be mounted */ @@ -65,4 +73,4 @@ typedef struct */ extern OS_BSP_PcRtemsGlobalData_t OS_BSP_PcRtemsGlobal; -#endif /* _PCRTEMS_BSP_INTERNAL_H_ */ +#endif /* PCRTEMS_BSP_INTERNAL_H */ diff --git a/src/bsp/shared/inc/bsp-impl.h b/src/bsp/shared/inc/bsp-impl.h index 1f67853a6..73f2ce4eb 100644 --- a/src/bsp/shared/inc/bsp-impl.h +++ b/src/bsp/shared/inc/bsp-impl.h @@ -40,10 +40,14 @@ * BSP-provided console or debug terminal device. */ -#ifndef _osapi_bsp_impl_ -#define _osapi_bsp_impl_ +#ifndef BSP_IMPL_H +#define BSP_IMPL_H -#include "osapi.h" +#include + +#include "osapi-common.h" +#include "osapi-bsp.h" +#include "osapi-error.h" /* * A set of simplified console control options @@ -90,10 +94,10 @@ */ typedef struct { - uint32 ArgC; /* number of boot/startup parameters in ArgV */ - char **ArgV; /* strings for boot/startup parameters */ - int32 AppStatus; /* value which can be returned to the OS (0=nominal) */ - uint32 MaxQueueDepth; /* Queue depth limit supported by BSP (0=no limit) */ + uint32 ArgC; /* number of boot/startup parameters in ArgV */ + char ** ArgV; /* strings for boot/startup parameters */ + int32 AppStatus; /* value which can be returned to the OS (0=nominal) */ + osal_blockcount_t MaxQueueDepth; /* Queue depth limit supported by BSP (0=no limit) */ } OS_BSP_GlobalData_t; /* @@ -118,7 +122,7 @@ extern OS_BSP_GlobalData_t OS_BSP_Global; Note: This should write the string as-is without buffering. ------------------------------------------------------------------*/ -void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen); +void OS_BSP_ConsoleOutput_Impl(const char *Str, size_t DataLen); /*---------------------------------------------------------------- Function: OS_BSP_ConsoleSetMode_Impl @@ -151,4 +155,4 @@ void OS_BSP_Shutdown_Impl(void); /********************* END bsp-impl.h *********************/ -#endif /* _osapi_bsp_impl_ */ +#endif /* BSP_IMPL_H */ diff --git a/src/bsp/shared/src/bsp_default_app_run.c b/src/bsp/shared/src/bsp_default_app_run.c index 7366555df..b0f1f545b 100644 --- a/src/bsp/shared/src/bsp_default_app_run.c +++ b/src/bsp/shared/src/bsp_default_app_run.c @@ -29,7 +29,7 @@ * which will override this default. */ -#include "osapi.h" +#include "osapi-common.h" #include "bsp-impl.h" /* diff --git a/src/bsp/shared/src/bsp_default_app_startup.c b/src/bsp/shared/src/bsp_default_app_startup.c index 57afb31c2..40e3aa511 100644 --- a/src/bsp/shared/src/bsp_default_app_startup.c +++ b/src/bsp/shared/src/bsp_default_app_startup.c @@ -30,7 +30,6 @@ */ #include -#include "osapi.h" #include "bsp-impl.h" diff --git a/src/bsp/shared/src/bsp_default_symtab.c b/src/bsp/shared/src/bsp_default_symtab.c index d2c0e8c32..7650da395 100644 --- a/src/bsp/shared/src/bsp_default_symtab.c +++ b/src/bsp/shared/src/bsp_default_symtab.c @@ -29,7 +29,7 @@ * which will override this default. */ -#include "osapi.h" +#include "osapi-module.h" #include "bsp-impl.h" OS_static_symbol_record_t OS_STATIC_SYMBOL_TABLE[] = { diff --git a/src/os/inc/common_types.h b/src/os/inc/common_types.h index a9bc35762..ae36830e5 100644 --- a/src/os/inc/common_types.h +++ b/src/os/inc/common_types.h @@ -28,8 +28,8 @@ * Assumes make file has defined processor family */ -#ifndef _common_types_ -#define _common_types_ +#ifndef COMMON_TYPES_H +#define COMMON_TYPES_H #ifdef __cplusplus extern "C" @@ -53,8 +53,7 @@ extern "C" ** Define compiler specific macros ** The __extension__ compiler pragma is required ** for the uint64 type using GCC with the ANSI C90 standard. -** Other macros can go in here as needed, for example alignment -** pragmas. +** Other macros can go in here as needed. ** ** NOTE: The white-box (coverage) unit testing may need to disable ** these extra attributes. These test builds define the OSAPI_NO_SPECIAL_ATTRIBS @@ -62,14 +61,10 @@ extern "C" */ #if defined(__GNUC__) && !defined(OSAPI_NO_SPECIAL_ATTRIBS) #define _EXTENSION_ __extension__ -#define OS_PACK __attribute__((packed)) -#define OS_ALIGN(n) __attribute__((aligned(n))) #define OS_USED __attribute__((used)) #define OS_PRINTF(n, m) __attribute__((format(printf, n, m))) #else #define _EXTENSION_ -#define OS_PACK -#define OS_ALIGN(n) #define OS_USED #define OS_PRINTF(n, m) #endif @@ -101,6 +96,35 @@ extern "C" */ typedef uint32_t osal_id_t; + /** + * A type used to represent a number of blocks or buffers + * + * This is used with file system and queue implementations. + */ + typedef size_t osal_blockcount_t; + + /** + * A type used to represent an index into a table structure + * + * This is used when referring directly to a table index as + * opposed to an object ID. It is primarily intended for + * internal use, but is also output from public APIs such as + * OS_ObjectIdToArrayIndex(). + */ + typedef uint32 osal_index_t; + + /** + * A type used to represent the runtime type or category of an OSAL object + */ + typedef uint32 osal_objtype_t; + + /** + * @brief General purpose OSAL callback function + * + * This may be used by multiple APIS + */ + typedef void (*OS_ArgCallback_t)(osal_id_t object_id, void *arg); + #ifndef NULL /* pointer to nothing */ #define NULL ((void *)0) #endif @@ -150,4 +174,18 @@ extern "C" } #endif +/* + * Type macros for literals + * + * These macros enforce that a literal or other value is + * interpreted as the intended type. Although implicit + * conversions between these types are often possible, using + * this makes it explicit in the code where a type conversion + * is expected. + */ +#define OSAL_SIZE_C(X) ((size_t)(X)) +#define OSAL_BLOCKCOUNT_C(X) ((osal_blockcount_t)(X)) +#define OSAL_INDEX_C(X) ((osal_index_t)(X)) +#define OSAL_OBJTYPE_C(X) ((osal_objtype_t)(X)) + #endif /* _common_types_ */ diff --git a/src/os/inc/osapi-binsem.h b/src/os/inc/osapi-binsem.h new file mode 100644 index 000000000..4474450bc --- /dev/null +++ b/src/os/inc/osapi-binsem.h @@ -0,0 +1,203 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * File: osapi-binsem.h + */ + +#ifndef OSAPI_BINSEM_H +#define OSAPI_BINSEM_H + +#include "osconfig.h" +#include "common_types.h" + +/** @defgroup OSSemaphoreStates OSAL Semaphore State Defines + * @{ + */ +#define OS_SEM_FULL 1 /**< @brief Semaphore full state */ +#define OS_SEM_EMPTY 0 /**< @brief Semaphore empty state */ +/**@}*/ + +/** @brief OSAL binary semaphore properties */ +typedef struct +{ + char name[OS_MAX_API_NAME]; + osal_id_t creator; + int32 value; +} OS_bin_sem_prop_t; + +/** @defgroup OSAPIBinSem OSAL Binary Semaphore APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Creates a binary semaphore + * + * Creates a binary semaphore with initial value specified by + * sem_initial_value and name specified by sem_name. sem_id will be + * returned to the caller + * + * @param[out] sem_id will be set to the non-zero ID of the newly-created resource + * @param[in] sem_name the name of the new resource to create + * @param[in] sem_initial_value the initial value of the binary semaphore + * @param[in] options Reserved for future use, should be passed as 0. + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if sen name or sem_id are NULL + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NO_FREE_IDS if all of the semaphore ids are taken + * @retval #OS_ERR_NAME_TAKEN if this is already the name of a binary semaphore + * @retval #OS_SEM_FAILURE if the OS call failed + */ +int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Unblock all tasks pending on the specified semaphore + * + * The function unblocks all tasks pending on the specified semaphore. However, + * this function does not change the state of the semaphore. + * + * @param[in] sem_id The object ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a binary semaphore + * @retval #OS_SEM_FAILURE if an unspecified failure occurs + */ +int32 OS_BinSemFlush(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Increment the semaphore value + * + * The function unlocks the semaphore referenced by sem_id by performing + * a semaphore unlock operation on that semaphore. If the semaphore value + * resulting from this operation is positive, then no threads were blocked + * waiting for the semaphore to become unlocked; the semaphore value is + * simply incremented for this semaphore. + * + * @param[in] sem_id The object ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_SEM_FAILURE the semaphore was not previously initialized or is not + * in the array of semaphores defined by the system + * @retval #OS_ERR_INVALID_ID if the id passed in is not a binary semaphore + */ +int32 OS_BinSemGive(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Decrement the semaphore value + * + * The locks the semaphore referenced by sem_id by performing a + * semaphore lock operation on that semaphore. If the semaphore value + * is currently zero, then the calling thread shall not return from + * the call until it either locks the semaphore or the call is + * interrupted. + * + * @param[in] sem_id The object ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID the Id passed in is not a valid binary semaphore + * @retval #OS_SEM_FAILURE if the OS call failed + */ +int32 OS_BinSemTake(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Decrement the semaphore value with a timeout + * + * The function locks the semaphore referenced by sem_id. However, + * if the semaphore cannot be locked without waiting for another process + * or thread to unlock the semaphore, this wait shall be terminated when + * the specified timeout, msecs, expires. + * + * @param[in] sem_id The object ID to operate on + * @param[in] msecs The maximum amount of time to block, in milliseconds + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_SEM_TIMEOUT if semaphore was not relinquished in time + * @retval #OS_SEM_FAILURE the semaphore was not previously initialized or is not + * in the array of semaphores defined by the system + * @retval #OS_ERR_INVALID_ID if the ID passed in is not a valid semaphore ID + */ +int32 OS_BinSemTimedWait(osal_id_t sem_id, uint32 msecs); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Deletes the specified Binary Semaphore + * + * This is the function used to delete a binary semaphore in the operating system. + * This also frees the respective sem_id to be used again when another semaphore is created. + * + * @param[in] sem_id The object ID to delete + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore + * @retval #OS_SEM_FAILURE the OS call failed + */ +int32 OS_BinSemDelete(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Find an existing semaphore ID by name + * + * This function tries to find a binary sem Id given the name of a bin_sem + * The id is returned through sem_id + * + * @param[out] sem_id will be set to the ID of the existing resource + * @param[in] sem_name the name of the existing resource to find + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER is semid or sem_name are NULL pointers + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table + */ +int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Fill a property object buffer with details regarding the resource + * + * This function will pass back a pointer to structure that contains + * all of the relevant info( name and creator) about the specified binary + * semaphore. + * + * @param[in] sem_id The object ID to operate on + * @param[out] bin_prop The property object buffer to fill + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid semaphore + * @retval #OS_INVALID_POINTER if the bin_prop pointer is null + */ +int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop); + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-bsp.h b/src/os/inc/osapi-bsp.h new file mode 100644 index 000000000..3fa39d140 --- /dev/null +++ b/src/os/inc/osapi-bsp.h @@ -0,0 +1,95 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-bsp.h + */ + +#ifndef OSAPI_BSP_H +#define OSAPI_BSP_H + +#include "osconfig.h" +#include "common_types.h" + +/**************************************************************************************** + BSP LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/** @defgroup OSAPIBsp OSAL BSP low level access APIs + * + * These are for OSAL internal BSP information access to pass any BSP-specific + * boot/command line/startup arguments through to the application, and return a + * status code back to the OS after exit. + * + * Not intended for user application use + * @{ + */ + +/*---------------------------------------------------------------- + Function: OS_BSP_GetArgC + + Purpose: Obtain the number of boot arguments passed from the bootloader + or shell if supported by the platform + + Returns: The number of boot arguments, or 0 if no arguments were passed + or not supported by the BSP. + ------------------------------------------------------------------*/ +uint32 OS_BSP_GetArgC(void); + +/*---------------------------------------------------------------- + Function: OS_BSP_GetArgV + + Purpose: Obtain an array of boot argument strings passed from the bootloader + or shell if supported by the platform + + Returns: Pointer to char* array containing the argument strings, or NULL if + no arguments are available or not supported by the BSP. + + The array is sized according to OS_BSP_GetArgC() + ------------------------------------------------------------------*/ +char *const *OS_BSP_GetArgV(void); + +/*---------------------------------------------------------------- + Function: OS_BSP_SetExitCode + + Purpose: Sets the status to be returned to the shell or bootloader + if supported by the platform. The value is an integer with + platform and application-defined meaning, but BSP's should + attempt to provide consistent meaning for the following values + + OS_SUCCESS: normal status (default) + OS_ERROR: any abnormal status + + Other more specific status values may be passed, with + implementation-defined behavior. Depending on the system + capabilities, the BSP implementation may either pass the + value through as-is, translate it to defined value, or + ignore it. + + Note this does NOT cause the application to exit, it only + sets the state that will be returned if/when the application + exits itself at a future time. + + ------------------------------------------------------------------*/ +void OS_BSP_SetExitCode(int32 code); + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-clock.h b/src/os/inc/osapi-clock.h new file mode 100644 index 000000000..b2fb0349d --- /dev/null +++ b/src/os/inc/osapi-clock.h @@ -0,0 +1,405 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-clock.h + */ + +#ifndef OSAPI_CLOCK_H +#define OSAPI_CLOCK_H + +#include "osconfig.h" +#include "common_types.h" + +/** + * @brief OSAL time interval structure + * + * This is used to represent a basic time interval. + * + * When used with OS_GetLocalTime/OS_SetLocalTime, this represents the + * interval from the OS's epoch point, typically 01 Jan 1970 00:00:00 UTC + * on systems that have a persistent real time clock (RTC), or the system + * boot time if there is no RTC available. + * + * Applications should not directly access fields within this structure, + * as the definition may change in future versions of OSAL. Instead, + * applications should use the accessor/conversion methods defined below. + */ +typedef struct +{ + int64 ticks; /**< Ticks elapsed since reference point */ +} OS_time_t; + +/** + * @brief Multipliers/divisors to convert ticks into standardized units + * + * Various fixed conversion factor constants used by the conversion routines + * + * A 100ns tick time allows max intervals of about +/- 14000 years in + * a 64-bit signed integer value. + * + * @note Applications should not directly use these values, but rather use + * conversion routines below to obtain standardized units (seconds/microseconds/etc). + */ +enum +{ + OS_TIME_TICK_RESOLUTION_NS = 100, + OS_TIME_TICKS_PER_SECOND = 1000000000 / OS_TIME_TICK_RESOLUTION_NS, + OS_TIME_TICKS_PER_MSEC = 1000000 / OS_TIME_TICK_RESOLUTION_NS, + OS_TIME_TICKS_PER_USEC = 1000 / OS_TIME_TICK_RESOLUTION_NS +}; + +/** @defgroup OSAPIClock OSAL Real Time Clock APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get the local time + * + * This function gets the local time from the underlying OS. + * + * @note Mission time management typically uses the cFE Time Service + * + * @param[out] time_struct An OS_time_t that will be set to the current time + * + * @return Get local time status, see @ref OSReturnCodes + */ +int32 OS_GetLocalTime(OS_time_t *time_struct); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Set the local time + * + * This function sets the local time on the underlying OS. + * + * @note Mission time management typically uses the cFE Time Services + * + * @param[in] time_struct An OS_time_t containing the current time + * + * @return Set local time status, see @ref OSReturnCodes + */ +int32 OS_SetLocalTime(const OS_time_t *time_struct); + +/*-------------------------------------------------------------------------------------*/ +/* + * Accessor / Unit Conversion routines for OS_time_t + * + * These routines allow the user to simply interpret OS_time_t intervals into + * in normalized units of whole seconds, milliseconds, microseconds, or nanoseconds. + */ +/*-------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get interval from an OS_time_t object normalized to whole number of seconds + * + * Extracts the number of whole seconds from a given OS_time_t object, discarding + * any fractional component. + * + * This may also replace a direct read of the "seconds" field from + * the OS_time_t object from previous versions of OSAL, where the + * structure was defined with separate seconds/microseconds fields. + * + * @sa OS_TimeGetMicrosecondsPart() + * + * @param[in] tm Time interval value + * @returns Whole number of seconds in time interval + */ +static inline int64 OS_TimeGetTotalSeconds(OS_time_t tm) +{ + return (tm.ticks / OS_TIME_TICKS_PER_SECOND); +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get interval from an OS_time_t object normalized to millisecond units + * + * Note this refers to the complete interval, not just the fractional part. + * + * @param[in] tm Time interval value + * @returns Whole number of milliseconds in time interval + */ +static inline int64 OS_TimeGetTotalMilliseconds(OS_time_t tm) +{ + return (tm.ticks / OS_TIME_TICKS_PER_MSEC); +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get interval from an OS_time_t object normalized to microsecond units + * + * Note this refers to the complete interval, not just the fractional part. + * + * @param[in] tm Time interval value + * @returns Whole number of microseconds in time interval + */ +static inline int64 OS_TimeGetTotalMicroseconds(OS_time_t tm) +{ + return (tm.ticks / OS_TIME_TICKS_PER_USEC); +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get interval from an OS_time_t object normalized to nanosecond units + * + * Note this refers to the complete interval, not just the fractional part. + * + * @note There is no protection against overflow of the 64-bit return value. + * Applications must use caution to ensure that the interval does not exceed the + * representable range of a signed 64 bit integer - approximately 140 years. + * + * @param[in] tm Time interval value + * @returns Whole number of microseconds in time interval + */ +static inline int64 OS_TimeGetTotalNanoseconds(OS_time_t tm) +{ + return (tm.ticks * OS_TIME_TICK_RESOLUTION_NS); +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get subseconds portion (fractional part only) from an OS_time_t object + * + * Extracts the fractional part from a given OS_time_t object. + * Units returned are in ticks, not normalized to any standard time unit. + * + * @param[in] tm Time interval value + * @returns Fractional/subsecond portion of time interval in ticks + */ +static inline int64 OS_TimeGetFractionalPart(OS_time_t tm) +{ + return (tm.ticks % OS_TIME_TICKS_PER_SECOND); +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get 32-bit normalized subseconds (fractional part only) from an OS_time_t object + * + * Extracts the fractional part from a given OS_time_t object in maximum precision, + * with units of 2^(-32) sec. This is a base-2 fixed-point fractional value + * with the point left-justified in the 32-bit value (i.e. left of MSB). + * + * This is (mostly) compatible with the CFE "subseconds" value, where 0x80000000 represents + * exactly one half second, and 0 represents a full second. + * + * @param[in] tm Time interval value + * @returns Fractional/subsecond portion of time interval as 32-bit fixed point value + */ +static inline uint32 OS_TimeGetSubsecondsPart(OS_time_t tm) +{ + /* + * This computation avoids a 32-bit left shift which may not be implemented. + * + * It also must round up, otherwise this may result in a value one + * less than the original when converted back to usec again. + */ + int64 frac = (OS_TimeGetFractionalPart(tm) << 30) + (OS_TIME_TICKS_PER_SECOND >> 2); + return (uint32)((frac - 1) / (OS_TIME_TICKS_PER_SECOND >> 2)); +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get milliseconds portion (fractional part only) from an OS_time_t object + * + * Extracts the fractional part from a given OS_time_t object normalized + * to units of milliseconds. + * + * @sa OS_TimeGetTotalSeconds() + * + * @param[in] tm Time interval value + * @returns Number of milliseconds in time interval + */ +static inline uint32 OS_TimeGetMillisecondsPart(OS_time_t tm) +{ + return (uint32)OS_TimeGetFractionalPart(tm) / OS_TIME_TICKS_PER_MSEC; +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get microseconds portion (fractional part only) from an OS_time_t object + * + * Extracts the fractional part from a given OS_time_t object normalized + * to units of microseconds. + * + * This function may be used to adapt applications initially implemented + * using an older OSAL version where OS_time_t was a structure containing + * a "seconds" and "microsecs" field. + * + * This function will obtain a value that is compatible with the "microsecs" field of + * OS_time_t as it was defined in previous versions of OSAL, as well as the "tv_usec" + * field of POSIX-style "struct timeval" values. + * + * @sa OS_TimeGetTotalSeconds() + * + * @param[in] tm Time interval value + * @returns Number of microseconds in time interval + */ +static inline uint32 OS_TimeGetMicrosecondsPart(OS_time_t tm) +{ + return (uint32)OS_TimeGetFractionalPart(tm) / OS_TIME_TICKS_PER_USEC; +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get nanoseconds portion (fractional part only) from an OS_time_t object + * + * Extracts the only number of nanoseconds from a given OS_time_t object. + * + * This function will obtain a value that is compatible with the "tv_nsec" field + * of POSIX-style "struct timespec" values. + * + * @sa OS_TimeGetTotalSeconds() + * + * @param[in] tm Time interval value + * @returns Number of nanoseconds in time interval + */ +static inline uint32 OS_TimeGetNanosecondsPart(OS_time_t tm) +{ + return (uint32)OS_TimeGetFractionalPart(tm) * OS_TIME_TICK_RESOLUTION_NS; +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Assemble/Convert a number of seconds + nanoseconds into an OS_time_t interval + * + * This creates an OS_time_t value using a whole number of seconds and a fractional + * part in units of nanoseconds. This is the inverse of OS_TimeGetTotalSeconds() + * and OS_TimeGetNanosecondsPart(), and should recreate the original OS_time_t + * value from these separate values (aside from any potential conversion losses + * due to limited resolution of the data types/units). + * + * @sa OS_TimeGetTotalSeconds(), OS_TimeGetNanosecondsPart() + * + * @param[in] seconds Whole number of seconds + * @param[in] nanoseconds Number of nanoseconds (fractional part only) + * @returns The input arguments represented as an OS_time_t interval + */ +static inline OS_time_t OS_TimeAssembleFromNanoseconds(int64 seconds, uint32 nanoseconds) +{ + OS_time_t result; + result.ticks = seconds * OS_TIME_TICKS_PER_SECOND; + result.ticks += nanoseconds / OS_TIME_TICK_RESOLUTION_NS; + return result; +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Assemble/Convert a number of seconds + microseconds into an OS_time_t interval + * + * This creates an OS_time_t value using a whole number of seconds and a fractional + * part in units of microseconds. This is the inverse of OS_TimeGetTotalSeconds() + * and OS_TimeGetMicrosecondsPart(), and should recreate the original OS_time_t + * value from these separate values (aside from any potential conversion losses + * due to limited resolution of the data types/units). + * + * @sa OS_TimeGetTotalSeconds(), OS_TimeGetMicrosecondsPart() + * + * @param[in] seconds Whole number of seconds + * @param[in] microseconds Number of microseconds (fractional part only) + * @returns The input arguments represented as an OS_time_t interval + */ +static inline OS_time_t OS_TimeAssembleFromMicroseconds(int64 seconds, uint32 microseconds) +{ + OS_time_t result; + result.ticks = seconds * OS_TIME_TICKS_PER_SECOND; + result.ticks += microseconds * OS_TIME_TICKS_PER_USEC; + return result; +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Assemble/Convert a number of seconds + milliseconds into an OS_time_t interval + * + * This creates an OS_time_t value using a whole number of seconds and a fractional + * part in units of milliseconds. This is the inverse of OS_TimeGetTotalSeconds() + * and OS_TimeGetMillisecondsPart(), and should recreate the original OS_time_t + * value from these separate values (aside from any potential conversion losses + * due to limited resolution of the data types/units). + * + * @sa OS_TimeGetTotalSeconds(), OS_TimeGetMillisecondsPart() + * + * @param[in] seconds Whole number of seconds + * @param[in] milliseconds Number of milliseconds (fractional part only) + * @returns The input arguments represented as an OS_time_t interval + */ +static inline OS_time_t OS_TimeAssembleFromMilliseconds(int64 seconds, uint32 milliseconds) +{ + OS_time_t result; + result.ticks = seconds * OS_TIME_TICKS_PER_SECOND; + result.ticks += milliseconds * OS_TIME_TICKS_PER_MSEC; + return result; +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Assemble/Convert a number of seconds + subseconds into an OS_time_t interval + * + * This creates an OS_time_t value using a whole number of seconds and a fractional + * part in units of sub-seconds (1/2^32). This is the inverse of OS_TimeGetTotalSeconds() + * and OS_TimeGetSubsecondsPart(), and should recreate the original OS_time_t + * value from these separate values (aside from any potential conversion losses + * due to limited resolution of the data types/units). + * + * @sa OS_TimeGetTotalSeconds(), OS_TimeGetNanosecondsPart() + * @param[in] seconds Whole number of seconds + * @param[in] subseconds Number of subseconds (32 bit fixed point fractional part) + * @returns The input arguments represented as an OS_time_t interval + */ +static inline OS_time_t OS_TimeAssembleFromSubseconds(int64 seconds, uint32 subseconds) +{ + OS_time_t result; + result.ticks = seconds * OS_TIME_TICKS_PER_SECOND; + /* this should not round in any way, as the 32-bit input value has higher precision */ + result.ticks += ((int64)subseconds * (OS_TIME_TICKS_PER_SECOND >> 2)) >> 30; + return result; +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Computes the sum of two time intervals + * + * @param[in] time1 The first interval + * @param[in] time2 The second interval + * + * @return The sum of the two intervals (time1 + time2) + */ +static inline OS_time_t OS_TimeAdd(OS_time_t time1, OS_time_t time2) +{ + return ((OS_time_t) {time1.ticks + time2.ticks}); +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Computes the difference between two time intervals + * + * @param[in] time1 The first interval + * @param[in] time2 The second interval + * + * @return The difference of the two intervals (time1 - time2) + */ +static inline OS_time_t OS_TimeSubtract(OS_time_t time1, OS_time_t time2) +{ + return ((OS_time_t) {time1.ticks - time2.ticks}); +} + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-common.h b/src/os/inc/osapi-common.h new file mode 100644 index 000000000..ac6b1bcdc --- /dev/null +++ b/src/os/inc/osapi-common.h @@ -0,0 +1,213 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @file osapi-common.h + */ + +#ifndef OSAPI_COMMON_H +#define OSAPI_COMMON_H + +#include "osconfig.h" +#include "common_types.h" + +/** + * @brief A set of events that can be used with BSP event callback routines + */ +typedef enum +{ + OS_EVENT_RESERVED = 0, /**< no-op/reserved event id value */ + + /** + * resource/id has been newly allocated but not yet created. + * + * This event is invoked from WITHIN the locked region, in + * the context of the task which is allocating the resource. + * + * If the handler returns non-success, the error will be returned + * to the caller and the creation process is aborted. + */ + OS_EVENT_RESOURCE_ALLOCATED, + + /** + * resource/id has been fully created/finalized. + * + * Invoked outside locked region, in the context + * of the task which created the resource. + * + * Data object is not used, passed as NULL. + * + * Return value is ignored - this is for information purposes only. + */ + OS_EVENT_RESOURCE_CREATED, + + /** + * resource/id has been deleted. + * + * Invoked outside locked region, in the context + * of the task which deleted the resource. + * + * Data object is not used, passed as NULL. + * + * Return value is ignored - this is for information purposes only. + */ + OS_EVENT_RESOURCE_DELETED, + + /** + * New task is starting. + * + * Invoked outside locked region, in the context + * of the task which is currently starting, before + * the entry point is called. + * + * Data object is not used, passed as NULL. + * + * If the handler returns non-success, task startup is aborted + * and the entry point is not called. + */ + OS_EVENT_TASK_STARTUP, + + OS_EVENT_MAX /**< placeholder for end of enum, not used */ +} OS_Event_t; + +/** + * @brief A callback routine for event handling. + * + * @param[in] event The event that occurred + * @param[in] object_id The associated object_id, or 0 if not associated with an object + * @param[inout] data An abstract data/context object associated with the event, or NULL. + * @return status Execution status, see @ref OSReturnCodes. + */ +typedef int32 (*OS_EventHandler_t)(OS_Event_t event, osal_id_t object_id, void *data); + +/** @defgroup OSAPICore OSAL Core Operation APIs + * + * These are for OSAL core operations for startup/initialization, running, and shutdown. + * Typically only used in bsps, unit tests, psps, etc. + * + * Not intended for user application use + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Application startup + * + * Startup abstraction such that the same BSP can be used for operations and testing. + */ +void OS_Application_Startup(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Application run + * + * Run abstraction such that the same BSP can be used for operations and testing. + */ +void OS_Application_Run(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Initialization of API + * + * This function returns initializes the internal data structures of the OS + * Abstraction Layer. It must be called in the application startup code before + * calling any other OS routines. + * + * @return Execution status, see @ref OSReturnCodes. Any error code (negative) + * means the OSAL can not be initialized. Typical platform specific response + * is to abort since additional OSAL calls will have undefined behavior. + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR @copybrief OS_ERROR + */ +int32 OS_API_Init(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Background thread implementation - waits forever for events to occur. + * + * This should be called from the BSP main routine or initial thread after all other + * board and application initialization has taken place and all other tasks are running. + * + * Typically just waits forever until "OS_shutdown" flag becomes true. + */ +void OS_IdleLoop(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief delete all resources created in OSAL. + * + * provides a means to clean up all resources allocated by this + * instance of OSAL. It would typically be used during an orderly + * shutdown but may also be helpful for testing purposes. + */ +void OS_DeleteAllObjects(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Initiate orderly shutdown + * + * Indicates that the OSAL application should perform an orderly shutdown + * of ALL tasks, clean up all resources, and exit the application. + * + * This allows the task currently blocked in OS_IdleLoop() to wake up, and + * for that function to return to its caller. + * + * This is preferred over e.g. OS_ApplicationExit() which exits immediately and + * does not provide for any means to clean up first. + * + * @param[in] flag set to true to initiate shutdown, false to cancel + */ +void OS_ApplicationShutdown(uint8 flag); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Exit/Abort the application + * + * Indicates that the OSAL application should exit and return control to the OS + * This is intended for e.g. scripted unit testing where the test needs to end + * without user intervention. + * + * This function does not return. Production code typically should not ever call this. + * + * @note This exits the entire process including tasks that have been created. + */ +void OS_ApplicationExit(int32 Status); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Callback routine registration + * + * This hook enables the application code to perform extra platform-specific + * operations on various system events such as resource creation/deletion. + * + * @note Some events are invoked while the resource is "locked" and therefore + * application-defined handlers for these events should not block or attempt + * to access other OSAL resources. + * + * @param[in] handler The application-provided event handler + * @return Execution status, see @ref OSReturnCodes. + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR @copybrief OS_ERROR + */ +int32 OS_RegisterEventHandler(OS_EventHandler_t handler); + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-constants.h b/src/os/inc/osapi-constants.h new file mode 100644 index 000000000..e3aa32f1c --- /dev/null +++ b/src/os/inc/osapi-constants.h @@ -0,0 +1,56 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @file osapi-constants.h + */ + +#ifndef OSAPI_CONSTANTS_H +#define OSAPI_CONSTANTS_H + +#include "osconfig.h" +#include "common_types.h" + +/* +** Defines for Queue Timeout parameters +*/ +#define OS_PEND (-1) +#define OS_CHECK (0) + +/** + * @brief Initializer for the osal_id_t type which will not match any valid value + */ +#define OS_OBJECT_ID_UNDEFINED ((osal_id_t) {0}) + +/** + * @brief Constant that may be passed to OS_ForEachObject()/OS_ForEachObjectOfType() to match any + * creator (i.e. get all objects) + */ +#define OS_OBJECT_CREATOR_ANY OS_OBJECT_ID_UNDEFINED + +/** + * @brief Maximum length of a local/native path name string + * + * This is a concatenation of the OSAL virtual path with the system + * mount point or device name + */ +#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) + +#endif diff --git a/src/os/inc/osapi-countsem.h b/src/os/inc/osapi-countsem.h new file mode 100644 index 000000000..b74cde754 --- /dev/null +++ b/src/os/inc/osapi-countsem.h @@ -0,0 +1,178 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-countsem.h + */ + +#ifndef OSAPI_COUNTSEM_H +#define OSAPI_COUNTSEM_H + +#include "osconfig.h" +#include "common_types.h" + +/** @brief OSAL counting semaphore properties */ +typedef struct +{ + char name[OS_MAX_API_NAME]; + osal_id_t creator; + int32 value; +} OS_count_sem_prop_t; + +/** @defgroup OSAPICountSem OSAL Counting Semaphore APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Creates a counting semaphore + * + * Creates a counting semaphore with initial value specified by + * sem_initial_value and name specified by sem_name. sem_id will be + * returned to the caller + * + * @param[out] sem_id will be set to the non-zero ID of the newly-created resource + * @param[in] sem_name the name of the new resource to create + * @param[in] sem_initial_value the initial value of the counting semaphore + * @param[in] options Reserved for future use, should be passed as 0. + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if sen name or sem_id are NULL + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NO_FREE_IDS if all of the semaphore ids are taken + * @retval #OS_ERR_NAME_TAKEN if this is already the name of a counting semaphore + * @retval #OS_SEM_FAILURE if the OS call failed + * @retval #OS_INVALID_SEM_VALUE if the semaphore value is too high + */ +int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Increment the semaphore value + * + * The function unlocks the semaphore referenced by sem_id by performing + * a semaphore unlock operation on that semaphore. If the semaphore value + * resulting from this operation is positive, then no threads were blocked + * waiting for the semaphore to become unlocked; the semaphore value is + * simply incremented for this semaphore. + * + * @param[in] sem_id The object ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_SEM_FAILURE the semaphore was not previously initialized or is not + * in the array of semaphores defined by the system + * @retval #OS_ERR_INVALID_ID if the id passed in is not a counting semaphore + */ +int32 OS_CountSemGive(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Decrement the semaphore value + * + * The locks the semaphore referenced by sem_id by performing a + * semaphore lock operation on that semaphore. If the semaphore value + * is currently zero, then the calling thread shall not return from + * the call until it either locks the semaphore or the call is + * interrupted. + * + * @param[in] sem_id The object ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID the Id passed in is not a valid counting semaphore + * @retval #OS_SEM_FAILURE if the OS call failed + */ +int32 OS_CountSemTake(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Decrement the semaphore value with timeout + * + * The function locks the semaphore referenced by sem_id. However, + * if the semaphore cannot be locked without waiting for another process + * or thread to unlock the semaphore, this wait shall be terminated when + * the specified timeout, msecs, expires. + * + * @param[in] sem_id The object ID to operate on + * @param[in] msecs The maximum amount of time to block, in milliseconds + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_SEM_TIMEOUT if semaphore was not relinquished in time + * @retval #OS_SEM_FAILURE the semaphore was not previously initialized or is not + * in the array of semaphores defined by the system + * @retval #OS_ERR_INVALID_ID if the ID passed in is not a valid semaphore ID + */ +int32 OS_CountSemTimedWait(osal_id_t sem_id, uint32 msecs); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Deletes the specified counting Semaphore. + * + * @param[in] sem_id The object ID to delete + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid counting semaphore + * @retval #OS_SEM_FAILURE the OS call failed + */ +int32 OS_CountSemDelete(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Find an existing semaphore ID by name + * + * This function tries to find a counting sem Id given the name of a count_sem + * The id is returned through sem_id + * + * @param[out] sem_id will be set to the ID of the existing resource + * @param[in] sem_name the name of the existing resource to find + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER is semid or sem_name are NULL pointers + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table + */ +int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Fill a property object buffer with details regarding the resource + * + * This function will pass back a pointer to structure that contains + * all of the relevant info( name and creator) about the specified counting + * semaphore. + * + * @param[in] sem_id The object ID to operate on + * @param[out] count_prop The property object buffer to fill + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid semaphore + * @retval #OS_INVALID_POINTER if the count_prop pointer is null + */ +int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop); + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-dir.h b/src/os/inc/osapi-dir.h new file mode 100644 index 000000000..a9c594dcc --- /dev/null +++ b/src/os/inc/osapi-dir.h @@ -0,0 +1,139 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-dir.h + */ + +#ifndef OSAPI_DIR_H +#define OSAPI_DIR_H + +#include "osconfig.h" +#include "common_types.h" + +/** @brief Directory entry */ +typedef struct +{ + char FileName[OS_MAX_FILE_NAME]; +} os_dirent_t; + +/** @brief Access filename part of the dirent structure */ +#define OS_DIRENTRY_NAME(x) ((x).FileName) + +/* + * Exported Functions + */ + +/** @defgroup OSAPIDir OSAL Directory APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Opens a directory + * + * Prepares for reading the files within a directory + * + * @param[out] dir_id The non-zero handle ID of the directory + * @param[in] path The directory to open + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Closes an open directory + * + * The directory referred to by dir_id will be closed + * + * @param[in] dir_id The handle ID of the directory + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_DirectoryClose(osal_id_t dir_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Rewinds an open directory + * + * Resets a directory read handle back to the first file. + * + * @param[in] dir_id The handle ID of the directory + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_DirectoryRewind(osal_id_t dir_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Reads the next name in the directory + * + * Obtains directory entry data for the next file from an open directory + * + * @param[in] dir_id The handle ID of the directory + * @param[out] dirent Buffer to store directory entry information + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Makes a new directory + * + * Makes a directory specified by path. + * + * @param[in] path The new directory name + * @param[in] access The permissions for the directory (reserved for future use) + * + * @note Current implementations do not utilize the "access" parameter. Applications + * should still pass the intended value (#OS_READ_WRITE or #OS_READ_ONLY) to be compatible + * with future implementations. + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if path is NULL + * @retval #OS_FS_ERR_PATH_TOO_LONG if the path is too long to be stored locally + * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed + * @retval #OS_ERROR if the OS call fails + */ +int32 OS_mkdir(const char *path, uint32 access); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Removes a directory from the file system. + * + * Removes a directory from the structure. + * The directory must be empty prior to this operation. + * + * @param[in] path The directory to remove + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if path is NULL + * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed + * @retval #OS_FS_ERR_PATH_TOO_LONG + * @retval #OS_ERROR if the directory remove operation failed + */ +int32 OS_rmdir(const char *path); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-error.h b/src/os/inc/osapi-error.h new file mode 100644 index 000000000..c0af8e57e --- /dev/null +++ b/src/os/inc/osapi-error.h @@ -0,0 +1,120 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-error.h + */ + +#ifndef OSAPI_ERROR_H +#define OSAPI_ERROR_H + +#include "common_types.h" + +/** @brief Error string name length + * + * The sizes of strings in OSAL functions are built with this limit in mind. + * Always check the uses of os_err_name_t when changing this value. + */ +#define OS_ERROR_NAME_LENGTH 35 + +/** + * @brief For the @ref OS_GetErrorName() function, to ensure + * everyone is making an array of the same length. + * + * Implementation note for developers: + * + * The sizes of strings in OSAL functions are built with this + * #OS_ERROR_NAME_LENGTH limit in mind. Always check the uses of os_err_name_t + * when changing this value. + */ +typedef char os_err_name_t[OS_ERROR_NAME_LENGTH]; + +/** @defgroup OSReturnCodes OSAL Return Code Defines + * + * @{ + */ +#define OS_SUCCESS (0) /**< @brief Successful execution */ +#define OS_ERROR (-1) /**< @brief Failed execution */ +#define OS_INVALID_POINTER (-2) /**< @brief Invalid pointer */ +#define OS_ERROR_ADDRESS_MISALIGNED (-3) /**< @brief Address misalignment */ +#define OS_ERROR_TIMEOUT (-4) /**< @brief Error timeout */ +#define OS_INVALID_INT_NUM (-5) /**< @brief Invalid Interrupt number */ +#define OS_SEM_FAILURE (-6) /**< @brief Semaphore failure */ +#define OS_SEM_TIMEOUT (-7) /**< @brief Semaphore timeout */ +#define OS_QUEUE_EMPTY (-8) /**< @brief Queue empty */ +#define OS_QUEUE_FULL (-9) /**< @brief Queue full */ +#define OS_QUEUE_TIMEOUT (-10) /**< @brief Queue timeout */ +#define OS_QUEUE_INVALID_SIZE (-11) /**< @brief Queue invalid size */ +#define OS_QUEUE_ID_ERROR (-12) /**< @brief Queue ID error */ +#define OS_ERR_NAME_TOO_LONG (-13) /**< @brief name length including null terminator greater than #OS_MAX_API_NAME */ +#define OS_ERR_NO_FREE_IDS (-14) /**< @brief No free IDs */ +#define OS_ERR_NAME_TAKEN (-15) /**< @brief Name taken */ +#define OS_ERR_INVALID_ID (-16) /**< @brief Invalid ID */ +#define OS_ERR_NAME_NOT_FOUND (-17) /**< @brief Name not found */ +#define OS_ERR_SEM_NOT_FULL (-18) /**< @brief Semaphore not full */ +#define OS_ERR_INVALID_PRIORITY (-19) /**< @brief Invalid priority */ +#define OS_INVALID_SEM_VALUE (-20) /**< @brief Invalid semaphore value */ +#define OS_ERR_FILE (-27) /**< @brief File error */ +#define OS_ERR_NOT_IMPLEMENTED (-28) /**< @brief Not implemented */ +#define OS_TIMER_ERR_INVALID_ARGS (-29) /**< @brief Timer invalid arguments */ +#define OS_TIMER_ERR_TIMER_ID (-30) /**< @brief Timer ID error */ +#define OS_TIMER_ERR_UNAVAILABLE (-31) /**< @brief Timer unavailable */ +#define OS_TIMER_ERR_INTERNAL (-32) /**< @brief Timer internal error */ +#define OS_ERR_OBJECT_IN_USE (-33) /**< @brief Object in use */ +#define OS_ERR_BAD_ADDRESS (-34) /**< @brief Bad address */ +#define OS_ERR_INCORRECT_OBJ_STATE (-35) /**< @brief Incorrect object state */ +#define OS_ERR_INCORRECT_OBJ_TYPE (-36) /**< @brief Incorrect object type */ +#define OS_ERR_STREAM_DISCONNECTED (-37) /**< @brief Stream disconnected */ +#define OS_ERR_OPERATION_NOT_SUPPORTED (-38) /**< @brief Requested operation not support on supplied object(s) */ +#define OS_ERR_INVALID_SIZE (-40) /**< @brief Invalid Size */ + +/* +** Defines for File System Calls +*/ +/* + * NOTE - these values used to overlap with the + * other OSAPI error codes. They now start at -100 + * to avoid this overlap. + */ +#define OS_FS_ERR_PATH_TOO_LONG (-103) /**< @brief FS path too long */ +#define OS_FS_ERR_NAME_TOO_LONG (-104) /**< @brief FS name too long */ +#define OS_FS_ERR_DRIVE_NOT_CREATED (-106) /**< @brief FS drive not created */ +#define OS_FS_ERR_DEVICE_NOT_FREE (-107) /**< @brief FS device not free */ +#define OS_FS_ERR_PATH_INVALID (-108) /**< @brief FS path invalid */ + +/**@}*/ + +/** @defgroup OSAPIError OSAL Error Info APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Convert an error number to a string + * + * @param[in] error_num Error number to convert + * @param[out] err_name Buffer to store error string + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-file.h b/src/os/inc/osapi-file.h new file mode 100644 index 000000000..421b64442 --- /dev/null +++ b/src/os/inc/osapi-file.h @@ -0,0 +1,523 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-file.h + */ + +#ifndef OSAPI_FILE_H +#define OSAPI_FILE_H + +#include "osconfig.h" +#include "common_types.h" +#include "osapi-clock.h" + +/** @defgroup OSFileAccess OSAL File Access Option Defines + * @{ + */ +#define OS_READ_ONLY 0 /**< Read only file access */ +#define OS_WRITE_ONLY 1 /**< Write only file access */ +#define OS_READ_WRITE 2 /**< Read write file access */ +/**@}*/ + +/** @defgroup OSFileOffset OSAL Reference Point For Seek Offset Defines + * @{ + */ +#define OS_SEEK_SET 0 /**< Seek offset set */ +#define OS_SEEK_CUR 1 /**< Seek offset current */ +#define OS_SEEK_END 2 /**< Seek offset end */ +/**@}*/ + +/** @brief OSAL file properties */ +typedef struct +{ + char Path[OS_MAX_PATH_LEN]; + osal_id_t User; + uint8 IsValid; /* For backward compatibility -- always true if OS_FDGetInfo returned true */ +} OS_file_prop_t; + +/** + * @brief File system status + * + * @note This used to be directly typedef'ed to the "struct stat" from the C library + * + * Some C libraries (glibc in particular) actually define member names to reference into + * sub-structures, so attempting to reuse a name like "st_mtime" might not work. + */ +typedef struct +{ + uint32 FileModeBits; + OS_time_t FileTime; + size_t FileSize; +} os_fstat_t; + +/** + * @brief File stat mode bits + * + * We must also define replacements for the stat structure's mode bits. + * This is currently just a small subset since the OSAL just presents a very + * simplified view of the filesystem to the upper layers. And since not all + * OS'es are POSIX, the more POSIX-specific bits are not relevant anyway. + */ +enum +{ + OS_FILESTAT_MODE_EXEC = 0x00001, + OS_FILESTAT_MODE_WRITE = 0x00002, + OS_FILESTAT_MODE_READ = 0x00004, + OS_FILESTAT_MODE_DIR = 0x10000 +}; + +/** @brief Access file stat mode bits */ +#define OS_FILESTAT_MODE(x) ((x).FileModeBits) +/** @brief File stat is directory logical */ +#define OS_FILESTAT_ISDIR(x) ((x).FileModeBits & OS_FILESTAT_MODE_DIR) +/** @brief File stat is executable logical */ +#define OS_FILESTAT_EXEC(x) ((x).FileModeBits & OS_FILESTAT_MODE_EXEC) +/** @brief File stat is write enabled logical */ +#define OS_FILESTAT_WRITE(x) ((x).FileModeBits & OS_FILESTAT_MODE_WRITE) +/** @brief File stat is read enabled logical */ +#define OS_FILESTAT_READ(x) ((x).FileModeBits & OS_FILESTAT_MODE_READ) +/** @brief Access file stat size field */ +#define OS_FILESTAT_SIZE(x) ((x).FileSize) +/** @brief Access file stat time field as a whole number of seconds */ +#define OS_FILESTAT_TIME(x) (OS_TimeGetTotalSeconds((x).FileTime)) + +/** + * @brief Flags that can be used with opening of a file (bitmask) + */ +typedef enum +{ + OS_FILE_FLAG_NONE = 0x00, + OS_FILE_FLAG_CREATE = 0x01, + OS_FILE_FLAG_TRUNCATE = 0x02, +} OS_file_flag_t; + +/* + * Exported Functions + */ + +/** @defgroup OSAPIFile OSAL Standard File APIs + * @{ + */ + +#ifndef OSAL_OMIT_DEPRECATED + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Creates a file specified by path + * + * Creates a file specified by const char *path, with read/write + * permissions by access. The file is also automatically opened by the + * create call. + * + * @param[in] path File name to create + * @param[in] access Intended access mode - see @ref OSFileAccess + * + * @note Valid handle IDs are never negative. Failure of this + * call can be checked by testing if the result is less than 0. + * + * @return A file handle ID or appropriate error code, see @ref OSReturnCodes + * @retval #OS_INVALID_POINTER if path is NULL + * @retval #OS_FS_ERR_PATH_TOO_LONG if path exceeds the maximum number of chars + * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed + * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long + * @retval #OS_ERROR if permissions are unknown or OS call fails + * @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left + * + * @deprecated Replaced by OS_OpenCreate() with flags set to + * OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE. + */ +int32 OS_creat(const char *path, int32 access); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Opens a file + * + * Opens a file. + * + * @param[in] path File name to create + * @param[in] access Intended access mode - see @ref OSFileAccess + * @param[in] mode The file permissions. This parameter is passed through to the + * native open call, but will be ignored. The file mode (or permissions) + * are ignored by the POSIX open call when the O_CREAT access flag is not passed in. + * + * @note Valid handle IDs are never negative. Failure of this + * call can be checked by testing if the result is less than 0. + * + * @return A file handle ID or appropriate error code, see @ref OSReturnCodes + * @retval #OS_INVALID_POINTER if path is NULL + * @retval #OS_FS_ERR_PATH_TOO_LONG if path exceeds the maximum number of chars + * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed + * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long + * @retval #OS_ERROR if permissions are unknown or OS call fails + * @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left + * + * @deprecated Replaced by OS_OpenCreate() with flags set to + * OS_FILE_FLAG_NONE. + */ +int32 OS_open(const char *path, int32 access, uint32 mode); + +#endif + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Open or create a file + * + * Implements the same as OS_open/OS_creat but follows the OSAL paradigm + * of outputting the ID/descriptor separately from the return value, rather + * than relying on the user to convert it back. + * + * @param[out] filedes The handle ID + * @param[in] path File name to create or open + * @param[in] flags The file permissions - see @ref OS_file_flag_t + * @param[in] access Intended access mode - see @ref OSFileAccess + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if the command was not executed properly + */ +int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Closes an open file handle + * + * This closes regular file handles and any other file-like resource, such as + * network streams or pipes. + * + * @param[in] filedes The handle ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if file descriptor could not be closed + * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + */ +int32 OS_close(osal_id_t filedes); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Read from a file handle + * + * Reads up to nbytes from a file, and puts them into buffer. + * + * @param[in] filedes The handle ID to operate on + * @param[out] buffer Storage location for file data + * @param[in] nbytes Maximum number of bytes to read + * + * @note All OSAL error codes are negative int32 values. Failure of this + * call can be checked by testing if the result is less than 0. + * + * @return A non-negative byte count or appropriate error code, see @ref OSReturnCodes + * @retval #OS_INVALID_POINTER if buffer is a null pointer + * @retval #OS_ERROR if OS call failed + * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + */ +int32 OS_read(osal_id_t filedes, void *buffer, size_t nbytes); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Write to a file handle + * + * Writes to a file. copies up to a maximum of nbytes of buffer to the file + * described in filedes + * + * @param[in] filedes The handle ID to operate on + * @param[in] buffer Source location for file data + * @param[in] nbytes Maximum number of bytes to read + * + * @note All OSAL error codes are negative int32 values. Failure of this + * call can be checked by testing if the result is less than 0. + * + * @return A non-negative byte count or appropriate error code, see @ref OSReturnCodes + * @retval #OS_INVALID_POINTER if buffer is NULL + * @retval #OS_ERROR if OS call failed + * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + */ +int32 OS_write(osal_id_t filedes, const void *buffer, size_t nbytes); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief File/Stream input read with a timeout + * + * This implements a time-limited read and is primarily intended for use with + * sockets but may also work with any other stream-like resource that the underlying + * OS supports. + * + * If data is immediately available on the file/socket, this will return that data + * along with the actual number of bytes that were immediately available. It will + * not block. + * + * If no data is immediately available, this will wait up to the given timeout for + * data to appear. If no data appears within the timeout period, then this returns + * an error code (not zero). + * + * In all cases this will return successfully as soon as at least 1 byte of actual + * data is available. It will not attempt to read the entire input buffer. + * + * If an EOF condition occurs prior to timeout, this function returns zero. + * + * @param[in] filedes The handle ID to operate on + * @param[in] buffer Source location for file data + * @param[in] nbytes Maximum number of bytes to read + * @param[in] timeout Maximum time to wait, in milliseconds (OS_PEND = forever) + * + * @return Byte count on success, zero for timeout, or appropriate error code, + * see @ref OSReturnCodes + */ +int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief File/Stream output write with a timeout + * + * This implements a time-limited write and is primarily intended for use with + * sockets but may also work with any other stream-like resource that the underlying + * OS supports. + * + * If output buffer space is immediately available on the file/socket, this will + * place data into the buffer and return the actual number of bytes that were + * queued for output. It will not block. + * + * If no output buffer space is immediately available, this will wait up to the + * given timeout for space to become available. If no space becomes available within + * the timeout period, then this returns an error code (not zero). + * + * In all cases this will return successfully as soon as at least 1 byte of actual + * data is output. It will _not_ attempt to write the entire output buffer. + * + * If an EOF condition occurs prior to timeout, this function returns zero. + * + * @param[in] filedes The handle ID to operate on + * @param[in] buffer Source location for file data + * @param[in] nbytes Maximum number of bytes to read + * @param[in] timeout Maximum time to wait, in milliseconds (OS_PEND = forever) + * + * @return Byte count on success, zero for timeout, or appropriate error code, + * see @ref OSReturnCodes + */ +int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Changes the permissions of a file + * + * @param[in] path File to change + * @param[in] access Desired access mode - see @ref OSFileAccess + * + * @note Some file systems do not implement permissions + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_chmod(const char *path, uint32 access); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain information about a file or directory + * + * Returns information about a file or directory in a os_fstat_t structure + * + * @param[in] path The file to operate on + * @param[out] filestats Buffer to store file information + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if path or filestats is NULL + * @retval #OS_FS_ERR_PATH_TOO_LONG if the path is too long to be stored locally + * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long to be stored + * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed + * @retval #OS_ERROR if the OS call failed + */ +int32 OS_stat(const char *path, os_fstat_t *filestats); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Seeks to the specified position of an open file + * + * Sets the read/write pointer to a specific offset in a specific file. + * + * @param[in] filedes The handle ID to operate on + * @param[in] offset The file offset to seek to + * @param[in] whence The reference point for offset, see @ref OSFileOffset + * + * @return Byte offset from the beginning of the file or appropriate error code, + see @ref OSReturnCodes + * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + * @retval #OS_ERROR if OS call failed + */ +int32 OS_lseek(osal_id_t filedes, int32 offset, uint32 whence); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Removes a file from the file system + * + * Removes a given filename from the drive + * + * @note The behvior of this API on an open file is not defined at the OSAL level + * due to dependencies on the underlying OS which may or may not allow the related + * operation based on a varienty of potential configurations. For portability, + * it is recommended that applications ensure the file is closed prior to removal. + * + * @param[in] path The file to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if there is no device or the driver returns error + * @retval #OS_INVALID_POINTER if path is NULL + * @retval #OS_FS_ERR_PATH_TOO_LONG if path is too long to be stored locally + * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed + * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file to remove is too long + */ +int32 OS_remove(const char *path); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Renames a file + * + * Changes the name of a file, where the source and destination + * reside on the same file system. + * + * @note The behvior of this API on an open file is not defined at the OSAL level + * due to dependencies on the underlying OS which may or may not allow the related + * operation based on a varienty of potential configurations. For portability, + * it is recommended that applications ensure the file is closed prior to removal. + * + * @param[in] old_filename The original filename + * @param[in] new_filename The desired filename + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if the file could not be opened or renamed. + * @retval #OS_INVALID_POINTER if old or new are NULL + * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed + * @retval #OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally + * @retval #OS_FS_ERR_NAME_TOO_LONG if the new name is too long to be stored locally + */ +int32 OS_rename(const char *old_filename, const char *new_filename); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Copies a single file from src to dest + * + * @note The behvior of this API on an open file is not defined at the OSAL level + * due to dependencies on the underlying OS which may or may not allow the related + * operation based on a varienty of potential configurations. For portability, + * it is recommended that applications ensure the file is closed prior to removal. + * + * @param[in] src The source file to operate on + * @param[in] dest The destination file + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if the file could not be accessed + * @retval #OS_INVALID_POINTER if src or dest are NULL + * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed + * @retval #OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally + * @retval #OS_FS_ERR_NAME_TOO_LONG if the dest name is too long to be stored locally + */ +int32 OS_cp(const char *src, const char *dest); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Move a single file from src to dest + * + * This first attempts to rename the file, which is faster if + * the source and destination reside on the same file system. + * + * If this fails, it falls back to copying the file and removing + * the original. + * + * @note The behvior of this API on an open file is not defined at the OSAL level + * due to dependencies on the underlying OS which may or may not allow the related + * operation based on a varienty of potential configurations. For portability, + * it is recommended that applications ensure the file is closed prior to removal. + * + * @param[in] src The source file to operate on + * @param[in] dest The destination file + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if the file could not be renamed. + * @retval #OS_INVALID_POINTER if src or dest are NULL + * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed + * @retval #OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally + * @retval #OS_FS_ERR_NAME_TOO_LONG if the dest name is too long to be stored locally + */ +int32 OS_mv(const char *src, const char *dest); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain information about an open file + * + * Copies the information of the given file descriptor into a structure passed in + * + * @param[in] filedes The handle ID to operate on + * @param[out] fd_prop Storage buffer for file information + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + */ +int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Checks to see if a file is open + * + * This function takes a filename and determines if the file is open. The function + * will return success if the file is open. + * + * @param[in] Filename The file to operate on + * + * @return OS_SUCCESS if the file is open, or appropriate error code + * @retval #OS_ERROR if the file is not open + */ +int32 OS_FileOpenCheck(const char *Filename); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Close all open files + * + * Closes All open files that were opened through the OSAL + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if one or more file close returned an error + */ +int32 OS_CloseAllFiles(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Close a file by filename + * + * Allows a file to be closed by name. + * This will only work if the name passed in is the same name used to open + * the file. + * + * @param[in] Filename The file to close + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_FS_ERR_PATH_INVALID if the file is not found + * @retval #OS_ERROR if the file close returned an error + */ +int32 OS_CloseFileByName(const char *Filename); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-filesys.h b/src/os/inc/osapi-filesys.h new file mode 100644 index 000000000..e49671b0d --- /dev/null +++ b/src/os/inc/osapi-filesys.h @@ -0,0 +1,328 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-filesys.h + */ + +#ifndef OSAPI_FILESYS_H +#define OSAPI_FILESYS_H + +#include "osconfig.h" +#include "common_types.h" + +#define OS_CHK_ONLY 0 /**< Unused, API takes bool */ +#define OS_REPAIR 1 /**< Unused, API takes bool */ + +/** @brief OSAL file system info */ +typedef struct +{ + uint32 MaxFds; /**< @brief Total number of file descriptors */ + uint32 FreeFds; /**< @brief Total number that are free */ + uint32 MaxVolumes; /**< @brief Maximum number of volumes */ + uint32 FreeVolumes; /**< @brief Total number of volumes free */ +} os_fsinfo_t; + +/* + * @brief The data type filled in by the OS_FileSysStatVolume() call. + * + * Encapsulates detail information about the size and available space + * in a mounted file system volume. + */ +typedef struct +{ + size_t block_size; /**< Block size of underlying FS */ + osal_blockcount_t total_blocks; /**< Total blocks in underlying FS */ + osal_blockcount_t blocks_free; /**< Available blocks in underlying FS */ +} OS_statvfs_t; + +/* + * Exported Functions + */ + +/** @defgroup OSAPIFileSys OSAL File System Level APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Create a fixed mapping between an existing directory and a virtual OSAL mount point. + * + * This mimics the behavior of a "FS_BASED" entry in the VolumeTable but is registered + * at runtime. It is intended to be called by the PSP/BSP prior to starting the application. + * + * @note OSAL virtual mount points are required to be a single, non-empty top-level directory + * name. Virtual path names always follow the form /\/\/\. + * Only the relative path may be omitted/empty (i.e. /\/\) but the + * virtual mount point must be present and not an empty string. In particular this means + * it is not possible to directly refer to files in the "root" of the native file system + * from OSAL. However it is possible to create a virtual map to the root, such as by calling: + * + * OS_FileSysAddFixedMap(&fs_id, "/", "/root"); + * + * + * @param[out] filesys_id A non-zero OSAL ID reflecting the file system + * @param[in] phys_path The native system directory (an existing mount point) + * @param[in] virt_path The virtual mount point of this filesystem + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const char *virt_path); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Makes a file system on the target + * + * Makes a file system on the target. Highly dependent on underlying OS and + * dependent on OS volume table definition. + * + * @note The "volname" parameter of RAM disks should always begin with the string "RAM", + * e.g. "RAMDISK" or "RAM0","RAM1", etc if multiple devices are created. The underlying + * implementation uses this to select the correct filesystem type/format, and this may + * also be used to differentiate between RAM disks and real physical disks. + * + * @param[in] address The address at which to start the new disk. If address == 0 + * space will be allocated by the OS. + * @param[in] devname The underlying kernel device to use, if applicable. + * @param[in] volname The name of the volume (see note) + * @param[in] blocksize The size of a single block on the drive + * @param[in] numblocks The number of blocks to allocate for the drive + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_INVALID_POINTER if devname is NULL + * @retval #OS_FS_ERR_DRIVE_NOT_CREATED if the OS calls to create the the drive failed + * @retval #OS_FS_ERR_DEVICE_NOT_FREE if the volume table is full + * @retval #OS_SUCCESS on creating the disk + */ +int32 OS_mkfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks); +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Mounts a file system + * + * Mounts a file system / block device at the given mount point. + * + * @param[in] devname The name of the drive to mount. devname is the same from #OS_mkfs + * @param[in] mountpoint The name to call this disk from now on + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_mount(const char *devname, const char *mountpoint); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Initializes an existing file system + * + * Initializes a file system on the target. + * + * @note The "volname" parameter of RAM disks should always begin with the string "RAM", + * e.g. "RAMDISK" or "RAM0","RAM1", etc if multiple devices are created. The underlying + * implementation uses this to select the correct filesystem type/format, and this may + * also be used to differentiate between RAM disks and real physical disks. + * + * @param[in] address The address at which to start the new disk. If address == 0, + * then space will be allocated by the OS + * @param[in] devname The underlying kernel device to use, if applicable. + * @param[in] volname The name of the volume (see note) + * @param[in] blocksize The size of a single block on the drive + * @param[in] numblocks The number of blocks to allocate for the drive + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if devname or volname are NULL + * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long + * @retval #OS_FS_ERR_DEVICE_NOT_FREE if the volume table is full + * @retval #OS_FS_ERR_DRIVE_NOT_CREATED on error + */ +int32 OS_initfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Removes a file system + * + * This function will remove or un-map the target file system. Note that this is not + * the same as un-mounting the file system. + * + * @param[in] devname The name of the "generic" drive + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if devname is NULL + * @retval #OS_ERROR is the drive specified cannot be located + */ +int32 OS_rmfs(const char *devname); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Unmounts a mounted file system + * + * This function will unmount a drive from the file system and make all open file + * descriptors useless. + * + * @note Any open file descriptors referencing this file system should + * be closed prior to unmounting a drive + * + * @param[in] mountpoint The mount point to remove from #OS_mount + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if name is NULL + * @retval #OS_FS_ERR_PATH_TOO_LONG if the absolute path given is too long + * @retval #OS_ERROR if the OS calls failed + */ +int32 OS_unmount(const char *mountpoint); + +#ifndef OSAL_OMIT_DEPRECATED + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain number of blocks free + * + * Returns the number of free blocks in a volume + * + * @param[in] name The device/path to operate on + * + * @return Block count or appropriate error code, see @ref OSReturnCodes + * @retval #OS_INVALID_POINTER if name is NULL + * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long + * @retval #OS_ERROR if the OS call failed + * + * @deprecated Replaced by OS_FileSysStatVolume() - + * Value can be obtained by reading the "blocks_free" struct member. + * + */ +int32 OS_fsBlocksFree(const char *name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtains the number of free bytes in a volume + * + * Returns the number of free bytes in a volume + * + * @note uses a 64 bit data type to support filesystems that + * are greater than 4 Gigabytes + * + * @param[in] name The device/path to operate on + * @param[out] bytes_free The number of free bytes + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if name is NULL + * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long + * @retval #OS_ERROR if the OS call failed + * + * @deprecated Replaced by OS_FileSysStatVolume(). + * Value can be obtained by multiplying the "blocks_free" by the "block_size" struct members. + */ +int32 OS_fsBytesFree(const char *name, uint64 *bytes_free); + +#endif /* OSAL_OMIT_DEPRECATED */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtains information about size and free space in a volume + * + * Populates the supplied OS_statvfs_t structure, which includes + * the block size and total/free blocks in a file system volume. + * + * This replaces two older OSAL calls: + * + * OS_fsBlocksFree() is determined by reading the blocks_free + * output struct member + * OS_fsBytesFree() is determined by multiplying blocks_free + * by the block_size member + * + * @param[in] name The device/path to operate on + * @param[out] statbuf Output structure to populate + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if name or statbuf is NULL + * @retval #OS_ERROR if the OS call failed + */ +int32 OS_FileSysStatVolume(const char *name, OS_statvfs_t *statbuf); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Checks the health of a file system and repairs it if necessary + * + * Checks the drives for inconsistencies and optionally also repairs it + * + * @note not all operating systems implement this function + * + * @param[in] name The device/path to operate on + * @param[in] repair Whether to also repair inconsistencies + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER Name is NULL + * @retval #OS_ERR_NOT_IMPLEMENTED @copybrief OS_ERR_NOT_IMPLEMENTED + * @retval #OS_ERROR @copybrief OS_ERROR + */ +int32 OS_chkfs(const char *name, bool repair); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtains the physical drive name associated with a mount point + * + * Returns the name of the physical volume associated with the drive, + * when given the OSAL mount point of the drive + * + * @param[out] PhysDriveName Buffer to store physical drive name + * @param[in] MountPoint OSAL mount point + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if either parameter is NULL + * @retval #OS_ERROR if the mountpoint could not be found + */ +int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Translates a OSAL Virtual file system path to a host Local path + * + * Translates a virtual path to an actual system path name + * + * @param[in] VirtualPath OSAL virtual path name + * @param[out] LocalPath Buffer to store native/translated path name + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if either parameter is NULL + */ +int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Returns information about the file system + * + * Returns information about the file system in an os_fsinfo_t. + * This includes the number of open files and file systems + * + * @param[out] filesys_info Buffer to store filesystem information + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if filesys_info is NULL + */ +int32 OS_GetFsInfo(os_fsinfo_t *filesys_info); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-heap.h b/src/os/inc/osapi-heap.h new file mode 100644 index 000000000..5bdd32973 --- /dev/null +++ b/src/os/inc/osapi-heap.h @@ -0,0 +1,58 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-heap.h + */ + +#ifndef OSAPI_HEAP_H +#define OSAPI_HEAP_H + +#include "osconfig.h" +#include "common_types.h" + +/** + * @brief OSAL heap properties + * + * @sa OS_HeapGetInfo() + */ +typedef struct +{ + size_t free_bytes; + osal_blockcount_t free_blocks; + size_t largest_free_block; +} OS_heap_prop_t; + +/** @defgroup OSAPIHeap OSAL Heap APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Return current info on the heap + * + * @param[out] heap_prop Storage buffer for heap info + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-idmap.h b/src/os/inc/osapi-idmap.h new file mode 100644 index 000000000..cd93b0f3e --- /dev/null +++ b/src/os/inc/osapi-idmap.h @@ -0,0 +1,264 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-idmap.h + */ + +#ifndef OSAPI_IDMAP_H +#define OSAPI_IDMAP_H + +#include "osconfig.h" +#include "common_types.h" + +/* Defines constants for making object ID's unique */ +#define OS_OBJECT_INDEX_MASK 0xFFFF /**< @brief Object index mask */ +#define OS_OBJECT_TYPE_SHIFT 16 /**< @brief Object type shift */ + +/** @defgroup OSObjectTypes OSAL Object Type Defines + * @{ + */ +#define OS_OBJECT_TYPE_UNDEFINED 0x00 /**< @brief Object type undefined */ +#define OS_OBJECT_TYPE_OS_TASK 0x01 /**< @brief Object task type */ +#define OS_OBJECT_TYPE_OS_QUEUE 0x02 /**< @brief Object queue type */ +#define OS_OBJECT_TYPE_OS_COUNTSEM 0x03 /**< @brief Object counting semaphore type */ +#define OS_OBJECT_TYPE_OS_BINSEM 0x04 /**< @brief Object binary semaphore type */ +#define OS_OBJECT_TYPE_OS_MUTEX 0x05 /**< @brief Object mutex type */ +#define OS_OBJECT_TYPE_OS_STREAM 0x06 /**< @brief Object stream type */ +#define OS_OBJECT_TYPE_OS_DIR 0x07 /**< @brief Object directory type */ +#define OS_OBJECT_TYPE_OS_TIMEBASE 0x08 /**< @brief Object timebase type */ +#define OS_OBJECT_TYPE_OS_TIMECB 0x09 /**< @brief Object timer callback type */ +#define OS_OBJECT_TYPE_OS_MODULE 0x0A /**< @brief Object module type */ +#define OS_OBJECT_TYPE_OS_FILESYS 0x0B /**< @brief Object file system type */ +#define OS_OBJECT_TYPE_OS_CONSOLE 0x0C /**< @brief Object console type */ +#define OS_OBJECT_TYPE_USER 0x10 /**< @brief Object user type */ +/**@}*/ + +/** @defgroup OSAPIObjUtil OSAL Object ID Utility APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain an integer value corresponding to an object ID + * + * Obtains an integer representation of an object id, generally + * for the purpose of printing to the console or system logs. + * + * The returned value is of the type "unsigned long" for direct use with + * printf-style functions. It is recommended to use the "%lx" conversion + * specifier as the hexidecimal encoding clearly delineates the internal fields. + * + * @note This provides the raw integer value and is _not_ suitable for use + * as an array index, as the result is not zero-based. See the + * OS_ConvertToArrayIndex() to obtain a zero-based index value. + * + * @param[in] object_id The object ID + * @returns integer value representation of object ID + * + * @hidecallgraph + * @hidecallergraph + */ +static inline unsigned long OS_ObjectIdToInteger(osal_id_t object_id) +{ + return object_id; +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain an osal ID corresponding to an integer value + * + * Provides the inverse of OS_ObjectIdToInteger(). Reconstitutes the original + * osal_id_t type from an integer representation. + * + * @param[in] value The integer representation of an OSAL ID + * @returns The ID value converted to an osal_id_t + * + * @hidecallgraph + * @hidecallergraph + */ +static inline osal_id_t OS_ObjectIdFromInteger(unsigned long value) +{ + return (osal_id_t)value; +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Check two OSAL object ID values for equality + * + * The OSAL ID values should be treated as abstract values by applications, and not + * directly manipulated using standard C operators. + * + * This checks two values for equality, replacing the "==" operator. + * + * @param[in] object_id1 The first object ID + * @param[in] object_id2 The second object ID + * @returns true if the object IDs are equal + * + * @hidecallgraph + * @hidecallergraph + */ +static inline bool OS_ObjectIdEqual(osal_id_t object_id1, osal_id_t object_id2) +{ + return (object_id1 == object_id2); +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Check if an object ID is defined. + * + * The OSAL ID values should be treated as abstract values by applications, and not + * directly manipulated using standard C operators. + * + * This returns false if the ID is NOT a defined resource (i.e. free/empty/invalid). + * + * @note OS_ObjectIdDefined(OS_OBJECT_ID_UNDEFINED) is always guaranteed to be false. + * + * @param[in] object_id The first object ID + * + * @hidecallgraph + * @hidecallergraph + */ +static inline bool OS_ObjectIdDefined(osal_id_t object_id) +{ + return (object_id != 0); +} + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain the name of an object given an arbitrary object ID + * + * All OSAL resources generally have a name associated with them. This + * allows application code to retrieve the name of any valid OSAL object ID. + * + * @param[in] object_id The object ID to operate on + * @param[out] buffer Buffer in which to store the name + * @param[in] buffer_size Size of the output storage buffer + * + * @returns #OS_SUCCESS if successful + * #OS_ERR_INVALID_ID if the passed-in ID is not a valid OSAL ID + * #OS_INVALID_POINTER if the passed-in buffer is invalid + * #OS_ERR_NAME_TOO_LONG if the name will not fit in the buffer provided + */ +int32 OS_GetResourceName(osal_id_t object_id, char *buffer, size_t buffer_size); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain the type of an object given an arbitrary object ID + * + * Given an arbitrary object ID, get the type of the object + * + * @param[in] object_id The object ID to operate on + * + * @return The object type portion of the object_id, see @ref OSObjectTypes for + * expected values + */ +osal_objtype_t OS_IdentifyObject(osal_id_t object_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Converts an abstract ID into a number suitable for use as an array index. + * + * This will return a unique zero-based integer number in the range of [0,MAX) for + * any valid object ID. This may be used by application code as an array index + * for indexing into local tables. + * + * @note This does NOT verify the validity of the ID, that is left to the caller. + * This is only the conversion logic. + * + * This routine accepts any object type, and returns a value based on the + * maximum number of objects for that type. This is equivalent to invoking + * OS_ObjectIdToArrayIndex() with the idtype set to OS_OBJECT_TYPE_UNDEFINED. + * + * @sa OS_ObjectIdToArrayIndex + * + * @param[in] object_id The object ID to operate on + * @param[out] *ArrayIndex The Index to return + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INCORRECT_OBJ_TYPE @copybrief OS_ERR_INCORRECT_OBJ_TYPE + */ +int32 OS_ConvertToArrayIndex(osal_id_t object_id, osal_index_t *ArrayIndex); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Converts an abstract ID into a number suitable for use as an array index. + * + * This will return a unique zero-based integer number in the range of [0,MAX) for + * any valid object ID. This may be used by application code as an array index + * for indexing into local tables. + * + * This routine operates on a specific object type, and returns a value based on the + * maximum number of objects for that type. + * + * If the idtype is passed as #OS_OBJECT_TYPE_UNDEFINED, then object type verification + * is skipped and any object ID will be accepted and converted to an index. In this + * mode, the range of the output depends on the actual passed-in object type. + * + * If the idtype is passed as any other value, the passed-in ID value is first + * confirmed to be the correct type. This check will guarantee that the output + * is within an expected range; for instance, if the type is passed as + * #OS_OBJECT_TYPE_OS_TASK, then the output index is guaranteed to be between 0 and + * #OS_MAX_TASKS-1 after successful conversion. + * + * @param[in] idtype The object type to convert + * @param[in] object_id The object ID to operate on + * @param[out] *ArrayIndex The Index to return + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INCORRECT_OBJ_TYPE @copybrief OS_ERR_INCORRECT_OBJ_TYPE + * */ +int32 OS_ObjectIdToArrayIndex(osal_objtype_t idtype, osal_id_t object_id, osal_index_t *ArrayIndex); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief call the supplied callback function for all valid object IDs + * + * Loops through all defined OSAL objects of all types and calls callback_ptr on each one + * If creator_id is nonzero then only objects with matching creator id are processed. + * + * @param[in] creator_id Filter objects to those created by a specific task + * This may be passed as OS_OBJECT_CREATOR_ANY to return all objects + * @param[in] callback_ptr Function to invoke for each matching object ID + * @param[in] callback_arg Opaque Argument to pass to callback function + */ +void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief call the supplied callback function for valid object IDs of a specific type + * + * Loops through all defined OSAL objects of a specific type and calls callback_ptr on each one + * If creator_id is nonzero then only objects with matching creator id are processed. + * + * @param[in] objtype The type of objects to iterate + * @param[in] creator_id Filter objects to those created by a specific task + * This may be passed as OS_OBJECT_CREATOR_ANY to return all objects + * @param[in] callback_ptr Function to invoke for each matching object ID + * @param[in] callback_arg Opaque Argument to pass to callback function + */ +void OS_ForEachObjectOfType(osal_objtype_t objtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, + void *callback_arg); + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-macros.h b/src/os/inc/osapi-macros.h new file mode 100644 index 000000000..120499a51 --- /dev/null +++ b/src/os/inc/osapi-macros.h @@ -0,0 +1,139 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @file osapi-macros.h + */ + +#ifndef OSAPI_MACROS_H +#define OSAPI_MACROS_H + +#include +#include +#include + +#include "osconfig.h" +#include "common_types.h" + +#ifdef OSAL_CONFIG_BUGCHECK_DISABLE + +/** + * @brief Placeholder for BUGCHECK + * + * When OSAL_CONFIG_BUGCHECK_DISABLE is specified, then + * the BUGCHECK/BUGREPORT macros become no-ops. + */ +#define BUGCHECK(...) + +/** + * @brief Placeholder for BUGREPORT + * + * When OSAL_CONFIG_BUGCHECK_DISABLE is specified, then + * the BUGCHECK/BUGREPORT macros become no-ops. + */ +#define BUGREPORT(...) + +#else /* Bug checking enabled */ + +#ifdef OSAL_CONFIG_BUGCHECK_STRICT + +/* + * This BUGREPORT implementation aborts the application so that the applicaiton + * can be debugged immediately. This prints the message direct to stderr, which is + * typically not buffered, so it should appear on the console before the abort occurs, + * but may appear out of order with respect to calls to OS_printf(). + */ +#define BUGREPORT(...) \ + do \ + { \ + fprintf(stderr, __VA_ARGS__); \ + abort(); \ + } while (false) + +#else + +#include "osapi-printf.h" + +/* + * This BUGREPORT simply prints the message using OS_printf, which is buffered. This + * has a minimal realtime impact as it only copies to the buffer, and the print will + * appear in order with respect to other calls to OS_printf() by the application. + */ +#define BUGREPORT(...) OS_printf(__VA_ARGS__) + +#endif /* OSAL_CONFIG_BUGCHECK_STRICT */ + +/** + * @brief Basic Bug-Checking macro + * + * This macro checks a conditional, and if it is FALSE, then it generates a report - + * which may in turn contain additional actions. + * + * BUGCHECK should only be used for conditions which are critical and must always be true. + * If such a condition is ever false then it indicates a bug in the application which + * must be resolved. It may or may not be possible to continue operation if a bugcheck + * fails. + * + * @sa ARGCHECK for checking non-critical values + */ +#define BUGCHECK(cond, errcode) \ + if (!(cond)) \ + { \ + BUGREPORT("\n**BUG** %s():%d:check \'%s\' FAILED --> %s\n\n", __func__, __LINE__, #cond, #errcode); \ + return errcode; \ + } + +#endif /* OSAL_CONFIG_BUGCHECK_DISABLE */ + +/** + * @brief Generic argument checking macro for non-critical values + * + * This macro checks a conditional that is expected to be true, and return a value + * if it evaluates false. + * + * ARGCHECK can be used to check for out of range or other invalid argument conditions + * which may (validly) occur at runtime and do not necessarily indicate bugs in the + * application. + * + * These argument checks are NOT considered a fatal errors. The application + * continues to run normally. This does not report the error on the console. + * + * As such, ARGCHECK actions are always compiled in - not selectable at compile-time. + * + * @sa BUGCHECK for checking critical values that indicate bugs + */ +#define ARGCHECK(cond, errcode) \ + if (!(cond)) \ + { \ + return errcode; \ + } + +/** + * @brief String length limit check macro + * + * This macro is a specialized version of ARGCHECK that confirms a string will fit + * into a buffer of the specified length, and return an error code if it will not. + * + * @note this uses ARGCHECK, thus treating a string too long as a normal runtime + * (i.e. non-bug) error condition with a typical error return to the caller. + */ +#define LENGTHCHECK(str, len, errcode) ARGCHECK(memchr(str, '\0', len), errcode) + +#endif diff --git a/src/os/inc/osapi-module.h b/src/os/inc/osapi-module.h new file mode 100644 index 000000000..d6f60fde6 --- /dev/null +++ b/src/os/inc/osapi-module.h @@ -0,0 +1,234 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-module.h + */ + +#ifndef OSAPI_MODULE_H +#define OSAPI_MODULE_H + +#include "osconfig.h" +#include "common_types.h" + +/* +** Defines +*/ + +/** + * @brief Requests OS_ModuleLoad() to add the symbols to the global symbol table + * + * When supplied as the "flags" argument to OS_ModuleLoad(), this indicates + * that the symbols in the loaded module should be added to the global symbol + * table. This will make symbols in this library available for use when + * resolving symbols in future module loads. + * + * This is the default mode of operation for OS_ModuleLoad(). + * + * @note On some operating systems, use of this option may make it difficult + * to unload the module in the future, if the symbols are in use by other entities. + * + */ +#define OS_MODULE_FLAG_GLOBAL_SYMBOLS 0x00 + +/** + * @brief Requests OS_ModuleLoad() to keep the symbols local/private to this module + * + * When supplied as the "flags" argument to OS_ModuleLoad(), this indicates + * that the symbols in the loaded module should NOT be added to the global + * symbol table. This means the symbols in the loaded library will not available + * to for use by other modules. + * + * Use this option is recommended for cases where no other entities will need + * to reference symbols within this module. This helps ensure that the module + * can be more safely unloaded in the future, by preventing other modules from + * binding to it. It also helps reduce the likelihood of symbol name conflicts + * among modules. + * + * @note To look up symbols within a module loaded with this flag, use + * OS_SymbolLookupInModule() instead of OS_SymbolLookup(). Also note that + * references obtained using this method are not tracked by the OS; the + * application must ensure that all references obtained in this manner have + * been cleaned up/released before unloading the module. + */ +#define OS_MODULE_FLAG_LOCAL_SYMBOLS 0x01 + +/* +** Typedefs +*/ + +/** @brief OSAL module address properties */ +typedef struct +{ + uint32 valid; + uint32 flags; + cpuaddr code_address; + cpuaddr code_size; + cpuaddr data_address; + cpuaddr data_size; + cpuaddr bss_address; + cpuaddr bss_size; +} OS_module_address_t; + +/** @brief OSAL module properties */ +typedef struct +{ + cpuaddr entry_point; + cpuaddr host_module_id; + char filename[OS_MAX_PATH_LEN]; + char name[OS_MAX_API_NAME]; + OS_module_address_t addr; +} OS_module_prop_t; + +/** + * @brief Associates a single symbol name with a memory address. + * + * If the OS_STATIC_SYMBOL_TABLE feature is enabled, then + * an array of these structures should be provided by the + * application. When the application needs to find a symbol + * address, the static table will be checked in addition + * to (or instead of) the OS/library-provided lookup function. + * + * This static symbol allows systems that do not implement + * dynamic module loading to maintain the same semantics + * as dynamically loaded modules. + */ +typedef const struct +{ + const char *Name; + void (*Address)(void); + const char *Module; +} OS_static_symbol_record_t; + +/** @defgroup OSAPILoader OSAL Dynamic Loader and Symbol APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Find the Address of a Symbol + * + * This calls to the OS dynamic symbol lookup implementation, + * and/or checks a static symbol table for a matching symbol name. + * + * The static table is intended to support embedded targets that do + * not have module loading capability or have it disabled. + * + * @param[out] symbol_address Set to the address of the symbol + * @param[in] symbol_name Name of the symbol to look up + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if the symbol could not be found + * @retval #OS_INVALID_POINTER if one of the pointers passed in are NULL + */ +int32 OS_SymbolLookup(cpuaddr *symbol_address, const char *symbol_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Find the Address of a Symbol within a module + * + * This is similar to OS_SymbolLookup() but for a specific module ID. + * This should be used to look up a symbol in a module that has been + * loaded with the #OS_MODULE_FLAG_LOCAL_SYMBOLS flag. + * + * @param[in] module_id Module ID that should contain the symbol + * @param[out] symbol_address Set to the address of the symbol + * @param[in] symbol_name Name of the symbol to look up + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if the symbol could not be found + * @retval #OS_INVALID_POINTER if one of the pointers passed in are NULL + */ +int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const char *symbol_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Dumps the system symbol table to a file + * + * Dumps the system symbol table to the specified filename + * + * @param[in] filename File to write to + * @param[in] size_limit Maximum number of bytes to write + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_NOT_IMPLEMENTED @copybrief OS_ERR_NOT_IMPLEMENTED + * @retval #OS_ERROR if the symbol table could not be read or dumped + */ +int32 OS_SymbolTableDump(const char *filename, size_t size_limit); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Loads an object file + * + * Loads an object file into the running operating system + * + * The "flags" parameter may influence how the loaded module symbols are made + * available for use in the application. See #OS_MODULE_FLAG_LOCAL_SYMBOLS + * and #OS_MODULE_FLAG_GLOBAL_SYMBOLS for descriptions. + * + * @param[out] module_id Non-zero OSAL ID corresponding to the loaded module + * @param[in] module_name Name of module + * @param[in] filename File containing the object code to load + * @param[in] flags Options for the loaded module + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if the module cannot be loaded + * @retval #OS_INVALID_POINTER if one of the parameters is NULL + * @retval #OS_ERR_NO_FREE_IDS if the module table is full + * @retval #OS_ERR_NAME_TAKEN if the name is in use + */ +int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *filename, uint32 flags); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Unloads the module file + * + * Unloads the module file from the running operating system + * + * @param[in] module_id OSAL ID of the previously the loaded module + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if the module is invalid or cannot be unloaded + */ +int32 OS_ModuleUnload(osal_id_t module_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain information about a module + * + * Returns information about the loadable module + * + * @param[in] module_id OSAL ID of the previously the loaded module + * @param[out] module_info Buffer to store module information + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the module id invalid + * @retval #OS_INVALID_POINTER if the pointer to the ModuleInfo structure is invalid + */ +int32 OS_ModuleInfo(osal_id_t module_id, OS_module_prop_t *module_info); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-mutex.h b/src/os/inc/osapi-mutex.h new file mode 100644 index 000000000..d7ba1664c --- /dev/null +++ b/src/os/inc/osapi-mutex.h @@ -0,0 +1,152 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * File: osapi-mutex.h + */ + +#ifndef OSAPI_MUTEX_H +#define OSAPI_MUTEX_H + +#include "osconfig.h" +#include "common_types.h" + +/** @brief OSAL mutex properties */ +typedef struct +{ + char name[OS_MAX_API_NAME]; + osal_id_t creator; +} OS_mut_sem_prop_t; + +/** @defgroup OSAPIMutex OSAL Mutex APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Creates a mutex semaphore + * + * Mutex semaphores are always created in the unlocked (full) state. + * + * @param[out] sem_id will be set to the non-zero ID of the newly-created resource + * @param[in] sem_name the name of the new resource to create + * @param[in] options reserved for future use. Should be passed as 0. + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if sem_id or sem_name are NULL + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NO_FREE_IDS if there are no more free mutex Ids + * @retval #OS_ERR_NAME_TAKEN if there is already a mutex with the same name + * @retval #OS_SEM_FAILURE if the OS call failed + */ +int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Releases the mutex object referenced by sem_id. + * + * If there are threads blocked on the mutex object referenced by + * mutex when this function is called, resulting in the mutex becoming + * available, the scheduling policy shall determine which thread shall + * acquire the mutex. + * + * @param[in] sem_id The object ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid mutex + * @retval #OS_SEM_FAILURE if an unspecified error occurs + */ +int32 OS_MutSemGive(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Acquire the mutex object referenced by sem_id. + * + * If the mutex is already locked, the calling thread shall + * block until the mutex becomes available. This operation shall + * return with the mutex object referenced by mutex in the locked state + * with the calling thread as its owner. + * + * @param[in] sem_id The object ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_SEM_FAILURE if the semaphore was not previously initialized or is + * not in the array of semaphores defined by the system + * @retval #OS_ERR_INVALID_ID the id passed in is not a valid mutex + */ +int32 OS_MutSemTake(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Deletes the specified Mutex Semaphore. + * + * Delete the semaphore. This also frees the respective sem_id such that it can be + * used again when another is created. + * + * @param[in] sem_id The object ID to delete + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid mutex + * @retval #OS_SEM_FAILURE if the OS call failed + */ +int32 OS_MutSemDelete(osal_id_t sem_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Find an existing mutex ID by name + * + * This function tries to find a mutex sem Id given the name of a mut_sem. + * The id is returned through sem_id + * + * @param[out] sem_id will be set to the ID of the existing resource + * @param[in] sem_name the name of the existing resource to find + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER is semid or sem_name are NULL pointers + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table + */ +int32 OS_MutSemGetIdByName(osal_id_t *sem_id, const char *sem_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Fill a property object buffer with details regarding the resource + * + * This function will pass back a pointer to structure that contains + * all of the relevant info( name and creator) about the specified mutex + * semaphore. + * + * @param[in] sem_id The object ID to operate on + * @param[out] mut_prop The property object buffer to fill + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid semaphore + * @retval #OS_INVALID_POINTER if the mut_prop pointer is null + */ +int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-network.h b/src/os/inc/osapi-network.h new file mode 100644 index 000000000..391492249 --- /dev/null +++ b/src/os/inc/osapi-network.h @@ -0,0 +1,71 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @file osapi-network.h + */ + +#ifndef OSAPI_NETWORK_H +#define OSAPI_NETWORK_H + +#include "osconfig.h" +#include "common_types.h" + +/** + * @defgroup OSALAPINetwork Network ID APIs + * + * Provides some basic methods to query a network host name and ID + * + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Gets the network ID of the local machine + * + * The ID is an implementation-defined value and may not be consistent + * in meaning across different platform types. + * + * @note This API may be removed in a future version of OSAL due to + * inconsistencies between platforms. + * + * @return The ID or fixed value of -1 if the host id could not be found. + * Note it is not possible to differentiate between error codes and valid + * network IDs here. It is assumed, however, that -1 is never a valid ID. + */ +int32 OS_NetworkGetID(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Gets the local machine network host name + * + * If configured in the underlying network stack, + * this function retrieves the local hostname of the system. + * + * @param[out] host_name Buffer to hold name information + * @param[in] name_len Maximum length of host name buffer + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_NetworkGetHostName(char *host_name, size_t name_len); + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-os-core.h b/src/os/inc/osapi-os-core.h index a6fa0d47c..5ea3b2acb 100644 --- a/src/os/inc/osapi-os-core.h +++ b/src/os/inc/osapi-os-core.h @@ -30,1521 +30,30 @@ #ifndef _osapi_core_ #define _osapi_core_ -#include /* for va_list */ - -/* Defines constants for making object ID's unique */ -#define OS_OBJECT_INDEX_MASK 0xFFFF /**< @brief Object index mask */ -#define OS_OBJECT_TYPE_SHIFT 16 /**< @brief Object type shift */ - -/** @defgroup OSObjectTypes OSAL Object Type Defines - * @{ - */ -#define OS_OBJECT_TYPE_UNDEFINED 0x00 /**< @brief Object type undefined */ -#define OS_OBJECT_TYPE_OS_TASK 0x01 /**< @brief Object task type */ -#define OS_OBJECT_TYPE_OS_QUEUE 0x02 /**< @brief Object queue type */ -#define OS_OBJECT_TYPE_OS_COUNTSEM 0x03 /**< @brief Object counting semaphore type */ -#define OS_OBJECT_TYPE_OS_BINSEM 0x04 /**< @brief Object binary semaphore type */ -#define OS_OBJECT_TYPE_OS_MUTEX 0x05 /**< @brief Object mutex type */ -#define OS_OBJECT_TYPE_OS_STREAM 0x06 /**< @brief Object stream type */ -#define OS_OBJECT_TYPE_OS_DIR 0x07 /**< @brief Object directory type */ -#define OS_OBJECT_TYPE_OS_TIMEBASE 0x08 /**< @brief Object timebase type */ -#define OS_OBJECT_TYPE_OS_TIMECB 0x09 /**< @brief Object timer callback type */ -#define OS_OBJECT_TYPE_OS_MODULE 0x0A /**< @brief Object module type */ -#define OS_OBJECT_TYPE_OS_FILESYS 0x0B /**< @brief Object file system type */ -#define OS_OBJECT_TYPE_OS_CONSOLE 0x0C /**< @brief Object console type */ -#define OS_OBJECT_TYPE_USER 0x10 /**< @brief Object user type */ -/**@}*/ - -/** @brief Upper limit for OSAL task priorities */ -#define OS_MAX_TASK_PRIORITY 255 - -/** - * @brief Initializer for the osal_id_t type which will not match any valid value - */ -#define OS_OBJECT_ID_UNDEFINED ((osal_id_t) {0}) - -/** - * @brief Constant that may be passed to OS_ForEachObject()/OS_ForEachObjectOfType() to match any - * creator (i.e. get all objects) - */ -#define OS_OBJECT_CREATOR_ANY OS_OBJECT_ID_UNDEFINED - -/** @defgroup OSSemaphoreStates OSAL Semaphore State Defines - * @{ - */ -#define OS_SEM_FULL 1 /**< @brief Semaphore full state */ -#define OS_SEM_EMPTY 0 /**< @brief Semaphore empty state */ -/**@}*/ - -/** @brief Floating point enabled state for a task */ -#define OS_FP_ENABLED 1 - -/** @brief Error string name length - * - * The sizes of strings in OSAL functions are built with this limit in mind. - * Always check the uses of os_err_name_t when changing this value. - */ -#define OS_ERROR_NAME_LENGTH 35 - -/* Object property structures */ - -/** @brief OSAL task properties */ -typedef struct -{ - char name[OS_MAX_API_NAME]; - osal_id_t creator; - uint32 stack_size; - uint32 priority; -} OS_task_prop_t; - -/** @brief OSAL queue properties */ -typedef struct -{ - char name[OS_MAX_API_NAME]; - osal_id_t creator; -} OS_queue_prop_t; - -/** @brief OSAL binary semaphore properties */ -typedef struct -{ - char name[OS_MAX_API_NAME]; - osal_id_t creator; - int32 value; -} OS_bin_sem_prop_t; - -/** @brief OSAL counting semaphore properties */ -typedef struct -{ - char name[OS_MAX_API_NAME]; - osal_id_t creator; - int32 value; -} OS_count_sem_prop_t; - -/** @brief OSAL mutexe properties */ -typedef struct -{ - char name[OS_MAX_API_NAME]; - osal_id_t creator; -} OS_mut_sem_prop_t; - -/** @brief OSAL time */ -typedef struct -{ - uint32 seconds; - uint32 microsecs; -} OS_time_t; - -/** @brief OSAL heap properties - * - * @sa OS_HeapGetInfo() - */ -typedef struct -{ - uint32 free_bytes; - uint32 free_blocks; - uint32 largest_free_block; -} OS_heap_prop_t; - -/** - * @brief An abstract structure capable of holding several OSAL IDs - * - * This is part of the select API and is manipulated using the - * related API calls. It should not be modified directly by applications. - * - * @sa OS_SelectFdZero(), OS_SelectFdAdd(), OS_SelectFdClear(), OS_SelectFdIsSet() - */ -typedef struct -{ - uint8 object_ids[(OS_MAX_NUM_OPEN_FILES + 7) / 8]; -} OS_FdSet; - -/** - * @brief For the OS_SelectSingle() function's in/out StateFlags parameter, - * the state(s) of the stream and the result of the select is a combination - * of one or more of these states. - * - * @sa OS_SelectSingle() - */ -typedef enum -{ - OS_STREAM_STATE_BOUND = 0x01, /**< @brief whether the stream is bound */ - OS_STREAM_STATE_CONNECTED = 0x02, /**< @brief whether the stream is connected */ - OS_STREAM_STATE_READABLE = 0x04, /**< @brief whether the stream is readable */ - OS_STREAM_STATE_WRITABLE = 0x08, /**< @brief whether the stream is writable */ -} OS_StreamState_t; - -/** - * @brief A set of events that can be used with event callback routines - */ -typedef enum -{ - OS_EVENT_RESERVED = 0, /**< no-op/reserved event id value */ - - /** - * resource/id has been newly allocated but not yet created. - * - * This event is invoked from WITHIN the locked region, in - * the context of the task which is allocating the resource. - * - * If the handler returns non-success, the error will be returned - * to the caller and the creation process is aborted. - */ - OS_EVENT_RESOURCE_ALLOCATED, - - /** - * resource/id has been fully created/finalized. - * - * Invoked outside locked region, in the context - * of the task which created the resource. - * - * Data object is not used, passed as NULL. - * - * Return value is ignored - this is for information purposes only. - */ - OS_EVENT_RESOURCE_CREATED, - - /** - * resource/id has been deleted. - * - * Invoked outside locked region, in the context - * of the task which deleted the resource. - * - * Data object is not used, passed as NULL. - * - * Return value is ignored - this is for information purposes only. - */ - OS_EVENT_RESOURCE_DELETED, - - /** - * New task is starting. - * - * Invoked outside locked region, in the context - * of the task which is currently starting, before - * the entry point is called. - * - * Data object is not used, passed as NULL. - * - * If the handler returns non-success, task startup is aborted - * and the entry point is not called. - */ - OS_EVENT_TASK_STARTUP, - - OS_EVENT_MAX /**< placeholder for end of enum, not used */ -} OS_Event_t; - -/** - * @brief A callback routine for event handling. - * - * @param[in] event The event that occurred - * @param[in] object_id The associated object_id, or 0 if not associated with an object - * @param[inout] data An abstract data/context object associated with the event, or NULL. - * @return status Execution status, see @ref OSReturnCodes. - */ -typedef int32 (*OS_EventHandler_t)(OS_Event_t event, osal_id_t object_id, void *data); - -/** - * @brief For the @ref OS_GetErrorName() function, to ensure - * everyone is making an array of the same length. - * - * Implementation note for developers: - * - * The sizes of strings in OSAL functions are built with this - * #OS_ERROR_NAME_LENGTH limit in mind. Always check the uses of os_err_name_t - * when changing this value. - */ -typedef char os_err_name_t[OS_ERROR_NAME_LENGTH]; +#ifdef OSAL_OMIT_DEPRECATED +#error This header header is deprecated +#endif /* -** These typedefs are for the task entry point -*/ -typedef void osal_task; /**< @brief For task entry point */ -typedef osal_task((*osal_task_entry)(void)); /**< @brief For task entry point */ - -/** - * @brief General purpose OSAL callback function - * - * This may be used by multiple APIS - */ -typedef void (*OS_ArgCallback_t)(osal_id_t object_id, void *arg); - -/** @defgroup OSAPICore OSAL Core Operation APIs - * - * These are for OSAL core operations for startup/initialization, running, and shutdown. - * Typically only used in bsps, unit tests, psps, etc. - * - * Not intended for user application use - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Application startup - * - * Startup abstraction such that the same BSP can be used for operations and testing. - */ -void OS_Application_Startup(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Application run - * - * Run abstraction such that the same BSP can be used for operations and testing. - */ -void OS_Application_Run(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Initialization of API - * - * This function returns initializes the internal data structures of the OS - * Abstraction Layer. It must be called in the application startup code before - * calling any other OS routines. - * - * @return Execution status, see @ref OSReturnCodes. Any error code (negative) - * means the OSAL can not be initialized. Typical platform specific response - * is to abort since additional OSAL calls will have undefined behavior. - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR @copybrief OS_ERROR - */ -int32 OS_API_Init(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Background thread implementation - waits forever for events to occur. - * - * This should be called from the BSP main routine or initial thread after all other - * board and application initialization has taken place and all other tasks are running. - * - * Typically just waits forever until "OS_shutdown" flag becomes true. - */ -void OS_IdleLoop(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief delete all resources created in OSAL. - * - * provides a means to clean up all resources allocated by this - * instance of OSAL. It would typically be used during an orderly - * shutdown but may also be helpful for testing purposes. - */ -void OS_DeleteAllObjects(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Initiate orderly shutdown - * - * Indicates that the OSAL application should perform an orderly shutdown - * of ALL tasks, clean up all resources, and exit the application. - * - * This allows the task currently blocked in OS_IdleLoop() to wake up, and - * for that function to return to its caller. - * - * This is preferred over e.g. OS_ApplicationExit() which exits immediately and - * does not provide for any means to clean up first. - * - * @param[in] flag set to true to initiate shutdown, false to cancel - */ -void OS_ApplicationShutdown(uint8 flag); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Exit/Abort the application - * - * Indicates that the OSAL application should exit and return control to the OS - * This is intended for e.g. scripted unit testing where the test needs to end - * without user intervention. - * - * This function does not return. Production code typically should not ever call this. - * - * @note This exits the entire process including tasks that have been created. - */ -void OS_ApplicationExit(int32 Status); -/**@}*/ - -/** @defgroup OSAPIObjUtil OSAL Object Utility APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain an integer value corresponding to an object ID - * - * Obtains an integer representation of an object id, generally - * for the purpose of printing to the console or system logs. - * - * The returned value is of the type "unsigned long" for direct use with - * printf-style functions. It is recommended to use the "%lx" conversion - * specifier as the hexidecimal encoding clearly delineates the internal fields. - * - * @note This provides the raw integer value and is _not_ suitable for use - * as an array index, as the result is not zero-based. See the - * OS_ConvertToArrayIndex() to obtain a zero-based index value. - * - * @param[in] object_id The object ID - * @returns integer value representation of object ID - * - * @hidecallgraph - * @hidecallergraph - */ -static inline unsigned long OS_ObjectIdToInteger(osal_id_t object_id) -{ - return object_id; -} - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain an osal ID corresponding to an integer value - * - * Provides the inverse of OS_ObjectIdToInteger(). Reconstitutes the original - * osal_id_t type from an integer representation. - * - * @param[in] value The integer representation of an OSAL ID - * @returns The ID value converted to an osal_id_t - * - * @hidecallgraph - * @hidecallergraph - */ -static inline osal_id_t OS_ObjectIdFromInteger(unsigned long value) -{ - return value; -} - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Check two OSAL object ID values for equality - * - * The OSAL ID values should be treated as abstract values by applications, and not - * directly manipulated using standard C operators. - * - * This checks two values for equality, replacing the "==" operator. - * - * @param[in] object_id1 The first object ID - * @param[in] object_id2 The second object ID - * @returns true if the object IDs are equal - * - * @hidecallgraph - * @hidecallergraph - */ -static inline bool OS_ObjectIdEqual(osal_id_t object_id1, osal_id_t object_id2) -{ - return (object_id1 == object_id2); -} - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Check if an object ID is defined. - * - * The OSAL ID values should be treated as abstract values by applications, and not - * directly manipulated using standard C operators. - * - * This returns false if the ID is NOT a defined resource (i.e. free/empty/invalid). - * - * @note OS_ObjectIdDefined(OS_OBJECT_ID_UNDEFINED) is always guaranteed to be false. - * - * @param[in] object_id The first object ID - * - * @hidecallgraph - * @hidecallergraph - */ -static inline bool OS_ObjectIdDefined(osal_id_t object_id) -{ - return (object_id != 0); -} - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain the name of an object given an arbitrary object ID - * - * All OSAL resources generally have a name associated with them. This - * allows application code to retrieve the name of any valid OSAL object ID. - * - * @param[in] object_id The object ID to operate on - * @param[out] buffer Buffer in which to store the name - * @param[in] buffer_size Size of the output storage buffer - * - * @returns #OS_SUCCESS if successful - * #OS_ERR_INVALID_ID if the passed-in ID is not a valid OSAL ID - * #OS_INVALID_POINTER if the passed-in buffer is invalid - * #OS_ERR_NAME_TOO_LONG if the name will not fit in the buffer provided - */ -int32 OS_GetResourceName(osal_id_t object_id, char *buffer, uint32 buffer_size); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain the type of an object given an arbitrary object ID - * - * Given an arbitrary object ID, get the type of the object - * - * @param[in] object_id The object ID to operate on - * - * @return The object type portion of the object_id, see @ref OSObjectTypes for - * expected values - */ -uint32 OS_IdentifyObject(osal_id_t object_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Converts an abstract ID into a number suitable for use as an array index. - * - * This will return a unique zero-based integer number in the range of [0,MAX) for - * any valid object ID. This may be used by application code as an array index - * for indexing into local tables. - * - * @note This does NOT verify the validity of the ID, that is left to the caller. - * This is only the conversion logic. - * - * This routine accepts any object type, and returns a value based on the - * maximum number of objects for that type. This is equivalent to invoking - * OS_ObjectIdToArrayIndex() with the idtype set to OS_OBJECT_TYPE_UNDEFINED. - * - * @sa OS_ObjectIdToArrayIndex - * - * @param[in] object_id The object ID to operate on - * @param[out] *ArrayIndex The Index to return - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INCORRECT_OBJ_TYPE @copybrief OS_ERR_INCORRECT_OBJ_TYPE - */ -int32 OS_ConvertToArrayIndex(osal_id_t object_id, uint32 *ArrayIndex); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Converts an abstract ID into a number suitable for use as an array index. - * - * This will return a unique zero-based integer number in the range of [0,MAX) for - * any valid object ID. This may be used by application code as an array index - * for indexing into local tables. - * - * This routine operates on a specific object type, and returns a value based on the - * maximum number of objects for that type. - * - * If the idtype is passed as #OS_OBJECT_TYPE_UNDEFINED, then object type verification - * is skipped and any object ID will be accepted and converted to an index. In this - * mode, the range of the output depends on the actual passed-in object type. - * - * If the idtype is passed as any other value, the passed-in ID value is first - * confirmed to be the correct type. This check will guarantee that the output - * is within an expected range; for instance, if the type is passed as - * #OS_OBJECT_TYPE_OS_TASK, then the output index is guaranteed to be between 0 and - * #OS_MAX_TASKS-1 after successful conversion. - * - * @param[in] idtype The object type to convert - * @param[in] object_id The object ID to operate on - * @param[out] *ArrayIndex The Index to return - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INCORRECT_OBJ_TYPE @copybrief OS_ERR_INCORRECT_OBJ_TYPE - * */ -int32 OS_ObjectIdToArrayIndex(uint32 idtype, osal_id_t object_id, uint32 *ArrayIndex); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief call the supplied callback function for all valid object IDs - * - * Loops through all defined OSAL objects of all types and calls callback_ptr on each one - * If creator_id is nonzero then only objects with matching creator id are processed. - * - * @param[in] creator_id Filter objects to those created by a specific task - * This may be passed as OS_OBJECT_CREATOR_ANY to return all objects - * @param[in] callback_ptr Function to invoke for each matching object ID - * @param[in] callback_arg Opaque Argument to pass to callback function - */ -void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief call the supplied callback function for valid object IDs of a specific type - * - * Loops through all defined OSAL objects of a specific type and calls callback_ptr on each one - * If creator_id is nonzero then only objects with matching creator id are processed. - * - * @param[in] objtype The type of objects to iterate - * @param[in] creator_id Filter objects to those created by a specific task - * This may be passed as OS_OBJECT_CREATOR_ANY to return all objects - * @param[in] callback_ptr Function to invoke for each matching object ID - * @param[in] callback_arg Opaque Argument to pass to callback function - */ -void OS_ForEachObjectOfType(uint32 objtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Callback routine registration - * - * This hook enables the application code to perform extra platform-specific - * operations on various system events such as resource creation/deletion. - * - * @note Some events are invoked while the resource is "locked" and therefore - * application-defined handlers for these events should not block or attempt - * to access other OSAL resources. - * - * @param[in] handler The application-provided event handler - * @return Execution status, see @ref OSReturnCodes. - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR @copybrief OS_ERROR - */ -int32 OS_RegisterEventHandler(OS_EventHandler_t handler); - -/**@}*/ - -/** @defgroup OSAPITask OSAL Task APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Creates a task and starts running it. - * - * Creates a task and passes back the id of the task created. Task names must be unique; - * if the name already exists this function fails. Names cannot be NULL. - * - * @param[out] task_id will be set to the non-zero ID of the newly-created resource - * @param[in] task_name the name of the new resource to create - * @param[in] function_pointer the entry point of the new task - * @param[in] stack_pointer pointer to the stack for the task, or NULL - * to allocate a stack from the system memory heap - * @param[in] stack_size the size of the stack, or 0 to use a default stack size. - * @param[in] priority initial priority of the new task - * @param[in] flags initial options for the new task - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if any of the necessary pointers are NULL - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_INVALID_PRIORITY if the priority is bad - * @retval #OS_ERR_NO_FREE_IDS if there can be no more tasks created - * @retval #OS_ERR_NAME_TAKEN if the name specified is already used by a task - * @retval #OS_ERROR if an unspecified/other error occurs - */ -int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, uint32 *stack_pointer, - uint32 stack_size, uint32 priority, uint32 flags); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Deletes the specified Task - * - * The task will be removed from the local tables. and the OS will - * be configured to stop executing the task at the next opportunity. - * - * @param[in] task_id The object ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the ID given to it is invalid - * @retval #OS_ERROR if the OS delete call fails - */ -int32 OS_TaskDelete(osal_id_t task_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Exits the calling task - * - * The calling thread is terminated. This function does not return. - */ -void OS_TaskExit(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Installs a handler for when the task is deleted. - * - * This function is used to install a callback that is called when the task is deleted. - * The callback is called when OS_TaskDelete is called with the task ID. A task delete - * handler is useful for cleaning up resources that a task creates, before the task is - * removed from the system. - * - * @param[in] function_pointer function to be called when task exits - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Delay a task for specified amount of milliseconds - * - * Causes the current thread to be suspended from execution for the period of millisecond. - * - * @param[in] millisecond Amount of time to delay - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if sleep fails or millisecond = 0 - */ -int32 OS_TaskDelay(uint32 millisecond); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Sets the given task to a new priority - * - * @param[in] task_id The object ID to operate on - * - * @param[in] new_priority Set the new priority - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the ID passed to it is invalid - * @retval #OS_ERR_INVALID_PRIORITY if the priority is greater than the max allowed - * @retval #OS_ERROR if the OS call to change the priority fails - */ -int32 OS_TaskSetPriority(osal_id_t task_id, uint32 new_priority); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obsolete - * @deprecated Explicit registration call no longer needed - * - * Obsolete function retained for compatibility purposes. - * Does Nothing in the current implementation. - * - * @return #OS_SUCCESS (always), see @ref OSReturnCodes - */ -int32 OS_TaskRegister(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain the task id of the calling task - * - * This function returns the task id of the calling task - * - * @return Task ID, or zero if the operation failed (zero is never a valid task ID) - */ -osal_id_t OS_TaskGetId(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Find an existing task ID by name - * - * This function tries to find a task Id given the name of a task - * - * @param[out] task_id will be set to the ID of the existing resource - * @param[in] task_name the name of the existing resource to find - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if the pointers passed in are NULL - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NAME_NOT_FOUND if the name wasn't found in the table - */ -int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Fill a property object buffer with details regarding the resource - * - * This function will pass back a pointer to structure that contains - * all of the relevant info (creator, stack size, priority, name) about the - * specified task. - * - * @param[in] task_id The object ID to operate on - * @param[out] task_prop The property object buffer to fill - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the ID passed to it is invalid - * @retval #OS_INVALID_POINTER if the task_prop pointer is NULL - */ -int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Reverse-lookup the OSAL task ID from an operating system ID - * - * This provides a method by which an external entity may find the OSAL task - * ID corresponding to a system-defined identifier (e.g. TASK_ID, pthread_t, rtems_id, etc). - * - * Normally OSAL does not expose the underlying OS-specific values to the application, - * but in some circumstances, such as exception handling, the OS may provide this information - * directly to handler outside of the normal OSAL API. - * - * @param[out] task_id The buffer where the task id output is stored - * @param[in] sysdata Pointer to the system-provided identification data - * @param[in] sysdata_size Size of the system-provided identification data - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - */ -int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t sysdata_size); - -/**@}*/ - -/** @defgroup OSAPIMsgQueue OSAL Message Queue APIs - * @{ - */ - -/** - * @brief Create a message queue - * - * This is the function used to create a queue in the operating system. - * Depending on the underlying operating system, the memory for the queue - * will be allocated automatically or allocated by the code that sets up - * the queue. Queue names must be unique; if the name already exists this - * function fails. Names cannot be NULL. - * - * - * @param[out] queue_id will be set to the non-zero ID of the newly-created resource - * @param[in] queue_name the name of the new resource to create - * @param[in] queue_depth the maximum depth of the queue - * @param[in] data_size the size of each entry in the queue - * @param[in] flags options for the queue (reserved for future use, pass as 0) - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if a pointer passed in is NULL - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NO_FREE_IDS if there are already the max queues created - * @retval #OS_ERR_NAME_TAKEN if the name is already being used on another queue - * @retval #OS_QUEUE_INVALID_SIZE if the queue depth exceeds the limit - * @retval #OS_ERROR if the OS create call fails - */ -int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, uint32 queue_depth, uint32 data_size, uint32 flags); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Deletes the specified message queue. - * - * This is the function used to delete a queue in the operating system. - * This also frees the respective queue_id to be used again when another queue is created. - * - * @note If There are messages on the queue, they will be lost and any subsequent - * calls to QueueGet or QueuePut to this queue will result in errors - * - * @param[in] queue_id The object ID to delete - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in does not exist - * @retval #OS_ERROR if the OS call to delete the queue fails - */ -int32 OS_QueueDelete(osal_id_t queue_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Receive a message on a message queue - * - * If a message is pending, it is returned immediately. Otherwise the calling task - * will block until a message arrives or the timeout expires. - * - * @param[in] queue_id The object ID to operate on - * @param[out] data The buffer to store the received message - * @param[in] size The size of the data buffer - * @param[out] size_copied Set to the actual size of the message - * @param[in] timeout The maximum amount of time to block, or OS_PEND to wait forever - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the given ID does not exist - * @retval #OS_INVALID_POINTER if a pointer passed in is NULL - * @retval #OS_QUEUE_EMPTY if the Queue has no messages on it to be recieved - * @retval #OS_QUEUE_TIMEOUT if the timeout was OS_PEND and the time expired - * @retval #OS_QUEUE_INVALID_SIZE if the size copied from the queue was not correct - */ -int32 OS_QueueGet(osal_id_t queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Put a message on a message queue. - * - * @param[in] queue_id The object ID to operate on - * @param[in] data The buffer containing the message to put - * @param[in] size The size of the data buffer - * @param[in] flags Currently reserved/unused, should be passed as 0 - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the queue id passed in is not a valid queue - * @retval #OS_INVALID_POINTER if the data pointer is NULL - * @retval #OS_QUEUE_FULL if the queue cannot accept another message - * @retval #OS_ERROR if the OS call returns an error - */ -int32 OS_QueuePut(osal_id_t queue_id, const void *data, uint32 size, uint32 flags); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Find an existing queue ID by name - * - * This function tries to find a queue Id given the name of the queue. The - * id of the queue is passed back in queue_id. - * - * @param[out] queue_id will be set to the ID of the existing resource - * @param[in] queue_name the name of the existing resource to find - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if the name or id pointers are NULL - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NAME_NOT_FOUND the name was not found in the table - */ -int32 OS_QueueGetIdByName(osal_id_t *queue_id, const char *queue_name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Fill a property object buffer with details regarding the resource - * - * This function will pass back a pointer to structure that contains - * all of the relevant info (name and creator) about the specified queue. - * - * @param[in] queue_id The object ID to operate on - * @param[out] queue_prop The property object buffer to fill - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if queue_prop is NULL - * @retval #OS_ERR_INVALID_ID if the ID given is not a valid queue - */ -int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop); -/**@}*/ - -/** @defgroup OSAPISem OSAL Semaphore APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Creates a binary semaphore - * - * Creates a binary semaphore with initial value specified by - * sem_initial_value and name specified by sem_name. sem_id will be - * returned to the caller - * - * @param[out] sem_id will be set to the non-zero ID of the newly-created resource - * @param[in] sem_name the name of the new resource to create - * @param[in] sem_initial_value the initial value of the binary semaphore - * @param[in] options Reserved for future use, should be passed as 0. - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if sen name or sem_id are NULL - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NO_FREE_IDS if all of the semaphore ids are taken - * @retval #OS_ERR_NAME_TAKEN if this is already the name of a binary semaphore - * @retval #OS_SEM_FAILURE if the OS call failed - */ -int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Unblock all tasks pending on the specified semaphore - * - * The function unblocks all tasks pending on the specified semaphore. However, - * this function does not change the state of the semaphore. - * - * @param[in] sem_id The object ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a binary semaphore - * @retval #OS_SEM_FAILURE if an unspecified failure occurs - */ -int32 OS_BinSemFlush(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Increment the semaphore value - * - * The function unlocks the semaphore referenced by sem_id by performing - * a semaphore unlock operation on that semaphore. If the semaphore value - * resulting from this operation is positive, then no threads were blocked - * waiting for the semaphore to become unlocked; the semaphore value is - * simply incremented for this semaphore. - * - * @param[in] sem_id The object ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_SEM_FAILURE the semaphore was not previously initialized or is not - * in the array of semaphores defined by the system - * @retval #OS_ERR_INVALID_ID if the id passed in is not a binary semaphore - */ -int32 OS_BinSemGive(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Decrement the semaphore value - * - * The locks the semaphore referenced by sem_id by performing a - * semaphore lock operation on that semaphore. If the semaphore value - * is currently zero, then the calling thread shall not return from - * the call until it either locks the semaphore or the call is - * interrupted. - * - * @param[in] sem_id The object ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID the Id passed in is not a valid binary semaphore - * @retval #OS_SEM_FAILURE if the OS call failed - */ -int32 OS_BinSemTake(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Decrement the semaphore value with a timeout - * - * The function locks the semaphore referenced by sem_id. However, - * if the semaphore cannot be locked without waiting for another process - * or thread to unlock the semaphore, this wait shall be terminated when - * the specified timeout, msecs, expires. - * - * @param[in] sem_id The object ID to operate on - * @param[in] msecs The maximum amount of time to block, in milliseconds - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_SEM_TIMEOUT if semaphore was not relinquished in time - * @retval #OS_SEM_FAILURE the semaphore was not previously initialized or is not - * in the array of semaphores defined by the system - * @retval #OS_ERR_INVALID_ID if the ID passed in is not a valid semaphore ID - */ -int32 OS_BinSemTimedWait(osal_id_t sem_id, uint32 msecs); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Deletes the specified Binary Semaphore - * - * This is the function used to delete a binary semaphore in the operating system. - * This also frees the respective sem_id to be used again when another semaphore is created. - * - * @param[in] sem_id The object ID to delete - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore - * @retval #OS_SEM_FAILURE the OS call failed - */ -int32 OS_BinSemDelete(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Find an existing semaphore ID by name - * - * This function tries to find a binary sem Id given the name of a bin_sem - * The id is returned through sem_id - * - * @param[out] sem_id will be set to the ID of the existing resource - * @param[in] sem_name the name of the existing resource to find - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER is semid or sem_name are NULL pointers - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table - */ -int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Fill a property object buffer with details regarding the resource - * - * This function will pass back a pointer to structure that contains - * all of the relevant info( name and creator) about the specified binary - * semaphore. - * - * @param[in] sem_id The object ID to operate on - * @param[out] bin_prop The property object buffer to fill - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid semaphore - * @retval #OS_INVALID_POINTER if the bin_prop pointer is null - */ -int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Creates a counting semaphore - * - * Creates a counting semaphore with initial value specified by - * sem_initial_value and name specified by sem_name. sem_id will be - * returned to the caller - * - * @param[out] sem_id will be set to the non-zero ID of the newly-created resource - * @param[in] sem_name the name of the new resource to create - * @param[in] sem_initial_value the initial value of the counting semaphore - * @param[in] options Reserved for future use, should be passed as 0. - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if sen name or sem_id are NULL - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NO_FREE_IDS if all of the semaphore ids are taken - * @retval #OS_ERR_NAME_TAKEN if this is already the name of a counting semaphore - * @retval #OS_SEM_FAILURE if the OS call failed - * @retval #OS_INVALID_SEM_VALUE if the semaphore value is too high - */ -int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Increment the semaphore value - * - * The function unlocks the semaphore referenced by sem_id by performing - * a semaphore unlock operation on that semaphore. If the semaphore value - * resulting from this operation is positive, then no threads were blocked - * waiting for the semaphore to become unlocked; the semaphore value is - * simply incremented for this semaphore. - * - * @param[in] sem_id The object ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_SEM_FAILURE the semaphore was not previously initialized or is not - * in the array of semaphores defined by the system - * @retval #OS_ERR_INVALID_ID if the id passed in is not a counting semaphore - */ -int32 OS_CountSemGive(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Decrement the semaphore value - * - * The locks the semaphore referenced by sem_id by performing a - * semaphore lock operation on that semaphore. If the semaphore value - * is currently zero, then the calling thread shall not return from - * the call until it either locks the semaphore or the call is - * interrupted. - * - * @param[in] sem_id The object ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID the Id passed in is not a valid counting semaphore - * @retval #OS_SEM_FAILURE if the OS call failed - */ -int32 OS_CountSemTake(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Decrement the semaphore value with timeout - * - * The function locks the semaphore referenced by sem_id. However, - * if the semaphore cannot be locked without waiting for another process - * or thread to unlock the semaphore, this wait shall be terminated when - * the specified timeout, msecs, expires. - * - * @param[in] sem_id The object ID to operate on - * @param[in] msecs The maximum amount of time to block, in milliseconds - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_SEM_TIMEOUT if semaphore was not relinquished in time - * @retval #OS_SEM_FAILURE the semaphore was not previously initialized or is not - * in the array of semaphores defined by the system - * @retval #OS_ERR_INVALID_ID if the ID passed in is not a valid semaphore ID - */ -int32 OS_CountSemTimedWait(osal_id_t sem_id, uint32 msecs); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Deletes the specified counting Semaphore. - * - * @param[in] sem_id The object ID to delete - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid counting semaphore - * @retval #OS_SEM_FAILURE the OS call failed - */ -int32 OS_CountSemDelete(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Find an existing semaphore ID by name - * - * This function tries to find a counting sem Id given the name of a count_sem - * The id is returned through sem_id - * - * @param[out] sem_id will be set to the ID of the existing resource - * @param[in] sem_name the name of the existing resource to find - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER is semid or sem_name are NULL pointers - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table - */ -int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Fill a property object buffer with details regarding the resource - * - * This function will pass back a pointer to structure that contains - * all of the relevant info( name and creator) about the specified counting - * semaphore. - * - * @param[in] sem_id The object ID to operate on - * @param[out] count_prop The property object buffer to fill - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid semaphore - * @retval #OS_INVALID_POINTER if the count_prop pointer is null - */ -int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Creates a mutex semaphore - * - * Mutex semaphores are always created in the unlocked (full) state. - * - * @param[out] sem_id will be set to the non-zero ID of the newly-created resource - * @param[in] sem_name the name of the new resource to create - * @param[in] options reserved for future use. Should be passed as 0. - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if sem_id or sem_name are NULL - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NO_FREE_IDS if there are no more free mutex Ids - * @retval #OS_ERR_NAME_TAKEN if there is already a mutex with the same name - * @retval #OS_SEM_FAILURE if the OS call failed - */ -int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Releases the mutex object referenced by sem_id. - * - * If there are threads blocked on the mutex object referenced by - * mutex when this function is called, resulting in the mutex becoming - * available, the scheduling policy shall determine which thread shall - * acquire the mutex. - * - * @param[in] sem_id The object ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid mutex - * @retval #OS_SEM_FAILURE if an unspecified error occurs - */ -int32 OS_MutSemGive(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Acquire the mutex object referenced by sem_id. - * - * If the mutex is already locked, the calling thread shall - * block until the mutex becomes available. This operation shall - * return with the mutex object referenced by mutex in the locked state - * with the calling thread as its owner. - * - * @param[in] sem_id The object ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_SEM_FAILURE if the semaphore was not previously initialized or is - * not in the array of semaphores defined by the system - * @retval #OS_ERR_INVALID_ID the id passed in is not a valid mutex - */ -int32 OS_MutSemTake(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Deletes the specified Mutex Semaphore. - * - * Delete the semaphore. This also frees the respective sem_id such that it can be - * used again when another is created. - * - * @param[in] sem_id The object ID to delete - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid mutex - * @retval #OS_SEM_FAILURE if the OS call failed - */ -int32 OS_MutSemDelete(osal_id_t sem_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Find an existing mutex ID by name - * - * This function tries to find a mutex sem Id given the name of a mut_sem. - * The id is returned through sem_id - * - * @param[out] sem_id will be set to the ID of the existing resource - * @param[in] sem_name the name of the existing resource to find - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER is semid or sem_name are NULL pointers - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table - */ -int32 OS_MutSemGetIdByName(osal_id_t *sem_id, const char *sem_name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Fill a property object buffer with details regarding the resource - * - * This function will pass back a pointer to structure that contains - * all of the relevant info( name and creator) about the specified mutex - * semaphore. - * - * @param[in] sem_id The object ID to operate on - * @param[out] mut_prop The property object buffer to fill - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid semaphore - * @retval #OS_INVALID_POINTER if the mut_prop pointer is null - */ -int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop); -/**@}*/ - -/** @defgroup OSAPITime OSAL Time APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Get the local time - * - * This function gets the local time from the underlying OS. - * - * @note Mission time management typically uses the cFE Time Service - * - * @param[out] time_struct An OS_time_t that will be set to the current time - * - * @return Get local time status, see @ref OSReturnCodes - */ -int32 OS_GetLocalTime(OS_time_t *time_struct); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Set the local time - * - * This function sets the local time on the underlying OS. - * - * @note Mission time management typically uses the cFE Time Services - * - * @param[in] time_struct An OS_time_t containing the current time - * - * @return Set local time status, see @ref OSReturnCodes - */ -int32 OS_SetLocalTime(OS_time_t *time_struct); -/**@}*/ - -/** @defgroup OSAPIHeap OSAL Heap APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Return current info on the heap - * - * @param[out] heap_prop Storage buffer for heap info - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop); -/**@}*/ - -/** @defgroup OSAPIError OSAL Error Info APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Convert an error number to a string - * - * @param[in] error_num Error number to convert - * @param[out] err_name Buffer to store error string - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name); -/**@}*/ - -/** @defgroup OSAPISelect OSAL Select APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Wait for events across multiple file handles - * - * Wait for any of the given sets of IDs to be become readable or writable - * - * This function will block until any of the following occurs: - * - At least one OSAL ID in the ReadSet is readable - * - At least one OSAL ID in the WriteSet is writable - * - The timeout has elapsed - * - * The sets are input/output parameters. On entry, these indicate the - * file handle(s) to wait for. On exit, these are set to the actual - * file handle(s) that have activity. - * - * If the timeout occurs this returns an error code and all output sets - * should be empty. - * - * @note This does not lock or otherwise protect the file handles in the - * given sets. If a filehandle supplied via one of the FdSet arguments - * is closed or modified by another while this function is in progress, - * the results are undefined. Because of this limitation, it is recommended - * to use OS_SelectSingle() whenever possible. - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Wait for events on a single file handle - * - * Wait for a single OSAL filehandle to change state - * - * This function can be used to wait for a single OSAL stream ID - * to become readable or writable. On entry, the "StateFlags" - * parameter should be set to the desired state (OS_STREAM_STATE_READABLE - * and/or OS_STREAM_STATE_WRITABLE) and upon return the flags - * will be set to the state actually detected. - * - * As this operates on a single ID, the filehandle is protected - * during this call, such that another thread accessing the same - * handle will return an error. However, it is important to note that - * once the call returns then other threads may then also read/write - * and affect the state before the current thread can service it. - * - * To mitigate this risk the application may prefer to use - * the OS_TimedRead/OS_TimedWrite calls. - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SelectSingle(osal_id_t objid, uint32 *StateFlags, int32 msecs); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Clear a FdSet structure - * - * After this call the set will contain no OSAL IDs - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SelectFdZero(OS_FdSet *Set); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Add an ID to an FdSet structure - * - * After this call the set will contain the given OSAL ID - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SelectFdAdd(OS_FdSet *Set, osal_id_t objid); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Clear an ID from an FdSet structure - * - * After this call the set will no longer contain the given OSAL ID - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SelectFdClear(OS_FdSet *Set, osal_id_t objid); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Check if an FdSet structure contains a given ID - * - * @return Boolean set status - * @retval true FdSet structure contains ID - * @retval false FDSet structure does not contain ID - */ -bool OS_SelectFdIsSet(OS_FdSet *Set, osal_id_t objid); -/**@}*/ - -/** @defgroup OSAPIPrintf OSAL Printf APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Abstraction for the system printf() call - * - * This function abstracts out the printf type statements. This is - * useful for using OS- specific thats that will allow non-polled - * print statements for the real time systems. - * - * Operates in a manner similar to the printf() call defined by the standard C - * library and takes all the parameters and formatting options of printf. - * This abstraction may implement additional buffering, if necessary, - * to improve the real-time performance of the call. - * - * Strings (including terminator) longer than #OS_BUFFER_SIZE will be truncated. - * - * The output of this routine also may be dynamically enabled or disabled by - * the OS_printf_enable() and OS_printf_disable() calls, respectively. - * - * @param[in] string Format string, followed by additional arguments - */ -void OS_printf(const char *string, ...) OS_PRINTF(1, 2); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief This function disables the output from OS_printf. - */ -void OS_printf_disable(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief This function enables the output from OS_printf. - * - */ -void OS_printf_enable(void); -/**@}*/ - -/**************************************************************************************** - BSP LOW-LEVEL IMPLEMENTATION FUNCTIONS - ****************************************************************************************/ - -/*---------------------------------------------------------------- - Function: OS_BSP_GetArgC - - Purpose: Obtain the number of boot arguments passed from the bootloader - or shell if supported by the platform - - Returns: The number of boot arguments, or 0 if no arguments were passed - or not supported by the BSP. - ------------------------------------------------------------------*/ -uint32 OS_BSP_GetArgC(void); - -/*---------------------------------------------------------------- - Function: OS_BSP_GetArgV - - Purpose: Obtain an array of boot argument strings passed from the bootloader - or shell if supported by the platform - - Returns: Pointer to char* array containing the argument strings, or NULL if - no arguments are available or not supported by the BSP. - - The array is sized according to OS_BSP_GetArgC() - ------------------------------------------------------------------*/ -char *const *OS_BSP_GetArgV(void); - -/*---------------------------------------------------------------- - Function: OS_BSP_SetExitCode - - Purpose: Sets the status to be returned to the shell or bootloader - if supported by the platform. The value is an integer with - platform and application-defined meaning, but BSP's should - attempt to provide consistent meaning for the following values - - OS_SUCCESS: normal status (default) - OS_ERROR: any abnormal status - - Other more specific status values may be passed, with - implementation-defined behavior. Depending on the system - capabilities, the BSP implementation may either pass the - value through as-is, translate it to defined value, or - ignore it. - - Note this does NOT cause the application to exit, it only - sets the state that will be returned if/when the application - exits itself at a future time. - - ------------------------------------------------------------------*/ -void OS_BSP_SetExitCode(int32 code); + * BACKWARD COMPATIBILITY HEADER + * + * OSAPI headers have beens split into subsystem-based components. + * + * This header is now just a wrapper that includes the same general + * set of components that this file traditionally supplied. + */ +#include "osapi-common.h" +#include "osapi-idmap.h" +#include "osapi-task.h" +#include "osapi-queue.h" +#include "osapi-binsem.h" +#include "osapi-countsem.h" +#include "osapi-mutex.h" +#include "osapi-clock.h" +#include "osapi-heap.h" +#include "osapi-error.h" +#include "osapi-select.h" +#include "osapi-printf.h" +#include "osapi-bsp.h" #endif diff --git a/src/os/inc/osapi-os-filesys.h b/src/os/inc/osapi-os-filesys.h index 764ae0d4e..a786261ee 100644 --- a/src/os/inc/osapi-os-filesys.h +++ b/src/os/inc/osapi-os-filesys.h @@ -30,891 +30,20 @@ #ifndef _osapi_filesys_ #define _osapi_filesys_ -/** @defgroup OSFileAccess OSAL File Access Option Defines - * @{ - */ -#define OS_READ_ONLY 0 /**< Read only file access */ -#define OS_WRITE_ONLY 1 /**< Write only file access */ -#define OS_READ_WRITE 2 /**< Read write file access */ -/**@}*/ - -/** @defgroup OSFileOffset OSAL Refernce Point For Seek Offset Defines - * @{ - */ -#define OS_SEEK_SET 0 /**< Seek offset set */ -#define OS_SEEK_CUR 1 /**< Seek offset current */ -#define OS_SEEK_END 2 /**< Seek offset end */ -/**@}*/ - -#define OS_CHK_ONLY 0 /**< Unused, API takes bool */ -#define OS_REPAIR 1 /**< Unused, API takes bool */ - -/* -** Length of a Device and Volume name -*/ -#define OS_FS_DEV_NAME_LEN 32 /**< Device name length */ -#define OS_FS_PHYS_NAME_LEN 64 /**< Physical drive name length */ -#define OS_FS_VOL_NAME_LEN 32 /**< Volume name length */ - -/** - * @brief Maximum length of a local/native path name string - * - * This is a concatenation of the OSAL virtual path with the system - * mount point or device name - */ -#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) - -/** @addtogroup OSReturnCodes - * @{ - */ -/* -** Defines for File System Calls -*/ -/* - * NOTE - these values used to overlap with the - * other OSAPI error codes. They now start at -100 - * to avoid this overlap. - */ -#define OS_FS_ERR_PATH_TOO_LONG (-103) /**< @brief FS path too long */ -#define OS_FS_ERR_NAME_TOO_LONG (-104) /**< @brief FS name too long */ -#define OS_FS_ERR_DRIVE_NOT_CREATED (-106) /**< @brief FS drive not created */ -#define OS_FS_ERR_DEVICE_NOT_FREE (-107) /**< @brief FS device not free */ -#define OS_FS_ERR_PATH_INVALID (-108) /**< @brief FS path invalid */ - -/**@}*/ - -/** @brief OSAL file system info */ -typedef struct -{ - uint32 MaxFds; /**< @brief Total number of file descriptors */ - uint32 FreeFds; /**< @brief Total number that are free */ - uint32 MaxVolumes; /**< @brief Maximum number of volumes */ - uint32 FreeVolumes; /**< @brief Total number of volumes free */ -} os_fsinfo_t; - -/** @brief OSAL file properties */ -typedef struct -{ - char Path[OS_MAX_PATH_LEN]; - osal_id_t User; - uint8 IsValid; /* For backward compatibility -- always true if OS_FDGetInfo returned true */ -} OS_file_prop_t; - -/** - * @brief File system status - * - * @note This used to be directly typedef'ed to the "struct stat" from the C library - * - * Some C libraries (glibc in particular) actually define member names to reference into - * sub-structures, so attempting to reuse a name like "st_mtime" might not work. - */ -typedef struct -{ - uint32 FileModeBits; - int32 FileTime; - uint32 FileSize; -} os_fstat_t; - -/** - * @brief File stat mode bits - * - * We must also define replacements for the stat structure's mode bits. - * This is currently just a small subset since the OSAL just presents a very - * simplified view of the filesystem to the upper layers. And since not all - * OS'es are POSIX, the more POSIX-specific bits are not relevant anyway. - */ -enum -{ - OS_FILESTAT_MODE_EXEC = 0x00001, - OS_FILESTAT_MODE_WRITE = 0x00002, - OS_FILESTAT_MODE_READ = 0x00004, - OS_FILESTAT_MODE_DIR = 0x10000 -}; - -/** @brief Access file stat mode bits */ -#define OS_FILESTAT_MODE(x) ((x).FileModeBits) -/** @brief File stat is directory logical */ -#define OS_FILESTAT_ISDIR(x) ((x).FileModeBits & OS_FILESTAT_MODE_DIR) -/** @brief File stat is executable logical */ -#define OS_FILESTAT_EXEC(x) ((x).FileModeBits & OS_FILESTAT_MODE_EXEC) -/** @brief File stat is write enabled logical */ -#define OS_FILESTAT_WRITE(x) ((x).FileModeBits & OS_FILESTAT_MODE_WRITE) -/** @brief File stat is read enabled logical */ -#define OS_FILESTAT_READ(x) ((x).FileModeBits & OS_FILESTAT_MODE_READ) -/** @brief Access file stat size field */ -#define OS_FILESTAT_SIZE(x) ((x).FileSize) -/** @brief Access file stat time field */ -#define OS_FILESTAT_TIME(x) ((x).FileTime) - -/** @brief Directory entry */ -typedef struct -{ - char FileName[OS_MAX_FILE_NAME]; -} os_dirent_t; - -/** - * @brief Flags that can be used with opening of a file (bitmask) - */ -typedef enum -{ - OS_FILE_FLAG_NONE = 0x00, - OS_FILE_FLAG_CREATE = 0x01, - OS_FILE_FLAG_TRUNCATE = 0x02, -} OS_file_flag_t; - -/** @brief Access filename part of the dirent structure */ -#define OS_DIRENTRY_NAME(x) ((x).FileName) - -/* - * Exported Functions - */ - -/** @defgroup OSAPIFile OSAL Standard File APIs - * @{ - */ - -#ifndef OSAL_OMIT_DEPRECATED - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Creates a file specified by path - * - * Creates a file specified by const char *path, with read/write - * permissions by access. The file is also automatically opened by the - * create call. - * - * @param[in] path File name to create - * @param[in] access Intended access mode - see @ref OSFileAccess - * - * @note Valid handle IDs are never negative. Failure of this - * call can be checked by testing if the result is less than 0. - * - * @return A file handle ID or appropriate error code, see @ref OSReturnCodes - * @retval #OS_INVALID_POINTER if path is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if path exceeds the maximum number of chars - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long - * @retval #OS_ERROR if permissions are unknown or OS call fails - * @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left - * - * @deprecated Replaced by OS_OpenCreate() with flags set to - * OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE. - */ -int32 OS_creat(const char *path, int32 access); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Opens a file - * - * Opens a file. - * - * @param[in] path File name to create - * @param[in] access Intended access mode - see @ref OSFileAccess - * @param[in] mode The file permissions. This parameter is passed through to the - * native open call, but will be ignored. The file mode (or permissions) - * are ignored by the POSIX open call when the O_CREAT access flag is not passed in. - * - * @note Valid handle IDs are never negative. Failure of this - * call can be checked by testing if the result is less than 0. - * - * @return A file handle ID or appropriate error code, see @ref OSReturnCodes - * @retval #OS_INVALID_POINTER if path is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if path exceeds the maximum number of chars - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long - * @retval #OS_ERROR if permissions are unknown or OS call fails - * @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left - * - * @deprecated Replaced by OS_OpenCreate() with flags set to - * OS_FILE_FLAG_NONE. - */ -int32 OS_open(const char *path, int32 access, uint32 mode); - +#ifdef OSAL_OMIT_DEPRECATED +#error This header header is deprecated #endif -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Open or create a file - * - * Implements the same as OS_open/OS_creat but follows the OSAL paradigm - * of outputting the ID/descriptor separately from the return value, rather - * than relying on the user to convert it back. - * - * @param[out] filedes The handle ID - * @param[in] path File name to create or open - * @param[in] flags The file permissions - see @ref OS_file_flag_t - * @param[in] access Intended access mode - see @ref OSFileAccess - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if the command was not executed properly - */ -int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Closes an open file handle - * - * This closes regular file handles and any other file-like resource, such as - * network streams or pipes. - * - * @param[in] filedes The handle ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if file descriptor could not be closed - * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid - */ -int32 OS_close(osal_id_t filedes); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Read from a file handle - * - * Reads up to nbytes from a file, and puts them into buffer. - * - * @param[in] filedes The handle ID to operate on - * @param[out] buffer Storage location for file data - * @param[in] nbytes Maximum number of bytes to read - * - * @note All OSAL error codes are negative int32 values. Failure of this - * call can be checked by testing if the result is less than 0. - * - * @return A non-negative byte count or appropriate error code, see @ref OSReturnCodes - * @retval #OS_INVALID_POINTER if buffer is a null pointer - * @retval #OS_ERROR if OS call failed - * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid - */ -int32 OS_read(osal_id_t filedes, void *buffer, uint32 nbytes); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Write to a file handle - * - * Writes to a file. copies up to a maximum of nbytes of buffer to the file - * described in filedes - * - * @param[in] filedes The handle ID to operate on - * @param[in] buffer Source location for file data - * @param[in] nbytes Maximum number of bytes to read - * - * @note All OSAL error codes are negative int32 values. Failure of this - * call can be checked by testing if the result is less than 0. - * - * @return A non-negative byte count or appropriate error code, see @ref OSReturnCodes - * @retval #OS_INVALID_POINTER if buffer is NULL - * @retval #OS_ERROR if OS call failed - * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid - */ -int32 OS_write(osal_id_t filedes, const void *buffer, uint32 nbytes); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief File/Stream input read with a timeout - * - * This implements a time-limited read and is primarily intended for use with - * sockets but may also work with any other stream-like resource that the underlying - * OS supports. - * - * If data is immediately available on the file/socket, this will return that data - * along with the actual number of bytes that were immediately available. It will - * not block. - * - * If no data is immediately available, this will wait up to the given timeout for - * data to appear. If no data appears within the timeout period, then this returns - * an error code (not zero). - * - * In all cases this will return successfully as soon as at least 1 byte of actual - * data is available. It will not attempt to read the entire input buffer. - * - * If an EOF condition occurs prior to timeout, this function returns zero. - * - * @param[in] filedes The handle ID to operate on - * @param[in] buffer Source location for file data - * @param[in] nbytes Maximum number of bytes to read - * @param[in] timeout Maximum time to wait, in milliseconds (OS_PEND = forever) - * - * @return Byte count on success, zero for timeout, or appropriate error code, - * see @ref OSReturnCodes - */ -int32 OS_TimedRead(osal_id_t filedes, void *buffer, uint32 nbytes, int32 timeout); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief File/Stream output write with a timeout - * - * This implements a time-limited write and is primarily intended for use with - * sockets but may also work with any other stream-like resource that the underlying - * OS supports. - * - * If output buffer space is immediately available on the file/socket, this will - * place data into the buffer and return the actual number of bytes that were - * queued for output. It will not block. - * - * If no output buffer space is immediately available, this will wait up to the - * given timeout for space to become available. If no space becomes available within - * the timeout period, then this returns an error code (not zero). - * - * In all cases this will return successfully as soon as at least 1 byte of actual - * data is output. It will _not_ attempt to write the entire output buffer. - * - * If an EOF condition occurs prior to timeout, this function returns zero. - * - * @param[in] filedes The handle ID to operate on - * @param[in] buffer Source location for file data - * @param[in] nbytes Maximum number of bytes to read - * @param[in] timeout Maximum time to wait, in milliseconds (OS_PEND = forever) - * - * @return Byte count on success, zero for timeout, or appropriate error code, - * see @ref OSReturnCodes - */ -int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, uint32 nbytes, int32 timeout); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Changes the permissions of a file - * - * @param[in] path File to change - * @param[in] access Desired access mode - see @ref OSFileAccess - * - * @note Some file systems do not implement permissions - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_chmod(const char *path, uint32 access); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain information about a file or directory - * - * Returns information about a file or directory in a os_fstat_t structure - * - * @param[in] path The file to operate on - * @param[out] filestats Buffer to store file information - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if path or filestats is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if the path is too long to be stored locally - * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long to be stored - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_ERROR if the OS call failed - */ -int32 OS_stat(const char *path, os_fstat_t *filestats); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Seeks to the specified position of an open file - * - * Sets the read/write pointer to a specific offset in a specific file. - * - * @param[in] filedes The handle ID to operate on - * @param[in] offset The file offset to seek to - * @param[in] whence The reference point for offset, see @ref OSFileOffset - * - * @return Byte offset from the beginning of the file or appropriate error code, - see @ref OSReturnCodes - * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid - * @retval #OS_ERROR if OS call failed - */ -int32 OS_lseek(osal_id_t filedes, int32 offset, uint32 whence); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Removes a file from the file system - * - * Removes a given filename from the drive - * - * @note The behvior of this API on an open file is not defined at the OSAL level - * due to dependencies on the underlying OS which may or may not allow the related - * operation based on a varienty of potential configurations. For portability, - * it is recommended that applications ensure the file is closed prior to removal. - * - * @param[in] path The file to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if there is no device or the driver returns error - * @retval #OS_INVALID_POINTER if path is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if path is too long to be stored locally - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file to remove is too long - */ -int32 OS_remove(const char *path); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Renames a file - * - * Changes the name of a file, where the source and destination - * reside on the same file system. - * - * @note The behvior of this API on an open file is not defined at the OSAL level - * due to dependencies on the underlying OS which may or may not allow the related - * operation based on a varienty of potential configurations. For portability, - * it is recommended that applications ensure the file is closed prior to removal. - * - * @param[in] old_filename The original filename - * @param[in] new_filename The desired filename - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if the file could not be opened or renamed. - * @retval #OS_INVALID_POINTER if old or new are NULL - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally - * @retval #OS_FS_ERR_NAME_TOO_LONG if the new name is too long to be stored locally - */ -int32 OS_rename(const char *old_filename, const char *new_filename); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Copies a single file from src to dest - * - * @note The behvior of this API on an open file is not defined at the OSAL level - * due to dependencies on the underlying OS which may or may not allow the related - * operation based on a varienty of potential configurations. For portability, - * it is recommended that applications ensure the file is closed prior to removal. - * - * @param[in] src The source file to operate on - * @param[in] dest The destination file - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if the file could not be accessed - * @retval #OS_INVALID_POINTER if src or dest are NULL - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally - * @retval #OS_FS_ERR_NAME_TOO_LONG if the dest name is too long to be stored locally - */ -int32 OS_cp(const char *src, const char *dest); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Move a single file from src to dest - * - * This first attempts to rename the file, which is faster if - * the source and destination reside on the same file system. - * - * If this fails, it falls back to copying the file and removing - * the original. - * - * @note The behvior of this API on an open file is not defined at the OSAL level - * due to dependencies on the underlying OS which may or may not allow the related - * operation based on a varienty of potential configurations. For portability, - * it is recommended that applications ensure the file is closed prior to removal. - * - * @param[in] src The source file to operate on - * @param[in] dest The destination file - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if the file could not be renamed. - * @retval #OS_INVALID_POINTER if src or dest are NULL - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally - * @retval #OS_FS_ERR_NAME_TOO_LONG if the dest name is too long to be stored locally - */ -int32 OS_mv(const char *src, const char *dest); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain information about an open file - * - * Copies the information of the given file descriptor into a structure passed in - * - * @param[in] filedes The handle ID to operate on - * @param[out] fd_prop Storage buffer for file information - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid - */ -int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Checks to see if a file is open - * - * This function takes a filename and determines if the file is open. The function - * will return success if the file is open. - * - * @param[in] Filename The file to operate on - * - * @return OS_SUCCESS if the file is open, or appropriate error code - * @retval #OS_ERROR if the file is not open - */ -int32 OS_FileOpenCheck(const char *Filename); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Close all open files - * - * Closes All open files that were opened through the OSAL - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if one or more file close returned an error - */ -int32 OS_CloseAllFiles(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Close a file by filename - * - * Allows a file to be closed by name. - * This will only work if the name passed in is the same name used to open - * the file. - * - * @param[in] Filename The file to close - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_FS_ERR_PATH_INVALID if the file is not found - * @retval #OS_ERROR if the file close returned an error - */ -int32 OS_CloseFileByName(const char *Filename); -/**@}*/ - -/** @defgroup OSAPIDir OSAL Directory APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Opens a directory - * - * Prepares for reading the files within a directory - * - * @param[out] dir_id The non-zero handle ID of the directory - * @param[in] path The directory to open - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Closes an open directory - * - * The directory referred to by dir_id will be closed - * - * @param[in] dir_id The handle ID of the directory - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_DirectoryClose(osal_id_t dir_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Rewinds an open directory - * - * Resets a directory read handle back to the first file. - * - * @param[in] dir_id The handle ID of the directory - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_DirectoryRewind(osal_id_t dir_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Reads the next name in the directory - * - * Obtains directory entry data for the next file from an open directory - * - * @param[in] dir_id The handle ID of the directory - * @param[out] dirent Buffer to store directory entry information - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Makes a new directory - * - * Makes a directory specified by path. - * - * @param[in] path The new directory name - * @param[in] access The permissions for the directory (reserved for future use) - * - * @note Current implementations do not utilize the "access" parameter. Applications - * should still pass the intended value (#OS_READ_WRITE or #OS_READ_ONLY) to be compatible - * with future implementations. - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if path is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if the path is too long to be stored locally - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_ERROR if the OS call fails - */ -int32 OS_mkdir(const char *path, uint32 access); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Removes a directory from the file system. - * - * Removes a directory from the structure. - * The directory must be empty prior to this operation. - * - * @param[in] path The directory to remove - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if path is NULL - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_FS_ERR_PATH_TOO_LONG - * @retval #OS_ERROR if the directory remove operation failed - */ -int32 OS_rmdir(const char *path); -/**@}*/ - -/** @defgroup OSAPIFileSys OSAL File System Level APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Create a fixed mapping between an existing directory and a virtual OSAL mount point. - * - * This mimics the behavior of a "FS_BASED" entry in the VolumeTable but is registered - * at runtime. It is intended to be called by the PSP/BSP prior to starting the application. - * - * @param[out] filesys_id A non-zero OSAL ID reflecting the file system - * @param[in] phys_path The native system directory (an existing mount point) - * @param[in] virt_path The virtual mount point of this filesystem - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const char *virt_path); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Makes a file system on the target - * - * Makes a file system on the target. Highly dependent on underlying OS and - * dependent on OS volume table definition. - * - * @note The "volname" parameter of RAM disks should always begin with the string "RAM", - * e.g. "RAMDISK" or "RAM0","RAM1", etc if multiple devices are created. The underlying - * implementation uses this to select the correct filesystem type/format, and this may - * also be used to differentiate between RAM disks and real physical disks. - * - * @param[in] address The address at which to start the new disk. If address == 0 - * space will be allocated by the OS. - * @param[in] devname The underlying kernel device to use, if applicable. - * @param[in] volname The name of the volume (see note) - * @param[in] blocksize The size of a single block on the drive - * @param[in] numblocks The number of blocks to allocate for the drive - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_INVALID_POINTER if devname is NULL - * @retval #OS_FS_ERR_DRIVE_NOT_CREATED if the OS calls to create the the drive failed - * @retval #OS_FS_ERR_DEVICE_NOT_FREE if the volume table is full - * @retval #OS_SUCCESS on creating the disk - */ -int32 OS_mkfs(char *address, const char *devname, const char *volname, uint32 blocksize, uint32 numblocks); -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Mounts a file system - * - * Mounts a file system / block device at the given mount point. - * - * @param[in] devname The name of the drive to mount. devname is the same from #OS_mkfs - * @param[in] mountpoint The name to call this disk from now on - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_mount(const char *devname, const char *mountpoint); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Initializes an existing file system - * - * Initializes a file system on the target. - * - * @note The "volname" parameter of RAM disks should always begin with the string "RAM", - * e.g. "RAMDISK" or "RAM0","RAM1", etc if multiple devices are created. The underlying - * implementation uses this to select the correct filesystem type/format, and this may - * also be used to differentiate between RAM disks and real physical disks. - * - * @param[in] address The address at which to start the new disk. If address == 0, - * then space will be allocated by the OS - * @param[in] devname The underlying kernel device to use, if applicable. - * @param[in] volname The name of the volume (see note) - * @param[in] blocksize The size of a single block on the drive - * @param[in] numblocks The number of blocks to allocate for the drive - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if devname or volname are NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long - * @retval #OS_FS_ERR_DEVICE_NOT_FREE if the volume table is full - * @retval #OS_FS_ERR_DRIVE_NOT_CREATED on error - */ -int32 OS_initfs(char *address, const char *devname, const char *volname, uint32 blocksize, uint32 numblocks); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Removes a file system - * - * This function will remove or un-map the target file system. Note that this is not - * the same as un-mounting the file system. - * - * @param[in] devname The name of the "generic" drive - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if devname is NULL - * @retval #OS_ERROR is the drive specified cannot be located - */ -int32 OS_rmfs(const char *devname); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Unmounts a mounted file system - * - * This function will unmount a drive from the file system and make all open file - * descriptors useless. - * - * @note Any open file descriptors referencing this file system should - * be closed prior to unmounting a drive - * - * @param[in] mountpoint The mount point to remove from #OS_mount - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if name is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if the absolute path given is too long - * @retval #OS_ERROR if the OS calls failed - */ -int32 OS_unmount(const char *mountpoint); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain number of blocks free - * - * Returns the number of free blocks in a volume - * - * @param[in] name The device/path to operate on - * - * @return Block count or appropriate error code, see @ref OSReturnCodes - * @retval #OS_INVALID_POINTER if name is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long - * @retval #OS_ERROR if the OS call failed - */ -int32 OS_fsBlocksFree(const char *name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtains the number of free bytes in a volume - * - * Returns the number of free bytes in a volume - * - * @note uses a 64 bit data type to support filesystems that - * are greater than 4 Gigabytes - * - * @param[in] name The device/path to operate on - * @param[out] bytes_free The number of free bytes - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if name is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long - * @retval #OS_ERROR if the OS call failed - */ -int32 OS_fsBytesFree(const char *name, uint64 *bytes_free); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Checks the health of a file system and repairs it if necessary - * - * Checks the drives for inconsistencies and optionally also repairs it - * - * @note not all operating systems implement this function - * - * @param[in] name The device/path to operate on - * @param[in] repair Whether to also repair inconsistencies - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER Name is NULL - * @retval #OS_ERR_NOT_IMPLEMENTED @copybrief OS_ERR_NOT_IMPLEMENTED - * @retval #OS_ERROR @copybrief OS_ERROR - */ -int32 OS_chkfs(const char *name, bool repair); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtains the physical drive name associated with a mount point - * - * Returns the name of the physical volume associated with the drive, - * when given the OSAL mount point of the drive - * - * @param[out] PhysDriveName Buffer to store physical drive name - * @param[in] MountPoint OSAL mount point - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if either parameter is NULL - * @retval #OS_ERROR if the mountpoint could not be found - */ -int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Translates a OSAL Virtual file system path to a host Local path - * - * Translates a virtual path to an actual system path name - * - * @param[in] VirtualPath OSAL virtual path name - * @param[out] LocalPath Buffer to store native/translated path name - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if either parameter is NULL - */ -int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Returns information about the file system - * - * Returns information about the file system in an os_fsinfo_t. - * This includes the number of open files and file systems - * - * @param[out] filesys_info Buffer to store filesystem information - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if filesys_info is NULL - */ -int32 OS_GetFsInfo(os_fsinfo_t *filesys_info); -/**@}*/ - -/** @defgroup OSAPIShell OSAL Shell APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Executes the command and sends output to a file - * - * Takes a shell command in and writes the output of that command to the specified file - * The output file must be opened previously with write access (OS_WRITE_ONLY or OS_READ_WRITE). +/* + * BACKWARD COMPATIBILITY HEADER * - * @param[in] Cmd Command to pass to shell - * @param[in] filedes File to send output to. + * OSAPI headers have beens split into subsystem-based components. * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if the command was not executed properly - * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + * This header is now just a wrapper that includes the same general + * set of components that this file traditionally supplied. */ -int32 OS_ShellOutputToFile(const char *Cmd, osal_id_t filedes); - -/**@}*/ +#include "osapi-file.h" +#include "osapi-filesys.h" +#include "osapi-shell.h" #endif diff --git a/src/os/inc/osapi-os-loader.h b/src/os/inc/osapi-os-loader.h index 811bc4cef..433b1d1a7 100644 --- a/src/os/inc/osapi-os-loader.h +++ b/src/os/inc/osapi-os-loader.h @@ -30,145 +30,18 @@ #ifndef _osapi_loader_ #define _osapi_loader_ -/* -** Defines -*/ +#ifdef OSAL_OMIT_DEPRECATED +#error This header header is deprecated +#endif /* -** Typedefs -*/ - -/** @brief OSAL module address properties */ -typedef struct -{ - uint32 valid; - uint32 flags; - cpuaddr code_address; - cpuaddr code_size; - cpuaddr data_address; - cpuaddr data_size; - cpuaddr bss_address; - cpuaddr bss_size; -} OS_module_address_t; - -/** @brief OSAL module properties */ -typedef struct -{ - cpuaddr entry_point; - cpuaddr host_module_id; - char filename[OS_MAX_PATH_LEN]; - char name[OS_MAX_API_NAME]; - OS_module_address_t addr; -} OS_module_prop_t; - -/** - * @brief Associates a single symbol name with a memory address. - * - * If the OS_STATIC_SYMBOL_TABLE feature is enabled, then - * an array of these structures should be provided by the - * application. When the application needs to find a symbol - * address, the static table will be checked in addition - * to (or instead of) the OS/library-provided lookup function. - * - * This static symbol allows systems that do not implement - * dynamic module loading to maintain the same semantics - * as dynamically loaded modules. - */ -typedef const struct -{ - const char *Name; - void (*Address)(void); - const char *Module; -} OS_static_symbol_record_t; - -/** @defgroup OSAPILoader OSAL Dynamic Loader and Symbol APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Find the Address of a Symbol - * - * This calls to the OS dynamic symbol lookup implementation, - * and/or checks a static symbol table for a matching symbol name. - * - * The static table is intended to support embedded targets that do - * not have module loading capability or have it disabled. - * - * @param[out] symbol_address Set to the address of the symbol - * @param[in] symbol_name Name of the symbol to look up - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if the symbol could not be found - * @retval #OS_INVALID_POINTER if one of the pointers passed in are NULL - */ -int32 OS_SymbolLookup(cpuaddr *symbol_address, const char *symbol_name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Dumps the system symbol table to a file - * - * Dumps the system symbol table to the specified filename - * - * @param[in] filename File to write to - * @param[in] size_limit Maximum number of bytes to write - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_NOT_IMPLEMENTED @copybrief OS_ERR_NOT_IMPLEMENTED - * @retval #OS_ERROR if the symbol table could not be read or dumped - */ -int32 OS_SymbolTableDump(const char *filename, uint32 size_limit); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Loads an object file - * - * Loads an object file into the running operating system - * - * @param[out] module_id Non-zero OSAL ID corresponding to the loaded module - * @param[in] module_name Name of module - * @param[in] filename File containing the object code to load - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if the module cannot be loaded - * @retval #OS_INVALID_POINTER if one of the parameters is NULL - * @retval #OS_ERR_NO_FREE_IDS if the module table is full - * @retval #OS_ERR_NAME_TAKEN if the name is in use - */ -int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *filename); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Unloads the module file - * - * Unloads the module file from the running operating system - * - * @param[in] module_id OSAL ID of the previously the loaded module - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERROR if the module is invalid or cannot be unloaded - */ -int32 OS_ModuleUnload(osal_id_t module_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain information about a module - * - * Returns information about the loadable module + * BACKWARD COMPATIBILITY HEADER * - * @param[in] module_id OSAL ID of the previously the loaded module - * @param[out] module_info Buffer to store module information + * OSAPI headers have beens split into subsystem-based components. * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the module id invalid - * @retval #OS_INVALID_POINTER if the pointer to the ModuleInfo structure is invalid + * This header is now just a wrapper that includes the same general + * set of components that this file traditionally supplied. */ -int32 OS_ModuleInfo(osal_id_t module_id, OS_module_prop_t *module_info); -/**@}*/ +#include "osapi-module.h" #endif diff --git a/src/os/inc/osapi-os-net.h b/src/os/inc/osapi-os-net.h index 5a270266f..6b18ca94e 100644 --- a/src/os/inc/osapi-os-net.h +++ b/src/os/inc/osapi-os-net.h @@ -30,377 +30,19 @@ #ifndef _osapi_network_ #define _osapi_network_ -/* NOTE - osconfig.h may optionally specify the value for OS_SOCADDR_MAX_LEN */ -#include - -/* - * The absolute maximum size of a network address - * - * The actual size varies by address type. - * - * This definition should be large enough to capture the - * largest address supported on the system. The default - * value here should be suitable for many use-cases while - * still keeping the address structure size within reason. - * - * The user may also provide a tuned value through osconfig.h - */ -#ifndef OS_SOCKADDR_MAX_LEN -#define OS_SOCKADDR_MAX_LEN 28 +#ifdef OSAL_OMIT_DEPRECATED +#error This header header is deprecated #endif /* - * -------------------------------------------------------------------------------------- - * Sockets API Data Types - * - * These data types are defined regardless of whether or not networking is compiled-in - * - * They are local to OSAL, they do not directly map to the library-provided types, and - * they do not occupy any space in the executable - * -------------------------------------------------------------------------------------- - */ - -/** @brief Socket domain */ -typedef enum -{ - OS_SocketDomain_INVALID, /**< @brief Invalid */ - OS_SocketDomain_INET, /**< @brief IPv4 address family, most commonly used) */ - OS_SocketDomain_INET6, /**< @brief IPv6 address family, depends on OS/network stack support */ - OS_SocketDomain_MAX /**< @brief Maximum */ -} OS_SocketDomain_t; - -/** @brief Socket type */ -typedef enum -{ - OS_SocketType_INVALID, /**< @brief Invalid */ - OS_SocketType_DATAGRAM, /**< @brief A connectionless, message-oriented socket */ - OS_SocketType_STREAM, /**< @brief A stream-oriented socket with the concept of a connection */ - OS_SocketType_MAX /**< @brief Maximum */ -} OS_SocketType_t; - -/** - * @brief Storage buffer for generic network address - * - * This is a union type that helps to ensure a minimum - * alignment value for the data storage, such that it can - * be cast to the system-specific type without - * increasing alignment requirements. - */ -typedef union -{ - uint8 Buffer[OS_SOCKADDR_MAX_LEN]; /**< @brief Ensures length of at least OS_SOCKADDR_MAX_LEN */ - uint32 AlignU32; /**< @brief Ensures uint32 alignment */ - void * AlignPtr; /**< @brief Ensures pointer alignment */ -} OS_SockAddrData_t; - -/** - * @brief Encapsulates a generic network address - * - * This is just an abstract buffer type that holds a network address. - * It is allocated for the worst-case size defined by OS_SOCKADDR_MAX_LEN, - * and the real size is stored within. - */ -typedef struct -{ - uint32 ActualLength; /**< @brief Length of the actual address data */ - OS_SockAddrData_t AddrData; /**< @brief Abstract Address data */ -} OS_SockAddr_t; - -/** - * @brief Encapsulates socket properties - * - * This is for consistency with other OSAL resource types. - * Currently no extra properties are exposed here but this - * could change in a future revision of OSAL as needed. - */ -typedef struct -{ - char name[OS_MAX_API_NAME]; /**< @brief Name of the socket */ - osal_id_t creator; /**< @brief OSAL TaskID which opened the socket */ -} OS_socket_prop_t; - -/** - * @defgroup OSAPISocketAddr OSAL Socket Address APIs - * - * These functions provide a means to manipulate network addresses in a manner that - * is (mostly) agnostic to the actual network address type. - * - * Every network address should be representable as a string (i.e. dotted decimal IP, etc). - * This can serve as a the "common denominator" to all address types. - * - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Initialize a socket address structure to hold an address of the given family - * - * The address is set to a suitable default value for the family. - * - * @param[out] Addr The address buffer to initialize - * @param[in] Domain The address family - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Get a string representation of a network host address - * - * The specific format of the output string depends on the address family. - * - * This string should be suitable to pass back into OS_SocketAddrFromString() - * which should recreate the same network address, and it should also - * be meaningful to a user of printed or logged as a C string. - * - * @note For IPv4, this would typically be the dotted-decimal format (X.X.X.X). - * - * @param[out] buffer Buffer to hold the output string - * @param[in] buflen Maximum length of the output string - * @param[in] Addr The network address buffer to convert - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SocketAddrToString(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Set a network host address from a string representation - * - * The specific format of the output string depends on the address family. - * - * The address structure should have been previously initialized using - * OS_SocketAddrInit() to set the address family type. - * - * @note For IPv4, this would typically be the dotted-decimal format (X.X.X.X). - * It is up to the discretion of the underlying implementation whether - * to accept hostnames, as this depends on the availability of DNS services. - * Since many embedded deployments do not have name services, this should - * not be relied upon. - * - * @param[out] Addr The address buffer to initialize - * @param[in] string The string to initialize the address from. - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SocketAddrFromString(OS_SockAddr_t *Addr, const char *string); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Get the port number of a network address - * - * For network prototcols that have the concept of a port number (such - * as TCP/IP and UDP/IP) this function gets the port number from the - * address structure. - * - * @param[out] PortNum Buffer to store the port number - * @param[in] Addr The network address buffer - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SocketAddrGetPort(uint16 *PortNum, const OS_SockAddr_t *Addr); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Set the port number of a network address - * - * For network prototcols that have the concept of a port number (such - * as TCP/IP and UDP/IP) this function sets the port number from the - * address structure. - * - * @param[in] PortNum The port number to set - * @param[out] Addr The network address buffer - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SocketAddrSetPort(OS_SockAddr_t *Addr, uint16 PortNum); -/**@}*/ - -/** - * @defgroup OSALAPISocket OSAL Socket Management APIs - * - * These functions are loosely related to the BSD Sockets API but made to be - * more consistent with other OSAL API functions. That is, they operate on - * OSAL IDs (32-bit opaque number values) and return an OSAL error code. - * - * OSAL Socket IDs are very closely related to File IDs and share the same ID - * number space. Additionally, the file OS_read() / OS_write() / OS_close() - * calls also work on sockets. - * - * Note that all of functions may return #OS_ERR_NOT_IMPLEMENTED if network support - * is not configured at compile time. - * - * @{ - */ - -/** - * @brief Opens a socket. - * - * A new, unconnected and unbound socket is allocated of the given domain and type. - * - * @param[out] sock_id Buffer to hold the non-zero OSAL ID - * @param[in] Domain The domain / address family of the socket (INET or INET6, etc) - * @param[in] Type The type of the socket (STREAM or DATAGRAM) - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_t Type); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Binds a socket to a given local address. - * - * The specified socket will be bound to the local address and port, if available. - * - * If the socket is connectionless, then it only binds to the local address. - * - * If the socket is connection-oriented (stream), then this will also put the - * socket into a listening state for incoming connections at the local address. - * - * @param[in] sock_id The socket ID - * @param[in] Addr The local address to bind to - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Connects a socket to a given remote address. - * - * The socket will be connected to the remote address and port, if available. - * This only applies to stream-oriented sockets. Calling this on a datagram - * socket will return an error (these sockets should use SendTo/RecvFrom). - * - * @param[in] sock_id The socket ID - * @param[in] Addr The remote address to connect to - * @param[in] timeout The maximum amount of time to wait, or OS_PEND to wait forever - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 timeout); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Waits for and accept the next incoming connection on the given socket - * - * This is used for sockets operating in a "server" role. The socket must be - * a stream type (connection-oriented) and previously bound to a local address - * using OS_SocketBind(). This will block the caller up to the given timeout - * or until an incoming connection request occurs, whichever happens first. - * - * The new stream connection is then returned to the caller and the original - * server socket ID can be reused for the next connection. - * - * @param[in] sock_id The server socket ID, previously bound using OS_SocketBind() - * @param[out] connsock_id The connection socket, a new ID that can be read/written - * @param[in] Addr The remote address of the incoming connection - * @param[in] timeout The maximum amount of time to wait, or OS_PEND to wait forever - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t *Addr, int32 timeout); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Reads data from a message-oriented (datagram) socket - * - * If a message is already available on the socket, this should immediately return - * that data without blocking. Otherwise, it may block up to the given timeout. - * - * @param[in] sock_id The socket ID, previously bound using OS_SocketBind() - * @param[out] buffer Pointer to message data receive buffer - * @param[in] buflen The maximum length of the message data to receive - * @param[out] RemoteAddr Buffer to store the remote network address (may be NULL) - * @param[in] timeout The maximum amount of time to wait, or OS_PEND to wait forever - * - * @return Count of actual bytes received or error status, see @ref OSReturnCodes - */ -int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Sends data to a message-oriented (datagram) socket - * - * This sends data in a non-blocking mode. If the socket is not currently able to - * queue the message, such as if its outbound buffer is full, then this returns - * an error code. - * - * @param[in] sock_id The socket ID, which must be of the datagram type - * @param[in] buffer Pointer to message data to send - * @param[in] buflen The length of the message data to send - * @param[in] RemoteAddr Buffer containing the remote network address to send to - * - * @return Count of actual bytes sent or error status, see @ref OSReturnCodes - */ -int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Gets an OSAL ID from a given name - * - * @note OSAL Sockets use generated names according to the address and type. - * - * @sa OS_SocketGetInfo() - * - * @param[out] sock_id Buffer to hold result - * @param[in] sock_name Name of socket to find - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER is id or name are NULL pointers - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table - */ -int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Gets information about an OSAL Socket ID - * - * OSAL Sockets use generated names according to the address and type. - * This allows applications to find the name of a given socket. - * - * @param[in] sock_id The socket ID - * @param[out] sock_prop Buffer to hold socket information - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid semaphore - * @retval #OS_INVALID_POINTER if the count_prop pointer is null - */ -int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Gets the network ID of the local machine - * - * The ID is an implementation-defined value and may not be consistent - * in meaning across different platform types. - * - * @note This API may be removed in a future version of OSAL due to - * inconsistencies between platforms. - * - * @return The ID or fixed value of -1 if the host id could not be found. - * Note it is not possible to differentiate between error codes and valid - * network IDs here. It is assumed, however, that -1 is never a valid ID. - */ -int32 OS_NetworkGetID(void); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Gets the local machine network host name - * - * If configured in the underlying network stack, - * this function retrieves the local hostname of the system. + * BACKWARD COMPATIBILITY HEADER * - * @param[out] host_name Buffer to hold name information - * @param[in] name_len Maximum length of host name buffer + * OSAPI headers have beens split into subsystem-based components. * - * @return Execution status, see @ref OSReturnCodes + * This header is now just a wrapper that includes the same general + * set of components that this file traditionally supplied. */ -int32 OS_NetworkGetHostName(char *host_name, uint32 name_len); -/**@}*/ +#include "osapi-sockets.h" +#include "osapi-network.h" #endif diff --git a/src/os/inc/osapi-os-timer.h b/src/os/inc/osapi-os-timer.h index 8cf2a2d58..7b27548f3 100644 --- a/src/os/inc/osapi-os-timer.h +++ b/src/os/inc/osapi-os-timer.h @@ -30,331 +30,19 @@ #ifndef _osapi_timer_ #define _osapi_timer_ -/* -** Typedefs -*/ -typedef void (*OS_TimerCallback_t)(osal_id_t timer_id); /**< @brief Timer callback */ -typedef uint32 (*OS_TimerSync_t)(uint32 timer_id); /**< @brief Timer sync */ - -/** @brief Timer properties */ -typedef struct -{ - char name[OS_MAX_API_NAME]; - osal_id_t creator; - uint32 start_time; - uint32 interval_time; - uint32 accuracy; - -} OS_timer_prop_t; - -/** @brief Time base properties */ -typedef struct -{ - char name[OS_MAX_API_NAME]; - osal_id_t creator; - uint32 nominal_interval_time; - uint32 freerun_time; - uint32 accuracy; -} OS_timebase_prop_t; - -/** @defgroup OSAPITimer OSAL Timer APIs - * @{ - */ - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Create an abstract Time Base resource - * - * An OSAL time base is an abstraction of a "timer tick" that can, in turn, be - * used for measurement of elapsed time between events. - * - * Time bases can be simulated by the operating system using the OS kernel-provided - * timing facilities, or based on a hardware timing source if provided by the BSP. - * - * A time base object has a servicing task associated with it, that runs at elevated - * priority and will thereby interrupt user-level tasks when timing ticks occur. - * - * If the external_sync function is passed as NULL, the operating system kernel - * timing resources will be utilized for a simulated timer tick. - * - * If the external_sync function is not NULL, this should point to a BSP-provided - * function that will block the calling task until the next tick occurs. This - * can be used for synchronizing with hardware events. - * - * @note When provisioning a tunable RTOS kernel, such as RTEMS, the kernel should - * be configured to support at least (OS_MAX_TASKS + OS_MAX_TIMEBASES) threads, - * to account for the helper threads associated with time base objects. - * - * @param[out] timebase_id A non-zero ID corresponding to the timebase resource - * @param[in] timebase_name The name of the time base - * @param[in] external_sync A synchronization function for BSP hardware-based timer ticks - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_TimeBaseCreate(osal_id_t *timebase_id, const char *timebase_name, OS_TimerSync_t external_sync); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Sets the tick period for simulated time base objects - * - * This sets the actual tick period for timing ticks that are - * simulated by the RTOS kernel (i.e. the "external_sync" parameter - * on the call to OS_TimeBaseCreate() is NULL). - * - * The RTOS will be configured to wake up the helper thread at the - * requested interval. - * - * This function has no effect for time bases that are using - * a BSP-provided external_sync function. - * - * @param[in] timebase_id The timebase resource to configure - * @param[in] start_time The amount of delay for the first tick, in microseconds. - * @param[in] interval_time The amount of delay between ticks, in microseconds. - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_TimeBaseSet(osal_id_t timebase_id, uint32 start_time, uint32 interval_time); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Deletes a time base object - * - * The helper task and any other resources associated with the time base - * abstraction will be freed. - * - * @param[in] timebase_id The timebase resource to delete - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_TimeBaseDelete(osal_id_t timebase_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Find the ID of an existing time base resource - * - * Given a time base name, find and output the ID associated with it. - * - * @param[out] timebase_id The timebase resource ID - * @param[in] timebase_name The name of the timebase resource to find - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if timebase_id or timebase_name are NULL pointers - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table - */ -int32 OS_TimeBaseGetIdByName(osal_id_t *timebase_id, const char *timebase_name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain information about a timebase resource - * - * Fills the buffer referred to by the timebase_prop parameter with - * relevant information about the time base resource. - * - * This function will pass back a pointer to structure that contains - * all of the relevant info( name and creator) about the specified timebase. - * - * @param[in] timebase_id The timebase resource ID - * @param[out] timebase_prop Buffer to store timebase properties - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid timebase - * @retval #OS_INVALID_POINTER if the timebase_prop pointer is null - */ -int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_prop); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Read the value of the timebase free run counter - * - * Poll the timer free-running time counter in a lightweight fashion. - * - * The free run count is a monotonically increasing value reflecting the - * total time elapsed since the timebase inception. Units are the - * same as the timebase itself, usually microseconds. - * - * Applications may quickly and efficiently calculate relative time - * differences by polling this value and subtracting the previous - * counter value. - * - * The absolute value of this counter is not relevant, because it - * will "roll over" after 2^32 units of time. For a timebase with - * microsecond units, this occurs approximately every 4294 seconds, - * or about 1.2 hours. - * - * @note To ensure consistency of results, the application should - * sample the value at a minimum of two times the roll over frequency, - * and calculate the difference between the consecutive samples. - * - * @param[in] timebase_id The timebase to operate on - * @param[out] freerun_val Buffer to store the free run counter - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid timebase - */ -int32 OS_TimeBaseGetFreeRun(osal_id_t timebase_id, uint32 *freerun_val); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Create a timer object - * - * A timer object is a resource that invokes the specified application-provided function - * upon timer expiration. Timers may be one-shot or periodic in nature. - * - * This function creates a dedicated (hidden) time base object to service this timer, - * which is created and deleted with the timer object itself. The internal time base - * is configured for an OS simulated timer tick at the same interval as the timer. - * - * @note clock_accuracy comes from the underlying OS tick value. The nearest integer - * microsecond value is returned, so may not be exact. - * - * @warning Depending on the OS, the callback_ptr function may be similar to an - * interrupt service routine. Calls that cause the code to block or require - * an application context (like sending events) are generally not supported. - * - * @param[out] timer_id The non-zero resource ID of the timer object - * @param[in] timer_name Name of the timer object - * @param[out] clock_accuracy Expected precision of the timer, in microseconds. This - * is the underlying tick value rounded to the nearest - * microsecond integer. - * @param[in] callback_ptr The function pointer of the timer callback or ISR that - * will be called by the timer. The user’s function is - * declared as follows: void timer_callback(uint32 timer_id) - * Where the timer_id is passed in to the function by the OSAL - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if any parameters are NULL - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NAME_TAKEN if the name is already in use by another timer. - * @retval #OS_ERR_NO_FREE_IDS if all of the timers are already allocated. - * @retval #OS_TIMER_ERR_INVALID_ARGS if the callback pointer is zero. - * @retval #OS_TIMER_ERR_UNAVAILABLE if the timer cannot be created. - */ -int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *clock_accuracy, - OS_TimerCallback_t callback_ptr); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Add a timer object based on an existing TimeBase resource - * - * A timer object is a resource that invokes the specified application-provided function - * upon timer expiration. Timers may be one-shot or periodic in nature. - * - * This function uses an existing time base object to service this timer, which must - * exist prior to adding the timer. The precision of the timer is the same - * as that of the underlying time base object. Multiple timer objects can be - * created referring to a single time base object. - * - * This routine also uses a different callback function prototype from OS_TimerCreate(), - * allowing a single opaque argument to be passed to the callback routine. - * The OSAL implementation does not use this parameter, and may be set NULL. - * - * @warning Depending on the OS, the callback_ptr function may be similar to an - * interrupt service routine. Calls that cause the code to block or require - * an application context (like sending events) are generally not supported. - * - * @param[out] timer_id The non-zero resource ID of the timer object - * @param[in] timer_name Name of the timer object - * @param[in] timebase_id The time base resource to use as a reference - * @param[in] callback_ptr Application-provided function to invoke - * @param[in] callback_arg Opaque argument to pass to callback function - * - * @return Execution status, see @ref OSReturnCodes - */ -int32 OS_TimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_t timebase_id, OS_ArgCallback_t callback_ptr, - void *callback_arg); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Configures a periodic or one shot timer - * - * This function programs the timer with a start time and an optional interval time. - * The start time is the time in microseconds when the user callback function will be - * called. If the interval time is non-zero, the timer will be reprogrammed with that - * interval in microseconds to call the user callback function periodically. If the start - * time and interval time are zero, the function will return an error. - * - * For a "one-shot" timer, the start_time configures the - * expiration time, and the interval_time should be passed as - * zero to indicate the timer is not to be automatically reset. - * - * @note The resolution of the times specified is limited to the clock accuracy - * returned in the OS_TimerCreate call. If the times specified in the start_msec - * or interval_msec parameters are less than the accuracy, they will be rounded - * up to the accuracy of the timer. - * - * @param[in] timer_id The timer ID to operate on - * @param[in] start_time Time in microseconds to the first expiration - * @param[in] interval_time Time in microseconds between subsequent intervals, value - * of zero will only call the user callback function once - * after the start_msec time. - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the timer_id is not valid. - * @retval #OS_TIMER_ERR_INTERNAL if there was an error programming the OS timer. - * @retval #OS_ERROR if both start time and interval time are zero. - */ -int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Deletes a timer resource - * - * The application callback associated with the timer will be stopped, - * and the resources freed for future use. - * - * @param[in] timer_id The timer ID to operate on - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the timer_id is invalid. - * @retval #OS_TIMER_ERR_INTERNAL if there was a problem deleting the timer in the host OS. - */ -int32 OS_TimerDelete(osal_id_t timer_id); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Locate an existing timer resource by name - * - * Outputs the ID associated with the given timer, if it exists. - * - * @param[out] timer_id The timer ID corresponding to the name - * @param[in] timer_name The timer name to find - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if timer_id or timer_name are NULL pointers - * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME - * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table - */ -int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name); +#ifdef OSAL_OMIT_DEPRECATED +#error This header header is deprecated +#endif -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Gets information about an existing timer - * - * This function takes timer_id, and looks it up in the OS table. It puts all of the - * information known about that timer into a structure pointer to by timer_prop. +/* + * BACKWARD COMPATIBILITY HEADER * - * @param[in] timer_id The timer ID to operate on - * @param[out] timer_prop Buffer containing timer properties - * - creator: the OS task ID of the task that created this timer - * - name: the string name of the timer - * - start_time: the start time in microseconds, if any - * - interval_time: the interval time in microseconds, if any - * - accuracy: the accuracy of the timer in microseconds + * OSAPI headers have beens split into subsystem-based components. * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid timer - * @retval #OS_INVALID_POINTER if the timer_prop pointer is null + * This header is now just a wrapper that includes the same general + * set of components that this file traditionally supplied. */ -int32 OS_TimerGetInfo(osal_id_t timer_id, OS_timer_prop_t *timer_prop); -/**@}*/ +#include "osapi-timebase.h" +#include "osapi-timer.h" #endif diff --git a/src/os/inc/osapi-printf.h b/src/os/inc/osapi-printf.h new file mode 100644 index 000000000..6e072419b --- /dev/null +++ b/src/os/inc/osapi-printf.h @@ -0,0 +1,71 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-printf.h + */ + +#ifndef OSAPI_PRINTF_H +#define OSAPI_PRINTF_H + +#include "osconfig.h" +#include "common_types.h" + +/** @defgroup OSAPIPrintf OSAL Printf APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Abstraction for the system printf() call + * + * This function abstracts out the printf type statements. This is + * useful for using OS- specific thats that will allow non-polled + * print statements for the real time systems. + * + * Operates in a manner similar to the printf() call defined by the standard C + * library and takes all the parameters and formatting options of printf. + * This abstraction may implement additional buffering, if necessary, + * to improve the real-time performance of the call. + * + * Strings (including terminator) longer than #OS_BUFFER_SIZE will be truncated. + * + * The output of this routine also may be dynamically enabled or disabled by + * the OS_printf_enable() and OS_printf_disable() calls, respectively. + * + * @param[in] string Format string, followed by additional arguments + */ +void OS_printf(const char *string, ...) OS_PRINTF(1, 2); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief This function disables the output from OS_printf. + */ +void OS_printf_disable(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief This function enables the output from OS_printf. + * + */ +void OS_printf_enable(void); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-queue.h b/src/os/inc/osapi-queue.h new file mode 100644 index 000000000..3bc5a877a --- /dev/null +++ b/src/os/inc/osapi-queue.h @@ -0,0 +1,166 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-queue.h + */ + +#ifndef OSAPI_QUEUE_H +#define OSAPI_QUEUE_H + +#include "osconfig.h" +#include "common_types.h" + +/** @brief OSAL queue properties */ +typedef struct +{ + char name[OS_MAX_API_NAME]; + osal_id_t creator; +} OS_queue_prop_t; + +/** @defgroup OSAPIMsgQueue OSAL Message Queue APIs + * @{ + */ + +/** + * @brief Create a message queue + * + * This is the function used to create a queue in the operating system. + * Depending on the underlying operating system, the memory for the queue + * will be allocated automatically or allocated by the code that sets up + * the queue. Queue names must be unique; if the name already exists this + * function fails. Names cannot be NULL. + * + * + * @param[out] queue_id will be set to the non-zero ID of the newly-created resource + * @param[in] queue_name the name of the new resource to create + * @param[in] queue_depth the maximum depth of the queue + * @param[in] data_size the size of each entry in the queue + * @param[in] flags options for the queue (reserved for future use, pass as 0) + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if a pointer passed in is NULL + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NO_FREE_IDS if there are already the max queues created + * @retval #OS_ERR_NAME_TAKEN if the name is already being used on another queue + * @retval #OS_QUEUE_INVALID_SIZE if the queue depth exceeds the limit + * @retval #OS_ERROR if the OS create call fails + */ +int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcount_t queue_depth, size_t data_size, + uint32 flags); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Deletes the specified message queue. + * + * This is the function used to delete a queue in the operating system. + * This also frees the respective queue_id to be used again when another queue is created. + * + * @note If There are messages on the queue, they will be lost and any subsequent + * calls to QueueGet or QueuePut to this queue will result in errors + * + * @param[in] queue_id The object ID to delete + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in does not exist + * @retval #OS_ERROR if the OS call to delete the queue fails + */ +int32 OS_QueueDelete(osal_id_t queue_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Receive a message on a message queue + * + * If a message is pending, it is returned immediately. Otherwise the calling task + * will block until a message arrives or the timeout expires. + * + * @param[in] queue_id The object ID to operate on + * @param[out] data The buffer to store the received message + * @param[in] size The size of the data buffer + * @param[out] size_copied Set to the actual size of the message + * @param[in] timeout The maximum amount of time to block, or OS_PEND to wait forever + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the given ID does not exist + * @retval #OS_INVALID_POINTER if a pointer passed in is NULL + * @retval #OS_QUEUE_EMPTY if the Queue has no messages on it to be recieved + * @retval #OS_QUEUE_TIMEOUT if the timeout was OS_PEND and the time expired + * @retval #OS_QUEUE_INVALID_SIZE if the size copied from the queue was not correct + */ +int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Put a message on a message queue. + * + * @param[in] queue_id The object ID to operate on + * @param[in] data The buffer containing the message to put + * @param[in] size The size of the data buffer + * @param[in] flags Currently reserved/unused, should be passed as 0 + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the queue id passed in is not a valid queue + * @retval #OS_INVALID_POINTER if the data pointer is NULL + * @retval #OS_QUEUE_FULL if the queue cannot accept another message + * @retval #OS_ERROR if the OS call returns an error + */ +int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flags); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Find an existing queue ID by name + * + * This function tries to find a queue Id given the name of the queue. The + * id of the queue is passed back in queue_id. + * + * @param[out] queue_id will be set to the ID of the existing resource + * @param[in] queue_name the name of the existing resource to find + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if the name or id pointers are NULL + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NAME_NOT_FOUND the name was not found in the table + */ +int32 OS_QueueGetIdByName(osal_id_t *queue_id, const char *queue_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Fill a property object buffer with details regarding the resource + * + * This function will pass back a pointer to structure that contains + * all of the relevant info (name and creator) about the specified queue. + * + * @param[in] queue_id The object ID to operate on + * @param[out] queue_prop The property object buffer to fill + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if queue_prop is NULL + * @retval #OS_ERR_INVALID_ID if the ID given is not a valid queue + */ +int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-select.h b/src/os/inc/osapi-select.h new file mode 100644 index 000000000..fefc18cd0 --- /dev/null +++ b/src/os/inc/osapi-select.h @@ -0,0 +1,157 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-select.h + */ + +#ifndef OSAPI_SELECT_H +#define OSAPI_SELECT_H + +#include "osconfig.h" +#include "common_types.h" + +/** + * @brief An abstract structure capable of holding several OSAL IDs + * + * This is part of the select API and is manipulated using the + * related API calls. It should not be modified directly by applications. + * + * @sa OS_SelectFdZero(), OS_SelectFdAdd(), OS_SelectFdClear(), OS_SelectFdIsSet() + */ +typedef struct +{ + uint8 object_ids[(OS_MAX_NUM_OPEN_FILES + 7) / 8]; +} OS_FdSet; + +/** + * @brief For the OS_SelectSingle() function's in/out StateFlags parameter, + * the state(s) of the stream and the result of the select is a combination + * of one or more of these states. + * + * @sa OS_SelectSingle() + */ +typedef enum +{ + OS_STREAM_STATE_BOUND = 0x01, /**< @brief whether the stream is bound */ + OS_STREAM_STATE_CONNECTED = 0x02, /**< @brief whether the stream is connected */ + OS_STREAM_STATE_READABLE = 0x04, /**< @brief whether the stream is readable */ + OS_STREAM_STATE_WRITABLE = 0x08, /**< @brief whether the stream is writable */ +} OS_StreamState_t; + +/** @defgroup OSAPISelect OSAL Select APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Wait for events across multiple file handles + * + * Wait for any of the given sets of IDs to be become readable or writable + * + * This function will block until any of the following occurs: + * - At least one OSAL ID in the ReadSet is readable + * - At least one OSAL ID in the WriteSet is writable + * - The timeout has elapsed + * + * The sets are input/output parameters. On entry, these indicate the + * file handle(s) to wait for. On exit, these are set to the actual + * file handle(s) that have activity. + * + * If the timeout occurs this returns an error code and all output sets + * should be empty. + * + * @note This does not lock or otherwise protect the file handles in the + * given sets. If a filehandle supplied via one of the FdSet arguments + * is closed or modified by another while this function is in progress, + * the results are undefined. Because of this limitation, it is recommended + * to use OS_SelectSingle() whenever possible. + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Wait for events on a single file handle + * + * Wait for a single OSAL filehandle to change state + * + * This function can be used to wait for a single OSAL stream ID + * to become readable or writable. On entry, the "StateFlags" + * parameter should be set to the desired state (OS_STREAM_STATE_READABLE + * and/or OS_STREAM_STATE_WRITABLE) and upon return the flags + * will be set to the state actually detected. + * + * As this operates on a single ID, the filehandle is protected + * during this call, such that another thread accessing the same + * handle will return an error. However, it is important to note that + * once the call returns then other threads may then also read/write + * and affect the state before the current thread can service it. + * + * To mitigate this risk the application may prefer to use + * the OS_TimedRead/OS_TimedWrite calls. + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SelectSingle(osal_id_t objid, uint32 *StateFlags, int32 msecs); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Clear a FdSet structure + * + * After this call the set will contain no OSAL IDs + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SelectFdZero(OS_FdSet *Set); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Add an ID to an FdSet structure + * + * After this call the set will contain the given OSAL ID + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SelectFdAdd(OS_FdSet *Set, osal_id_t objid); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Clear an ID from an FdSet structure + * + * After this call the set will no longer contain the given OSAL ID + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SelectFdClear(OS_FdSet *Set, osal_id_t objid); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Check if an FdSet structure contains a given ID + * + * @return Boolean set status + * @retval true FdSet structure contains ID + * @retval false FDSet structure does not contain ID + */ +bool OS_SelectFdIsSet(OS_FdSet *Set, osal_id_t objid); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-shell.h b/src/os/inc/osapi-shell.h new file mode 100644 index 000000000..914f0775f --- /dev/null +++ b/src/os/inc/osapi-shell.h @@ -0,0 +1,54 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-shell.h + */ + +#ifndef OSAPI_SHELL_H +#define OSAPI_SHELL_H + +#include "osconfig.h" +#include "common_types.h" + +/** @defgroup OSAPIShell OSAL Shell APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Executes the command and sends output to a file + * + * Takes a shell command in and writes the output of that command to the specified file + * The output file must be opened previously with write access (OS_WRITE_ONLY or OS_READ_WRITE). + * + * @param[in] Cmd Command to pass to shell + * @param[in] filedes File to send output to. + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if the command was not executed properly + * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + */ +int32 OS_ShellOutputToFile(const char *Cmd, osal_id_t filedes); + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-sockets.h b/src/os/inc/osapi-sockets.h new file mode 100644 index 000000000..743c6d810 --- /dev/null +++ b/src/os/inc/osapi-sockets.h @@ -0,0 +1,402 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-sockets.h + */ + +#ifndef OSAPI_SOCKETS_H +#define OSAPI_SOCKETS_H + +/* NOTE - osconfig.h may optionally specify the value for OS_SOCADDR_MAX_LEN */ +#include "osconfig.h" +#include "common_types.h" + +/* + * The absolute maximum size of a network address + * + * The actual size varies by address type. + * + * This definition should be large enough to capture the + * largest address supported on the system. The default + * value here should be suitable for many use-cases while + * still keeping the address structure size within reason. + * + * The user may also provide a tuned value through osconfig.h + */ +#ifndef OS_SOCKADDR_MAX_LEN +#define OS_SOCKADDR_MAX_LEN 28 +#endif + +/* + * -------------------------------------------------------------------------------------- + * Sockets API Data Types + * + * These data types are defined regardless of whether or not networking is compiled-in + * + * They are local to OSAL, they do not directly map to the library-provided types, and + * they do not occupy any space in the executable + * -------------------------------------------------------------------------------------- + */ + +/** @brief Socket domain */ +typedef enum +{ + OS_SocketDomain_INVALID, /**< @brief Invalid */ + OS_SocketDomain_INET, /**< @brief IPv4 address family, most commonly used) */ + OS_SocketDomain_INET6, /**< @brief IPv6 address family, depends on OS/network stack support */ + OS_SocketDomain_MAX /**< @brief Maximum */ +} OS_SocketDomain_t; + +/** @brief Socket type */ +typedef enum +{ + OS_SocketType_INVALID, /**< @brief Invalid */ + OS_SocketType_DATAGRAM, /**< @brief A connectionless, message-oriented socket */ + OS_SocketType_STREAM, /**< @brief A stream-oriented socket with the concept of a connection */ + OS_SocketType_MAX /**< @brief Maximum */ +} OS_SocketType_t; + +/** + * @brief Storage buffer for generic network address + * + * This is a union type that helps to ensure a minimum + * alignment value for the data storage, such that it can + * be cast to the system-specific type without + * increasing alignment requirements. + */ +typedef union +{ + uint8 Buffer[OS_SOCKADDR_MAX_LEN]; /**< @brief Ensures length of at least OS_SOCKADDR_MAX_LEN */ + uint32 AlignU32; /**< @brief Ensures uint32 alignment */ + void * AlignPtr; /**< @brief Ensures pointer alignment */ +} OS_SockAddrData_t; + +/** + * @brief Encapsulates a generic network address + * + * This is just an abstract buffer type that holds a network address. + * It is allocated for the worst-case size defined by OS_SOCKADDR_MAX_LEN, + * and the real size is stored within. + */ +typedef struct +{ + size_t ActualLength; /**< @brief Length of the actual address data */ + OS_SockAddrData_t AddrData; /**< @brief Abstract Address data */ +} OS_SockAddr_t; + +/** + * @brief Encapsulates socket properties + * + * This is for consistency with other OSAL resource types. + * Currently no extra properties are exposed here but this + * could change in a future revision of OSAL as needed. + */ +typedef struct +{ + char name[OS_MAX_API_NAME]; /**< @brief Name of the socket */ + osal_id_t creator; /**< @brief OSAL TaskID which opened the socket */ +} OS_socket_prop_t; + +/** + * @defgroup OSAPISocketAddr OSAL Socket Address APIs + * + * These functions provide a means to manipulate network addresses in a manner that + * is (mostly) agnostic to the actual network address type. + * + * Every network address should be representable as a string (i.e. dotted decimal IP, etc). + * This can serve as a the "common denominator" to all address types. + * + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Initialize a socket address structure to hold an address of the given family + * + * The address is set to a suitable default value for the family. + * + * @param[out] Addr The address buffer to initialize + * @param[in] Domain The address family + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get a string representation of a network host address + * + * The specific format of the output string depends on the address family. + * + * This string should be suitable to pass back into OS_SocketAddrFromString() + * which should recreate the same network address, and it should also + * be meaningful to a user of printed or logged as a C string. + * + * @note For IPv4, this would typically be the dotted-decimal format (X.X.X.X). + * + * @param[out] buffer Buffer to hold the output string + * @param[in] buflen Maximum length of the output string + * @param[in] Addr The network address buffer to convert + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SocketAddrToString(char *buffer, size_t buflen, const OS_SockAddr_t *Addr); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Set a network host address from a string representation + * + * The specific format of the output string depends on the address family. + * + * The address structure should have been previously initialized using + * OS_SocketAddrInit() to set the address family type. + * + * @note For IPv4, this would typically be the dotted-decimal format (X.X.X.X). + * It is up to the discretion of the underlying implementation whether + * to accept hostnames, as this depends on the availability of DNS services. + * Since many embedded deployments do not have name services, this should + * not be relied upon. + * + * @param[out] Addr The address buffer to initialize + * @param[in] string The string to initialize the address from. + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SocketAddrFromString(OS_SockAddr_t *Addr, const char *string); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Get the port number of a network address + * + * For network prototcols that have the concept of a port number (such + * as TCP/IP and UDP/IP) this function gets the port number from the + * address structure. + * + * @param[out] PortNum Buffer to store the port number + * @param[in] Addr The network address buffer + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SocketAddrGetPort(uint16 *PortNum, const OS_SockAddr_t *Addr); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Set the port number of a network address + * + * For network prototcols that have the concept of a port number (such + * as TCP/IP and UDP/IP) this function sets the port number from the + * address structure. + * + * @param[in] PortNum The port number to set + * @param[out] Addr The network address buffer + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SocketAddrSetPort(OS_SockAddr_t *Addr, uint16 PortNum); +/**@}*/ + +/** + * @defgroup OSALAPISocket OSAL Socket Management APIs + * + * These functions are loosely related to the BSD Sockets API but made to be + * more consistent with other OSAL API functions. That is, they operate on + * OSAL IDs (32-bit opaque number values) and return an OSAL error code. + * + * OSAL Socket IDs are very closely related to File IDs and share the same ID + * number space. Additionally, the file OS_read() / OS_write() / OS_close() + * calls also work on sockets. + * + * Note that all of functions may return #OS_ERR_NOT_IMPLEMENTED if network support + * is not configured at compile time. + * + * @{ + */ + +/** + * @brief Opens a socket. + * + * A new, unconnected and unbound socket is allocated of the given domain and type. + * + * @param[out] sock_id Buffer to hold the non-zero OSAL ID + * @param[in] Domain The domain / address family of the socket (INET or INET6, etc) + * @param[in] Type The type of the socket (STREAM or DATAGRAM) + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_t Type); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Binds a socket to a given local address. + * + * The specified socket will be bound to the local address and port, if available. + * + * If the socket is connectionless, then it only binds to the local address. + * + * If the socket is connection-oriented (stream), then this will also put the + * socket into a listening state for incoming connections at the local address. + * + * @param[in] sock_id The socket ID + * @param[in] Addr The local address to bind to + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Connects a socket to a given remote address. + * + * The socket will be connected to the remote address and port, if available. + * This only applies to stream-oriented sockets. Calling this on a datagram + * socket will return an error (these sockets should use SendTo/RecvFrom). + * + * @param[in] sock_id The socket ID + * @param[in] Addr The remote address to connect to + * @param[in] timeout The maximum amount of time to wait, or OS_PEND to wait forever + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 timeout); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Waits for and accept the next incoming connection on the given socket + * + * This is used for sockets operating in a "server" role. The socket must be + * a stream type (connection-oriented) and previously bound to a local address + * using OS_SocketBind(). This will block the caller up to the given timeout + * or until an incoming connection request occurs, whichever happens first. + * + * The new stream connection is then returned to the caller and the original + * server socket ID can be reused for the next connection. + * + * @param[in] sock_id The server socket ID, previously bound using OS_SocketBind() + * @param[out] connsock_id The connection socket, a new ID that can be read/written + * @param[in] Addr The remote address of the incoming connection + * @param[in] timeout The maximum amount of time to wait, or OS_PEND to wait forever + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t *Addr, int32 timeout); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Reads data from a message-oriented (datagram) socket + * + * If a message is already available on the socket, this should immediately return + * that data without blocking. Otherwise, it may block up to the given timeout. + * + * @param[in] sock_id The socket ID, previously bound using OS_SocketBind() + * @param[out] buffer Pointer to message data receive buffer + * @param[in] buflen The maximum length of the message data to receive + * @param[out] RemoteAddr Buffer to store the remote network address (may be NULL) + * @param[in] timeout The maximum amount of time to wait, or OS_PEND to wait forever + * + * @return Count of actual bytes received or error status, see @ref OSReturnCodes + */ +int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Sends data to a message-oriented (datagram) socket + * + * This sends data in a non-blocking mode. If the socket is not currently able to + * queue the message, such as if its outbound buffer is full, then this returns + * an error code. + * + * @param[in] sock_id The socket ID, which must be of the datagram type + * @param[in] buffer Pointer to message data to send + * @param[in] buflen The length of the message data to send + * @param[in] RemoteAddr Buffer containing the remote network address to send to + * + * @return Count of actual bytes sent or error status, see @ref OSReturnCodes + */ +int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Gets an OSAL ID from a given name + * + * @note OSAL Sockets use generated names according to the address and type. + * + * @sa OS_SocketGetInfo() + * + * @param[out] sock_id Buffer to hold result + * @param[in] sock_name Name of socket to find + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER is id or name are NULL pointers + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table + */ +int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Gets information about an OSAL Socket ID + * + * OSAL Sockets use generated names according to the address and type. + * This allows applications to find the name of a given socket. + * + * @param[in] sock_id The socket ID + * @param[out] sock_prop Buffer to hold socket information + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid semaphore + * @retval #OS_INVALID_POINTER if the count_prop pointer is null + */ +int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Gets the network ID of the local machine + * + * The ID is an implementation-defined value and may not be consistent + * in meaning across different platform types. + * + * @note This API may be removed in a future version of OSAL due to + * inconsistencies between platforms. + * + * @return The ID or fixed value of -1 if the host id could not be found. + * Note it is not possible to differentiate between error codes and valid + * network IDs here. It is assumed, however, that -1 is never a valid ID. + */ +int32 OS_NetworkGetID(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Gets the local machine network host name + * + * If configured in the underlying network stack, + * this function retrieves the local hostname of the system. + * + * @param[out] host_name Buffer to hold name information + * @param[in] name_len Maximum length of host name buffer + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_NetworkGetHostName(char *host_name, size_t name_len); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-task.h b/src/os/inc/osapi-task.h new file mode 100644 index 000000000..acc7e1304 --- /dev/null +++ b/src/os/inc/osapi-task.h @@ -0,0 +1,251 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-task.h + */ + +#ifndef OSAPI_TASK_H +#define OSAPI_TASK_H + +#include "osconfig.h" +#include "common_types.h" + +/** @brief Upper limit for OSAL task priorities */ +#define OS_MAX_TASK_PRIORITY 255 + +/** @brief Floating point enabled state for a task */ +#define OS_FP_ENABLED 1 + +/** + * @brief Type to be used for OSAL task priorities. + * + * OSAL priorities are in reverse order, and range + * from 0 (highest; will preempt all other tasks) to + * 255 (lowest; will not preempt any other task). + */ +typedef uint8_t osal_priority_t; + +#define OSAL_PRIORITY_C(X) ((osal_priority_t) {X}) + +/** + * @brief Type to be used for OSAL stack pointer. + */ +typedef void *osal_stackptr_t; + +#define OSAL_STACKPTR_C(X) ((osal_stackptr_t) {X}) +#define OSAL_TASK_STACK_ALLOCATE OSAL_STACKPTR_C(NULL) + +/** @brief OSAL task properties */ +typedef struct +{ + char name[OS_MAX_API_NAME]; + osal_id_t creator; + size_t stack_size; + osal_priority_t priority; +} OS_task_prop_t; + +/* +** These typedefs are for the task entry point +*/ +typedef void osal_task; /**< @brief For task entry point */ +typedef osal_task((*osal_task_entry)(void)); /**< @brief For task entry point */ + +/** @defgroup OSAPITask OSAL Task APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Creates a task and starts running it. + * + * Creates a task and passes back the id of the task created. Task names must be unique; + * if the name already exists this function fails. Names cannot be NULL. + * + * @param[out] task_id will be set to the non-zero ID of the newly-created resource + * @param[in] task_name the name of the new resource to create + * @param[in] function_pointer the entry point of the new task + * @param[in] stack_pointer pointer to the stack for the task, or NULL + * to allocate a stack from the system memory heap + * @param[in] stack_size the size of the stack, or 0 to use a default stack size. + * @param[in] priority initial priority of the new task + * @param[in] flags initial options for the new task + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if any of the necessary pointers are NULL + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_INVALID_PRIORITY if the priority is bad + * @retval #OS_ERR_NO_FREE_IDS if there can be no more tasks created + * @retval #OS_ERR_NAME_TAKEN if the name specified is already used by a task + * @retval #OS_ERROR if an unspecified/other error occurs + */ +int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, + osal_stackptr_t stack_pointer, size_t stack_size, osal_priority_t priority, uint32 flags); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Deletes the specified Task + * + * The task will be removed from the local tables. and the OS will + * be configured to stop executing the task at the next opportunity. + * + * @param[in] task_id The object ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the ID given to it is invalid + * @retval #OS_ERROR if the OS delete call fails + */ +int32 OS_TaskDelete(osal_id_t task_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Exits the calling task + * + * The calling thread is terminated. This function does not return. + */ +void OS_TaskExit(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Installs a handler for when the task is deleted. + * + * This function is used to install a callback that is called when the task is deleted. + * The callback is called when OS_TaskDelete is called with the task ID. A task delete + * handler is useful for cleaning up resources that a task creates, before the task is + * removed from the system. + * + * @param[in] function_pointer function to be called when task exits + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Delay a task for specified amount of milliseconds + * + * Causes the current thread to be suspended from execution for the period of millisecond. + * + * @param[in] millisecond Amount of time to delay + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERROR if sleep fails or millisecond = 0 + */ +int32 OS_TaskDelay(uint32 millisecond); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Sets the given task to a new priority + * + * @param[in] task_id The object ID to operate on + * + * @param[in] new_priority Set the new priority + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the ID passed to it is invalid + * @retval #OS_ERR_INVALID_PRIORITY if the priority is greater than the max allowed + * @retval #OS_ERROR if the OS call to change the priority fails + */ +int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obsolete + * @deprecated Explicit registration call no longer needed + * + * Obsolete function retained for compatibility purposes. + * Does Nothing in the current implementation. + * + * @return #OS_SUCCESS (always), see @ref OSReturnCodes + */ +int32 OS_TaskRegister(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain the task id of the calling task + * + * This function returns the task id of the calling task + * + * @return Task ID, or zero if the operation failed (zero is never a valid task ID) + */ +osal_id_t OS_TaskGetId(void); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Find an existing task ID by name + * + * This function tries to find a task Id given the name of a task + * + * @param[out] task_id will be set to the ID of the existing resource + * @param[in] task_name the name of the existing resource to find + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if the pointers passed in are NULL + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NAME_NOT_FOUND if the name wasn't found in the table + */ +int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Fill a property object buffer with details regarding the resource + * + * This function will pass back a pointer to structure that contains + * all of the relevant info (creator, stack size, priority, name) about the + * specified task. + * + * @param[in] task_id The object ID to operate on + * @param[out] task_prop The property object buffer to fill + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the ID passed to it is invalid + * @retval #OS_INVALID_POINTER if the task_prop pointer is NULL + */ +int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Reverse-lookup the OSAL task ID from an operating system ID + * + * This provides a method by which an external entity may find the OSAL task + * ID corresponding to a system-defined identifier (e.g. TASK_ID, pthread_t, rtems_id, etc). + * + * Normally OSAL does not expose the underlying OS-specific values to the application, + * but in some circumstances, such as exception handling, the OS may provide this information + * directly to a BSP handler outside of the normal OSAL API. + * + * @param[out] task_id The buffer where the task id output is stored + * @param[in] sysdata Pointer to the system-provided identification data + * @param[in] sysdata_size Size of the system-provided identification data + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + */ +int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t sysdata_size); + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-timebase.h b/src/os/inc/osapi-timebase.h new file mode 100644 index 000000000..1e709ee2b --- /dev/null +++ b/src/os/inc/osapi-timebase.h @@ -0,0 +1,188 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @file osapi-timebase.h + */ + +#ifndef OSAPI_TIMEBASE_H +#define OSAPI_TIMEBASE_H + +#include "osconfig.h" +#include "common_types.h" + +/* +** Typedefs +*/ +typedef uint32 (*OS_TimerSync_t)(osal_id_t timer_id); /**< @brief Timer sync */ + +/** @brief Time base properties */ +typedef struct +{ + char name[OS_MAX_API_NAME]; + osal_id_t creator; + uint32 nominal_interval_time; + uint32 freerun_time; + uint32 accuracy; +} OS_timebase_prop_t; + +/** @defgroup OSAPITimebase OSAL Time Base APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Create an abstract Time Base resource + * + * An OSAL time base is an abstraction of a "timer tick" that can, in turn, be + * used for measurement of elapsed time between events. + * + * Time bases can be simulated by the operating system using the OS kernel-provided + * timing facilities, or based on a hardware timing source if provided by the BSP. + * + * A time base object has a servicing task associated with it, that runs at elevated + * priority and will thereby interrupt user-level tasks when timing ticks occur. + * + * If the external_sync function is passed as NULL, the operating system kernel + * timing resources will be utilized for a simulated timer tick. + * + * If the external_sync function is not NULL, this should point to a BSP-provided + * function that will block the calling task until the next tick occurs. This + * can be used for synchronizing with hardware events. + * + * @note When provisioning a tunable RTOS kernel, such as RTEMS, the kernel should + * be configured to support at least (OS_MAX_TASKS + OS_MAX_TIMEBASES) threads, + * to account for the helper threads associated with time base objects. + * + * @param[out] timebase_id A non-zero ID corresponding to the timebase resource + * @param[in] timebase_name The name of the time base + * @param[in] external_sync A synchronization function for BSP hardware-based timer ticks + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_TimeBaseCreate(osal_id_t *timebase_id, const char *timebase_name, OS_TimerSync_t external_sync); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Sets the tick period for simulated time base objects + * + * This sets the actual tick period for timing ticks that are + * simulated by the RTOS kernel (i.e. the "external_sync" parameter + * on the call to OS_TimeBaseCreate() is NULL). + * + * The RTOS will be configured to wake up the helper thread at the + * requested interval. + * + * This function has no effect for time bases that are using + * a BSP-provided external_sync function. + * + * @param[in] timebase_id The timebase resource to configure + * @param[in] start_time The amount of delay for the first tick, in microseconds. + * @param[in] interval_time The amount of delay between ticks, in microseconds. + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_TimeBaseSet(osal_id_t timebase_id, uint32 start_time, uint32 interval_time); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Deletes a time base object + * + * The helper task and any other resources associated with the time base + * abstraction will be freed. + * + * @param[in] timebase_id The timebase resource to delete + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_TimeBaseDelete(osal_id_t timebase_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Find the ID of an existing time base resource + * + * Given a time base name, find and output the ID associated with it. + * + * @param[out] timebase_id The timebase resource ID + * @param[in] timebase_name The name of the timebase resource to find + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if timebase_id or timebase_name are NULL pointers + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table + */ +int32 OS_TimeBaseGetIdByName(osal_id_t *timebase_id, const char *timebase_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Obtain information about a timebase resource + * + * Fills the buffer referred to by the timebase_prop parameter with + * relevant information about the time base resource. + * + * This function will pass back a pointer to structure that contains + * all of the relevant info( name and creator) about the specified timebase. + * + * @param[in] timebase_id The timebase resource ID + * @param[out] timebase_prop Buffer to store timebase properties + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid timebase + * @retval #OS_INVALID_POINTER if the timebase_prop pointer is null + */ +int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_prop); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Read the value of the timebase free run counter + * + * Poll the timer free-running time counter in a lightweight fashion. + * + * The free run count is a monotonically increasing value reflecting the + * total time elapsed since the timebase inception. Units are the + * same as the timebase itself, usually microseconds. + * + * Applications may quickly and efficiently calculate relative time + * differences by polling this value and subtracting the previous + * counter value. + * + * The absolute value of this counter is not relevant, because it + * will "roll over" after 2^32 units of time. For a timebase with + * microsecond units, this occurs approximately every 4294 seconds, + * or about 1.2 hours. + * + * @note To ensure consistency of results, the application should + * sample the value at a minimum of two times the roll over frequency, + * and calculate the difference between the consecutive samples. + * + * @param[in] timebase_id The timebase to operate on + * @param[out] freerun_val Buffer to store the free run counter + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid timebase + */ +int32 OS_TimeBaseGetFreeRun(osal_id_t timebase_id, uint32 *freerun_val); + +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-timer.h b/src/os/inc/osapi-timer.h new file mode 100644 index 000000000..785364eb4 --- /dev/null +++ b/src/os/inc/osapi-timer.h @@ -0,0 +1,211 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file osapi-timer.h + */ + +#ifndef OSAPI_TIMER_H +#define OSAPI_TIMER_H + +#include "osconfig.h" +#include "common_types.h" + +/* +** Typedefs +*/ +typedef void (*OS_TimerCallback_t)(osal_id_t timer_id); /**< @brief Timer callback */ + +/** @brief Timer properties */ +typedef struct +{ + char name[OS_MAX_API_NAME]; + osal_id_t creator; + uint32 start_time; + uint32 interval_time; + uint32 accuracy; + +} OS_timer_prop_t; + +/** @defgroup OSAPITimer OSAL Timer APIs + * @{ + */ + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Create a timer object + * + * A timer object is a resource that invokes the specified application-provided function + * upon timer expiration. Timers may be one-shot or periodic in nature. + * + * This function creates a dedicated (hidden) time base object to service this timer, + * which is created and deleted with the timer object itself. The internal time base + * is configured for an OS simulated timer tick at the same interval as the timer. + * + * @note clock_accuracy comes from the underlying OS tick value. The nearest integer + * microsecond value is returned, so may not be exact. + * + * @warning Depending on the OS, the callback_ptr function may be similar to an + * interrupt service routine. Calls that cause the code to block or require + * an application context (like sending events) are generally not supported. + * + * @param[out] timer_id The non-zero resource ID of the timer object + * @param[in] timer_name Name of the timer object + * @param[out] clock_accuracy Expected precision of the timer, in microseconds. This + * is the underlying tick value rounded to the nearest + * microsecond integer. + * @param[in] callback_ptr The function pointer of the timer callback or ISR that + * will be called by the timer. The user’s function is + * declared as follows: void timer_callback(uint32 timer_id) + * Where the timer_id is passed in to the function by the OSAL + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if any parameters are NULL + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NAME_TAKEN if the name is already in use by another timer. + * @retval #OS_ERR_NO_FREE_IDS if all of the timers are already allocated. + * @retval #OS_TIMER_ERR_INVALID_ARGS if the callback pointer is zero. + * @retval #OS_TIMER_ERR_UNAVAILABLE if the timer cannot be created. + */ +int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *clock_accuracy, + OS_TimerCallback_t callback_ptr); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Add a timer object based on an existing TimeBase resource + * + * A timer object is a resource that invokes the specified application-provided function + * upon timer expiration. Timers may be one-shot or periodic in nature. + * + * This function uses an existing time base object to service this timer, which must + * exist prior to adding the timer. The precision of the timer is the same + * as that of the underlying time base object. Multiple timer objects can be + * created referring to a single time base object. + * + * This routine also uses a different callback function prototype from OS_TimerCreate(), + * allowing a single opaque argument to be passed to the callback routine. + * The OSAL implementation does not use this parameter, and may be set NULL. + * + * @warning Depending on the OS, the callback_ptr function may be similar to an + * interrupt service routine. Calls that cause the code to block or require + * an application context (like sending events) are generally not supported. + * + * @param[out] timer_id The non-zero resource ID of the timer object + * @param[in] timer_name Name of the timer object + * @param[in] timebase_id The time base resource to use as a reference + * @param[in] callback_ptr Application-provided function to invoke + * @param[in] callback_arg Opaque argument to pass to callback function + * + * @return Execution status, see @ref OSReturnCodes + */ +int32 OS_TimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_t timebase_id, OS_ArgCallback_t callback_ptr, + void *callback_arg); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Configures a periodic or one shot timer + * + * This function programs the timer with a start time and an optional interval time. + * The start time is the time in microseconds when the user callback function will be + * called. If the interval time is non-zero, the timer will be reprogrammed with that + * interval in microseconds to call the user callback function periodically. If the start + * time and interval time are zero, the function will return an error. + * + * For a "one-shot" timer, the start_time configures the + * expiration time, and the interval_time should be passed as + * zero to indicate the timer is not to be automatically reset. + * + * @note The resolution of the times specified is limited to the clock accuracy + * returned in the OS_TimerCreate call. If the times specified in the start_msec + * or interval_msec parameters are less than the accuracy, they will be rounded + * up to the accuracy of the timer. + * + * @param[in] timer_id The timer ID to operate on + * @param[in] start_time Time in microseconds to the first expiration + * @param[in] interval_time Time in microseconds between subsequent intervals, value + * of zero will only call the user callback function once + * after the start_msec time. + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the timer_id is not valid. + * @retval #OS_TIMER_ERR_INTERNAL if there was an error programming the OS timer. + * @retval #OS_ERROR if both start time and interval time are zero. + */ +int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Deletes a timer resource + * + * The application callback associated with the timer will be stopped, + * and the resources freed for future use. + * + * @param[in] timer_id The timer ID to operate on + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the timer_id is invalid. + * @retval #OS_TIMER_ERR_INTERNAL if there was a problem deleting the timer in the host OS. + */ +int32 OS_TimerDelete(osal_id_t timer_id); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Locate an existing timer resource by name + * + * Outputs the ID associated with the given timer, if it exists. + * + * @param[out] timer_id The timer ID corresponding to the name + * @param[in] timer_name The timer name to find + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_INVALID_POINTER if timer_id or timer_name are NULL pointers + * @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME + * @retval #OS_ERR_NAME_NOT_FOUND if the name was not found in the table + */ +int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name); + +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Gets information about an existing timer + * + * This function takes timer_id, and looks it up in the OS table. It puts all of the + * information known about that timer into a structure pointer to by timer_prop. + * + * @param[in] timer_id The timer ID to operate on + * @param[out] timer_prop Buffer containing timer properties + * - creator: the OS task ID of the task that created this timer + * - name: the string name of the timer + * - start_time: the start time in microseconds, if any + * - interval_time: the interval time in microseconds, if any + * - accuracy: the accuracy of the timer in microseconds + * + * @return Execution status, see @ref OSReturnCodes + * @retval #OS_SUCCESS @copybrief OS_SUCCESS + * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid timer + * @retval #OS_INVALID_POINTER if the timer_prop pointer is null + */ +int32 OS_TimerGetInfo(osal_id_t timer_id, OS_timer_prop_t *timer_prop); +/**@}*/ + +#endif diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index 26adec058..9923b82c3 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -24,13 +24,13 @@ * See @ref cfsversions for version and build number and description * */ -#ifndef _osapi_version_h_ -#define _osapi_version_h_ +#ifndef OSAPI_VERSION_H +#define OSAPI_VERSION_H /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 60 +#define OS_BUILD_NUMBER 262 #define OS_BUILD_BASELINE "v5.1.0-rc1" /* @@ -38,9 +38,10 @@ */ #define OS_MAJOR_VERSION 5 /*!< @brief ONLY APPLY for OFFICIAL releases. Major version number. */ #define OS_MINOR_VERSION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Minor version number. */ -#define OS_REVISION \ - 99 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. If set to "99" it indicates a \ +#define OS_REVISION \ + 99 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. A value of "99" indicates an unreleased \ development version. */ + #define OS_MISSION_REV 0 /*!< @brief ONLY USED by MISSION Implementations. Mission revision */ /* @@ -71,7 +72,7 @@ OSAL 4.1 is present. */ #define OSAL_API_VERSION ((OS_MAJOR_VERSION * 10000) + (OS_MINOR_VERSION * 100) + OS_REVISION) -#endif /* _osapi_version_h_ */ +#endif /* OSAPI_VERSION_H */ /************************/ /* End of File Comment */ diff --git a/src/os/inc/osapi.h b/src/os/inc/osapi.h index 46ac687a0..11701501a 100644 --- a/src/os/inc/osapi.h +++ b/src/os/inc/osapi.h @@ -27,8 +27,13 @@ * for the OS Abstraction Layer, Core OS module */ -#ifndef _osapi_ -#define _osapi_ +#ifndef OSAPI_H +#define OSAPI_H + +#ifdef __cplusplus +extern "C" +{ +#endif /* * Note - the "osapi-os-filesys.h" file previously included these system headers @@ -46,59 +51,10 @@ */ #include #include +#include #include "common_types.h" -#ifdef __cplusplus -extern "C" -{ -#endif - -/** @defgroup OSReturnCodes OSAL Return Code Defines - * @{ - */ -#define OS_SUCCESS (0) /**< @brief Successful execution */ -#define OS_ERROR (-1) /**< @brief Failed execution */ -#define OS_INVALID_POINTER (-2) /**< @brief Invalid pointer */ -#define OS_ERROR_ADDRESS_MISALIGNED (-3) /**< @brief Address misalignment */ -#define OS_ERROR_TIMEOUT (-4) /**< @brief Error timeout */ -#define OS_INVALID_INT_NUM (-5) /**< @brief Invalid Interrupt number */ -#define OS_SEM_FAILURE (-6) /**< @brief Semaphore failure */ -#define OS_SEM_TIMEOUT (-7) /**< @brief Semaphore timeout */ -#define OS_QUEUE_EMPTY (-8) /**< @brief Queue empty */ -#define OS_QUEUE_FULL (-9) /**< @brief Queue full */ -#define OS_QUEUE_TIMEOUT (-10) /**< @brief Queue timeout */ -#define OS_QUEUE_INVALID_SIZE (-11) /**< @brief Queue invalid size */ -#define OS_QUEUE_ID_ERROR (-12) /**< @brief Queue ID error */ -#define OS_ERR_NAME_TOO_LONG (-13) /**< @brief name length including null terminator greater than #OS_MAX_API_NAME */ -#define OS_ERR_NO_FREE_IDS (-14) /**< @brief No free IDs */ -#define OS_ERR_NAME_TAKEN (-15) /**< @brief Name taken */ -#define OS_ERR_INVALID_ID (-16) /**< @brief Invalid ID */ -#define OS_ERR_NAME_NOT_FOUND (-17) /**< @brief Name not found */ -#define OS_ERR_SEM_NOT_FULL (-18) /**< @brief Semaphore not full */ -#define OS_ERR_INVALID_PRIORITY (-19) /**< @brief Invalid priority */ -#define OS_INVALID_SEM_VALUE (-20) /**< @brief Invalid semaphore value */ -#define OS_ERR_FILE (-27) /**< @brief File error */ -#define OS_ERR_NOT_IMPLEMENTED (-28) /**< @brief Not implemented */ -#define OS_TIMER_ERR_INVALID_ARGS (-29) /**< @brief Timer invalid arguments */ -#define OS_TIMER_ERR_TIMER_ID (-30) /**< @brief Timer ID error */ -#define OS_TIMER_ERR_UNAVAILABLE (-31) /**< @brief Timer unavailable */ -#define OS_TIMER_ERR_INTERNAL (-32) /**< @brief Timer internal error */ -#define OS_ERR_OBJECT_IN_USE (-33) /**< @brief Object in use */ -#define OS_ERR_BAD_ADDRESS (-34) /**< @brief Bad address */ -#define OS_ERR_INCORRECT_OBJ_STATE (-35) /**< @brief Incorrect object state */ -#define OS_ERR_INCORRECT_OBJ_TYPE (-36) /**< @brief Incorrect object type */ -#define OS_ERR_STREAM_DISCONNECTED (-37) /**< @brief Stream disconnected */ -#define OS_ERR_OPERATION_NOT_SUPPORTED (-38) /**< @brief Requested operation is not support on the supplied object(s) \ - */ -/**@}*/ - -/* -** Defines for Queue Timeout parameters -*/ -#define OS_PEND (-1) -#define OS_CHECK (0) - #include "osapi-version.h" /* @@ -109,11 +65,29 @@ extern "C" /* ** Include the OS API modules */ -#include "osapi-os-core.h" -#include "osapi-os-filesys.h" -#include "osapi-os-net.h" -#include "osapi-os-loader.h" -#include "osapi-os-timer.h" +#include "osapi-binsem.h" +#include "osapi-clock.h" +#include "osapi-common.h" +#include "osapi-constants.h" +#include "osapi-countsem.h" +#include "osapi-dir.h" +#include "osapi-error.h" +#include "osapi-file.h" +#include "osapi-filesys.h" +#include "osapi-heap.h" +#include "osapi-macros.h" +#include "osapi-idmap.h" +#include "osapi-module.h" +#include "osapi-mutex.h" +#include "osapi-network.h" +#include "osapi-printf.h" +#include "osapi-queue.h" +#include "osapi-select.h" +#include "osapi-shell.h" +#include "osapi-sockets.h" +#include "osapi-task.h" +#include "osapi-timebase.h" +#include "osapi-timer.h" /* ****************************************************************************** @@ -122,6 +96,8 @@ extern "C" ***************************************************************************** */ +#include "osapi-bsp.h" + #ifdef __cplusplus } #endif diff --git a/src/os/portable/os-impl-bsd-select.c b/src/os/portable/os-impl-bsd-select.c index 67ae82bed..dbfb19622 100644 --- a/src/os/portable/os-impl-bsd-select.c +++ b/src/os/portable/os-impl-bsd-select.c @@ -42,9 +42,9 @@ #include #include -#include #include "os-impl-select.h" #include "os-shared-select.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -74,12 +74,12 @@ *-----------------------------------------------------------------*/ static int OS_FdSet_ConvertIn_Impl(fd_set *os_set, OS_FdSet *OSAL_set) { - uint32 offset; - uint32 bit; - uint32 id; - uint8 objids; - int osfd; - int maxfd; + size_t offset; + size_t bit; + osal_index_t id; + uint8 objids; + int osfd; + int maxfd; maxfd = -1; for (offset = 0; offset < sizeof(OSAL_set->object_ids); ++offset) @@ -90,7 +90,7 @@ static int OS_FdSet_ConvertIn_Impl(fd_set *os_set, OS_FdSet *OSAL_set) { if (objids & 0x01) { - id = (offset * 8) + bit; + id = OSAL_INDEX_C((offset * 8) + bit); osfd = OS_impl_filehandle_table[id].fd; if (osfd >= 0 && OS_impl_filehandle_table[id].selectable) { @@ -122,11 +122,11 @@ static int OS_FdSet_ConvertIn_Impl(fd_set *os_set, OS_FdSet *OSAL_set) *-----------------------------------------------------------------*/ static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input) { - uint32 offset; - uint32 bit; - uint32 id; - uint8 objids; - int osfd; + size_t offset; + size_t bit; + osal_index_t id; + uint8 objids; + int osfd; for (offset = 0; offset < sizeof(Input->object_ids); ++offset) { @@ -136,7 +136,7 @@ static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input) { if (objids & 0x01) { - id = (offset * 8) + bit; + id = OSAL_INDEX_C((offset * 8) + bit); osfd = OS_impl_filehandle_table[id].fd; if (osfd < 0 || !FD_ISSET(osfd, output)) { @@ -249,17 +249,20 @@ static int32 OS_DoSelect(int maxfd, fd_set *rd_set, fd_set *wr_set, int32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs) +int32 OS_SelectSingle_Impl(const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs) { - int32 return_code; - fd_set wr_set; - fd_set rd_set; + int32 return_code; + fd_set wr_set; + fd_set rd_set; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); /* * If called on a stream_id which does not support this * operation, return immediately and do not invoke the system call */ - if (!OS_impl_filehandle_table[stream_id].selectable) + if (!impl->selectable) { return OS_ERR_OPERATION_NOT_SUPPORTED; } @@ -270,22 +273,22 @@ int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs) FD_ZERO(&rd_set); if (*SelectFlags & OS_STREAM_STATE_READABLE) { - FD_SET(OS_impl_filehandle_table[stream_id].fd, &rd_set); + FD_SET(impl->fd, &rd_set); } if (*SelectFlags & OS_STREAM_STATE_WRITABLE) { - FD_SET(OS_impl_filehandle_table[stream_id].fd, &wr_set); + FD_SET(impl->fd, &wr_set); } - return_code = OS_DoSelect(OS_impl_filehandle_table[stream_id].fd, &rd_set, &wr_set, msecs); + return_code = OS_DoSelect(impl->fd, &rd_set, &wr_set, msecs); if (return_code == OS_SUCCESS) { - if (!FD_ISSET(OS_impl_filehandle_table[stream_id].fd, &rd_set)) + if (!FD_ISSET(impl->fd, &rd_set)) { *SelectFlags &= ~OS_STREAM_STATE_READABLE; } - if (!FD_ISSET(OS_impl_filehandle_table[stream_id].fd, &wr_set)) + if (!FD_ISSET(impl->fd, &wr_set)) { *SelectFlags &= ~OS_STREAM_STATE_WRITABLE; } diff --git a/src/os/portable/os-impl-bsd-sockets.c b/src/os/portable/os-impl-bsd-sockets.c index 524fe42a3..8b66ca1b1 100644 --- a/src/os/portable/os-impl-bsd-sockets.c +++ b/src/os/portable/os-impl-bsd-sockets.c @@ -57,6 +57,7 @@ #include "os-shared-file.h" #include "os-shared-select.h" #include "os-shared-sockets.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -84,16 +85,21 @@ typedef union * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketOpen_Impl(uint32 sock_id) +int32 OS_SocketOpen_Impl(const OS_object_token_t *token) { - int os_domain; - int os_type; - int os_proto; - int os_flags; + int os_domain; + int os_type; + int os_proto; + int os_flags; + OS_impl_file_internal_record_t *impl; + OS_stream_internal_record_t * stream; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + stream = OS_OBJECT_TABLE_GET(OS_stream_table, *token); os_proto = 0; - switch (OS_stream_table[sock_id].socket_type) + switch (stream->socket_type) { case OS_SocketType_DATAGRAM: os_type = SOCK_DGRAM; @@ -106,7 +112,7 @@ int32 OS_SocketOpen_Impl(uint32 sock_id) return OS_ERR_NOT_IMPLEMENTED; } - switch (OS_stream_table[sock_id].socket_domain) + switch (stream->socket_domain) { case OS_SocketDomain_INET: os_domain = AF_INET; @@ -120,28 +126,19 @@ int32 OS_SocketOpen_Impl(uint32 sock_id) return OS_ERR_NOT_IMPLEMENTED; } - switch (OS_stream_table[sock_id].socket_domain) + /* Only AF_INET* at this point, can add cases if support is expanded */ + switch (stream->socket_type) { - case OS_SocketDomain_INET: - case OS_SocketDomain_INET6: - switch (OS_stream_table[sock_id].socket_type) - { - case OS_SocketType_DATAGRAM: - os_proto = IPPROTO_UDP; - break; - case OS_SocketType_STREAM: - os_proto = IPPROTO_TCP; - break; - default: - break; - } + case OS_SocketType_DATAGRAM: + os_proto = IPPROTO_UDP; break; - default: + case OS_SocketType_STREAM: + os_proto = IPPROTO_TCP; break; } - OS_impl_filehandle_table[sock_id].fd = socket(os_domain, os_type, os_proto); - if (OS_impl_filehandle_table[sock_id].fd < 0) + impl->fd = socket(os_domain, os_type, os_proto); + if (impl->fd < 0) { return OS_ERROR; } @@ -151,18 +148,18 @@ int32 OS_SocketOpen_Impl(uint32 sock_id) * code restarts. However if setting the option fails then it is not worth bailing out over. */ os_flags = 1; - setsockopt(OS_impl_filehandle_table[sock_id].fd, SOL_SOCKET, SO_REUSEADDR, &os_flags, sizeof(os_flags)); + setsockopt(impl->fd, SOL_SOCKET, SO_REUSEADDR, &os_flags, sizeof(os_flags)); /* * Set the standard options on the filehandle by default -- * this may set it to non-blocking mode if the implementation supports it. * any blocking would be done explicitly via the select() wrappers */ - os_flags = fcntl(OS_impl_filehandle_table[sock_id].fd, F_GETFL); + os_flags = fcntl(impl->fd, F_GETFL); os_flags |= OS_IMPL_SOCKET_FLAGS; - fcntl(OS_impl_filehandle_table[sock_id].fd, F_SETFL, os_flags); + fcntl(impl->fd, F_SETFL, os_flags); - OS_impl_filehandle_table[sock_id].selectable = ((os_flags & O_NONBLOCK) != 0); + impl->selectable = ((os_flags & O_NONBLOCK) != 0); return OS_SUCCESS; } /* end OS_SocketOpen_Impl */ @@ -175,11 +172,16 @@ int32 OS_SocketOpen_Impl(uint32 sock_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr) +int32 OS_SocketBind_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr) { - int os_result; - socklen_t addrlen; - const struct sockaddr *sa; + int os_result; + socklen_t addrlen; + const struct sockaddr * sa; + OS_impl_file_internal_record_t *impl; + OS_stream_internal_record_t * stream; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + stream = OS_OBJECT_TABLE_GET(OS_stream_table, *token); sa = (const struct sockaddr *)&Addr->AddrData; @@ -203,7 +205,7 @@ int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr) return OS_ERR_BAD_ADDRESS; } - os_result = bind(OS_impl_filehandle_table[sock_id].fd, sa, addrlen); + os_result = bind(impl->fd, sa, addrlen); if (os_result < 0) { OS_DEBUG("bind: %s\n", strerror(errno)); @@ -211,9 +213,9 @@ int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr) } /* Start listening on the socket (implied for stream sockets) */ - if (OS_stream_table[sock_id].socket_type == OS_SocketType_STREAM) + if (stream->socket_type == OS_SocketType_STREAM) { - os_result = listen(OS_impl_filehandle_table[sock_id].fd, 10); + os_result = listen(impl->fd, 10); if (os_result < 0) { OS_DEBUG("listen: %s\n", strerror(errno)); @@ -231,14 +233,17 @@ int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 timeout) +int32 OS_SocketConnect_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr, int32 timeout) { - int32 return_code; - int os_status; - int sockopt; - socklen_t slen; - uint32 operation; - const struct sockaddr *sa; + int32 return_code; + int os_status; + int sockopt; + socklen_t slen; + uint32 operation; + const struct sockaddr * sa; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); sa = (const struct sockaddr *)&Addr->AddrData; switch (sa->sa_family) @@ -263,7 +268,7 @@ int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 tim else { return_code = OS_SUCCESS; - os_status = connect(OS_impl_filehandle_table[sock_id].fd, sa, slen); + os_status = connect(impl->fd, sa, slen); if (os_status < 0) { if (errno != EINPROGRESS) @@ -273,9 +278,9 @@ int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 tim else { operation = OS_STREAM_STATE_WRITABLE; - if (OS_impl_filehandle_table[sock_id].selectable) + if (impl->selectable) { - return_code = OS_SelectSingle_Impl(sock_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(token, &operation, timeout); } if (return_code == OS_SUCCESS) { @@ -285,10 +290,9 @@ int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 tim } else { - sockopt = 0; - slen = sizeof(sockopt); - os_status = - getsockopt(OS_impl_filehandle_table[sock_id].fd, SOL_SOCKET, SO_ERROR, &sockopt, &slen); + sockopt = 0; + slen = sizeof(sockopt); + os_status = getsockopt(impl->fd, SOL_SOCKET, SO_ERROR, &sockopt, &slen); if (os_status < 0 || sockopt != 0) { return_code = OS_ERROR; @@ -309,17 +313,23 @@ int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 tim * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Addr, int32 timeout) +int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_token_t *conn_token, + OS_SockAddr_t *Addr, int32 timeout) { - int32 return_code; - uint32 operation; - socklen_t addrlen; - int os_flags; + int32 return_code; + uint32 operation; + socklen_t addrlen; + int os_flags; + OS_impl_file_internal_record_t *sock_impl; + OS_impl_file_internal_record_t *conn_impl; + + sock_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *sock_token); + conn_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *conn_token); operation = OS_STREAM_STATE_READABLE; - if (OS_impl_filehandle_table[sock_id].selectable) + if (sock_impl->selectable) { - return_code = OS_SelectSingle_Impl(sock_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(sock_token, &operation, timeout); } else { @@ -334,10 +344,9 @@ int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Ad } else { - addrlen = Addr->ActualLength; - OS_impl_filehandle_table[connsock_id].fd = - accept(OS_impl_filehandle_table[sock_id].fd, (struct sockaddr *)&Addr->AddrData, &addrlen); - if (OS_impl_filehandle_table[connsock_id].fd < 0) + addrlen = Addr->ActualLength; + conn_impl->fd = accept(sock_impl->fd, (struct sockaddr *)&Addr->AddrData, &addrlen); + if (conn_impl->fd < 0) { return_code = OS_ERROR; } @@ -350,11 +359,11 @@ int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Ad * this may set it to non-blocking mode if the implementation supports it. * any blocking would be done explicitly via the select() wrappers */ - os_flags = fcntl(OS_impl_filehandle_table[connsock_id].fd, F_GETFL); + os_flags = fcntl(conn_impl->fd, F_GETFL); os_flags |= OS_IMPL_SOCKET_FLAGS; - fcntl(OS_impl_filehandle_table[connsock_id].fd, F_SETFL, os_flags); + fcntl(conn_impl->fd, F_SETFL, os_flags); - OS_impl_filehandle_table[connsock_id].selectable = ((os_flags & O_NONBLOCK) != 0); + conn_impl->selectable = ((os_flags & O_NONBLOCK) != 0); } } } @@ -370,14 +379,18 @@ int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Ad * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) +int32 OS_SocketRecvFrom_Impl(const OS_object_token_t *token, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, + int32 timeout) { - int32 return_code; - int os_result; - int waitflags; - uint32 operation; - struct sockaddr *sa; - socklen_t addrlen; + int32 return_code; + int os_result; + int waitflags; + uint32 operation; + struct sockaddr * sa; + socklen_t addrlen; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); if (RemoteAddr == NULL) { @@ -395,10 +408,10 @@ int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_Soc * If "O_NONBLOCK" flag is set then use select() * Note this is the only way to get a correct timeout */ - if (OS_impl_filehandle_table[sock_id].selectable) + if (impl->selectable) { waitflags = MSG_DONTWAIT; - return_code = OS_SelectSingle_Impl(sock_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(token, &operation, timeout); } else { @@ -422,7 +435,7 @@ int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_Soc } else { - os_result = recvfrom(OS_impl_filehandle_table[sock_id].fd, buffer, buflen, waitflags, sa, &addrlen); + os_result = recvfrom(impl->fd, buffer, buflen, waitflags, sa, &addrlen); if (os_result < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) @@ -458,11 +471,15 @@ int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_Soc * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr) +int32 OS_SocketSendTo_Impl(const OS_object_token_t *token, const void *buffer, size_t buflen, + const OS_SockAddr_t *RemoteAddr) { - int os_result; - socklen_t addrlen; - const struct sockaddr *sa; + int os_result; + socklen_t addrlen; + const struct sockaddr * sa; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); sa = (const struct sockaddr *)&RemoteAddr->AddrData; switch (sa->sa_family) @@ -485,7 +502,7 @@ int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, co return OS_ERR_BAD_ADDRESS; } - os_result = sendto(OS_impl_filehandle_table[sock_id].fd, buffer, buflen, MSG_DONTWAIT, sa, addrlen); + os_result = sendto(impl->fd, buffer, buflen, MSG_DONTWAIT, sa, addrlen); if (os_result < 0) { OS_DEBUG("sendto: %s\n", strerror(errno)); @@ -503,7 +520,7 @@ int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, co * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketGetInfo_Impl(uint32 sock_id, OS_socket_prop_t *sock_prop) +int32 OS_SocketGetInfo_Impl(const OS_object_token_t *token, OS_socket_prop_t *sock_prop) { return OS_SUCCESS; } /* end OS_SocketGetInfo_Impl */ @@ -539,7 +556,7 @@ int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) #endif default: sa_family = 0; - addrlen = 0; + addrlen = 0; break; } @@ -548,7 +565,7 @@ int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) return OS_ERR_NOT_IMPLEMENTED; } - Addr->ActualLength = addrlen; + Addr->ActualLength = OSAL_SIZE_C(addrlen); Accessor->sockaddr.sa_family = sa_family; return OS_SUCCESS; @@ -562,7 +579,7 @@ int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketAddrToString_Impl(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr) +int32 OS_SocketAddrToString_Impl(char *buffer, size_t buflen, const OS_SockAddr_t *Addr) { const void * addrbuffer; const OS_SockAddr_Accessor_t *Accessor; diff --git a/src/os/portable/os-impl-console-bsp.c b/src/os/portable/os-impl-console-bsp.c index ddc6369eb..c0ba15325 100644 --- a/src/os/portable/os-impl-console-bsp.c +++ b/src/os/portable/os-impl-console-bsp.c @@ -35,10 +35,13 @@ #include #include +#include "osapi-printf.h" + #include "bsp-impl.h" #include "os-impl-console.h" #include "os-shared-printf.h" +#include "os-shared-idmap.h" /**************************************************************************************** CONSOLE OUTPUT @@ -52,14 +55,14 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_ConsoleOutput_Impl(uint32 local_id) +void OS_ConsoleOutput_Impl(const OS_object_token_t *token) { - uint32 StartPos; - uint32 EndPos; - long WriteSize; + size_t StartPos; + size_t EndPos; + size_t WriteSize; OS_console_internal_record_t *console; - console = &OS_console_table[local_id]; + console = OS_OBJECT_TABLE_GET(OS_console_table, *token); StartPos = console->ReadPos; EndPos = console->WritePos; while (StartPos != EndPos) diff --git a/src/os/portable/os-impl-no-loader.c b/src/os/portable/os-impl-no-loader.c index 37713589a..b576bff62 100644 --- a/src/os/portable/os-impl-no-loader.c +++ b/src/os/portable/os-impl-no-loader.c @@ -27,7 +27,6 @@ * for all calls. */ -#include #include "os-shared-module.h" /*---------------------------------------------------------------- @@ -38,7 +37,7 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) { return OS_ERR_NOT_IMPLEMENTED; @@ -52,7 +51,7 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(uint32 module_id) +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) { return OS_ERR_NOT_IMPLEMENTED; @@ -66,7 +65,7 @@ int32 OS_ModuleUnload_Impl(uint32 module_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(uint32 module_id, OS_module_prop_t *module_prop) +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop) { return OS_ERR_NOT_IMPLEMENTED; diff --git a/src/os/portable/os-impl-no-network.c b/src/os/portable/os-impl-no-network.c index b7dba2fb0..b25a6faf9 100644 --- a/src/os/portable/os-impl-no-network.c +++ b/src/os/portable/os-impl-no-network.c @@ -28,7 +28,6 @@ * */ -#include #include "os-shared-network.h" /**************************************************************************************** @@ -56,7 +55,7 @@ int32 OS_NetworkGetID_Impl(int32 *IdBuf) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_NetworkGetHostName_Impl(char *host_name, uint32 name_len) +int32 OS_NetworkGetHostName_Impl(char *host_name, size_t name_len) { return OS_ERR_NOT_IMPLEMENTED; } /* end OS_NetworkGetHostName_Impl */ diff --git a/src/os/portable/os-impl-no-shell.c b/src/os/portable/os-impl-no-shell.c index 31bead6e3..77ca23208 100644 --- a/src/os/portable/os-impl-no-shell.c +++ b/src/os/portable/os-impl-no-shell.c @@ -34,7 +34,7 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) { return OS_ERR_NOT_IMPLEMENTED; } diff --git a/src/os/portable/os-impl-no-sockets.c b/src/os/portable/os-impl-no-sockets.c index f2ed25204..8a4befeda 100644 --- a/src/os/portable/os-impl-no-sockets.c +++ b/src/os/portable/os-impl-no-sockets.c @@ -30,7 +30,7 @@ INCLUDE FILES ***************************************************************************************/ -#include +#include "osapi-sockets.h" #include "os-shared-sockets.h" /**************************************************************************************** @@ -42,157 +42,124 @@ ***************************************************************************************/ /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketOpen_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SocketOpen_Impl(uint32 sock_id) +int32 OS_SocketOpen_Impl(const OS_object_token_t *token) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketOpen_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketBind_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr) +int32 OS_SocketBind_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketBind_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketConnect_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 timeout) +int32 OS_SocketConnect_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr, int32 timeout) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketConnect_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketAccept_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Addr, int32 timeout) +int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_token_t *conn_token, + OS_SockAddr_t *Addr, int32 timeout) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketAccept_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketRecvFrom_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) +int32 OS_SocketRecvFrom_Impl(const OS_object_token_t *token, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, + int32 timeout) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketRecvFrom_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketSendTo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr) +int32 OS_SocketSendTo_Impl(const OS_object_token_t *token, const void *buffer, size_t buflen, + const OS_SockAddr_t *RemoteAddr) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketSendTo_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SocketGetInfo_Impl(uint32 sock_id, OS_socket_prop_t *sock_prop) +int32 OS_SocketGetInfo_Impl(const OS_object_token_t *token, OS_socket_prop_t *sock_prop) { return OS_SUCCESS; -} /* end OS_SocketGetInfo_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketAddrInit_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketAddrInit_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketAddrToString_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SocketAddrToString_Impl(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr) +int32 OS_SocketAddrToString_Impl(char *buffer, size_t buflen, const OS_SockAddr_t *Addr) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketAddrToString_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketAddrFromString_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ int32 OS_SocketAddrFromString_Impl(OS_SockAddr_t *Addr, const char *string) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketAddrFromString_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketAddrGetPort_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ int32 OS_SocketAddrGetPort_Impl(uint16 *PortNum, const OS_SockAddr_t *Addr) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketAddrGetPort_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no network configuration * - * Function: OS_SocketAddrSetPort_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum) { return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_SocketAddrSetPort_Impl */ +} diff --git a/src/os/portable/os-impl-no-symtab.c b/src/os/portable/os-impl-no-symtab.c index fb602ecae..270fd598d 100644 --- a/src/os/portable/os-impl-no-symtab.c +++ b/src/os/portable/os-impl-no-symtab.c @@ -27,33 +27,35 @@ * for all calls. */ -#include +#include "osapi-module.h" #include "os-shared-module.h" /*---------------------------------------------------------------- + * Implementation for no dynamic loader configuration * - * Function: OS_SymbolLookup_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) { return OS_ERR_NOT_IMPLEMENTED; - -} /* end OS_SymbolLookup_Impl */ +} /*---------------------------------------------------------------- + * Implementation for no dynamic loader configuration * - * Function: OS_SymbolTableDump_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail + * See prototype for argument/return detail + *-----------------------------------------------------------------*/ +int32 OS_ModuleSymbolLookup_Impl(const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName) +{ + return OS_ERR_NOT_IMPLEMENTED; +} + +/*---------------------------------------------------------------- + * Implementation for no dynamic loader configuration * + * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_SymbolTableDump_Impl(const char *filename, uint32 SizeLimit) +int32 OS_SymbolTableDump_Impl(const char *filename, size_t SizeLimit) { return (OS_ERR_NOT_IMPLEMENTED); - -} /* end OS_SymbolTableDump_Impl */ +} diff --git a/src/os/portable/os-impl-posix-dirs.c b/src/os/portable/os-impl-posix-dirs.c index 740a8fb73..05b246f6d 100644 --- a/src/os/portable/os-impl-posix-dirs.c +++ b/src/os/portable/os-impl-posix-dirs.c @@ -49,6 +49,7 @@ #include "os-impl-dirs.h" #include "os-shared-dir.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -104,14 +105,19 @@ int32 OS_DirCreate_Impl(const char *local_path, uint32 access) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) +int32 OS_DirOpen_Impl(const OS_object_token_t *token, const char *local_path) { - DIR *dp = opendir(local_path); + DIR * dp = opendir(local_path); + OS_impl_dir_internal_record_t *impl; + if (dp == NULL) { return OS_ERROR; } - OS_impl_dir_table[local_id].dp = dp; + + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); + impl->dp = dp; + return OS_SUCCESS; } /* end OS_DirOpen_Impl */ @@ -123,10 +129,15 @@ int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirClose_Impl(uint32 local_id) +int32 OS_DirClose_Impl(const OS_object_token_t *token) { - closedir(OS_impl_dir_table[local_id].dp); - OS_impl_dir_table[local_id].dp = NULL; + OS_impl_dir_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); + + closedir(impl->dp); + impl->dp = NULL; + return OS_SUCCESS; } /* end OS_DirClose_Impl */ @@ -138,9 +149,11 @@ int32 OS_DirClose_Impl(uint32 local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) +int32 OS_DirRead_Impl(const OS_object_token_t *token, os_dirent_t *dirent) { - struct dirent *de; + struct dirent * de; + OS_impl_dir_internal_record_t *impl; + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); /* NOTE - the readdir() call is non-reentrant .... * However, this is performed while the global dir table lock is taken. @@ -151,7 +164,7 @@ int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) */ /* cppcheck-suppress readdirCalled */ /* cppcheck-suppress nonreentrantFunctionsreaddir */ - de = readdir(OS_impl_dir_table[local_id].dp); + de = readdir(impl->dp); if (de == NULL) { return OS_ERROR; @@ -171,9 +184,11 @@ int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirRewind_Impl(uint32 local_id) +int32 OS_DirRewind_Impl(const OS_object_token_t *token) { - rewinddir(OS_impl_dir_table[local_id].dp); + OS_impl_dir_internal_record_t *impl; + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); + rewinddir(impl->dp); return OS_SUCCESS; } /* end OS_DirRewind_Impl */ diff --git a/src/os/portable/os-impl-posix-dl-loader.c b/src/os/portable/os-impl-posix-dl-loader.c index 55aa9ac3c..3843d5050 100644 --- a/src/os/portable/os-impl-posix-dl-loader.c +++ b/src/os/portable/os-impl-posix-dl-loader.c @@ -48,6 +48,7 @@ #include "os-impl-loader.h" #include "os-shared-module.h" +#include "os-shared-idmap.h" /**************************************************************************************** Module Loader API @@ -61,13 +62,47 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) { - int32 status = OS_ERROR; + int32 status = OS_ERROR; + int dl_mode; + OS_impl_module_internal_record_t *impl; + OS_module_internal_record_t * module; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); + module = OS_OBJECT_TABLE_GET(OS_module_table, *token); + + /* + * RTLD_NOW should instruct dlopen() to resolve all the symbols in the + * module immediately, as opposed to waiting until they are used. + * The latter (lazy mode) is non-deterministic - a resolution error on + * a rarely-used symbol could cause a random failure far in the future. + */ + dl_mode = RTLD_NOW; + + if ((module->flags & OS_MODULE_FLAG_LOCAL_SYMBOLS) != 0) + { + /* + * Do not add the symbols in this module to the global symbol table. + * This mode helps prevent any unanticipated references into this + * module, which can in turn prevent unloading via dlclose(). + */ + dl_mode |= RTLD_LOCAL; + } + else + { + /* + * Default mode - add symbols to the global symbol table, so they + * will be available to resolve symbols in future module loads. + * However, any such references will prevent unloading of this + * module via dlclose(). + */ + dl_mode |= RTLD_GLOBAL; + } dlerror(); - OS_impl_module_table[module_id].dl_handle = dlopen(translated_path, RTLD_NOW | RTLD_GLOBAL); - if (OS_impl_module_table[module_id].dl_handle != NULL) + impl->dl_handle = dlopen(translated_path, dl_mode); + if (impl->dl_handle != NULL) { status = OS_SUCCESS; } @@ -88,18 +123,21 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(uint32 module_id) +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) { - int32 status = OS_ERROR; + int32 status = OS_ERROR; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); /* ** Attempt to close/unload the module */ dlerror(); - if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) + if (dlclose(impl->dl_handle) == 0) { - OS_impl_module_table[module_id].dl_handle = NULL; - status = OS_SUCCESS; + impl->dl_handle = NULL; + status = OS_SUCCESS; } else { @@ -118,7 +156,7 @@ int32 OS_ModuleUnload_Impl(uint32 module_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(uint32 module_id, OS_module_prop_t *module_prop) +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop) { /* * Limiting strictly to POSIX-defined API means there is no defined diff --git a/src/os/portable/os-impl-posix-dl-symtab.c b/src/os/portable/os-impl-posix-dl-symtab.c index 98d861e55..629ba8d8e 100644 --- a/src/os/portable/os-impl-posix-dl-symtab.c +++ b/src/os/portable/os-impl-posix-dl-symtab.c @@ -47,6 +47,7 @@ #include "os-impl-loader.h" #include "os-shared-module.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -78,23 +79,25 @@ /*---------------------------------------------------------------- * - * Function: OS_SymbolLookup_Impl + * Function: OS_GenericSymbolLookup_Impl * * Purpose: Implemented per internal OSAL API * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_GenericSymbolLookup_Impl(void *dl_handle, cpuaddr *SymbolAddress, const char *SymbolName) { - int32 status = OS_ERROR; const char *dlError; /* Pointer to error string */ void * Function; + int32 status; + + status = OS_ERROR; /* * call dlerror() to clear any prior error that might have occurred. */ dlerror(); - Function = dlsym(OSAL_DLSYM_DEFAULT_HANDLE, SymbolName); + Function = dlsym(dl_handle, SymbolName); dlError = dlerror(); /* @@ -110,16 +113,64 @@ int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) * and as such all valid symbols should be non-NULL, so NULL is considered * an error even if the C library doesn't consider this an error. */ - if (dlError == NULL && Function != NULL) + if (dlError != NULL) + { + OS_DEBUG("Error: %s: %s\n", SymbolName, dlError); + } + else if (Function == NULL) + { + /* technically not an error per POSIX, but in practice should not happen */ + OS_DEBUG("Error: %s: dlsym() returned NULL\n", SymbolName); + } + else { - *SymbolAddress = (cpuaddr)Function; - status = OS_SUCCESS; + status = OS_SUCCESS; } + *SymbolAddress = (cpuaddr)Function; + + return status; +} + +/*---------------------------------------------------------------- + * + * Function: OS_GlobalSymbolLookup_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +{ + int32 status; + + status = OS_GenericSymbolLookup_Impl(OSAL_DLSYM_DEFAULT_HANDLE, SymbolAddress, SymbolName); + return status; } /* end OS_SymbolLookup_Impl */ +/*---------------------------------------------------------------- + * + * Function: OS_ModuleSymbolLookup_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleSymbolLookup_Impl(const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName) +{ + int32 status; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); + + status = OS_GenericSymbolLookup_Impl(impl->dl_handle, SymbolAddress, SymbolName); + + return status; + +} /* end OS_ModuleSymbolLookup_Impl */ + /*---------------------------------------------------------------- * * Function: OS_SymbolTableDump_Impl @@ -130,7 +181,7 @@ int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) * POSIX DL does not provide * *-----------------------------------------------------------------*/ -int32 OS_SymbolTableDump_Impl(const char *filename, uint32 SizeLimit) +int32 OS_SymbolTableDump_Impl(const char *filename, size_t SizeLimit) { /* * Limiting strictly to POSIX-defined API means there is no defined diff --git a/src/os/portable/os-impl-posix-files.c b/src/os/portable/os-impl-posix-files.c index 43628d5df..d97a205fa 100644 --- a/src/os/portable/os-impl-posix-files.c +++ b/src/os/portable/os-impl-posix-files.c @@ -41,11 +41,15 @@ * remove() * rename() */ + +#include #include #include +#include #include "os-impl-files.h" #include "os-shared-file.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -63,10 +67,13 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int32 access) +int32 OS_FileOpen_Impl(const OS_object_token_t *token, const char *local_path, int32 flags, int32 access) { - int os_perm; - int os_mode; + int os_perm; + int os_mode; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); /* ** Check for a valid access mode @@ -100,9 +107,9 @@ int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int os_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - OS_impl_filehandle_table[local_id].fd = open(local_path, os_perm, os_mode); + impl->fd = open(local_path, os_perm, os_mode); - if (OS_impl_filehandle_table[local_id].fd < 0) + if (impl->fd < 0) { OS_DEBUG("open(%s): %s\n", local_path, strerror(errno)); return OS_ERROR; @@ -112,7 +119,7 @@ int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int * If the flags included O_NONBLOCK, then * enable the "select" call on this handle. */ - OS_impl_filehandle_table[local_id].selectable = ((os_perm & O_NONBLOCK) != 0); + impl->selectable = ((os_perm & O_NONBLOCK) != 0); return OS_SUCCESS; } /* end OS_FileOpen_Impl */ @@ -127,10 +134,11 @@ int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int *-----------------------------------------------------------------*/ int32 OS_FileStat_Impl(const char *local_path, os_fstat_t *FileStats) { - struct stat st; - mode_t readbits; - mode_t writebits; - mode_t execbits; + struct stat st; + mode_t readbits; + mode_t writebits; + mode_t execbits; + struct timespec filetime; if (stat(local_path, &st) < 0) { @@ -138,7 +146,31 @@ int32 OS_FileStat_Impl(const char *local_path, os_fstat_t *FileStats) } FileStats->FileSize = st.st_size; - FileStats->FileTime = st.st_mtime; + + /* + * NOTE: Traditional timestamps are only a whole number of seconds (time_t) + * POSIX.1-2008 expands this to have a full "struct timespec" with nanosecond + * resolution. + * + * GLIBC (and likely other C libraries that use similar feature selection) + * will expose this value based on _POSIX_C_SOURCE or _XOPEN_SOURCE minimum + * values. Otherwise this just falls back to standard 1-second resolution + * available via the "st_mtime" member. + */ +#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) + /* + * Better - use the full resolution (seconds + nanoseconds) as specified in POSIX.1-2008 + */ + filetime = st.st_mtim; +#else + /* + * Fallback - every POSIX-compliant implementation must expose "st_mtime" field. + */ + filetime.tv_sec = st.st_mtime; + filetime.tv_nsec = 0; +#endif + + FileStats->FileTime = OS_TimeAssembleFromNanoseconds(filetime.tv_sec, filetime.tv_nsec); /* note that the "fst_mode" member is already zeroed by the caller */ if (S_ISDIR(st.st_mode)) @@ -197,14 +229,25 @@ int32 OS_FileChmod_Impl(const char *local_path, uint32 access) mode_t writebits; struct stat st; int fd; + int32 status; /* Open file to avoid filename race potential */ - fd = open(local_path, O_RDONLY); + fd = open(local_path, O_RDONLY, 0); if (fd < 0) { - return OS_ERROR; + fd = open(local_path, O_WRONLY, 0); + if (fd < 0) + { + OS_DEBUG("open(%s): %s (%d)\n", local_path, strerror(errno), errno); + return OS_ERROR; + } } + /* + * NOTE: After this point, execution must proceed to the end of this routine + * so that the "fd" opened above can be properly closed. + */ + /* * In order to preserve any OTHER mode bits, * first stat() the file and then modify the st_mode @@ -216,58 +259,81 @@ int32 OS_FileChmod_Impl(const char *local_path, uint32 access) */ if (fstat(fd, &st) < 0) { - return OS_ERROR; - } - - /* always check world bits */ - readbits = S_IROTH; - writebits = S_IWOTH; - - if (OS_IMPL_SELF_EUID == st.st_uid) - { - /* we own the file so use user bits */ - readbits |= S_IRUSR; - writebits |= S_IWUSR; - } - - if (OS_IMPL_SELF_EGID == st.st_gid) - { - /* our group owns the file so use group bits */ - readbits |= S_IRGRP; - writebits |= S_IWGRP; - } - - if (access == OS_WRITE_ONLY || access == OS_READ_WRITE) - { - /* set all "write" mode bits */ - st.st_mode |= writebits; - } - else - { - /* clear all "write" mode bits */ - st.st_mode &= ~writebits; - } - - if (access == OS_READ_ONLY || access == OS_READ_WRITE) - { - /* set all "read" mode bits */ - st.st_mode |= readbits; + OS_DEBUG("fstat(%s): %s (%d)\n", local_path, strerror(errno), errno); + status = OS_ERROR; } else { - /* clear all "read" mode bits */ - st.st_mode &= ~readbits; - } - - /* finally, write the modified mode back to the file */ - if (fchmod(fd, st.st_mode) < 0) - { - return OS_ERROR; + /* always check world bits */ + readbits = S_IROTH; + writebits = S_IWOTH; + + if (OS_IMPL_SELF_EUID == st.st_uid) + { + /* we own the file so use user bits */ + readbits |= S_IRUSR; + writebits |= S_IWUSR; + } + + if (OS_IMPL_SELF_EGID == st.st_gid) + { + /* our group owns the file so use group bits */ + readbits |= S_IRGRP; + writebits |= S_IWGRP; + } + + if (access == OS_WRITE_ONLY || access == OS_READ_WRITE) + { + /* set all "write" mode bits */ + st.st_mode |= writebits; + } + else + { + /* clear all "write" mode bits */ + st.st_mode &= ~writebits; + } + + if (access == OS_READ_ONLY || access == OS_READ_WRITE) + { + /* set all "read" mode bits */ + st.st_mode |= readbits; + } + else + { + /* clear all "read" mode bits */ + st.st_mode &= ~readbits; + } + + /* finally, write the modified mode back to the file */ + if (fchmod(fd, st.st_mode) < 0) + { + /* + * These particular errnos generally indicate that the + * underlying filesystem does not support chmod() + * + * This is often the case for FAT / DOSFS filesystems + * which do not have UNIX-style permissions, or (in the + * case of EROFS) if the filesystem is mounted read-only. + */ + if (errno == ENOTSUP || errno == ENOSYS || errno == EROFS) + { + status = OS_ERR_NOT_IMPLEMENTED; + } + else + { + OS_DEBUG("fchmod(%s): %s (%d)\n", local_path, strerror(errno), errno); + status = OS_ERROR; + } + } + else + { + status = OS_SUCCESS; + } } close(fd); - return OS_SUCCESS; + return status; } /* end OS_FileChmod_Impl */ diff --git a/src/os/portable/os-impl-posix-gettime.c b/src/os/portable/os-impl-posix-gettime.c index 670a18353..ddf59232f 100644 --- a/src/os/portable/os-impl-posix-gettime.c +++ b/src/os/portable/os-impl-posix-gettime.c @@ -47,7 +47,7 @@ #include #include -#include +#include "osapi-clock.h" #include "os-impl-gettime.h" #include "os-shared-clock.h" @@ -73,9 +73,8 @@ int32 OS_GetLocalTime_Impl(OS_time_t *time_struct) if (Status == 0) { - time_struct->seconds = time.tv_sec; - time_struct->microsecs = time.tv_nsec / 1000; - ReturnCode = OS_SUCCESS; + *time_struct = OS_TimeAssembleFromNanoseconds(time.tv_sec, time.tv_nsec); + ReturnCode = OS_SUCCESS; } else { @@ -100,8 +99,8 @@ int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct) int32 ReturnCode; struct timespec time; - time.tv_sec = time_struct->seconds; - time.tv_nsec = (time_struct->microsecs * 1000); + time.tv_sec = OS_TimeGetTotalSeconds(*time_struct); + time.tv_nsec = OS_TimeGetNanosecondsPart(*time_struct); Status = clock_settime(OSAL_GETTIME_SOURCE_CLOCK, &time); diff --git a/src/os/portable/os-impl-posix-io.c b/src/os/portable/os-impl-posix-io.c index 1f9860cb1..cabe43541 100644 --- a/src/os/portable/os-impl-posix-io.c +++ b/src/os/portable/os-impl-posix-io.c @@ -48,6 +48,7 @@ #include "os-impl-io.h" #include "os-shared-file.h" #include "os-shared-select.h" +#include "os-shared-idmap.h" /* some OS libraries (e.g. VxWorks) do not declare the API to be const-correct * It can still use this generic implementation but the call to write() must be @@ -66,11 +67,14 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GenericClose_Impl(uint32 local_id) +int32 OS_GenericClose_Impl(const OS_object_token_t *token) { - int result; + int result; + OS_impl_file_internal_record_t *impl; - result = close(OS_impl_filehandle_table[local_id].fd); + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + + result = close(impl->fd); if (result < 0) { /* @@ -86,7 +90,7 @@ int32 OS_GenericClose_Impl(uint32 local_id) */ OS_DEBUG("close: %s\n", strerror(errno)); } - OS_impl_filehandle_table[local_id].fd = -1; + impl->fd = -1; return OS_SUCCESS; } /* end OS_GenericClose_Impl */ @@ -98,10 +102,14 @@ int32 OS_GenericClose_Impl(uint32 local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GenericSeek_Impl(uint32 local_id, int32 offset, uint32 whence) +int32 OS_GenericSeek_Impl(const OS_object_token_t *token, int32 offset, uint32 whence) { - int where; - int32 result; + int where; + off_t os_result; + int32 retval; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); switch (whence) { @@ -118,8 +126,8 @@ int32 OS_GenericSeek_Impl(uint32 local_id, int32 offset, uint32 whence) return OS_ERROR; } - result = lseek(OS_impl_filehandle_table[local_id].fd, (off_t)offset, where); - if (result < 0) + os_result = lseek(impl->fd, (off_t)offset, where); + if (os_result == (off_t)-1) { if (errno == ESPIPE) { @@ -130,7 +138,7 @@ int32 OS_GenericSeek_Impl(uint32 local_id, int32 offset, uint32 whence) * Use a different error code to differentiate from an * error involving a bad whence/offset */ - result = OS_ERR_NOT_IMPLEMENTED; + retval = OS_ERR_NOT_IMPLEMENTED; } else { @@ -138,11 +146,20 @@ int32 OS_GenericSeek_Impl(uint32 local_id, int32 offset, uint32 whence) * Most likely the "whence" and/or "offset" combo was not valid. */ OS_DEBUG("lseek: %s\n", strerror(errno)); - result = OS_ERROR; + retval = OS_ERROR; } } + else + { + /* + * convert value to int32 type for returning to caller. + * Note that this could potentially overflow an int32 + * for a large file seek. + */ + retval = (int32)os_result; + } - return result; + return retval; } /* end OS_GenericSeek_Impl */ /*---------------------------------------------------------------- @@ -153,11 +170,14 @@ int32 OS_GenericSeek_Impl(uint32 local_id, int32 offset, uint32 whence) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GenericRead_Impl(uint32 local_id, void *buffer, uint32 nbytes, int32 timeout) +int32 OS_GenericRead_Impl(const OS_object_token_t *token, void *buffer, size_t nbytes, int32 timeout) { - int32 return_code; - int os_result; - uint32 operation; + int32 return_code; + ssize_t os_result; + uint32 operation; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); return_code = OS_SUCCESS; @@ -173,14 +193,14 @@ int32 OS_GenericRead_Impl(uint32 local_id, void *buffer, uint32 nbytes, int32 ti * * Note that a timeout will not work unless selectable is true. */ - if (OS_impl_filehandle_table[local_id].selectable) + if (impl->selectable) { - return_code = OS_SelectSingle_Impl(local_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(token, &operation, timeout); } if (return_code == OS_SUCCESS && (operation & OS_STREAM_STATE_READABLE) != 0) { - os_result = read(OS_impl_filehandle_table[local_id].fd, buffer, nbytes); + os_result = read(impl->fd, buffer, nbytes); if (os_result < 0) { OS_DEBUG("read: %s\n", strerror(errno)); @@ -188,7 +208,8 @@ int32 OS_GenericRead_Impl(uint32 local_id, void *buffer, uint32 nbytes, int32 ti } else { - return_code = os_result; + /* type conversion from ssize_t to int32 for return */ + return_code = (int32)os_result; } } } @@ -204,11 +225,14 @@ int32 OS_GenericRead_Impl(uint32 local_id, void *buffer, uint32 nbytes, int32 ti * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, int32 timeout) +int32 OS_GenericWrite_Impl(const OS_object_token_t *token, const void *buffer, size_t nbytes, int32 timeout) { - int32 return_code; - int os_result; - uint32 operation; + int32 return_code; + ssize_t os_result; + uint32 operation; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); return_code = OS_SUCCESS; @@ -224,16 +248,16 @@ int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, i * * Note that a timeout will not work unless selectable is true. */ - if (OS_impl_filehandle_table[local_id].selectable) + if (impl->selectable) { - return_code = OS_SelectSingle_Impl(local_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(token, &operation, timeout); } if (return_code == OS_SUCCESS && (operation & OS_STREAM_STATE_WRITABLE) != 0) { /* on some system libraries for which the write() argument is not * qualified correctly, it needs to be case to a void* here */ - os_result = write(OS_impl_filehandle_table[local_id].fd, GENERIC_IO_CONST_DATA_CAST buffer, nbytes); + os_result = write(impl->fd, GENERIC_IO_CONST_DATA_CAST buffer, nbytes); if (os_result < 0) { OS_DEBUG("write: %s\n", strerror(errno)); @@ -241,7 +265,8 @@ int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, i } else { - return_code = os_result; + /* type conversion from ssize_t to int32 for return */ + return_code = (int32)os_result; } } } diff --git a/src/os/portable/os-impl-posix-network.c b/src/os/portable/os-impl-posix-network.c index bd114b645..f6d5f540a 100644 --- a/src/os/portable/os-impl-posix-network.c +++ b/src/os/portable/os-impl-posix-network.c @@ -58,7 +58,7 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_NetworkGetHostName_Impl(char *host_name, uint32 name_len) +int32 OS_NetworkGetHostName_Impl(char *host_name, size_t name_len) { int32 return_code; diff --git a/src/os/posix/inc/os-impl-binsem.h b/src/os/posix/inc/os-impl-binsem.h index 41bb54870..356ec8e94 100644 --- a/src/os/posix/inc/os-impl-binsem.h +++ b/src/os/posix/inc/os-impl-binsem.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_BINSEM_H_ -#define INCLUDE_OS_IMPL_BINSEM_H_ +#ifndef OS_IMPL_BINSEM_H +#define OS_IMPL_BINSEM_H -#include +#include "osconfig.h" #include #include @@ -44,4 +44,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_binsem_internal_record_t OS_impl_bin_sem_table[OS_MAX_BIN_SEMAPHORES]; -#endif /* INCLUDE_OS_IMPL_BINSEM_H_ */ +#endif /* OS_IMPL_BINSEM_H */ diff --git a/src/os/posix/inc/os-impl-console.h b/src/os/posix/inc/os-impl-console.h index 82a65ee28..3ed7ac81f 100644 --- a/src/os/posix/inc/os-impl-console.h +++ b/src/os/posix/inc/os-impl-console.h @@ -25,11 +25,11 @@ * */ -#ifndef INCLUDE_OS_IMPL_CONSOLE_H_ -#define INCLUDE_OS_IMPL_CONSOLE_H_ +#ifndef OS_IMPL_CONSOLE_H +#define OS_IMPL_CONSOLE_H #include -#include +#include "osconfig.h" #include #include @@ -42,4 +42,4 @@ typedef struct extern OS_impl_console_internal_record_t OS_impl_console_table[OS_MAX_CONSOLES]; -#endif /* INCLUDE_OS_IMPL_CONSOLE_H_ */ +#endif /* OS_IMPL_CONSOLE_H */ diff --git a/src/os/posix/inc/os-impl-countsem.h b/src/os/posix/inc/os-impl-countsem.h index 9c8c2f5e6..176fcd9ec 100644 --- a/src/os/posix/inc/os-impl-countsem.h +++ b/src/os/posix/inc/os-impl-countsem.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_COUNTSEM_H_ -#define INCLUDE_OS_IMPL_COUNTSEM_H_ +#ifndef OS_IMPL_COUNTSEM_H +#define OS_IMPL_COUNTSEM_H -#include +#include "osconfig.h" #include typedef struct @@ -39,4 +39,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_countsem_internal_record_t OS_impl_count_sem_table[OS_MAX_COUNT_SEMAPHORES]; -#endif /* INCLUDE_OS_IMPL_COUNTSEM_H_ */ +#endif /* OS_IMPL_COUNTSEM_H */ diff --git a/src/os/posix/inc/os-impl-dirs.h b/src/os/posix/inc/os-impl-dirs.h index 787bb5220..e10b8e185 100644 --- a/src/os/posix/inc/os-impl-dirs.h +++ b/src/os/posix/inc/os-impl-dirs.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_DIRS_H_ -#define INCLUDE_OS_IMPL_DIRS_H_ +#ifndef OS_IMPL_DIRS_H +#define OS_IMPL_DIRS_H -#include +#include "osconfig.h" #include #include #include @@ -45,4 +45,4 @@ typedef struct */ extern OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; -#endif /* INCLUDE_OS_IMPL_DIRS_H_ */ +#endif /* OS_IMPL_DIRS_H */ diff --git a/src/os/posix/inc/os-impl-files.h b/src/os/posix/inc/os-impl-files.h index fb098aecd..ec9f1e01c 100644 --- a/src/os/posix/inc/os-impl-files.h +++ b/src/os/posix/inc/os-impl-files.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_IMPL_FILES_H_ -#define INCLUDE_OS_IMPL_FILES_H_ +#ifndef OS_IMPL_FILES_H +#define OS_IMPL_FILES_H #include "os-impl-io.h" @@ -48,4 +48,4 @@ extern gid_t OS_IMPL_SELF_EGID; extern const int OS_IMPL_REGULAR_FILE_FLAGS; -#endif /* INCLUDE_OS_IMPL_FILES_H_ */ +#endif /* OS_IMPL_FILES_H */ diff --git a/src/os/posix/inc/os-impl-gettime.h b/src/os/posix/inc/os-impl-gettime.h index 491bd27db..c48d6f324 100644 --- a/src/os/posix/inc/os-impl-gettime.h +++ b/src/os/posix/inc/os-impl-gettime.h @@ -25,12 +25,12 @@ * */ -#ifndef INCLUDE_OS_IMPL_GETTIME_H_ -#define INCLUDE_OS_IMPL_GETTIME_H_ +#ifndef OS_IMPL_GETTIME_H +#define OS_IMPL_GETTIME_H -#include +#include "osconfig.h" #include #define OSAL_GETTIME_SOURCE_CLOCK CLOCK_MONOTONIC -#endif /* INCLUDE_OS_IMPL_GETTIME_H_ */ +#endif /* OS_IMPL_GETTIME_H */ diff --git a/src/os/posix/inc/os-impl-idmap.h b/src/os/posix/inc/os-impl-idmap.h new file mode 100644 index 000000000..00194e1ac --- /dev/null +++ b/src/os/posix/inc/os-impl-idmap.h @@ -0,0 +1,44 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file os-impl-idmap.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef OS_IMPL_IDMAP_H +#define OS_IMPL_IDMAP_H + +#include "osconfig.h" +#include "osapi-idmap.h" +#include + +typedef struct +{ + pthread_mutex_t mutex; + pthread_cond_t cond; +} OS_impl_objtype_lock_t; + +/* Tables where the lock state information is stored */ +extern OS_impl_objtype_lock_t *const OS_impl_objtype_lock_table[OS_OBJECT_TYPE_USER]; + +#endif /* OS_IMPL_IDMAP_H */ diff --git a/src/os/posix/inc/os-impl-io.h b/src/os/posix/inc/os-impl-io.h index a6154b8ca..9db8e7c81 100644 --- a/src/os/posix/inc/os-impl-io.h +++ b/src/os/posix/inc/os-impl-io.h @@ -25,11 +25,11 @@ * */ -#ifndef INCLUDE_OS_IMPL_IO_H_ -#define INCLUDE_OS_IMPL_IO_H_ +#ifndef OS_IMPL_IO_H +#define OS_IMPL_IO_H -#include -#include +#include "osconfig.h" +#include "common_types.h" #include #include #include @@ -39,13 +39,13 @@ typedef struct { int fd; bool selectable; -} OS_Posix_file_internal_record_t; +} OS_impl_file_internal_record_t; /* * The global file handle table. * * This is shared by all OSAL entities that perform low-level I/O. */ -extern OS_Posix_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; +extern OS_impl_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; -#endif /* INCLUDE_OS_IMPL_IO_H_ */ +#endif /* OS_IMPL_IO_H */ diff --git a/src/os/posix/inc/os-impl-loader.h b/src/os/posix/inc/os-impl-loader.h index d98a72883..b7dc4b641 100644 --- a/src/os/posix/inc/os-impl-loader.h +++ b/src/os/posix/inc/os-impl-loader.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_LOADER_H_ -#define INCLUDE_OS_IMPL_LOADER_H_ +#ifndef OS_IMPL_LOADER_H +#define OS_IMPL_LOADER_H -#include +#include "osconfig.h" #include /* @@ -52,4 +52,4 @@ typedef struct */ extern OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; -#endif /* INCLUDE_OS_IMPL_LOADER_H_ */ +#endif /* OS_IMPL_LOADER_H */ diff --git a/src/os/posix/inc/os-impl-mutex.h b/src/os/posix/inc/os-impl-mutex.h index f3014c449..61db43dbf 100644 --- a/src/os/posix/inc/os-impl-mutex.h +++ b/src/os/posix/inc/os-impl-mutex.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_MUTEX_H_ -#define INCLUDE_OS_IMPL_MUTEX_H_ +#ifndef OS_IMPL_MUTEX_H +#define OS_IMPL_MUTEX_H -#include +#include "osconfig.h" #include /* Mutexes */ @@ -40,4 +40,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_mutex_internal_record_t OS_impl_mutex_table[OS_MAX_MUTEXES]; -#endif /* INCLUDE_OS_IMPL_MUTEX_H_ */ +#endif /* OS_IMPL_MUTEX_H */ diff --git a/src/os/posix/inc/os-impl-network.h b/src/os/posix/inc/os-impl-network.h index 6a912471c..977f978d6 100644 --- a/src/os/posix/inc/os-impl-network.h +++ b/src/os/posix/inc/os-impl-network.h @@ -25,9 +25,9 @@ * */ -#ifndef INCLUDE_OS_IMPL_NETWORK_H_ -#define INCLUDE_OS_IMPL_NETWORK_H_ +#ifndef OS_IMPL_NETWORK_H +#define OS_IMPL_NETWORK_H #include -#endif /* INCLUDE_OS_IMPL_NETWORK_H_ */ +#endif /* OS_IMPL_NETWORK_H */ diff --git a/src/os/posix/inc/os-impl-queues.h b/src/os/posix/inc/os-impl-queues.h index 4f92150ca..673b6a0a0 100644 --- a/src/os/posix/inc/os-impl-queues.h +++ b/src/os/posix/inc/os-impl-queues.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_QUEUES_H_ -#define INCLUDE_OS_IMPL_QUEUES_H_ +#ifndef OS_IMPL_QUEUES_H +#define OS_IMPL_QUEUES_H -#include +#include "osconfig.h" #include /* queues */ @@ -40,4 +40,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_queue_internal_record_t OS_impl_queue_table[OS_MAX_QUEUES]; -#endif /* INCLUDE_OS_IMPL_QUEUES_H_ */ +#endif /* OS_IMPL_QUEUES_H */ diff --git a/src/os/posix/inc/os-impl-select.h b/src/os/posix/inc/os-impl-select.h index 9b6cc8c34..bdcdc9ba0 100644 --- a/src/os/posix/inc/os-impl-select.h +++ b/src/os/posix/inc/os-impl-select.h @@ -25,12 +25,12 @@ * */ -#ifndef INCLUDE_OS_IMPL_SELECT_H_ -#define INCLUDE_OS_IMPL_SELECT_H_ +#ifndef OS_IMPL_SELECT_H +#define OS_IMPL_SELECT_H #include "os-impl-io.h" #include #include -#endif /* INCLUDE_OS_IMPL_SELECT_H_ */ +#endif /* OS_IMPL_SELECT_H */ diff --git a/src/os/posix/inc/os-impl-sockets.h b/src/os/posix/inc/os-impl-sockets.h index bf93418b6..217253246 100644 --- a/src/os/posix/inc/os-impl-sockets.h +++ b/src/os/posix/inc/os-impl-sockets.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_IMPL_SOCKETS_H_ -#define INCLUDE_OS_IMPL_SOCKETS_H_ +#ifndef OS_IMPL_SOCKETS_H +#define OS_IMPL_SOCKETS_H #include "os-impl-io.h" @@ -43,4 +43,4 @@ */ #define OS_IMPL_SOCKET_FLAGS O_NONBLOCK -#endif /* INCLUDE_OS_IMPL_SOCKETS_H_ */ +#endif /* OS_IMPL_SOCKETS_H */ diff --git a/src/os/posix/inc/os-impl-tasks.h b/src/os/posix/inc/os-impl-tasks.h index 0c8eef544..da25cd0ea 100644 --- a/src/os/posix/inc/os-impl-tasks.h +++ b/src/os/posix/inc/os-impl-tasks.h @@ -25,10 +25,12 @@ * */ -#ifndef INCLUDE_OS_IMPL_TASKS_H_ -#define INCLUDE_OS_IMPL_TASKS_H_ +#ifndef OS_IMPL_TASKS_H +#define OS_IMPL_TASKS_H -#include +#include + +#include "osconfig.h" #include /*tasks */ @@ -40,4 +42,7 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_task_internal_record_t OS_impl_task_table[OS_MAX_TASKS]; -#endif /* INCLUDE_OS_IMPL_TASKS_H_ */ +int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, osal_priority_t priority, size_t stacksz, + PthreadFuncPtr_t entry, void *entry_arg); + +#endif /* OS_IMPL_TASKS_H */ diff --git a/src/os/posix/inc/os-impl-timebase.h b/src/os/posix/inc/os-impl-timebase.h index edd1a4c87..a995f4b8b 100644 --- a/src/os/posix/inc/os-impl-timebase.h +++ b/src/os/posix/inc/os-impl-timebase.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_TIMEBASE_H_ -#define INCLUDE_OS_IMPL_TIMEBASE_H_ +#ifndef OS_IMPL_TIMEBASE_H +#define OS_IMPL_TIMEBASE_H -#include +#include "osconfig.h" #include #include @@ -50,4 +50,4 @@ typedef struct extern OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; -#endif /* INCLUDE_OS_IMPL_TIMEBASE_H_ */ +#endif /* OS_IMPL_TIMEBASE_H */ diff --git a/src/os/posix/inc/os-posix.h b/src/os/posix/inc/os-posix.h index 965ba58f5..9c2c1d2c9 100644 --- a/src/os/posix/inc/os-posix.h +++ b/src/os/posix/inc/os-posix.h @@ -28,8 +28,8 @@ * may contain POSIX-specific definitions. */ -#ifndef INCLUDE_OS_POSIX_H_ -#define INCLUDE_OS_POSIX_H_ +#ifndef OS_POSIX_H +#define OS_POSIX_H /**************************************************************************************** COMMON INCLUDE FILES @@ -74,7 +74,7 @@ typedef struct typedef struct { bool EnableTaskPriorities; - uint32 TruncateQueueDepth; + osal_blockcount_t TruncateQueueDepth; uint32 ClockAccuracyNsec; pthread_key_t ThreadKey; sigset_t MaximumSigMask; @@ -105,10 +105,8 @@ int32 OS_Posix_StreamAPI_Impl_Init(void); int32 OS_Posix_DirAPI_Impl_Init(void); int32 OS_Posix_FileSysAPI_Impl_Init(void); -int32 OS_Posix_TableMutex_Init(uint32 idtype); +int32 OS_Posix_TableMutex_Init(osal_objtype_t idtype); -int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t stacksz, PthreadFuncPtr_t entry, - void *entry_arg); -void OS_Posix_CompAbsDelayTime(uint32 msecs, struct timespec *tm); +void OS_Posix_CompAbsDelayTime(uint32 msecs, struct timespec *tm); -#endif /* INCLUDE_OS_POSIX_H_ */ +#endif /* OS_POSIX_H */ diff --git a/src/os/posix/src/os-impl-binsem.c b/src/os/posix/src/os-impl-binsem.c index 6e27cbb41..42999931a 100644 --- a/src/os/posix/src/os-impl-binsem.c +++ b/src/os/posix/src/os-impl-binsem.c @@ -32,6 +32,7 @@ ***************************************************************************************/ #include "os-posix.h" +#include "os-shared-idmap.h" #include "os-shared-binsem.h" #include "os-impl-binsem.h" @@ -118,7 +119,7 @@ int32 OS_Posix_BinSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 initial_value, uint32 options) +int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 initial_value, uint32 options) { int ret; int attr_created; @@ -141,7 +142,7 @@ int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 initial_value, uint32 options) attr_created = 0; mutex_created = 0; cond_created = 0; - sem = &OS_impl_bin_sem_table[sem_id]; + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); memset(sem, 0, sizeof(*sem)); do @@ -197,6 +198,17 @@ int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 initial_value, uint32 options) cond_created = 1; + /* + * Check sem call, avoids unreachable destroy logic + */ + ret = pthread_cond_signal(&(sem->cv)); + if (ret != 0) + { + OS_DEBUG("Error: initial pthread_cond_signal failed: %s\n", strerror(ret)); + return_code = OS_SEM_FAILURE; + break; + } + /* ** fill out the proper OSAL table fields */ @@ -240,12 +252,12 @@ int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 initial_value, uint32 options) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl(uint32 sem_id) +int32 OS_BinSemDelete_Impl(const OS_object_token_t *token) { OS_impl_binsem_internal_record_t *sem; int32 return_code; - sem = &OS_impl_bin_sem_table[sem_id]; + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); if (pthread_cond_destroy(&(sem->cv)) != 0) { @@ -279,11 +291,11 @@ int32 OS_BinSemDelete_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl(uint32 sem_id) +int32 OS_BinSemGive_Impl(const OS_object_token_t *token) { OS_impl_binsem_internal_record_t *sem; - sem = &OS_impl_bin_sem_table[sem_id]; + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* * Note there is a possibility that another thread is concurrently taking this sem, @@ -324,11 +336,11 @@ int32 OS_BinSemGive_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl(uint32 sem_id) +int32 OS_BinSemFlush_Impl(const OS_object_token_t *token) { OS_impl_binsem_internal_record_t *sem; - sem = &OS_impl_bin_sem_table[sem_id]; + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* Lock the mutex ( not the table! ) */ if (OS_Posix_BinSemAcquireMutex(&sem->id) != OS_SUCCESS) @@ -358,10 +370,13 @@ int32 OS_BinSemFlush_Impl(uint32 sem_id) becomes nonzero (via SemGive) or the semaphore gets flushed. ---------------------------------------------------------------------------------------*/ -static int32 OS_GenericBinSemTake_Impl(OS_impl_binsem_internal_record_t *sem, const struct timespec *timeout) +static int32 OS_GenericBinSemTake_Impl(const OS_object_token_t *token, const struct timespec *timeout) { - sig_atomic_t flush_count; - int32 return_code; + sig_atomic_t flush_count; + int32 return_code; + OS_impl_binsem_internal_record_t *sem; + + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* * Note - this lock should be quickly available - should not delay here. @@ -441,9 +456,9 @@ static int32 OS_GenericBinSemTake_Impl(OS_impl_binsem_internal_record_t *sem, co * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl(uint32 sem_id) +int32 OS_BinSemTake_Impl(const OS_object_token_t *token) { - return (OS_GenericBinSemTake_Impl(&OS_impl_bin_sem_table[sem_id], NULL)); + return (OS_GenericBinSemTake_Impl(token, NULL)); } /* end OS_BinSemTake_Impl */ /*---------------------------------------------------------------- @@ -454,7 +469,7 @@ int32 OS_BinSemTake_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl(uint32 sem_id, uint32 msecs) +int32 OS_BinSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { struct timespec ts; @@ -463,7 +478,7 @@ int32 OS_BinSemTimedWait_Impl(uint32 sem_id, uint32 msecs) */ OS_Posix_CompAbsDelayTime(msecs, &ts); - return (OS_GenericBinSemTake_Impl(&OS_impl_bin_sem_table[sem_id], &ts)); + return (OS_GenericBinSemTake_Impl(token, &ts)); } /* end OS_BinSemTimedWait_Impl */ /*---------------------------------------------------------------- @@ -474,9 +489,13 @@ int32 OS_BinSemTimedWait_Impl(uint32 sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl(uint32 sem_id, OS_bin_sem_prop_t *sem_prop) +int32 OS_BinSemGetInfo_Impl(const OS_object_token_t *token, OS_bin_sem_prop_t *sem_prop) { + OS_impl_binsem_internal_record_t *sem; + + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* put the info into the stucture */ - sem_prop->value = OS_impl_bin_sem_table[sem_id].current_value; + sem_prop->value = sem->current_value; return OS_SUCCESS; } /* end OS_BinSemGetInfo_Impl */ diff --git a/src/os/posix/src/os-impl-common.c b/src/os/posix/src/os-impl-common.c index 4412dba35..8fbd44ea4 100644 --- a/src/os/posix/src/os-impl-common.c +++ b/src/os/posix/src/os-impl-common.c @@ -40,7 +40,6 @@ #include "os-shared-common.h" #include "os-shared-idmap.h" -#include "os-shared-errors.h" POSIX_GlobalVars_t POSIX_GlobalVars = {0}; @@ -52,7 +51,7 @@ POSIX_GlobalVars_t POSIX_GlobalVars = {0}; returns: OS_SUCCESS or OS_ERROR ---------------------------------------------------------------------------------------*/ -int32 OS_API_Impl_Init(uint32 idtype) +int32 OS_API_Impl_Init(osal_objtype_t idtype) { int32 return_code; diff --git a/src/os/posix/src/os-impl-console.c b/src/os/posix/src/os-impl-console.c index a97799683..e1bca4450 100644 --- a/src/os/posix/src/os-impl-console.c +++ b/src/os/posix/src/os-impl-console.c @@ -31,8 +31,11 @@ #include "os-posix.h" #include "os-impl-console.h" +#include "os-impl-tasks.h" +#include "os-shared-idmap.h" #include "os-shared-printf.h" +#include "os-shared-common.h" /* * By default the console output is always asynchronous @@ -59,9 +62,11 @@ OS_impl_console_internal_record_t OS_impl_console_table[OS_MAX_CONSOLES]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(uint32 local_id) +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; + + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); if (local->is_async) { @@ -71,7 +76,7 @@ void OS_ConsoleWakeup_Impl(uint32 local_id) else { /* output directly */ - OS_ConsoleOutput_Impl(local_id); + OS_ConsoleOutput_Impl(token); } } /* end OS_ConsoleWakeup_Impl */ @@ -87,13 +92,20 @@ static void *OS_ConsoleTask_Entry(void *arg) { OS_U32ValueWrapper_t local_arg; OS_impl_console_internal_record_t *local; + OS_object_token_t token; local_arg.opaque_arg = arg; - local = &OS_impl_console_table[local_arg.value]; - while (true) + if (OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_CONSOLE, local_arg.id, &token) == OS_SUCCESS) { - OS_ConsoleOutput_Impl(local_arg.value); - sem_wait(&local->data_sem); + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, token); + + /* Loop forever (unless shutdown is set) */ + while (OS_SharedGlobalVars.ShutdownFlag != OS_SHUTDOWN_MAGIC_NUMBER) + { + OS_ConsoleOutput_Impl(&token); + sem_wait(&local->data_sem); + } + OS_ObjectIdRelease(&token); } return NULL; } /* end OS_ConsoleTask_Entry */ @@ -106,33 +118,35 @@ static void *OS_ConsoleTask_Entry(void *arg) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(uint32 local_id) +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; pthread_t consoletask; int32 return_code; OS_U32ValueWrapper_t local_arg = {0}; - if (local_id == 0) + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); + + if (token->obj_idx == 0) { return_code = OS_SUCCESS; local->is_async = OS_CONSOLE_ASYNC; if (local->is_async) { - if (sem_init(&OS_impl_console_table[local_id].data_sem, 0, 0) < 0) + if (sem_init(&local->data_sem, 0, 0) < 0) { return_code = OS_SEM_FAILURE; } else { - local_arg.value = local_id; - return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, 0, + local_arg.id = OS_ObjectIdFromToken(token); + return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, 0, OS_ConsoleTask_Entry, local_arg.opaque_arg); if (return_code != OS_SUCCESS) { - sem_destroy(&OS_impl_console_table[local_id].data_sem); + sem_destroy(&local->data_sem); } } } diff --git a/src/os/posix/src/os-impl-countsem.c b/src/os/posix/src/os-impl-countsem.c index 22fd5cc71..dac78b6ab 100644 --- a/src/os/posix/src/os-impl-countsem.c +++ b/src/os/posix/src/os-impl-countsem.c @@ -32,6 +32,7 @@ #include "os-posix.h" #include "os-impl-countsem.h" #include "os-shared-countsem.h" +#include "os-shared-idmap.h" /* * Added SEM_VALUE_MAX Define @@ -74,14 +75,18 @@ int32 OS_Posix_CountSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_CountSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + if (sem_initial_value > SEM_VALUE_MAX) { return OS_INVALID_SEM_VALUE; } - if (sem_init(&OS_impl_count_sem_table[sem_id].id, 0, sem_initial_value) < 0) + if (sem_init(&impl->id, 0, sem_initial_value) < 0) { return OS_SEM_FAILURE; } @@ -98,9 +103,13 @@ int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 opt * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl(uint32 sem_id) +int32 OS_CountSemDelete_Impl(const OS_object_token_t *token) { - if (sem_destroy(&OS_impl_count_sem_table[sem_id].id) < 0) + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + if (sem_destroy(&impl->id) < 0) { return OS_SEM_FAILURE; } @@ -117,9 +126,13 @@ int32 OS_CountSemDelete_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl(uint32 sem_id) +int32 OS_CountSemGive_Impl(const OS_object_token_t *token) { - if (sem_post(&OS_impl_count_sem_table[sem_id].id) < 0) + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + if (sem_post(&impl->id) < 0) { return OS_SEM_FAILURE; } @@ -136,9 +149,13 @@ int32 OS_CountSemGive_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl(uint32 sem_id) +int32 OS_CountSemTake_Impl(const OS_object_token_t *token) { - if (sem_wait(&OS_impl_count_sem_table[sem_id].id) < 0) + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + if (sem_wait(&impl->id) < 0) { return OS_SEM_FAILURE; } @@ -154,17 +171,20 @@ int32 OS_CountSemTake_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl(uint32 sem_id, uint32 msecs) +int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - struct timespec ts; - int result; + struct timespec ts; + int result; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); /* ** Compute an absolute time for the delay */ OS_Posix_CompAbsDelayTime(msecs, &ts); - if (sem_timedwait(&OS_impl_count_sem_table[sem_id].id, &ts) == 0) + if (sem_timedwait(&impl->id, &ts) == 0) { result = OS_SUCCESS; } @@ -189,11 +209,14 @@ int32 OS_CountSemTimedWait_Impl(uint32 sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl(uint32 sem_id, OS_count_sem_prop_t *count_prop) +int32 OS_CountSemGetInfo_Impl(const OS_object_token_t *token, OS_count_sem_prop_t *count_prop) { - int sval; + int sval; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); - if (sem_getvalue(&OS_impl_count_sem_table[sem_id].id, &sval) < 0) + if (sem_getvalue(&impl->id, &sval) < 0) { return OS_SEM_FAILURE; } diff --git a/src/os/posix/src/os-impl-files.c b/src/os/posix/src/os-impl-files.c index 320867963..c828947b0 100644 --- a/src/os/posix/src/os-impl-files.c +++ b/src/os/posix/src/os-impl-files.c @@ -48,7 +48,7 @@ * * This is shared by all OSAL entities that perform low-level I/O. */ -OS_Posix_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; +OS_impl_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; /* * These two constants (EUID and EGID) are local cache of the @@ -85,7 +85,7 @@ const int OS_IMPL_REGULAR_FILE_FLAGS = O_NONBLOCK; ---------------------------------------------------------------------------------------*/ int32 OS_Posix_StreamAPI_Impl_Init(void) { - uint32 local_id; + osal_index_t local_id; /* * init all filehandles to -1, which is always invalid. diff --git a/src/os/posix/src/os-impl-filesys.c b/src/os/posix/src/os-impl-filesys.c index bd67779cb..4213b39ad 100644 --- a/src/os/posix/src/os-impl-filesys.c +++ b/src/os/posix/src/os-impl-filesys.c @@ -44,6 +44,7 @@ #include "os-posix.h" #include "os-shared-filesys.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -82,9 +83,9 @@ int32 OS_Posix_FileSysAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStartVolume_Impl(uint32 filesys_id) +int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct stat stat_buf; const char * tmpdir; uint32 i; @@ -97,6 +98,8 @@ int32 OS_FileSysStartVolume_Impl(uint32 filesys_id) VOLATILE_DISK_LOC_MAX }; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + /* * Determine basic type of filesystem, if not already known */ @@ -184,7 +187,7 @@ int32 OS_FileSysStartVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStopVolume_Impl(uint32 filesys_id) +int32 OS_FileSysStopVolume_Impl(const OS_object_token_t *token) { /* * This is a no-op. @@ -207,7 +210,7 @@ int32 OS_FileSysStopVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysFormatVolume_Impl(uint32 filesys_id) +int32 OS_FileSysFormatVolume_Impl(const OS_object_token_t *token) { /* * In theory, this should wipe any existing files in the ramdisk, @@ -230,11 +233,13 @@ int32 OS_FileSysFormatVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysMountVolume_Impl(uint32 filesys_id) +int32 OS_FileSysMountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct stat stat_buf; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + /* * This will do a mkdir() for the mount point if it does * not already exist. @@ -282,7 +287,7 @@ int32 OS_FileSysMountVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysUnmountVolume_Impl(uint32 filesys_id) +int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token) { /* * NOTE: Mounting/Unmounting on POSIX is not implemented. @@ -303,19 +308,21 @@ int32 OS_FileSysUnmountVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result) +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct statvfs stat_buf; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + if (statvfs(local->system_mountpt, &stat_buf) != 0) { return OS_ERROR; } - result->block_size = stat_buf.f_bsize; - result->blocks_free = stat_buf.f_bfree; - result->total_blocks = stat_buf.f_blocks; + result->block_size = OSAL_SIZE_C(stat_buf.f_bsize); + result->blocks_free = OSAL_BLOCKCOUNT_C(stat_buf.f_bfree); + result->total_blocks = OSAL_BLOCKCOUNT_C(stat_buf.f_blocks); return (OS_SUCCESS); } /* end OS_FileSysStatVolume_Impl */ @@ -328,7 +335,7 @@ int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysCheckVolume_Impl(uint32 filesys_id, bool repair) +int32 OS_FileSysCheckVolume_Impl(const OS_object_token_t *token, bool repair) { return OS_ERR_NOT_IMPLEMENTED; } /* end OS_FileSysCheckVolume_Impl */ diff --git a/src/os/posix/src/os-impl-idmap.c b/src/os/posix/src/os-impl-idmap.c index 233d81d15..60c7ce0c2 100644 --- a/src/os/posix/src/os-impl-idmap.c +++ b/src/os/posix/src/os-impl-idmap.c @@ -34,46 +34,45 @@ #include #include "os-shared-idmap.h" - -typedef struct -{ - pthread_mutex_t mutex; - sigset_t sigmask; -} POSIX_GlobalLock_t; - -static POSIX_GlobalLock_t OS_global_task_table_mut; -static POSIX_GlobalLock_t OS_queue_table_mut; -static POSIX_GlobalLock_t OS_bin_sem_table_mut; -static POSIX_GlobalLock_t OS_mutex_table_mut; -static POSIX_GlobalLock_t OS_count_sem_table_mut; -static POSIX_GlobalLock_t OS_stream_table_mut; -static POSIX_GlobalLock_t OS_dir_table_mut; -static POSIX_GlobalLock_t OS_timebase_table_mut; -static POSIX_GlobalLock_t OS_timecb_table_mut; -static POSIX_GlobalLock_t OS_module_table_mut; -static POSIX_GlobalLock_t OS_filesys_table_mut; -static POSIX_GlobalLock_t OS_console_mut; - -static POSIX_GlobalLock_t *const MUTEX_TABLE[] = { +#include "os-impl-idmap.h" + +static OS_impl_objtype_lock_t OS_global_task_table_lock; +static OS_impl_objtype_lock_t OS_queue_table_lock; +static OS_impl_objtype_lock_t OS_bin_sem_table_lock; +static OS_impl_objtype_lock_t OS_mutex_table_lock; +static OS_impl_objtype_lock_t OS_count_sem_table_lock; +static OS_impl_objtype_lock_t OS_stream_table_lock; +static OS_impl_objtype_lock_t OS_dir_table_lock; +static OS_impl_objtype_lock_t OS_timebase_table_lock; +static OS_impl_objtype_lock_t OS_timecb_table_lock; +static OS_impl_objtype_lock_t OS_module_table_lock; +static OS_impl_objtype_lock_t OS_filesys_table_lock; +static OS_impl_objtype_lock_t OS_console_lock; + +OS_impl_objtype_lock_t *const OS_impl_objtype_lock_table[OS_OBJECT_TYPE_USER] = { [OS_OBJECT_TYPE_UNDEFINED] = NULL, - [OS_OBJECT_TYPE_OS_TASK] = &OS_global_task_table_mut, - [OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_mut, - [OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_mut, - [OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_mut, - [OS_OBJECT_TYPE_OS_MUTEX] = &OS_mutex_table_mut, - [OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_mut, - [OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_mut, - [OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_mut, - [OS_OBJECT_TYPE_OS_TIMECB] = &OS_timecb_table_mut, - [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_mut, - [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_mut, - [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_mut, + [OS_OBJECT_TYPE_OS_TASK] = &OS_global_task_table_lock, + [OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_lock, + [OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_lock, + [OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_lock, + [OS_OBJECT_TYPE_OS_MUTEX] = &OS_mutex_table_lock, + [OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_lock, + [OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_lock, + [OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_lock, + [OS_OBJECT_TYPE_OS_TIMECB] = &OS_timecb_table_lock, + [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_lock, + [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_lock, + [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_lock, }; -enum +/*--------------------------------------------------------------------------------------- + * Helper function for releasing the mutex in case the thread + * executing pthread_condwait() is canceled. + ----------------------------------------------------------------------------------------*/ +void OS_Posix_ReleaseTableMutex(void *mut) { - MUTEX_TABLE_SIZE = (sizeof(MUTEX_TABLE) / sizeof(MUTEX_TABLE[0])) -}; + pthread_mutex_unlock(mut); +} /*---------------------------------------------------------------- * @@ -83,32 +82,19 @@ enum * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_Lock_Global_Impl(uint32 idtype) +void OS_Lock_Global_Impl(osal_objtype_t idtype) { - POSIX_GlobalLock_t *mut; - sigset_t previous; + OS_impl_objtype_lock_t *impl; + int ret; - mut = MUTEX_TABLE[idtype]; - - if (mut == NULL) - { - return OS_ERROR; - } + impl = OS_impl_objtype_lock_table[idtype]; - if (pthread_sigmask(SIG_SETMASK, &POSIX_GlobalVars.MaximumSigMask, &previous) != 0) + ret = pthread_mutex_lock(&impl->mutex); + if (ret != 0) { - return OS_ERROR; + OS_DEBUG("pthread_mutex_lock(&impl->mutex): %s", strerror(ret)); } - if (pthread_mutex_lock(&mut->mutex) != 0) - { - return OS_ERROR; - } - - /* Only set values inside the GlobalLock _after_ it is locked */ - mut->sigmask = previous; - - return OS_SUCCESS; } /* end OS_Lock_Global_Impl */ /*---------------------------------------------------------------- @@ -119,37 +105,73 @@ int32 OS_Lock_Global_Impl(uint32 idtype) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_Unlock_Global_Impl(uint32 idtype) +void OS_Unlock_Global_Impl(osal_objtype_t idtype) { - POSIX_GlobalLock_t *mut; - sigset_t previous; + OS_impl_objtype_lock_t *impl; + int ret; - if (idtype < MUTEX_TABLE_SIZE) - { - mut = MUTEX_TABLE[idtype]; - } - else + impl = OS_impl_objtype_lock_table[idtype]; + + /* Notify any waiting threads that the state _may_ have changed */ + ret = pthread_cond_broadcast(&impl->cond); + if (ret != 0) { - mut = NULL; + OS_DEBUG("pthread_cond_broadcast(&impl->cond): %s", strerror(ret)); + /* unexpected but keep going (not critical) */ } - if (mut == NULL) + ret = pthread_mutex_unlock(&impl->mutex); + if (ret != 0) { - return OS_ERROR; + OS_DEBUG("pthread_mutex_unlock(&impl->mutex): %s", strerror(ret)); } - /* Only get values inside the GlobalLock _before_ it is unlocked */ - previous = mut->sigmask; +} /* end OS_Unlock_Global_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_WaitForStateChange_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_WaitForStateChange_Impl(osal_objtype_t idtype, uint32 attempts) +{ + OS_impl_objtype_lock_t *impl; + struct timespec ts; + + impl = OS_impl_objtype_lock_table[idtype]; - if (pthread_mutex_unlock(&mut->mutex) != 0) + /* + * because pthread_cond_timedwait() is also a cancellation point, + * this pushes a cleanup handler to ensure that if canceled during this call, + * the mutex will be released. + */ + pthread_cleanup_push(OS_Posix_ReleaseTableMutex, &impl->mutex); + + clock_gettime(CLOCK_REALTIME, &ts); + + if (attempts <= 10) + { + /* Wait an increasing amount of time, starting at 10ms */ + ts.tv_nsec += attempts * attempts * 10000000; + if (ts.tv_nsec >= 1000000000) + { + ts.tv_nsec -= 1000000000; + ++ts.tv_sec; + } + } + else { - return OS_ERROR; + /* wait 1 second (max for polling) */ + ++ts.tv_sec; } - pthread_sigmask(SIG_SETMASK, &previous, NULL); + pthread_cond_timedwait(&impl->cond, &impl->mutex, &ts); - return OS_SUCCESS; -} /* end OS_Unlock_Global_Impl */ + pthread_cleanup_pop(false); +} /*--------------------------------------------------------------------------------------- Name: OS_Posix_TableMutex_Init @@ -158,27 +180,23 @@ int32 OS_Unlock_Global_Impl(uint32 idtype) returns: OS_SUCCESS or OS_ERROR ---------------------------------------------------------------------------------------*/ -int32 OS_Posix_TableMutex_Init(uint32 idtype) +int32 OS_Posix_TableMutex_Init(osal_objtype_t idtype) { - int ret; - int32 return_code = OS_SUCCESS; - pthread_mutexattr_t mutex_attr; + int ret; + int32 return_code = OS_SUCCESS; + pthread_mutexattr_t mutex_attr; + OS_impl_objtype_lock_t *impl; - do + impl = OS_impl_objtype_lock_table[idtype]; + if (impl == NULL) { - if (idtype >= MUTEX_TABLE_SIZE) - { - break; - } - - /* Initialize the table mutex for the given idtype */ - if (MUTEX_TABLE[idtype] == NULL) - { - break; - } + return OS_SUCCESS; + } + do + { /* - ** initialize the pthread mutex attribute structure with default values + * initialize the pthread mutex attribute structure with default values */ ret = pthread_mutexattr_init(&mutex_attr); if (ret != 0) @@ -189,7 +207,7 @@ int32 OS_Posix_TableMutex_Init(uint32 idtype) } /* - ** Allow the mutex to use priority inheritance + * Allow the mutex to use priority inheritance */ ret = pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT); if (ret != 0) @@ -200,10 +218,10 @@ int32 OS_Posix_TableMutex_Init(uint32 idtype) } /* - ** Set the mutex type to RECURSIVE so a thread can do nested locks - ** TBD - not sure if this is really desired, but keep it for now. + * Use normal (faster/non-recursive) mutex implementation + * There should not be any instances of OSAL locking its own table more than once. */ - ret = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); + ret = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_NORMAL); if (ret != 0) { OS_DEBUG("Error: pthread_mutexattr_settype failed: %s\n", strerror(ret)); @@ -211,13 +229,24 @@ int32 OS_Posix_TableMutex_Init(uint32 idtype) break; } - ret = pthread_mutex_init(&MUTEX_TABLE[idtype]->mutex, &mutex_attr); + ret = pthread_mutex_init(&impl->mutex, &mutex_attr); if (ret != 0) { OS_DEBUG("Error: pthread_mutex_init failed: %s\n", strerror(ret)); return_code = OS_ERROR; break; } + + /* create a condition variable with default attributes. + * This will be broadcast every time the object table changes */ + ret = pthread_cond_init(&impl->cond, NULL); + if (ret != 0) + { + OS_DEBUG("Error: pthread_cond_init failed: %s\n", strerror(ret)); + return_code = OS_ERROR; + break; + } + } while (0); return (return_code); diff --git a/src/os/posix/src/os-impl-mutex.c b/src/os/posix/src/os-impl-mutex.c index 3fbd17479..5a0e43593 100644 --- a/src/os/posix/src/os-impl-mutex.c +++ b/src/os/posix/src/os-impl-mutex.c @@ -31,6 +31,7 @@ #include "os-posix.h" #include "os-shared-mutex.h" +#include "os-shared-idmap.h" #include "os-impl-mutex.h" /* Tables where the OS object information is stored */ @@ -61,10 +62,13 @@ int32 OS_Posix_MutexAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) +int32 OS_MutSemCreate_Impl(const OS_object_token_t *token, uint32 options) { - int return_code; - pthread_mutexattr_t mutex_attr; + int return_code; + pthread_mutexattr_t mutex_attr; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* ** initialize the attribute with default values @@ -72,8 +76,8 @@ int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) return_code = pthread_mutexattr_init(&mutex_attr); if (return_code != 0) { - OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_init failed ID = %u: %s\n", (unsigned int)sem_id, - strerror(return_code)); + OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_init failed ID = %lu: %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(return_code)); return OS_SEM_FAILURE; } @@ -83,8 +87,8 @@ int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) return_code = pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT); if (return_code != 0) { - OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_setprotocol failed ID = %u: %s\n", - (unsigned int)sem_id, strerror(return_code)); + OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_setprotocol failed ID = %lu: %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(return_code)); return OS_SEM_FAILURE; } @@ -94,8 +98,8 @@ int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) return_code = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); if (return_code != 0) { - OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_settype failed ID = %u: %s\n", - (unsigned int)sem_id, strerror(return_code)); + OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_settype failed ID = %lu: %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(return_code)); return OS_SEM_FAILURE; } @@ -103,10 +107,11 @@ int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) ** create the mutex ** upon successful initialization, the state of the mutex becomes initialized and unlocked */ - return_code = pthread_mutex_init(&OS_impl_mutex_table[sem_id].id, &mutex_attr); + return_code = pthread_mutex_init(&impl->id, &mutex_attr); if (return_code != 0) { - OS_DEBUG("Error: Mutex could not be created. ID = %u: %s\n", (unsigned int)sem_id, strerror(return_code)); + OS_DEBUG("Error: Mutex could not be created. ID = %lu: %s\n", OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), + strerror(return_code)); return OS_SEM_FAILURE; } @@ -121,11 +126,14 @@ int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl(uint32 sem_id) +int32 OS_MutSemDelete_Impl(const OS_object_token_t *token) { - int status; + int status; + OS_impl_mutex_internal_record_t *impl; - status = pthread_mutex_destroy(&(OS_impl_mutex_table[sem_id].id)); /* 0 = success */ + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); + + status = pthread_mutex_destroy(&(impl->id)); /* 0 = success */ if (status != 0) { @@ -144,14 +152,17 @@ int32 OS_MutSemDelete_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl(uint32 sem_id) +int32 OS_MutSemGive_Impl(const OS_object_token_t *token) { - int status; + int status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* ** Unlock the mutex */ - status = pthread_mutex_unlock(&(OS_impl_mutex_table[sem_id].id)); + status = pthread_mutex_unlock(&(impl->id)); if (status != 0) { return OS_SEM_FAILURE; @@ -168,14 +179,17 @@ int32 OS_MutSemGive_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl(uint32 sem_id) +int32 OS_MutSemTake_Impl(const OS_object_token_t *token) { - int status; + int status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* ** Lock the mutex */ - status = pthread_mutex_lock(&(OS_impl_mutex_table[sem_id].id)); + status = pthread_mutex_lock(&(impl->id)); if (status != 0) { return OS_SEM_FAILURE; @@ -192,7 +206,7 @@ int32 OS_MutSemTake_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl(uint32 sem_id, OS_mut_sem_prop_t *mut_prop) +int32 OS_MutSemGetInfo_Impl(const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop) { return OS_SUCCESS; diff --git a/src/os/posix/src/os-impl-no-module.c b/src/os/posix/src/os-impl-no-module.c index 5d9eda065..c7c2c0ffb 100644 --- a/src/os/posix/src/os-impl-no-module.c +++ b/src/os/posix/src/os-impl-no-module.c @@ -32,7 +32,7 @@ #include #include -#include +#include "osapi.h" #include "os-shared-module.h" /*---------------------------------------------------------------- diff --git a/src/os/posix/src/os-impl-queues.c b/src/os/posix/src/os-impl-queues.c index bb5f505d8..87ce7e935 100644 --- a/src/os/posix/src/os-impl-queues.c +++ b/src/os/posix/src/os-impl-queues.c @@ -67,7 +67,7 @@ int32 OS_Posix_QueueAPI_Impl_Init(void) /* * Initialize this to zero to indicate no limit */ - POSIX_GlobalVars.TruncateQueueDepth = 0; + POSIX_GlobalVars.TruncateQueueDepth = OSAL_BLOCKCOUNT_C(0); #endif return OS_SUCCESS; @@ -81,17 +81,22 @@ int32 OS_Posix_QueueAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) +int32 OS_QueueCreate_Impl(const OS_object_token_t *token, uint32 flags) { - int return_code; - mqd_t queueDesc; - struct mq_attr queueAttr; - char name[OS_MAX_API_NAME * 2]; + int return_code; + mqd_t queueDesc; + struct mq_attr queueAttr; + char name[OS_MAX_API_NAME * 2]; + OS_impl_queue_internal_record_t *impl; + OS_queue_internal_record_t * queue; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + queue = OS_OBJECT_TABLE_GET(OS_queue_table, *token); /* set queue attributes */ memset(&queueAttr, 0, sizeof(queueAttr)); - queueAttr.mq_maxmsg = OS_queue_table[queue_id].max_depth; - queueAttr.mq_msgsize = OS_queue_table[queue_id].max_size; + queueAttr.mq_maxmsg = queue->max_depth; + queueAttr.mq_msgsize = queue->max_size; /* * The "TruncateQueueDepth" indicates a soft limit to the size of a queue. @@ -107,7 +112,7 @@ int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) ** Construct the queue name: ** The name will consist of "/.queue_name" */ - snprintf(name, sizeof(name), "/%d.%s", (int)getpid(), OS_global_queue_table[queue_id].name_entry); + snprintf(name, sizeof(name), "/%d.%s", (int)getpid(), queue->queue_name); /* ** create message queue @@ -128,8 +133,8 @@ int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) } else { - OS_impl_queue_table[queue_id].id = queueDesc; - return_code = OS_SUCCESS; + impl->id = queueDesc; + return_code = OS_SUCCESS; /* * Unlink the queue right now -- @@ -159,12 +164,15 @@ int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl(uint32 queue_id) +int32 OS_QueueDelete_Impl(const OS_object_token_t *token) { - int32 return_code; + int32 return_code; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* Try to delete and unlink the queue */ - if (mq_close(OS_impl_queue_table[queue_id].id) != 0) + if (mq_close(impl->id) != 0) { OS_DEBUG("OS_QueueDelete Error during mq_close(). errno = %d (%s)\n", errno, strerror(errno)); return_code = OS_ERROR; @@ -185,11 +193,14 @@ int32 OS_QueueDelete_Impl(uint32 queue_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) +int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout) { - int32 return_code; - ssize_t sizeCopied; - struct timespec ts; + int32 return_code; + ssize_t sizeCopied; + struct timespec ts; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* ** Read the message queue for data @@ -203,7 +214,7 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co */ do { - sizeCopied = mq_receive(OS_impl_queue_table[queue_id].id, data, size, NULL); + sizeCopied = mq_receive(impl->id, data, size, NULL); } while (sizeCopied < 0 && errno == EINTR); } else @@ -232,7 +243,7 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co */ do { - sizeCopied = mq_timedreceive(OS_impl_queue_table[queue_id].id, data, size, NULL, &ts); + sizeCopied = mq_timedreceive(impl->id, data, size, NULL, &ts); } while (timeout != OS_CHECK && sizeCopied < 0 && errno == EINTR); } /* END timeout */ @@ -240,7 +251,7 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co /* Figure out the return code */ if (sizeCopied == -1) { - *size_copied = 0; + *size_copied = OSAL_SIZE_C(0); /* Map the system errno to the most appropriate OSAL return code */ if (errno == EMSGSIZE) @@ -266,7 +277,7 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co } else { - *size_copied = sizeCopied; + *size_copied = OSAL_SIZE_C(sizeCopied); return_code = OS_SUCCESS; } @@ -281,11 +292,14 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueuePut_Impl(uint32 queue_id, const void *data, uint32 size, uint32 flags) +int32 OS_QueuePut_Impl(const OS_object_token_t *token, const void *data, size_t size, uint32 flags) { - int32 return_code; - int result; - struct timespec ts; + int32 return_code; + int result; + struct timespec ts; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* * NOTE - using a zero timeout here for the same reason that QueueGet does --- @@ -298,7 +312,7 @@ int32 OS_QueuePut_Impl(uint32 queue_id, const void *data, uint32 size, uint32 fl /* send message */ do { - result = mq_timedsend(OS_impl_queue_table[queue_id].id, data, size, 1, &ts); + result = mq_timedsend(impl->id, data, size, 1, &ts); } while (result == -1 && errno == EINTR); if (result == 0) diff --git a/src/os/posix/src/os-impl-shell.c b/src/os/posix/src/os-impl-shell.c index 76cb1538c..445ae4d38 100644 --- a/src/os/posix/src/os-impl-shell.c +++ b/src/os/posix/src/os-impl-shell.c @@ -57,12 +57,15 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) { - pid_t cpid; - uint32 local_id; - int wstat; - const char *shell = getenv("SHELL"); + pid_t cpid; + uint32 local_id; + int wstat; + const char * shell = getenv("SHELL"); + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); if (shell == NULL) { @@ -79,8 +82,8 @@ int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) if (cpid == 0) { /* child process */ - dup2(OS_impl_filehandle_table[file_id].fd, STDOUT_FILENO); - dup2(OS_impl_filehandle_table[file_id].fd, STDERR_FILENO); + dup2(impl->fd, STDOUT_FILENO); + dup2(impl->fd, STDERR_FILENO); /* close all _other_ filehandles */ for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) diff --git a/src/os/posix/src/os-impl-tasks.c b/src/os/posix/src/os-impl-tasks.c index ab6cdf4aa..bf1761772 100644 --- a/src/os/posix/src/os-impl-tasks.c +++ b/src/os/posix/src/os-impl-tasks.c @@ -61,7 +61,7 @@ OS_impl_task_internal_record_t OS_impl_task_table[OS_MAX_TASKS]; * to be within the range of [0,OS_MAX_TASK_PRIORITY] * ----------------------------------------------------------------------------*/ -static int OS_PriorityRemap(uint32 InputPri) +static int OS_PriorityRemap(osal_priority_t InputPri) { int OutputPri; @@ -206,6 +206,7 @@ static bool OS_Posix_GetSchedulerParams(int sched_policy, POSIX_PriorityLimits_t int32 OS_Posix_TaskAPI_Impl_Init(void) { int ret; + long ret_long; int sig; struct sched_param sched_param; int sched_policy; @@ -417,7 +418,13 @@ int32 OS_Posix_TaskAPI_Impl_Init(void) } #endif - POSIX_GlobalVars.PageSize = sysconf(_SC_PAGESIZE); + ret_long = sysconf(_SC_PAGESIZE); + if (ret_long < 0) + { + OS_DEBUG("Could not get page size via sysconf: %s\n", strerror(errno)); + return OS_ERROR; + } + POSIX_GlobalVars.PageSize = ret_long; return OS_SUCCESS; } /* end OS_Posix_TaskAPI_Impl_Init */ @@ -429,8 +436,8 @@ int32 OS_Posix_TaskAPI_Impl_Init(void) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t stacksz, PthreadFuncPtr_t entry, - void *entry_arg) +int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, osal_priority_t priority, size_t stacksz, + PthreadFuncPtr_t entry, void *entry_arg) { int return_code = 0; pthread_attr_t custom_attr; @@ -477,6 +484,16 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t return (OS_ERROR); } + /* + ** Set the thread to be joinable by default + */ + return_code = pthread_attr_setdetachstate(&custom_attr, PTHREAD_CREATE_JOINABLE); + if (return_code != 0) + { + OS_DEBUG("pthread_attr_setdetachstate error in OS_TaskCreate: %s\n", strerror(return_code)); + return (OS_ERROR); + } + /* ** Test to see if the original main task scheduling priority worked. ** If so, then also set the attributes for this task. Otherwise attributes @@ -541,12 +558,6 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t ** Do not treat anything bad that happens after this point as fatal. ** The task is running, after all - better to leave well enough alone. */ - return_code = pthread_detach(*pthr); - if (return_code != 0) - { - OS_DEBUG("pthread_detach error in OS_TaskCreate: %s\n", strerror(return_code)); - } - return_code = pthread_attr_destroy(&custom_attr); if (return_code != 0) { @@ -564,21 +575,52 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) +int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags) { - OS_U32ValueWrapper_t arg; - int32 return_code; + OS_U32ValueWrapper_t arg; + int32 return_code; + OS_impl_task_internal_record_t *impl; + OS_task_internal_record_t * task; arg.opaque_arg = NULL; - arg.id = OS_global_task_table[task_id].active_id; + arg.id = OS_ObjectIdFromToken(token); + + task = OS_OBJECT_TABLE_GET(OS_task_table, *token); + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); - return_code = - OS_Posix_InternalTaskCreate_Impl(&OS_impl_task_table[task_id].id, OS_task_table[task_id].priority, - OS_task_table[task_id].stack_size, OS_PthreadTaskEntry, arg.opaque_arg); + return_code = OS_Posix_InternalTaskCreate_Impl(&impl->id, task->priority, task->stack_size, OS_PthreadTaskEntry, + arg.opaque_arg); return return_code; } /* end OS_TaskCreate_Impl */ +/*---------------------------------------------------------------- + * + * Function: OS_TaskDetach_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskDetach_Impl(const OS_object_token_t *token) +{ + OS_impl_task_internal_record_t *impl; + int ret; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + + ret = pthread_detach(impl->id); + + if (ret != 0) + { + OS_DEBUG("pthread_detach: Failed on Task ID = %lu, err = %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(ret)); + return OS_ERROR; + } + + return OS_SUCCESS; +} + /*---------------------------------------------------------------- * * Function: OS_TaskMatch_Impl @@ -587,9 +629,13 @@ int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(uint32 task_id) +int32 OS_TaskMatch_Impl(const OS_object_token_t *token) { - if (pthread_equal(pthread_self(), OS_impl_task_table[task_id].id) == 0) + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + + if (pthread_equal(pthread_self(), impl->id) == 0) { return OS_ERROR; } @@ -605,15 +651,49 @@ int32 OS_TaskMatch_Impl(uint32 task_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl(uint32 task_id) +int32 OS_TaskDelete_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + void * retval; + int ret; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Try to delete the task ** If this fails, not much recourse - the only potential cause of failure ** to cancel here is that the thread ID is invalid because it already exited itself, ** and if that is true there is nothing wrong - everything is OK to continue normally. */ - pthread_cancel(OS_impl_task_table[task_id].id); + ret = pthread_cancel(impl->id); + if (ret != 0) + { + OS_DEBUG("pthread_cancel: Failed on Task ID = %lu, err = %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(ret)); + + /* fall through (will still return OS_SUCCESS) */ + } + else + { + /* + * Note that "pthread_cancel" is a request - and successful return above + * only means that the cancellation request is pending. + * + * pthread_join() will wait until the thread has actually exited. + * + * This is important for CFE, as task deletion often occurs in + * conjunction with an application reload - which means the next + * call is likely to be OS_ModuleUnload(). So is critical that all + * tasks potentially executing code within that module have actually + * been stopped - not just pending cancellation. + */ + ret = pthread_join(impl->id, &retval); + if (ret != 0) + { + OS_DEBUG("pthread_join: Failed on Task ID = %lu, err = %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(ret)); + } + } return OS_SUCCESS; } /* end OS_TaskDelete_Impl */ @@ -678,11 +758,15 @@ int32 OS_TaskDelay_Impl(uint32 millisecond) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl(uint32 task_id, uint32 new_priority) +int32 OS_TaskSetPriority_Impl(const OS_object_token_t *token, osal_priority_t new_priority) { int os_priority; int ret; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + if (POSIX_GlobalVars.EnableTaskPriorities) { /* Change OSAL priority into a priority that will work for this OS */ @@ -691,11 +775,11 @@ int32 OS_TaskSetPriority_Impl(uint32 task_id, uint32 new_priority) /* ** Set priority */ - ret = pthread_setschedprio(OS_impl_task_table[task_id].id, os_priority); + ret = pthread_setschedprio(impl->id, os_priority); if (ret != 0) { - OS_DEBUG("pthread_setschedprio: Task ID = %u, prio = %d, err = %s\n", (unsigned int)task_id, os_priority, - strerror(ret)); + OS_DEBUG("pthread_setschedprio: Task ID = %lu, prio = %d, err = %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), os_priority, strerror(ret)); return (OS_ERROR); } } @@ -715,6 +799,17 @@ int32 OS_TaskRegister_Impl(osal_id_t global_task_id) { int32 return_code; OS_U32ValueWrapper_t arg; + int old_state; + int old_type; + + /* + * Set cancel state=ENABLED, type=DEFERRED + * This should be the default for new threads, but + * setting explicitly to be sure that a pthread_join() + * will work as expected in case this thread is deleted. + */ + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_state); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &old_type); arg.opaque_arg = 0; arg.id = global_task_id; @@ -758,7 +853,7 @@ osal_id_t OS_TaskGetId_Impl(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl(uint32 task_id, OS_task_prop_t *task_prop) +int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_prop) { return OS_SUCCESS; } /* end OS_TaskGetInfo_Impl */ @@ -771,11 +866,14 @@ int32 OS_TaskGetInfo_Impl(uint32 task_id, OS_task_prop_t *task_prop) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj) +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { - const pthread_t *target = (const pthread_t *)ref; + const pthread_t * target = (const pthread_t *)ref; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); - return (pthread_equal(*target, OS_impl_task_table[local_id].id) != 0); + return (pthread_equal(*target, impl->id) != 0); } /*---------------------------------------------------------------- @@ -786,7 +884,7 @@ bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_r * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size) +int32 OS_TaskValidateSystemData_Impl(const void *sysdata, size_t sysdata_size) { if (sysdata == NULL || sysdata_size != sizeof(pthread_t)) { diff --git a/src/os/posix/src/os-impl-timebase.c b/src/os/posix/src/os-impl-timebase.c index c4c23b13e..669f17e7e 100644 --- a/src/os/posix/src/os-impl-timebase.c +++ b/src/os/posix/src/os-impl-timebase.c @@ -36,6 +36,7 @@ #include "os-posix.h" #include "os-impl-timebase.h" +#include "os-impl-tasks.h" #include "os-shared-timebase.h" #include "os-shared-idmap.h" @@ -108,9 +109,13 @@ static void OS_UsecToTimespec(uint32 usecs, struct timespec *time_spec) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseLock_Impl(uint32 local_id) +void OS_TimeBaseLock_Impl(const OS_object_token_t *token) { - pthread_mutex_lock(&OS_impl_timebase_table[local_id].handler_mutex); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + pthread_mutex_lock(&impl->handler_mutex); } /* end OS_TimeBaseLock_Impl */ /*---------------------------------------------------------------- @@ -121,9 +126,13 @@ void OS_TimeBaseLock_Impl(uint32 local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseUnlock_Impl(uint32 local_id) +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) { - pthread_mutex_unlock(&OS_impl_timebase_table[local_id].handler_mutex); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + pthread_mutex_unlock(&impl->handler_mutex); } /* end OS_TimeBaseUnlock_Impl */ /*---------------------------------------------------------------- @@ -133,42 +142,49 @@ void OS_TimeBaseUnlock_Impl(uint32 local_id) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -static uint32 OS_TimeBase_SigWaitImpl(uint32 timer_id) +static uint32 OS_TimeBase_SigWaitImpl(osal_id_t obj_id) { int ret; - OS_impl_timebase_internal_record_t *local; + OS_object_token_t token; + OS_impl_timebase_internal_record_t *impl; + OS_timebase_internal_record_t * timebase; uint32 interval_time; int sig; - local = &OS_impl_timebase_table[timer_id]; - - ret = sigwait(&local->sigset, &sig); + interval_time = 0; - if (ret != 0) - { - /* - * the sigwait call failed. - * returning 0 will cause the process to repeat. - */ - interval_time = 0; - } - else if (local->reset_flag == 0) - { - /* - * Normal steady-state behavior. - * interval_time reflects the configured interval time. - */ - interval_time = OS_timebase_table[timer_id].nominal_interval_time; - } - else + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, obj_id, &token) == OS_SUCCESS) { - /* - * Reset/First interval behavior. - * timer_set() was invoked since the previous interval occurred (if any). - * interval_time reflects the configured start time. - */ - interval_time = OS_timebase_table[timer_id].nominal_start_time; - local->reset_flag = 0; + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + + ret = sigwait(&impl->sigset, &sig); + + if (ret != 0) + { + /* + * the sigwait call failed. + * returning 0 will cause the process to repeat. + */ + } + else if (impl->reset_flag == 0) + { + /* + * Normal steady-state behavior. + * interval_time reflects the configured interval time. + */ + interval_time = timebase->nominal_interval_time; + } + else + { + /* + * Reset/First interval behavior. + * timer_set() was invoked since the previous interval occurred (if any). + * interval_time reflects the configured start time. + */ + interval_time = timebase->nominal_start_time; + impl->reset_flag = 0; + } } return interval_time; @@ -190,7 +206,7 @@ static uint32 OS_TimeBase_SigWaitImpl(uint32 timer_id) int32 OS_Posix_TimeBaseAPI_Impl_Init(void) { int status; - int i; + osal_index_t idx; pthread_mutexattr_t mutex_attr; struct timespec clock_resolution; int32 return_code; @@ -210,7 +226,7 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void) status = clock_getres(OS_PREFERRED_CLOCK, &clock_resolution); if (status != 0) { - OS_DEBUG("failed in clock_getres: %s\n", strerror(status)); + OS_DEBUG("failed in clock_getres: %s\n", strerror(errno)); return_code = OS_ERROR; break; } @@ -253,14 +269,14 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void) break; } - for (i = 0; i < OS_MAX_TIMEBASES; ++i) + for (idx = 0; idx < OS_MAX_TIMEBASES; ++idx) { /* ** create the timebase sync mutex ** This gives a mechanism to synchronize updates to the timer chain with the ** expiration of the timer and processing the chain. */ - status = pthread_mutex_init(&OS_impl_timebase_table[i].handler_mutex, &mutex_attr); + status = pthread_mutex_init(&OS_impl_timebase_table[idx].handler_mutex, &mutex_attr); if (status != 0) { OS_DEBUG("Error: Mutex could not be created: %s\n", strerror(status)); @@ -314,19 +330,20 @@ static void *OS_TimeBasePthreadEntry(void *arg) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseCreate_Impl(uint32 timer_id) +int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token) { int32 return_code; int status; int i; + osal_index_t idx; struct sigevent evp; struct timespec ts; OS_impl_timebase_internal_record_t *local; - OS_common_record_t * global; + OS_timebase_internal_record_t * timebase; OS_U32ValueWrapper_t arg; - local = &OS_impl_timebase_table[timer_id]; - global = &OS_global_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); /* * Spawn a dedicated time base handler thread @@ -339,9 +356,9 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * the global table lock. */ arg.opaque_arg = NULL; - arg.id = global->active_id; - return_code = - OS_Posix_InternalTaskCreate_Impl(&local->handler_thread, 0, 0, OS_TimeBasePthreadEntry, arg.opaque_arg); + arg.id = OS_ObjectIdFromToken(token); + return_code = OS_Posix_InternalTaskCreate_Impl(&local->handler_thread, OSAL_PRIORITY_C(0), 0, + OS_TimeBasePthreadEntry, arg.opaque_arg); if (return_code != OS_SUCCESS) { return return_code; @@ -359,7 +376,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * If no external sync function is provided then this will set up a POSIX * timer to locally simulate the timer tick using the CPU clock. */ - if (OS_timebase_table[timer_id].external_sync == NULL) + if (timebase->external_sync == NULL) { sigemptyset(&local->sigset); @@ -368,12 +385,12 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * This is all done while the global lock is held so no chance of the * underlying tables changing */ - for (i = 0; i < OS_MAX_TIMEBASES; ++i) + for (idx = 0; idx < OS_MAX_TIMEBASES; ++idx) { - if (i != timer_id && OS_ObjectIdDefined(OS_global_timebase_table[i].active_id) && - OS_impl_timebase_table[i].assigned_signal != 0) + if (OS_ObjectIdIsValid(OS_global_timebase_table[idx].active_id) && + OS_impl_timebase_table[idx].assigned_signal != 0) { - sigaddset(&local->sigset, OS_impl_timebase_table[i].assigned_signal); + sigaddset(&local->sigset, OS_impl_timebase_table[idx].assigned_signal); } } @@ -438,7 +455,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * and doing it this way should still work on a system where sizeof(sival_int) < sizeof(uint32) * (as long as sizeof(sival_int) >= number of bits in OS_OBJECT_INDEX_MASK) */ - evp.sigev_value.sival_int = (int)OS_ObjectIdToSerialNumber_Impl(global->active_id); + evp.sigev_value.sival_int = (int)OS_ObjectIdToSerialNumber_Impl(OS_ObjectIdFromToken(token)); /* ** Create the timer @@ -452,7 +469,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) break; } - OS_timebase_table[timer_id].external_sync = OS_TimeBase_SigWaitImpl; + timebase->external_sync = OS_TimeBase_SigWaitImpl; } while (0); } @@ -479,14 +496,16 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time) +int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uint32 interval_time) { OS_impl_timebase_internal_record_t *local; struct itimerspec timeout; int32 return_code; int status; + OS_timebase_internal_record_t * timebase; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); return_code = OS_SUCCESS; /* There is only something to do here if we are generating a simulated tick */ @@ -513,11 +532,11 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time } else if (interval_time > 0) { - OS_timebase_table[timer_id].accuracy_usec = (uint32)((timeout.it_interval.tv_nsec + 999) / 1000); + timebase->accuracy_usec = (uint32)((timeout.it_interval.tv_nsec + 999) / 1000); } else { - OS_timebase_table[timer_id].accuracy_usec = (uint32)((timeout.it_value.tv_nsec + 999) / 1000); + timebase->accuracy_usec = (uint32)((timeout.it_value.tv_nsec + 999) / 1000); } } @@ -533,12 +552,12 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseDelete_Impl(uint32 timer_id) +int32 OS_TimeBaseDelete_Impl(const OS_object_token_t *token) { OS_impl_timebase_internal_record_t *local; int status; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); pthread_cancel(local->handler_thread); @@ -547,7 +566,7 @@ int32 OS_TimeBaseDelete_Impl(uint32 timer_id) */ if (local->assigned_signal != 0) { - status = timer_delete(OS_impl_timebase_table[timer_id].host_timerid); + status = timer_delete(local->host_timerid); if (status < 0) { OS_DEBUG("Error deleting timer: %s\n", strerror(errno)); @@ -568,7 +587,7 @@ int32 OS_TimeBaseDelete_Impl(uint32 timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseGetInfo_Impl(uint32 timer_id, OS_timebase_prop_t *timer_prop) +int32 OS_TimeBaseGetInfo_Impl(const OS_object_token_t *token, OS_timebase_prop_t *timer_prop) { return OS_SUCCESS; diff --git a/src/os/rtems/inc/os-impl-binsem.h b/src/os/rtems/inc/os-impl-binsem.h index 5b0324cac..7437e6c5b 100644 --- a/src/os/rtems/inc/os-impl-binsem.h +++ b/src/os/rtems/inc/os-impl-binsem.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_BINSEM_H_ -#define INCLUDE_OS_IMPL_BINSEM_H_ +#ifndef OS_IMPL_BINSEM_H +#define OS_IMPL_BINSEM_H -#include +#include "osconfig.h" #include typedef struct @@ -39,4 +39,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_binsem_internal_record_t OS_impl_bin_sem_table[OS_MAX_BIN_SEMAPHORES]; -#endif /* INCLUDE_OS_IMPL_BINSEM_H_ */ +#endif /* OS_IMPL_BINSEM_H */ diff --git a/src/os/rtems/inc/os-impl-console.h b/src/os/rtems/inc/os-impl-console.h index b74d52b00..03663aad9 100644 --- a/src/os/rtems/inc/os-impl-console.h +++ b/src/os/rtems/inc/os-impl-console.h @@ -25,11 +25,11 @@ * */ -#ifndef INCLUDE_OS_IMPL_CONSOLE_H_ -#define INCLUDE_OS_IMPL_CONSOLE_H_ +#ifndef OS_IMPL_CONSOLE_H +#define OS_IMPL_CONSOLE_H #include -#include +#include "osconfig.h" #include #include @@ -42,4 +42,4 @@ typedef struct extern OS_impl_console_internal_record_t OS_impl_console_table[OS_MAX_CONSOLES]; -#endif /* INCLUDE_OS_IMPL_CONSOLE_H_ */ +#endif /* OS_IMPL_CONSOLE_H */ diff --git a/src/os/rtems/inc/os-impl-countsem.h b/src/os/rtems/inc/os-impl-countsem.h index fc3cf73a7..5070ee6db 100644 --- a/src/os/rtems/inc/os-impl-countsem.h +++ b/src/os/rtems/inc/os-impl-countsem.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_COUNTSEM_H_ -#define INCLUDE_OS_IMPL_COUNTSEM_H_ +#ifndef OS_IMPL_COUNTSEM_H +#define OS_IMPL_COUNTSEM_H -#include +#include "osconfig.h" #include typedef struct @@ -39,4 +39,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_countsem_internal_record_t OS_impl_count_sem_table[OS_MAX_COUNT_SEMAPHORES]; -#endif /* INCLUDE_OS_IMPL_COUNTSEM_H_ */ +#endif /* OS_IMPL_COUNTSEM_H */ diff --git a/src/os/rtems/inc/os-impl-dirs.h b/src/os/rtems/inc/os-impl-dirs.h index 82bca79b3..8db0eee60 100644 --- a/src/os/rtems/inc/os-impl-dirs.h +++ b/src/os/rtems/inc/os-impl-dirs.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_DIRS_H_ -#define INCLUDE_OS_IMPL_DIRS_H_ +#ifndef OS_IMPL_DIRS_H +#define OS_IMPL_DIRS_H -#include +#include "osconfig.h" #include #include #include @@ -45,4 +45,4 @@ typedef struct */ extern OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; -#endif /* INCLUDE_OS_IMPL_DIRS_H_ */ +#endif /* OS_IMPL_DIRS_H */ diff --git a/src/os/rtems/inc/os-impl-files.h b/src/os/rtems/inc/os-impl-files.h index a5d5ea848..c15b915b6 100644 --- a/src/os/rtems/inc/os-impl-files.h +++ b/src/os/rtems/inc/os-impl-files.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_IMPL_FILES_H_ -#define INCLUDE_OS_IMPL_FILES_H_ +#ifndef OS_IMPL_FILES_H +#define OS_IMPL_FILES_H #include "os-impl-io.h" @@ -42,4 +42,4 @@ #define OS_IMPL_REGULAR_FILE_FLAGS 0 -#endif /* INCLUDE_OS_IMPL_FILES_H_ */ +#endif /* OS_IMPL_FILES_H */ diff --git a/src/os/rtems/inc/os-impl-gettime.h b/src/os/rtems/inc/os-impl-gettime.h index 166a125d2..28690e350 100644 --- a/src/os/rtems/inc/os-impl-gettime.h +++ b/src/os/rtems/inc/os-impl-gettime.h @@ -25,12 +25,12 @@ * */ -#ifndef INCLUDE_OS_IMPL_GETTIME_H_ -#define INCLUDE_OS_IMPL_GETTIME_H_ +#ifndef OS_IMPL_GETTIME_H +#define OS_IMPL_GETTIME_H -#include +#include "osconfig.h" #include #define OSAL_GETTIME_SOURCE_CLOCK CLOCK_MONOTONIC -#endif /* INCLUDE_OS_IMPL_GETTIME_H_ */ +#endif /* OS_IMPL_GETTIME_H */ diff --git a/src/os/rtems/inc/os-impl-idmap.h b/src/os/rtems/inc/os-impl-idmap.h new file mode 100644 index 000000000..1f0285192 --- /dev/null +++ b/src/os/rtems/inc/os-impl-idmap.h @@ -0,0 +1,43 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file os-impl-idmap.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef OS_IMPL_IDMAP_H +#define OS_IMPL_IDMAP_H + +#include "osconfig.h" +#include "osapi-idmap.h" +#include + +typedef struct +{ + rtems_id id; +} OS_impl_objtype_lock_t; + +/* Tables where the lock state information is stored */ +extern OS_impl_objtype_lock_t *const OS_impl_objtype_lock_table[OS_OBJECT_TYPE_USER]; + +#endif /* OS_IMPL_IDMAP_H */ diff --git a/src/os/rtems/inc/os-impl-io.h b/src/os/rtems/inc/os-impl-io.h index 9fc1893c1..da6432214 100644 --- a/src/os/rtems/inc/os-impl-io.h +++ b/src/os/rtems/inc/os-impl-io.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_IO_H_ -#define INCLUDE_OS_IMPL_IO_H_ +#ifndef OS_IMPL_IO_H +#define OS_IMPL_IO_H -#include +#include "osconfig.h" #include #include @@ -36,7 +36,7 @@ typedef struct { int fd; bool selectable; -} OS_Rtems_filehandle_entry_t; +} OS_impl_file_internal_record_t; /* * The global file handle table. @@ -44,6 +44,6 @@ typedef struct * This table is shared across multiple units (files, sockets, etc) and they will share * the same file handle table from the basic file I/O. */ -extern OS_Rtems_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; +extern OS_impl_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; -#endif /* INCLUDE_OS_IMPL_IO_H_ */ +#endif /* OS_IMPL_IO_H */ diff --git a/src/os/rtems/inc/os-impl-loader.h b/src/os/rtems/inc/os-impl-loader.h index 53c964630..12503c023 100644 --- a/src/os/rtems/inc/os-impl-loader.h +++ b/src/os/rtems/inc/os-impl-loader.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_LOADER_H_ -#define INCLUDE_OS_IMPL_LOADER_H_ +#ifndef OS_IMPL_LOADER_H +#define OS_IMPL_LOADER_H -#include +#include "osconfig.h" #include #include @@ -50,4 +50,4 @@ typedef struct extern OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; -#endif /* INCLUDE_OS_IMPL_LOADER_H_ */ +#endif /* OS_IMPL_LOADER_H */ diff --git a/src/os/rtems/inc/os-impl-mutex.h b/src/os/rtems/inc/os-impl-mutex.h index df247192e..be17d462a 100644 --- a/src/os/rtems/inc/os-impl-mutex.h +++ b/src/os/rtems/inc/os-impl-mutex.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_MUTEX_H_ -#define INCLUDE_OS_IMPL_MUTEX_H_ +#ifndef OS_IMPL_MUTEX_H +#define OS_IMPL_MUTEX_H -#include +#include "osconfig.h" #include typedef struct @@ -39,4 +39,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_mutex_internal_record_t OS_impl_mutex_table[OS_MAX_MUTEXES]; -#endif /* INCLUDE_OS_IMPL_MUTEX_H_ */ +#endif /* OS_IMPL_MUTEX_H */ diff --git a/src/os/rtems/inc/os-impl-queues.h b/src/os/rtems/inc/os-impl-queues.h index cf47ff9e4..354abec24 100644 --- a/src/os/rtems/inc/os-impl-queues.h +++ b/src/os/rtems/inc/os-impl-queues.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_QUEUES_H_ -#define INCLUDE_OS_IMPL_QUEUES_H_ +#ifndef OS_IMPL_QUEUES_H +#define OS_IMPL_QUEUES_H -#include +#include "osconfig.h" #include typedef struct @@ -39,4 +39,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_queue_internal_record_t OS_impl_queue_table[OS_MAX_QUEUES]; -#endif /* INCLUDE_OS_IMPL_QUEUES_H_ */ +#endif /* OS_IMPL_QUEUES_H */ diff --git a/src/os/rtems/inc/os-impl-select.h b/src/os/rtems/inc/os-impl-select.h index a2080c79c..4e6164365 100644 --- a/src/os/rtems/inc/os-impl-select.h +++ b/src/os/rtems/inc/os-impl-select.h @@ -25,12 +25,12 @@ * */ -#ifndef INCLUDE_OS_IMPL_SELECT_H_ -#define INCLUDE_OS_IMPL_SELECT_H_ +#ifndef OS_IMPL_SELECT_H +#define OS_IMPL_SELECT_H #include "os-impl-io.h" #include #include -#endif /* INCLUDE_OS_IMPL_SELECT_H_ */ +#endif /* OS_IMPL_SELECT_H */ diff --git a/src/os/rtems/inc/os-impl-sockets.h b/src/os/rtems/inc/os-impl-sockets.h index 1144bc383..a1e557801 100644 --- a/src/os/rtems/inc/os-impl-sockets.h +++ b/src/os/rtems/inc/os-impl-sockets.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_IMPL_SOCKETS_H_ -#define INCLUDE_OS_IMPL_SOCKETS_H_ +#ifndef OS_IMPL_SOCKETS_H +#define OS_IMPL_SOCKETS_H #include "os-impl-io.h" @@ -43,4 +43,4 @@ */ #define OS_IMPL_SOCKET_FLAGS O_NONBLOCK -#endif /* INCLUDE_OS_IMPL_SOCKETS_H_ */ +#endif /* OS_IMPL_SOCKETS_H */ diff --git a/src/os/rtems/inc/os-impl-tasks.h b/src/os/rtems/inc/os-impl-tasks.h index f1e648c08..d8fb5dd47 100644 --- a/src/os/rtems/inc/os-impl-tasks.h +++ b/src/os/rtems/inc/os-impl-tasks.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_TASKS_H_ -#define INCLUDE_OS_IMPL_TASKS_H_ +#ifndef OS_IMPL_TASKS_H +#define OS_IMPL_TASKS_H -#include +#include "osconfig.h" #include typedef struct @@ -39,4 +39,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_task_internal_record_t OS_impl_task_table[OS_MAX_TASKS]; -#endif /* INCLUDE_OS_IMPL_TASKS_H_ */ +#endif /* OS_IMPL_TASKS_H */ diff --git a/src/os/rtems/inc/os-impl-timebase.h b/src/os/rtems/inc/os-impl-timebase.h index 86853f96c..998d6354f 100644 --- a/src/os/rtems/inc/os-impl-timebase.h +++ b/src/os/rtems/inc/os-impl-timebase.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_TIMEBASE_H_ -#define INCLUDE_OS_IMPL_TIMEBASE_H_ +#ifndef OS_IMPL_TIMEBASE_H +#define OS_IMPL_TIMEBASE_H -#include +#include "osconfig.h" #include #include @@ -50,4 +50,4 @@ typedef struct extern OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; -#endif /* INCLUDE_OS_IMPL_TIMEBASE_H_ */ +#endif /* OS_IMPL_TIMEBASE_H */ diff --git a/src/os/rtems/inc/os-rtems.h b/src/os/rtems/inc/os-rtems.h index c8cf01159..b901f3911 100644 --- a/src/os/rtems/inc/os-rtems.h +++ b/src/os/rtems/inc/os-rtems.h @@ -28,8 +28,8 @@ * may contain RTEMS-specific definitions. */ -#ifndef INCLUDE_OS_RTEMS_H_ -#define INCLUDE_OS_RTEMS_H_ +#ifndef OS_RTEMS_H +#define OS_RTEMS_H /**************************************************************************************** COMMON INCLUDE FILES @@ -52,6 +52,20 @@ /**************************************************************************************** DEFINES ***************************************************************************************/ +/* + * Handle the data structure and API name changes between RTEMS 4.11 and RTEMS 5.1 + */ +#ifdef _RTEMS_5_ +#define OSAL_HEAP_INFO_BLOCK Heap_Information_block +#define OSAL_UNRESOLV_REC_TYPE rtems_rtl_unresolv_rec +#define OSAL_UNRESOLVED_SYMBOL rtems_rtl_unresolved_symbol +#define OSAL_UNRESOLVED_ITERATE rtems_rtl_unresolved_iterate +#else +#define OSAL_HEAP_INFO_BLOCK region_information_block +#define OSAL_UNRESOLV_REC_TYPE rtems_rtl_unresolv_rec_t +#define OSAL_UNRESOLVED_SYMBOL rtems_rtl_unresolved_name +#define OSAL_UNRESOLVED_ITERATE rtems_rtl_unresolved_interate +#endif /**************************************************************************************** TYPEDEFS @@ -84,6 +98,6 @@ int32 OS_Rtems_StreamAPI_Impl_Init(void); int32 OS_Rtems_DirAPI_Impl_Init(void); int32 OS_Rtems_FileSysAPI_Impl_Init(void); -int32 OS_Rtems_TableMutex_Init(uint32 idtype); +int32 OS_Rtems_TableMutex_Init(osal_objtype_t idtype); -#endif /* INCLUDE_OS_RTEMS_H_ */ +#endif /* OS_RTEMS_H */ diff --git a/src/os/rtems/src/os-impl-binsem.c b/src/os/rtems/src/os-impl-binsem.c index 5d34c2079..8d15204fa 100644 --- a/src/os/rtems/src/os-impl-binsem.c +++ b/src/os/rtems/src/os-impl-binsem.c @@ -87,17 +87,20 @@ int32 OS_Rtems_BinSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { - rtems_status_code status; - rtems_name r_name; + rtems_status_code status; + rtems_name r_name; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* ** RTEMS task names are 4 byte integers. ** It is convenient to use the OSAL ID in here, as we know it is already unique ** and trying to use the real name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_bin_sem_table[sem_id].active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); /* Check to make sure the sem value is going to be either 0 or 1 */ if (sem_initial_value > 1) @@ -106,8 +109,7 @@ int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 optio } /* Create RTEMS Semaphore */ - status = rtems_semaphore_create(r_name, sem_initial_value, OSAL_BINARY_SEM_ATTRIBS, 0, - &(OS_impl_bin_sem_table[sem_id].id)); + status = rtems_semaphore_create(r_name, sem_initial_value, OSAL_BINARY_SEM_ATTRIBS, 0, &(impl->id)); /* check if Create failed */ if (status != RTEMS_SUCCESSFUL) @@ -128,11 +130,14 @@ int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 optio * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl(uint32 sem_id) +int32 OS_BinSemDelete_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); - status = rtems_semaphore_delete(OS_impl_bin_sem_table[sem_id].id); + status = rtems_semaphore_delete(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_delete error: %s\n", rtems_status_text(status)); @@ -151,11 +156,14 @@ int32 OS_BinSemDelete_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl(uint32 sem_id) +int32 OS_BinSemGive_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); - status = rtems_semaphore_release(OS_impl_bin_sem_table[sem_id].id); + status = rtems_semaphore_release(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_release error: %s\n", rtems_status_text(status)); @@ -173,12 +181,15 @@ int32 OS_BinSemGive_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl(uint32 sem_id) +int32 OS_BinSemFlush_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* Give Semaphore */ - status = rtems_semaphore_flush(OS_impl_bin_sem_table[sem_id].id); + status = rtems_semaphore_flush(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_flush error: %s\n", rtems_status_text(status)); @@ -197,11 +208,14 @@ int32 OS_BinSemFlush_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl(uint32 sem_id) +int32 OS_BinSemTake_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); - status = rtems_semaphore_obtain(OS_impl_bin_sem_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); /* ** If the semaphore is flushed, this function will return ** RTEMS_UNSATISFIED. If this happens, the OSAL does not want to return @@ -228,17 +242,20 @@ int32 OS_BinSemTake_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl(uint32 sem_id, uint32 msecs) +int32 OS_BinSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - rtems_status_code status; - int TimeInTicks; + rtems_status_code status; + int TimeInTicks; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); if (OS_Milli2Ticks(msecs, &TimeInTicks) != OS_SUCCESS) { return OS_ERROR; } - status = rtems_semaphore_obtain(OS_impl_bin_sem_table[sem_id].id, RTEMS_WAIT, TimeInTicks); + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, TimeInTicks); if (status == RTEMS_TIMEOUT) { @@ -264,7 +281,7 @@ int32 OS_BinSemTimedWait_Impl(uint32 sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl(uint32 sem_id, OS_bin_sem_prop_t *bin_prop) +int32 OS_BinSemGetInfo_Impl(const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop) { /* RTEMS has no API for obtaining the current value of a semaphore */ return OS_SUCCESS; diff --git a/src/os/rtems/src/os-impl-common.c b/src/os/rtems/src/os-impl-common.c index 2d396901b..5e32e286b 100644 --- a/src/os/rtems/src/os-impl-common.c +++ b/src/os/rtems/src/os-impl-common.c @@ -37,6 +37,7 @@ #include "os-rtems.h" #include "os-shared-common.h" +#include "os-shared-idmap.h" RTEMS_GlobalVars_t RTEMS_GlobalVars = {0}; @@ -52,7 +53,7 @@ RTEMS_GlobalVars_t RTEMS_GlobalVars = {0}; returns: OS_SUCCESS or OS_ERROR ---------------------------------------------------------------------------------------*/ -int32 OS_API_Impl_Init(uint32 idtype) +int32 OS_API_Impl_Init(osal_objtype_t idtype) { int32 return_code; diff --git a/src/os/rtems/src/os-impl-console.c b/src/os/rtems/src/os-impl-console.c index 84c84ae0c..7aa2622e3 100644 --- a/src/os/rtems/src/os-impl-console.c +++ b/src/os/rtems/src/os-impl-console.c @@ -38,6 +38,7 @@ #include "os-rtems.h" #include "os-shared-printf.h" #include "os-shared-idmap.h" +#include "os-shared-common.h" /**************************************************************************************** DEFINES @@ -86,9 +87,11 @@ OS_impl_console_internal_record_t OS_impl_console_table[OS_MAX_CONSOLES]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(uint32 local_id) +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; + + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); if (local->is_async) { @@ -98,7 +101,7 @@ void OS_ConsoleWakeup_Impl(uint32 local_id) else { /* output directly */ - OS_ConsoleOutput_Impl(local_id); + OS_ConsoleOutput_Impl(token); } } /* end OS_ConsoleWakeup_Impl */ @@ -111,14 +114,21 @@ void OS_ConsoleWakeup_Impl(uint32 local_id) *-----------------------------------------------------------------*/ static void OS_ConsoleTask_Entry(rtems_task_argument arg) { - uint32 local_id = arg; + OS_object_token_t token; OS_impl_console_internal_record_t *local; - local = &OS_impl_console_table[local_id]; - while (true) + if (OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_CONSOLE, OS_ObjectIdFromInteger(arg), &token) == + OS_SUCCESS) { - OS_ConsoleOutput_Impl(local_id); - rtems_semaphore_obtain(local->data_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, token); + + /* Loop forever (unless shutdown is set) */ + while (OS_SharedGlobalVars.ShutdownFlag != OS_SHUTDOWN_MAGIC_NUMBER) + { + OS_ConsoleOutput_Impl(&token); + rtems_semaphore_obtain(local->data_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + } + OS_ObjectIdRelease(&token); } } /* end OS_ConsoleTask_Entry */ @@ -130,15 +140,17 @@ static void OS_ConsoleTask_Entry(rtems_task_argument arg) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(uint32 local_id) +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; int32 return_code; rtems_name r_name; rtems_id r_task_id; rtems_status_code status; - if (local_id == 0) + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); + + if (OS_ObjectIndexFromToken(token) == 0) { return_code = OS_SUCCESS; local->is_async = OS_CONSOLE_ASYNC; @@ -152,7 +164,7 @@ int32 OS_ConsoleCreate_Impl(uint32 local_id) ** It is convenient to use the OSAL ID in here, as we know it is already unique ** and trying to use the real name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_console_table[local_id].active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); status = rtems_semaphore_create(r_name, 0, RTEMS_PRIORITY, 0, &local->data_sem); if (status != RTEMS_SUCCESSFUL) { @@ -175,9 +187,9 @@ int32 OS_ConsoleCreate_Impl(uint32 local_id) else { /* will place the task in 'ready for scheduling' state */ - status = rtems_task_start(r_task_id, /*rtems task id*/ - OS_ConsoleTask_Entry, /* task entry point */ - (rtems_task_argument)local_id); /* passed argument */ + status = rtems_task_start(r_task_id, /*rtems task id*/ + OS_ConsoleTask_Entry, /* task entry point */ + (rtems_task_argument)r_name); /* passed argument */ if (status != RTEMS_SUCCESSFUL) { diff --git a/src/os/rtems/src/os-impl-countsem.c b/src/os/rtems/src/os-impl-countsem.c index 21b3caeee..33b1719b6 100644 --- a/src/os/rtems/src/os-impl-countsem.c +++ b/src/os/rtems/src/os-impl-countsem.c @@ -84,10 +84,13 @@ int32 OS_Rtems_CountSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_CountSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { - rtems_status_code status; - rtems_name r_name; + rtems_status_code status; + rtems_name r_name; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); /* ** Verify that the semaphore maximum value is not too high @@ -102,9 +105,8 @@ int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 opt ** It is convenient to use the OSAL ID in here, as we know it is already unique ** and trying to use the real name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_count_sem_table[sem_id].active_id); - status = rtems_semaphore_create(r_name, sem_initial_value, OSAL_COUNT_SEM_ATTRIBS, 0, - &(OS_impl_count_sem_table[sem_id].id)); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); + status = rtems_semaphore_create(r_name, sem_initial_value, OSAL_COUNT_SEM_ATTRIBS, 0, &(impl->id)); /* check if Create failed */ if (status != RTEMS_SUCCESSFUL) @@ -125,11 +127,14 @@ int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 opt * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl(uint32 sem_id) +int32 OS_CountSemDelete_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); - status = rtems_semaphore_delete(OS_impl_count_sem_table[sem_id].id); + status = rtems_semaphore_delete(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_delete error: %s\n", rtems_status_text(status)); @@ -148,11 +153,14 @@ int32 OS_CountSemDelete_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl(uint32 sem_id) +int32 OS_CountSemGive_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); - status = rtems_semaphore_release(OS_impl_count_sem_table[sem_id].id); + status = rtems_semaphore_release(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_release error: %s\n", rtems_status_text(status)); @@ -171,11 +179,14 @@ int32 OS_CountSemGive_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl(uint32 sem_id) +int32 OS_CountSemTake_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_countsem_internal_record_t *impl; - status = rtems_semaphore_obtain(OS_impl_count_sem_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_obtain error: %s\n", rtems_status_text(status)); @@ -194,17 +205,20 @@ int32 OS_CountSemTake_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl(uint32 sem_id, uint32 msecs) +int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - rtems_status_code status; - int TimeInTicks; + rtems_status_code status; + int TimeInTicks; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); if (OS_Milli2Ticks(msecs, &TimeInTicks) != OS_SUCCESS) { return OS_ERROR; } - status = rtems_semaphore_obtain(OS_impl_count_sem_table[sem_id].id, RTEMS_WAIT, TimeInTicks); + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, TimeInTicks); if (status == RTEMS_TIMEOUT) { return OS_SEM_TIMEOUT; @@ -228,7 +242,7 @@ int32 OS_CountSemTimedWait_Impl(uint32 sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl(uint32 sem_id, OS_count_sem_prop_t *count_prop) +int32 OS_CountSemGetInfo_Impl(const OS_object_token_t *token, OS_count_sem_prop_t *count_prop) { /* RTEMS does not provide an API to get the value */ return OS_SUCCESS; diff --git a/src/os/rtems/src/os-impl-files.c b/src/os/rtems/src/os-impl-files.c index d82de88fe..48e76807d 100644 --- a/src/os/rtems/src/os-impl-files.c +++ b/src/os/rtems/src/os-impl-files.c @@ -47,7 +47,7 @@ * This is shared by all OSAL entities that perform low-level I/O. */ /* The file/stream table is referenced by multiple entities, i.e. sockets, select, etc */ -OS_Rtems_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; +OS_impl_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; /**************************************************************************************** IMPLEMENTATION-SPECIFIC ROUTINES diff --git a/src/os/rtems/src/os-impl-filesys.c b/src/os/rtems/src/os-impl-filesys.c index 1ad989e03..4bdea8453 100644 --- a/src/os/rtems/src/os-impl-filesys.c +++ b/src/os/rtems/src/os-impl-filesys.c @@ -104,13 +104,16 @@ int32 OS_Rtems_FileSysAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStartVolume_Impl(uint32 filesys_id) +int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; rtems_status_code sc; int32 return_code; + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + return_code = OS_ERR_NOT_IMPLEMENTED; memset(impl, 0, sizeof(*impl)); @@ -161,7 +164,7 @@ int32 OS_FileSysStartVolume_Impl(uint32 filesys_id) impl->mount_fstype = RTEMS_FILESYSTEM_TYPE_RFS; impl->mount_options = RTEMS_FILESYSTEM_READ_WRITE; snprintf(impl->blockdev_name, sizeof(impl->blockdev_name), "%s%c", RAMDISK_DEVICE_BASE_NAME, - (int)filesys_id + 'a'); + (int)OS_ObjectIndexFromToken(token) + 'a'); sc = rtems_blkdev_create(impl->blockdev_name, local->blocksize, local->numblocks, ramdisk_ioctl, impl->allocated_disk); @@ -205,9 +208,11 @@ int32 OS_FileSysStartVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStopVolume_Impl(uint32 filesys_id) +int32 OS_FileSysStopVolume_Impl(const OS_object_token_t *token) { - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_impl_filesys_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); /* * If this was a dynamically allocated disk, then unlink it. @@ -229,14 +234,17 @@ int32 OS_FileSysStopVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysFormatVolume_Impl(uint32 filesys_id) +int32 OS_FileSysFormatVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; rtems_rfs_format_config config; int32 return_code; int sc; + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + return_code = OS_ERR_NOT_IMPLEMENTED; switch (local->fstype) @@ -291,12 +299,15 @@ int32 OS_FileSysFormatVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysMountVolume_Impl(uint32 filesys_id) +int32 OS_FileSysMountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; struct stat stat_buf; + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + /* * This will do a mkdir() for the mount point if it does * not already exist. @@ -345,9 +356,11 @@ int32 OS_FileSysMountVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysUnmountVolume_Impl(uint32 filesys_id) +int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; + + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); if (local->fstype == OS_FILESYS_TYPE_VOLATILE_DISK || local->fstype == OS_FILESYS_TYPE_NORMAL_DISK) { @@ -373,12 +386,14 @@ int32 OS_FileSysUnmountVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result) +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct statvfs stat_buf; int32 return_code; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + if (statvfs(local->system_mountpt, &stat_buf) != 0) { /* @@ -415,7 +430,7 @@ int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysCheckVolume_Impl(uint32 filesys_id, bool repair) +int32 OS_FileSysCheckVolume_Impl(const OS_object_token_t *token, bool repair) { return OS_ERR_NOT_IMPLEMENTED; } /* end OS_FileSysCheckVolume_Impl */ diff --git a/src/os/rtems/src/os-impl-heap.c b/src/os/rtems/src/os-impl-heap.c index 17addccc0..4e67125cb 100644 --- a/src/os/rtems/src/os-impl-heap.c +++ b/src/os/rtems/src/os-impl-heap.c @@ -46,8 +46,8 @@ *-----------------------------------------------------------------*/ int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop) { - region_information_block info; - int status; + OSAL_HEAP_INFO_BLOCK info; + int status; status = malloc_info(&info); diff --git a/src/os/rtems/src/os-impl-idmap.c b/src/os/rtems/src/os-impl-idmap.c index 6d6b15f00..cdce72602 100644 --- a/src/os/rtems/src/os-impl-idmap.c +++ b/src/os/rtems/src/os-impl-idmap.c @@ -33,6 +33,7 @@ #include "os-rtems.h" #include "os-shared-idmap.h" +#include "os-impl-idmap.h" /**************************************************************************************** DEFINES @@ -44,38 +45,33 @@ GLOBALS ***************************************************************************************/ -rtems_id OS_task_table_sem; -rtems_id OS_queue_table_sem; -rtems_id OS_bin_sem_table_sem; -rtems_id OS_mutex_table_sem; -rtems_id OS_count_sem_table_sem; -rtems_id OS_stream_table_mut; -rtems_id OS_dir_table_mut; -rtems_id OS_timebase_table_mut; -rtems_id OS_timecb_table_mut; -rtems_id OS_module_table_mut; -rtems_id OS_filesys_table_mut; -rtems_id OS_console_mut; - -static rtems_id *const MUTEX_TABLE[] = { +static OS_impl_objtype_lock_t OS_task_table_lock; +static OS_impl_objtype_lock_t OS_queue_table_lock; +static OS_impl_objtype_lock_t OS_bin_sem_table_lock; +static OS_impl_objtype_lock_t OS_mutex_table_lock; +static OS_impl_objtype_lock_t OS_count_sem_table_lock; +static OS_impl_objtype_lock_t OS_stream_table_lock; +static OS_impl_objtype_lock_t OS_dir_table_lock; +static OS_impl_objtype_lock_t OS_timebase_table_lock; +static OS_impl_objtype_lock_t OS_timecb_table_lock; +static OS_impl_objtype_lock_t OS_module_table_lock; +static OS_impl_objtype_lock_t OS_filesys_table_lock; +static OS_impl_objtype_lock_t OS_console_lock; + +OS_impl_objtype_lock_t *const OS_impl_objtype_lock_table[OS_OBJECT_TYPE_USER] = { [OS_OBJECT_TYPE_UNDEFINED] = NULL, - [OS_OBJECT_TYPE_OS_TASK] = &OS_task_table_sem, - [OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_sem, - [OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_sem, - [OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_sem, - [OS_OBJECT_TYPE_OS_MUTEX] = &OS_mutex_table_sem, - [OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_mut, - [OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_mut, - [OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_mut, - [OS_OBJECT_TYPE_OS_TIMECB] = &OS_timecb_table_mut, - [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_mut, - [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_mut, - [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_mut, -}; - -enum -{ - MUTEX_TABLE_SIZE = (sizeof(MUTEX_TABLE) / sizeof(MUTEX_TABLE[0])) + [OS_OBJECT_TYPE_OS_TASK] = &OS_task_table_lock, + [OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_lock, + [OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_lock, + [OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_lock, + [OS_OBJECT_TYPE_OS_MUTEX] = &OS_mutex_table_lock, + [OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_lock, + [OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_lock, + [OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_lock, + [OS_OBJECT_TYPE_OS_TIMECB] = &OS_timecb_table_lock, + [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_lock, + [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_lock, + [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_lock, }; /*---------------------------------------------------------------- @@ -86,30 +82,19 @@ enum * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_Lock_Global_Impl(uint32 idtype) +void OS_Lock_Global_Impl(osal_objtype_t idtype) { - rtems_id *mut; + OS_impl_objtype_lock_t *impl; + rtems_status_code rtems_sc; - if (idtype < MUTEX_TABLE_SIZE) - { - mut = MUTEX_TABLE[idtype]; - } - else - { - mut = NULL; - } + impl = OS_impl_objtype_lock_table[idtype]; - if (mut == NULL) + rtems_sc = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + if (rtems_sc != RTEMS_SUCCESSFUL) { - return OS_ERROR; + OS_DEBUG("OS_Lock_Global_Impl: rtems_semaphore_obtain failed: %s\n", rtems_status_text(rtems_sc)); } - if (rtems_semaphore_obtain(*mut, RTEMS_WAIT, RTEMS_NO_TIMEOUT) != 0) - { - return OS_ERROR; - } - - return OS_SUCCESS; } /* end OS_Lock_Global_Impl */ /*---------------------------------------------------------------- @@ -120,31 +105,46 @@ int32 OS_Lock_Global_Impl(uint32 idtype) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_Unlock_Global_Impl(uint32 idtype) +void OS_Unlock_Global_Impl(osal_objtype_t idtype) { - rtems_id *mut; + OS_impl_objtype_lock_t *impl; + rtems_status_code rtems_sc; - if (idtype < MUTEX_TABLE_SIZE) - { - mut = MUTEX_TABLE[idtype]; - } - else + impl = OS_impl_objtype_lock_table[idtype]; + + rtems_sc = rtems_semaphore_release(impl->id); + if (rtems_sc != RTEMS_SUCCESSFUL) { - mut = NULL; + OS_DEBUG("OS_Unlock_Global_Impl: rtems_semaphore_release failed: %s\n", rtems_status_text(rtems_sc)); } - if (mut == NULL) +} /* end OS_Unlock_Global_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_WaitForStateChange_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_WaitForStateChange_Impl(osal_objtype_t idtype, uint32 attempts) +{ + rtems_interval wait_ticks; + + if (attempts <= 10) { - return OS_ERROR; + wait_ticks = attempts * attempts; } - - if (rtems_semaphore_release(*mut) != 0) + else { - return OS_ERROR; + wait_ticks = 100; } - return OS_SUCCESS; -} /* end OS_Unlock_Global_Impl */ + OS_Unlock_Global_Impl(idtype); + rtems_task_wake_after(wait_ticks); + OS_Lock_Global_Impl(idtype); +} /**************************************************************************************** INITIALIZATION FUNCTION @@ -158,22 +158,24 @@ int32 OS_Unlock_Global_Impl(uint32 idtype) returns: OS_SUCCESS or OS_ERROR ---------------------------------------------------------------------------------------*/ -int32 OS_Rtems_TableMutex_Init(uint32 idtype) +int32 OS_Rtems_TableMutex_Init(osal_objtype_t idtype) { - int32 return_code = OS_SUCCESS; - rtems_status_code rtems_sc; + OS_impl_objtype_lock_t *impl; + rtems_status_code rtems_sc; - /* Initialize the table mutex for the given idtype */ - if (idtype < MUTEX_TABLE_SIZE && MUTEX_TABLE[idtype] != NULL) + impl = OS_impl_objtype_lock_table[idtype]; + if (impl == NULL) { - rtems_sc = rtems_semaphore_create(idtype, 1, OSAL_TABLE_MUTEX_ATTRIBS, 0, MUTEX_TABLE[idtype]); + return OS_SUCCESS; + } - if (rtems_sc != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Error: rtems_semaphore_create failed: %s\n", rtems_status_text(rtems_sc)); - return_code = OS_ERROR; - } + /* Initialize the table mutex for the given idtype */ + rtems_sc = rtems_semaphore_create(idtype, 1, OSAL_TABLE_MUTEX_ATTRIBS, 0, &impl->id); + if (rtems_sc != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Error: rtems_semaphore_create failed: %s\n", rtems_status_text(rtems_sc)); + return OS_ERROR; } - return (return_code); + return OS_SUCCESS; } /* end OS_Rtems_TableMutex_Init */ diff --git a/src/os/rtems/src/os-impl-loader.c b/src/os/rtems/src/os-impl-loader.c index 89fbbedce..dd986511d 100644 --- a/src/os/rtems/src/os-impl-loader.c +++ b/src/os/rtems/src/os-impl-loader.c @@ -34,6 +34,7 @@ #include "os-rtems.h" #include "os-impl-loader.h" #include "os-shared-module.h" +#include "os-shared-idmap.h" /**************************************************************************************** GLOBAL DATA @@ -73,14 +74,14 @@ int32 OS_Rtems_ModuleAPI_Impl_Init(void) * This could be fine-tuned later. * *-----------------------------------------------------------------*/ -static bool OS_rtems_rtl_check_unresolved(rtems_rtl_unresolv_rec_t *rec, void *data) +static bool OS_rtems_rtl_check_unresolved(OSAL_UNRESOLV_REC_TYPE *rec, void *data) { int32 *status = data; switch (rec->type) { - case rtems_rtl_unresolved_name: - OS_DEBUG("unresolved name: %s\n", rec->rec.name.name); + case OSAL_UNRESOLVED_SYMBOL: + OS_DEBUG("unresolved symbol: %s\n", rec->rec.name.name); *status = OS_ERROR; break; case rtems_rtl_unresolved_reloc: @@ -104,11 +105,14 @@ static bool OS_rtems_rtl_check_unresolved(rtems_rtl_unresolv_rec_t *rec, void *d * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) { - int32 status = OS_ERROR; - int unresolved; - void *dl_handle; + int32 status = OS_ERROR; + int unresolved; + void * dl_handle; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); dlerror(); dl_handle = dlopen(translated_path, RTLD_NOW | RTLD_GLOBAL); @@ -142,7 +146,7 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) OS_DEBUG("module has has unresolved externals\n"); status = OS_SUCCESS; /* note - not final, probably overridden */ - rtems_rtl_unresolved_interate(OS_rtems_rtl_check_unresolved, &status); + OSAL_UNRESOLVED_ITERATE(OS_rtems_rtl_check_unresolved, &status); } else { @@ -152,7 +156,7 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) if (status == OS_SUCCESS) { /* success: save for future use */ - OS_impl_module_table[module_id].dl_handle = dl_handle; + impl->dl_handle = dl_handle; } else if (dl_handle != NULL) { @@ -177,18 +181,21 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(uint32 module_id) +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) { - int32 status = OS_ERROR; + int32 status = OS_ERROR; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); /* ** Attempt to close/unload the module */ dlerror(); - if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) + if (dlclose(impl->dl_handle) == 0) { - OS_impl_module_table[module_id].dl_handle = NULL; - status = OS_SUCCESS; + impl->dl_handle = NULL; + status = OS_SUCCESS; } else { @@ -207,7 +214,7 @@ int32 OS_ModuleUnload_Impl(uint32 module_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(uint32 module_id, OS_module_prop_t *module_prop) +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop) { /* ** RTEMS does not specify a way to get these values diff --git a/src/os/rtems/src/os-impl-mutex.c b/src/os/rtems/src/os-impl-mutex.c index 4ae538954..48874bdcc 100644 --- a/src/os/rtems/src/os-impl-mutex.c +++ b/src/os/rtems/src/os-impl-mutex.c @@ -85,16 +85,19 @@ int32 OS_Rtems_MutexAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) +int32 OS_MutSemCreate_Impl(const OS_object_token_t *token, uint32 options) { - rtems_status_code status; - rtems_name r_name; + rtems_status_code status; + rtems_name r_name; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* ** Try to create the mutex */ - r_name = OS_ObjectIdToInteger(OS_global_mutex_table[sem_id].active_id); - status = rtems_semaphore_create(r_name, 1, OSAL_MUTEX_ATTRIBS, 0, &OS_impl_mutex_table[sem_id].id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); + status = rtems_semaphore_create(r_name, 1, OSAL_MUTEX_ATTRIBS, 0, &impl->id); if (status != RTEMS_SUCCESSFUL) { @@ -114,11 +117,14 @@ int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl(uint32 sem_id) +int32 OS_MutSemDelete_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); - status = rtems_semaphore_delete(OS_impl_mutex_table[sem_id].id); + status = rtems_semaphore_delete(impl->id); if (status != RTEMS_SUCCESSFUL) { /* clean up? */ @@ -138,12 +144,15 @@ int32 OS_MutSemDelete_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl(uint32 sem_id) +int32 OS_MutSemGive_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* Give the mutex */ - status = rtems_semaphore_release(OS_impl_mutex_table[sem_id].id); + status = rtems_semaphore_release(impl->id); if (status != RTEMS_SUCCESSFUL) { @@ -163,11 +172,14 @@ int32 OS_MutSemGive_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl(uint32 sem_id) +int32 OS_MutSemTake_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); - status = rtems_semaphore_obtain(OS_impl_mutex_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (status != RTEMS_SUCCESSFUL) { @@ -187,7 +199,7 @@ int32 OS_MutSemTake_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl(uint32 sem_id, OS_mut_sem_prop_t *mut_prop) +int32 OS_MutSemGetInfo_Impl(const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop) { /* RTEMS provides no additional info */ return OS_SUCCESS; diff --git a/src/os/rtems/src/os-impl-network.c b/src/os/rtems/src/os-impl-network.c index c5a8a20ef..19c92e485 100644 --- a/src/os/rtems/src/os-impl-network.c +++ b/src/os/rtems/src/os-impl-network.c @@ -57,7 +57,7 @@ int32 OS_NetworkGetID_Impl(int32 *IdBuf) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_NetworkGetHostName_Impl(char *host_name, uint32 name_len) +int32 OS_NetworkGetHostName_Impl(char *host_name, size_t name_len) { int32 return_code; diff --git a/src/os/rtems/src/os-impl-queues.c b/src/os/rtems/src/os-impl-queues.c index dcd9ddbe8..2e8ec2188 100644 --- a/src/os/rtems/src/os-impl-queues.c +++ b/src/os/rtems/src/os-impl-queues.c @@ -78,17 +78,22 @@ int32 OS_Rtems_QueueAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) +int32 OS_QueueCreate_Impl(const OS_object_token_t *token, uint32 flags) { - rtems_status_code status; - rtems_name r_name; + rtems_status_code status; + rtems_name r_name; + OS_impl_queue_internal_record_t *impl; + OS_queue_internal_record_t * queue; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + queue = OS_OBJECT_TABLE_GET(OS_queue_table, *token); /* ** RTEMS task names are 4 byte integers. ** It is convenient to use the OSAL queue ID in here, as we know it is already unique ** and trying to use the real queue name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_queue_table[queue_id].active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); /* ** Create the message queue. @@ -96,12 +101,11 @@ int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) ** (RTEMS_FIFO or RTEMS_PRIORITY) is irrelevant since only one task waits ** on each queue. */ - status = rtems_message_queue_create( - r_name, /* 32-bit RTEMS object name; not used */ - OS_queue_table[queue_id].max_depth, /* maximum number of messages in queue (queue depth) */ - OS_queue_table[queue_id].max_size, /* maximum size in bytes of a message */ - RTEMS_FIFO | RTEMS_LOCAL, /* attributes (default) */ - &(OS_impl_queue_table[queue_id].id) /* object ID returned for queue */ + status = rtems_message_queue_create(r_name, /* 32-bit RTEMS object name; not used */ + queue->max_depth, /* maximum number of messages in queue (queue depth) */ + queue->max_size, /* maximum size in bytes of a message */ + RTEMS_FIFO | RTEMS_LOCAL, /* attributes (default) */ + &(impl->id) /* object ID returned for queue */ ); /* @@ -125,12 +129,15 @@ int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl(uint32 queue_id) +int32 OS_QueueDelete_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* Try to delete the queue */ - status = rtems_message_queue_delete(OS_impl_queue_table[queue_id].id); + status = rtems_message_queue_delete(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled queue_delete error: %s\n", rtems_status_text(status)); @@ -149,17 +156,20 @@ int32 OS_QueueDelete_Impl(uint32 queue_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) +int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout) { - int32 return_code; - rtems_status_code status; - rtems_interval ticks; - int tick_count; - rtems_option option_set; - size_t rtems_size; - rtems_id rtems_queue_id; + int32 return_code; + rtems_status_code status; + rtems_interval ticks; + int tick_count; + rtems_option option_set; + size_t rtems_size; + rtems_id rtems_queue_id; + OS_impl_queue_internal_record_t *impl; - rtems_queue_id = OS_impl_queue_table[queue_id].id; + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + + rtems_queue_id = impl->id; /* Get Message From Message Queue */ if (timeout == OS_PEND) @@ -243,12 +253,15 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueuePut_Impl(uint32 queue_id, const void *data, uint32 size, uint32 flags) +int32 OS_QueuePut_Impl(const OS_object_token_t *token, const void *data, size_t size, uint32 flags) { - rtems_status_code status; - rtems_id rtems_queue_id; + rtems_status_code status; + rtems_id rtems_queue_id; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); - rtems_queue_id = OS_impl_queue_table[queue_id].id; + rtems_queue_id = impl->id; /* Write the buffer pointer to the queue. If an error occurred, report it ** with the corresponding SB status code. @@ -287,7 +300,7 @@ int32 OS_QueuePut_Impl(uint32 queue_id, const void *data, uint32 size, uint32 fl * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGetInfo_Impl(uint32 queue_id, OS_queue_prop_t *queue_prop) +int32 OS_QueueGetInfo_Impl(const OS_object_token_t *token, OS_queue_prop_t *queue_prop) { /* No extra info for queues in the OS implementation */ return OS_SUCCESS; diff --git a/src/os/rtems/src/os-impl-tasks.c b/src/os/rtems/src/os-impl-tasks.c index 8db7432fe..f1fa62b4b 100644 --- a/src/os/rtems/src/os-impl-tasks.c +++ b/src/os/rtems/src/os-impl-tasks.c @@ -42,6 +42,8 @@ #include "os-shared-idmap.h" #include "os-shared-timebase.h" +#include "osapi-printf.h" + /**************************************************************************************** DEFINES ***************************************************************************************/ @@ -90,19 +92,24 @@ int32 OS_Rtems_TaskAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) +int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags) { - rtems_status_code status; - rtems_name r_name; - rtems_mode r_mode; - rtems_attribute r_attributes; + rtems_status_code status; + rtems_name r_name; + rtems_mode r_mode; + rtems_attribute r_attributes; + OS_impl_task_internal_record_t *impl; + OS_task_internal_record_t * task; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + task = OS_OBJECT_TABLE_GET(OS_task_table, *token); /* ** RTEMS task names are 4 byte integers. ** It is convenient to use the OSAL task ID in here, as we know it is already unique ** and trying to use the real task name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_task_table[task_id].active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); r_mode = RTEMS_PREEMPT | RTEMS_NO_ASR | RTEMS_NO_TIMESLICE | RTEMS_INTERRUPT_LEVEL(0); /* @@ -115,8 +122,7 @@ int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) r_attributes |= RTEMS_FLOATING_POINT; } - status = rtems_task_create(r_name, OS_task_table[task_id].priority, OS_task_table[task_id].stack_size, r_mode, - r_attributes, &OS_impl_task_table[task_id].id); + status = rtems_task_create(r_name, task->priority, task->stack_size, r_mode, r_attributes, &impl->id); /* check if task_create failed */ if (status != RTEMS_SUCCESSFUL) @@ -127,15 +133,14 @@ int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) } /* will place the task in 'ready for scheduling' state */ - status = rtems_task_start( - OS_impl_task_table[task_id].id, /*rtems task id*/ - (rtems_task_entry)OS_RtemsEntry, /* task entry point */ - (rtems_task_argument)OS_ObjectIdToInteger(OS_global_task_table[task_id].active_id)); /* passed argument */ + status = rtems_task_start(impl->id, /*rtems task id*/ + (rtems_task_entry)OS_RtemsEntry, /* task entry point */ + (rtems_task_argument)r_name); /* passed argument */ if (status != RTEMS_SUCCESSFUL) { OS_printf("rtems_task_start failed: %s\n", rtems_status_text(status)); - rtems_task_delete(OS_impl_task_table[task_id].id); + rtems_task_delete(impl->id); return OS_ERROR; } @@ -151,8 +156,12 @@ int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl(uint32 task_id) +int32 OS_TaskDelete_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Try to delete the task ** If this fails, not much recourse - the only potential cause of failure @@ -160,10 +169,24 @@ int32 OS_TaskDelete_Impl(uint32 task_id) ** and if that is true there is nothing wrong - everything is OK to continue normally. */ - rtems_task_delete(OS_impl_task_table[task_id].id); + rtems_task_delete(impl->id); return OS_SUCCESS; } /* end OS_TaskDelete_Impl */ +/*---------------------------------------------------------------- + * + * Function: OS_TaskDetach_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskDetach_Impl(const OS_object_token_t *token) +{ + /* No-op on RTEMS */ + return OS_SUCCESS; +} + /*---------------------------------------------------------------- * * Function: OS_TaskExit_Impl @@ -221,13 +244,16 @@ int32 OS_TaskDelay_Impl(uint32 milli_second) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl(uint32 task_id, uint32 new_priority) +int32 OS_TaskSetPriority_Impl(const OS_object_token_t *token, osal_priority_t new_priority) { - rtems_task_priority old_pri; - rtems_status_code status; + rtems_task_priority old_pri; + rtems_status_code status; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); /* Set RTEMS Task Priority */ - status = rtems_task_set_priority(OS_impl_task_table[task_id].id, new_priority, &old_pri); + status = rtems_task_set_priority(impl->id, new_priority, &old_pri); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled task_set_priority error: %s\n", rtems_status_text(status)); @@ -246,12 +272,16 @@ int32 OS_TaskSetPriority_Impl(uint32 task_id, uint32 new_priority) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(uint32 task_id) +int32 OS_TaskMatch_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Get RTEMS Task Id */ - if (rtems_task_self() != OS_impl_task_table[task_id].id) + if (rtems_task_self() != impl->id) { return (OS_ERROR); } @@ -329,7 +359,7 @@ osal_id_t OS_TaskGetId_Impl(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl(uint32 task_id, OS_task_prop_t *task_prop) +int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_prop) { return OS_SUCCESS; @@ -343,7 +373,7 @@ int32 OS_TaskGetInfo_Impl(uint32 task_id, OS_task_prop_t *task_prop) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size) +int32 OS_TaskValidateSystemData_Impl(const void *sysdata, size_t sysdata_size) { if (sysdata == NULL || sysdata_size != sizeof(rtems_id)) { @@ -360,9 +390,12 @@ int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj) +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { - const rtems_id *target = (const rtems_id *)ref; + const rtems_id * target = (const rtems_id *)ref; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); - return (*target == OS_impl_task_table[local_id].id); + return (*target == impl->id); } diff --git a/src/os/rtems/src/os-impl-timebase.c b/src/os/rtems/src/os-impl-timebase.c index 8d047ec75..321b02109 100644 --- a/src/os/rtems/src/os-impl-timebase.c +++ b/src/os/rtems/src/os-impl-timebase.c @@ -36,6 +36,8 @@ #include "os-shared-timebase.h" #include "os-shared-idmap.h" +#include "osapi-printf.h" + /**************************************************************************************** INTERNAL FUNCTION PROTOTYPES ***************************************************************************************/ @@ -89,9 +91,13 @@ OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseLock_Impl(uint32 local_id) +void OS_TimeBaseLock_Impl(const OS_object_token_t *token) { - rtems_semaphore_obtain(OS_impl_timebase_table[local_id].handler_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + rtems_semaphore_obtain(impl->handler_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); } /* end OS_TimeBaseLock_Impl */ /*---------------------------------------------------------------- @@ -102,9 +108,13 @@ void OS_TimeBaseLock_Impl(uint32 local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseUnlock_Impl(uint32 local_id) +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) { - rtems_semaphore_release(OS_impl_timebase_table[local_id].handler_mutex); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + rtems_semaphore_release(impl->handler_mutex); } /* end OS_TimeBaseUnlock_Impl */ /*---------------------------------------------------------------- @@ -119,14 +129,14 @@ void OS_TimeBaseUnlock_Impl(uint32 local_id) static rtems_timer_service_routine OS_TimeBase_ISR(rtems_id rtems_timer_id, void *arg) { OS_U32ValueWrapper_t user_data; - uint32 local_id; + OS_object_token_t token; OS_impl_timebase_internal_record_t *local; user_data.opaque_arg = arg; - OS_ConvertToArrayIndex(user_data.id, &local_id); - local = &OS_impl_timebase_table[local_id]; - if (OS_ObjectIdEqual(OS_global_timebase_table[local_id].active_id, user_data.id)) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, user_data.id, &token) == OS_SUCCESS) { + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); + /* * Reset the timer, but only if an interval was selected */ @@ -154,33 +164,39 @@ static rtems_timer_service_routine OS_TimeBase_ISR(rtems_id rtems_timer_id, void * Pends on the semaphore for the next timer tick * *-----------------------------------------------------------------*/ -static uint32 OS_TimeBase_WaitImpl(uint32 local_id) +static uint32 OS_TimeBase_WaitImpl(osal_id_t timebase_id) { - OS_impl_timebase_internal_record_t *local; + OS_object_token_t token; + OS_impl_timebase_internal_record_t *impl; uint32 tick_time; - local = &OS_impl_timebase_table[local_id]; + tick_time = 0; - /* - * Pend for the tick arrival - */ - rtems_semaphore_obtain(local->tick_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - - /* - * Determine how long this tick was. - * Note that there are plenty of ways this become wrong if the timer - * is reset right around the time a tick comes in. However, it is - * impossible to guarantee the behavior of a reset if the timer is running. - * (This is not an expected use-case anyway; the timer should be set and forget) - */ - if (local->reset_flag == 0) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &token) == OS_SUCCESS) { - tick_time = local->configured_interval_time; - } - else - { - tick_time = local->configured_start_time; - local->reset_flag = 0; + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); + + /* + * Pend for the tick arrival + */ + rtems_semaphore_obtain(impl->tick_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + + /* + * Determine how long this tick was. + * Note that there are plenty of ways this become wrong if the timer + * is reset right around the time a tick comes in. However, it is + * impossible to guarantee the behavior of a reset if the timer is running. + * (This is not an expected use-case anyway; the timer should be set and forget) + */ + if (impl->reset_flag == 0) + { + tick_time = impl->configured_interval_time; + } + else + { + tick_time = impl->configured_start_time; + impl->reset_flag = 0; + } } return tick_time; @@ -280,22 +296,22 @@ void OS_UsecsToTicks(uint32 usecs, rtems_interval *ticks) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseCreate_Impl(uint32 timer_id) +int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token) { int32 return_code; rtems_status_code rtems_sc; OS_impl_timebase_internal_record_t *local; - OS_common_record_t * global; rtems_name r_name; + OS_timebase_internal_record_t * timebase; return_code = OS_SUCCESS; - local = &OS_impl_timebase_table[timer_id]; - global = &OS_global_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); /* * The RTEMS classic name for dependent resources */ - r_name = OS_ObjectIdToInteger(global->active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); /* * Set up the necessary OS constructs @@ -306,10 +322,10 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * If no external sync function is provided then this will set up an RTEMS * timer to locally simulate the timer tick using the CPU clock. */ - local->simulate_flag = (OS_timebase_table[timer_id].external_sync == NULL); + local->simulate_flag = (timebase->external_sync == NULL); if (local->simulate_flag) { - OS_timebase_table[timer_id].external_sync = OS_TimeBase_WaitImpl; + timebase->external_sync = OS_TimeBase_WaitImpl; /* * The tick_sem is a simple semaphore posted by the ISR and taken by the @@ -376,10 +392,9 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) else { /* will place the task in 'ready for scheduling' state */ - rtems_sc = - rtems_task_start(local->handler_task, /*rtems task id*/ - (rtems_task_entry)OS_TimeBase_CallbackThread, /* task entry point */ - (rtems_task_argument)OS_ObjectIdToInteger(global->active_id)); /* passed argument */ + rtems_sc = rtems_task_start(local->handler_task, /*rtems task id*/ + (rtems_task_entry)OS_TimeBase_CallbackThread, /* task entry point */ + (rtems_task_argument)r_name); /* passed argument */ if (rtems_sc != RTEMS_SUCCESSFUL) { @@ -410,15 +425,17 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time) +int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uint32 interval_time) { OS_U32ValueWrapper_t user_data; OS_impl_timebase_internal_record_t *local; int32 return_code; int status; rtems_interval start_ticks; + OS_timebase_internal_record_t * timebase; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); return_code = OS_SUCCESS; /* There is only something to do here if we are generating a simulated tick */ @@ -458,7 +475,7 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time OS_UsecsToTicks(start_time, &start_ticks); user_data.opaque_arg = NULL; - user_data.id = OS_global_timebase_table[timer_id].active_id; + user_data.id = OS_ObjectIdFromToken(token); status = rtems_timer_fire_after(local->rtems_timer_id, start_ticks, OS_TimeBase_ISR, user_data.opaque_arg); if (status != RTEMS_SUCCESSFUL) @@ -475,23 +492,23 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time if (local->configured_start_time != start_time) { OS_DEBUG("WARNING: timer %lu start_time requested=%luus, configured=%luus\n", - (unsigned long)timer_id, (unsigned long)start_time, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), (unsigned long)start_time, (unsigned long)local->configured_start_time); } if (local->configured_interval_time != interval_time) { OS_DEBUG("WARNING: timer %lu interval_time requested=%luus, configured=%luus\n", - (unsigned long)timer_id, (unsigned long)interval_time, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), (unsigned long)interval_time, (unsigned long)local->configured_interval_time); } if (local->interval_ticks > 0) { - OS_timebase_table[timer_id].accuracy_usec = local->configured_interval_time; + timebase->accuracy_usec = local->configured_interval_time; } else { - OS_timebase_table[timer_id].accuracy_usec = local->configured_start_time; + timebase->accuracy_usec = local->configured_start_time; } } } @@ -512,13 +529,13 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseDelete_Impl(uint32 timer_id) +int32 OS_TimeBaseDelete_Impl(const OS_object_token_t *token) { rtems_status_code rtems_sc; OS_impl_timebase_internal_record_t *local; int32 return_code; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); return_code = OS_SUCCESS; /* @@ -576,7 +593,7 @@ int32 OS_TimeBaseDelete_Impl(uint32 timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseGetInfo_Impl(uint32 timer_id, OS_timebase_prop_t *timer_prop) +int32 OS_TimeBaseGetInfo_Impl(const OS_object_token_t *token, OS_timebase_prop_t *timer_prop) { return OS_SUCCESS; diff --git a/src/os/shared/inc/os-shared-binsem.h b/src/os/shared/inc/os-shared-binsem.h index 8304d2b2e..b4273c426 100644 --- a/src/os/shared/inc/os-shared-binsem.h +++ b/src/os/shared/inc/os-shared-binsem.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_BINSEM_H_ -#define INCLUDE_OS_SHARED_BINSEM_H_ +#ifndef OS_SHARED_BINSEM_H +#define OS_SHARED_BINSEM_H +#include "osapi-binsem.h" #include /* other objects that have only an API name and no other data */ @@ -62,7 +63,7 @@ int32 OS_BinSemAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 options); +int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options); /*---------------------------------------------------------------- Function: OS_BinSemFlush_Impl @@ -72,7 +73,7 @@ int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 optio Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl(uint32 sem_id); +int32 OS_BinSemFlush_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_BinSemGive_Impl @@ -81,7 +82,7 @@ int32 OS_BinSemFlush_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl(uint32 sem_id); +int32 OS_BinSemGive_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_BinSemTake_Impl @@ -91,7 +92,7 @@ int32 OS_BinSemGive_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl(uint32 sem_id); +int32 OS_BinSemTake_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_BinSemTimedWait_Impl @@ -101,7 +102,7 @@ int32 OS_BinSemTake_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code OS_SEM_TIMEOUT must be returned if the time limit was reached ------------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl(uint32 sem_id, uint32 msecs); +int32 OS_BinSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs); /*---------------------------------------------------------------- Function: OS_BinSemDelete_Impl @@ -110,7 +111,7 @@ int32 OS_BinSemTimedWait_Impl(uint32 sem_id, uint32 msecs); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl(uint32 sem_id); +int32 OS_BinSemDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_BinSemGetInfo_Impl @@ -119,6 +120,6 @@ int32 OS_BinSemDelete_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl(uint32 sem_id, OS_bin_sem_prop_t *bin_prop); +int32 OS_BinSemGetInfo_Impl(const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop); -#endif /* INCLUDE_OS_SHARED_BINSEM_H_ */ +#endif /* OS_SHARED_BINSEM_H */ diff --git a/src/os/shared/inc/os-shared-clock.h b/src/os/shared/inc/os-shared-clock.h index 60cada199..dab3a5ea1 100644 --- a/src/os/shared/inc/os-shared-clock.h +++ b/src/os/shared/inc/os-shared-clock.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_CLOCK_H_ -#define INCLUDE_OS_SHARED_CLOCK_H_ +#ifndef OS_SHARED_CLOCK_H +#define OS_SHARED_CLOCK_H +#include "osapi-clock.h" #include /* @@ -53,4 +54,4 @@ int32 OS_GetLocalTime_Impl(OS_time_t *time_struct); ------------------------------------------------------------------*/ int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct); -#endif /* INCLUDE_OS_SHARED_CLOCK_H_ */ +#endif /* OS_SHARED_CLOCK_H */ diff --git a/src/os/shared/inc/os-shared-common.h b/src/os/shared/inc/os-shared-common.h index e98858a33..f9eb15180 100644 --- a/src/os/shared/inc/os-shared-common.h +++ b/src/os/shared/inc/os-shared-common.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_COMMON_H_ -#define INCLUDE_OS_SHARED_COMMON_H_ +#ifndef OS_SHARED_COMMON_H +#define OS_SHARED_COMMON_H +#include "osapi-common.h" #include /* @@ -52,8 +53,8 @@ struct OS_shared_global_vars */ volatile bool PrintfEnabled; volatile uint32 ShutdownFlag; - int32 MicroSecPerTick; - int32 TicksPerSecond; + uint32 MicroSecPerTick; + uint32 TicksPerSecond; /* * The event handler is an application-defined callback @@ -87,7 +88,7 @@ int32 OS_NotifyEvent(OS_Event_t event, osal_id_t object_id, void *data); returns: OS_SUCCESS on success, or relevant error code ---------------------------------------------------------------------------------------*/ -int32 OS_API_Impl_Init(uint32 idtype); +int32 OS_API_Impl_Init(osal_objtype_t idtype); /* * This functions implement a the OS-specific portion @@ -127,4 +128,27 @@ void OS_IdleLoop_Impl(void); ------------------------------------------------------------------*/ void OS_ApplicationShutdown_Impl(void); -#endif /* INCLUDE_OS_SHARED_COMMON_H_ */ +/*---------------------------------------------------------------- + + Function: OS_strnlen + + Purpose: Utility function to safely find the length of a string + within a fixed-size array buffer. + + Provides a local OSAL routine to get the functionality + of the (non-C99) "strnlen()" function, via the + C89/C99 standard "memchr()" function instead. + + ------------------------------------------------------------------*/ +static inline size_t OS_strnlen(const char *s, size_t maxlen) +{ + const char *end = memchr(s, 0, maxlen); + if (end != NULL) + { + /* actual length of string is difference */ + maxlen = end - s; + } + return maxlen; +} + +#endif /* OS_SHARED_COMMON_H */ diff --git a/src/os/shared/inc/os-shared-countsem.h b/src/os/shared/inc/os-shared-countsem.h index 8298aad38..c02cc9db4 100644 --- a/src/os/shared/inc/os-shared-countsem.h +++ b/src/os/shared/inc/os-shared-countsem.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_COUNTSEM_H_ -#define INCLUDE_OS_SHARED_COUNTSEM_H_ +#ifndef OS_SHARED_COUNTSEM_H +#define OS_SHARED_COUNTSEM_H +#include "osapi-countsem.h" #include /* other objects that have only an API name and no other data */ @@ -62,7 +63,7 @@ int32 OS_CountSemAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 options); +int32 OS_CountSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options); /*---------------------------------------------------------------- Function: OS_CountSemGive_Impl @@ -71,7 +72,7 @@ int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 opt Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl(uint32 sem_id); +int32 OS_CountSemGive_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_CountSemTake_Impl @@ -81,7 +82,7 @@ int32 OS_CountSemGive_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl(uint32 sem_id); +int32 OS_CountSemTake_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_CountSemTimedWait_Impl @@ -91,7 +92,7 @@ int32 OS_CountSemTake_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code OS_SEM_TIMEOUT must be returned if the time limit was reached ------------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl(uint32 sem_id, uint32 msecs); +int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs); /*---------------------------------------------------------------- Function: OS_CountSemDelete_Impl @@ -100,7 +101,7 @@ int32 OS_CountSemTimedWait_Impl(uint32 sem_id, uint32 msecs); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl(uint32 sem_id); +int32 OS_CountSemDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_CountSemGetInfo_Impl @@ -109,6 +110,6 @@ int32 OS_CountSemDelete_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl(uint32 sem_id, OS_count_sem_prop_t *count_prop); +int32 OS_CountSemGetInfo_Impl(const OS_object_token_t *token, OS_count_sem_prop_t *count_prop); -#endif /* INCLUDE_OS_SHARED_COUNTSEM_H_ */ +#endif /* OS_SHARED_COUNTSEM_H */ diff --git a/src/os/shared/inc/os-shared-dir.h b/src/os/shared/inc/os-shared-dir.h index 79d783e86..081f5ae60 100644 --- a/src/os/shared/inc/os-shared-dir.h +++ b/src/os/shared/inc/os-shared-dir.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_DIR_H_ -#define INCLUDE_OS_SHARED_DIR_H_ +#ifndef OS_SHARED_DIR_H +#define OS_SHARED_DIR_H +#include "osapi-dir.h" #include /* directory objects */ @@ -72,7 +73,7 @@ int32 OS_DirCreate_Impl(const char *local_path, uint32 access); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path); +int32 OS_DirOpen_Impl(const OS_object_token_t *token, const char *local_path); /*---------------------------------------------------------------- Function: OS_DirClose_Impl @@ -81,7 +82,7 @@ int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_DirClose_Impl(uint32 local_id); +int32 OS_DirClose_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_DirRead_Impl @@ -90,7 +91,7 @@ int32 OS_DirClose_Impl(uint32 local_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent); +int32 OS_DirRead_Impl(const OS_object_token_t *token, os_dirent_t *dirent); /*---------------------------------------------------------------- Function: OS_DirRewind_Impl @@ -99,7 +100,7 @@ int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_DirRewind_Impl(uint32 local_id); +int32 OS_DirRewind_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_DirRemove_Impl @@ -110,4 +111,4 @@ int32 OS_DirRewind_Impl(uint32 local_id); ------------------------------------------------------------------*/ int32 OS_DirRemove_Impl(const char *local_path); -#endif /* INCLUDE_OS_SHARED_DIR_H_ */ +#endif /* OS_SHARED_DIR_H */ diff --git a/src/os/shared/inc/os-shared-errors.h b/src/os/shared/inc/os-shared-errors.h index 0b4968f62..a93764caf 100644 --- a/src/os/shared/inc/os-shared-errors.h +++ b/src/os/shared/inc/os-shared-errors.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_SHARED_ERRORS_H_ -#define INCLUDE_OS_SHARED_ERRORS_H_ +#ifndef OS_SHARED_ERRORS_H +#define OS_SHARED_ERRORS_H #include @@ -39,4 +39,4 @@ typedef struct extern const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[]; -#endif /* INCLUDE_OS_SHARED_ERRORS_H_ */ +#endif /* OS_SHARED_ERRORS_H */ diff --git a/src/os/shared/inc/os-shared-file.h b/src/os/shared/inc/os-shared-file.h index 75c8fc912..715908dc3 100644 --- a/src/os/shared/inc/os-shared-file.h +++ b/src/os/shared/inc/os-shared-file.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_FILE_H_ -#define INCLUDE_OS_SHARED_FILE_H_ +#ifndef OS_SHARED_FILE_H +#define OS_SHARED_FILE_H +#include "osapi-file.h" #include typedef struct @@ -78,7 +79,7 @@ int32 OS_FileAPI_Init(void); Returns: File position (non-negative) on success, or relevant error code (negative) ------------------------------------------------------------------*/ -int32 OS_GenericSeek_Impl(uint32 local_id, int32 offset, uint32 whence); +int32 OS_GenericSeek_Impl(const OS_object_token_t *token, int32 offset, uint32 whence); /*---------------------------------------------------------------- Function: OS_GenericRead_Impl @@ -88,7 +89,7 @@ int32 OS_GenericSeek_Impl(uint32 local_id, int32 offset, uint32 whence); Returns: Number of bytes read (non-negative) on success, or relevant error code (negative) ------------------------------------------------------------------*/ -int32 OS_GenericRead_Impl(uint32 local_id, void *buffer, uint32 nbytes, int32 timeout); +int32 OS_GenericRead_Impl(const OS_object_token_t *token, void *buffer, size_t nbytes, int32 timeout); /*---------------------------------------------------------------- Function: OS_GenericWrite_Impl @@ -98,7 +99,7 @@ int32 OS_GenericRead_Impl(uint32 local_id, void *buffer, uint32 nbytes, int32 ti Returns: Number of bytes written (non-negative) on success, or relevant error code (negative) ------------------------------------------------------------------*/ -int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, int32 timeout); +int32 OS_GenericWrite_Impl(const OS_object_token_t *token, const void *buffer, size_t nbytes, int32 timeout); /*---------------------------------------------------------------- Function: OS_GenericClose_Impl @@ -108,7 +109,7 @@ int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, i Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_GenericClose_Impl(uint32 local_id); +int32 OS_GenericClose_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileOpen_Impl @@ -118,7 +119,7 @@ int32 OS_GenericClose_Impl(uint32 local_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int32 access); +int32 OS_FileOpen_Impl(const OS_object_token_t *token, const char *local_path, int32 flags, int32 access); /*---------------------------------------------------------------- Function: OS_ShellOutputToFile_Impl @@ -127,7 +128,7 @@ int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 stream_id, const char *Cmd); +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd); /**************************************************************************************** Filename-based Operations @@ -182,4 +183,12 @@ int32 OS_FileRename_Impl(const char *old_path, const char *new_path); ------------------------------------------------------------------*/ int32 OS_FileChmod_Impl(const char *local_path, uint32 access); -#endif /* INCLUDE_OS_SHARED_FILE_H_ */ +/* + * Internal helper function + * + * Not called outside this unit, but need to be prototyped + * here for coverage test. + */ +int32 OS_FileIteratorClose(osal_id_t filedes, void *arg); + +#endif /* OS_SHARED_FILE_H */ diff --git a/src/os/shared/inc/os-shared-filesys.h b/src/os/shared/inc/os-shared-filesys.h index c4227ce59..b16a3765e 100644 --- a/src/os/shared/inc/os-shared-filesys.h +++ b/src/os/shared/inc/os-shared-filesys.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_FILESYS_H_ -#define INCLUDE_OS_SHARED_FILESYS_H_ +#ifndef OS_SHARED_FILESYS_H +#define OS_SHARED_FILESYS_H +#include "osapi-filesys.h" #include /** @@ -83,22 +84,6 @@ enum OS_FILESYS_TYPE_MAX }; -/* - * The data type filled in by the "statvfs" call. - * - * This is defined here since there is no public API to get this info, - * only the total bytes free is accessible via the current OSAL API. - * - * However, returning the detailed info at this level means that the - * more detailed information could be made available with a new API call. - */ -typedef struct -{ - uint32 block_size; - uint64 total_blocks; - uint64 blocks_free; -} OS_statvfs_t; - typedef struct { char device_name[OS_FS_DEV_NAME_LEN]; /**< The name of the underlying block device, if applicable */ @@ -107,11 +92,11 @@ typedef struct operating system */ char virtual_mountpt[OS_MAX_PATH_LEN]; /**< The name/prefix in the OSAL Virtual File system exposed to applications */ - char * address; - uint32 blocksize; - uint32 numblocks; - uint8 flags; - uint8 fstype; + char * address; + size_t blocksize; + osal_blockcount_t numblocks; + uint8 flags; + uint8 fstype; } OS_filesys_internal_record_t; /* @@ -140,7 +125,7 @@ int32 OS_FileSysAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysStartVolume_Impl(uint32 filesys_id); +int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileSysStopVolume_Impl @@ -149,7 +134,7 @@ int32 OS_FileSysStartVolume_Impl(uint32 filesys_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysStopVolume_Impl(uint32 filesys_id); +int32 OS_FileSysStopVolume_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileSysFormatVolume_Impl @@ -158,7 +143,7 @@ int32 OS_FileSysStopVolume_Impl(uint32 filesys_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysFormatVolume_Impl(uint32 filesys_id); +int32 OS_FileSysFormatVolume_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileSysCheckVolume_Impl @@ -167,7 +152,7 @@ int32 OS_FileSysFormatVolume_Impl(uint32 filesys_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysCheckVolume_Impl(uint32 filesys_id, bool repair); +int32 OS_FileSysCheckVolume_Impl(const OS_object_token_t *token, bool repair); /*---------------------------------------------------------------- Function: OS_FileSysStatVolume_Impl @@ -176,7 +161,7 @@ int32 OS_FileSysCheckVolume_Impl(uint32 filesys_id, bool repair); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result); +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result); /*---------------------------------------------------------------- Function: OS_FileSysMountVolume_Impl @@ -185,7 +170,7 @@ int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysMountVolume_Impl(uint32 filesys_id); +int32 OS_FileSysMountVolume_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileSysUnmountVolume_Impl @@ -194,7 +179,7 @@ int32 OS_FileSysMountVolume_Impl(uint32 filesys_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysUnmountVolume_Impl(uint32 filesys_id); +int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token); /* * Internal helper functions @@ -202,8 +187,9 @@ int32 OS_FileSysUnmountVolume_Impl(uint32 filesys_id); * Not normally invoked outside this unit, except for unit testing */ -bool OS_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_common_record_t *obj); -int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fsvolname, uint32 blocksize, - uint32 numblocks, bool should_format); +bool OS_FileSys_FindVirtMountPoint(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); +int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fsvolname, size_t blocksize, + osal_blockcount_t numblocks, bool should_format); +bool OS_FileSysFilterFree(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); -#endif /* INCLUDE_OS_SHARED_FILESYS_H_ */ +#endif /* OS_SHARED_FILESYS_H */ diff --git a/src/os/shared/inc/os-shared-globaldefs.h b/src/os/shared/inc/os-shared-globaldefs.h index cbca0704c..dc35c88c4 100644 --- a/src/os/shared/inc/os-shared-globaldefs.h +++ b/src/os/shared/inc/os-shared-globaldefs.h @@ -28,11 +28,15 @@ * so they are put into a common header file. */ -#ifndef INCLUDE_OSAPI_SHARED_GLOBALDEFS_H_ -#define INCLUDE_OSAPI_SHARED_GLOBALDEFS_H_ +#ifndef OSAPI_SHARED_GLOBALDEFS_H_ +#define OSAPI_SHARED_GLOBALDEFS_H_ -/* All subsystems reference the public API */ -#include +/* All subsystems reference the same config, common types, and other constants */ +#include "osconfig.h" +#include "common_types.h" +#include "osapi-constants.h" +#include "osapi-error.h" +#include "osapi-macros.h" /* * The "common_record" is part of the generic ID mapping - @@ -48,6 +52,15 @@ typedef struct OS_common_record OS_common_record_t; struct OS_shared_global_vars; typedef struct OS_shared_global_vars OS_SharedGlobalVars_t; +/* + * The "OS_object_token" tracks to the type of lock currently held + * and the specific object record the requested operation should + * execute on. All operations start by obtaining a token, which must + * be released when the operation is complete. + */ +struct OS_object_token; +typedef struct OS_object_token OS_object_token_t; + /* * Wrapper for encoding of other types into a generic void* type required as argument * to callbacks and pthread entry/return values, etc. @@ -56,12 +69,10 @@ typedef struct OS_shared_global_vars OS_SharedGlobalVars_t; */ typedef union { - void * opaque_arg; - OS_ArgCallback_t arg_callback_func; - OS_TimerCallback_t timer_callback_func; - osal_task_entry entry_func; - osal_id_t id; - uint32 value; + void * opaque_arg; + OS_ArgCallback_t arg_callback_func; + osal_id_t id; + osal_index_t idx; } OS_U32ValueWrapper_t; /* @@ -79,4 +90,52 @@ extern void OS_DebugPrintf(uint32 Level, const char *Func, uint32 Line, const ch #define OS_DEBUG(...) #endif -#endif /* INCLUDE_OS_SHARED_GLOBALDEFS_H_ */ +/* + * An OSAL-specific check macro for NULL pointer. + * Checked via BUGCHECK - considered a bug/fatal error if check fails. + * + * Returns OS_INVALID_POINTER if pointer is NULL. + */ +#define OS_CHECK_POINTER(ptr) BUGCHECK((ptr) != NULL, OS_INVALID_POINTER) + +/* + * An OSAL-specific check macro for an input buffer size. + * Checked via ARGCHECK - non-fatal if check fails. + * + * Returns OS_ERR_INVALID_SIZE if size is 0. + * + * Also returns OS_ERR_INVALID_SIZE if size is excessively large. + * Currently (UINT32_MAX/2) is used as the upper limit, as some API calls + * (e.g. read/write) return a size as an int32 type, and therefore the + * operation cannot exceed the bounds of this type. + */ +#define OS_CHECK_SIZE(val) ARGCHECK((val) > 0 && (val) < (UINT32_MAX / 2), OS_ERR_INVALID_SIZE) + +/* + * An OSAL-specific check macro for arbitrary string argument validation. + * + * First confirms string is not null using OS_CHECK_POINTER, then checks the maximum + * length of the string using LENGTHCHECK. + */ +#define OS_CHECK_STRING(str, maxlen, errcode) \ + do \ + { \ + OS_CHECK_POINTER(str); \ + LENGTHCHECK(str, maxlen, errcode); \ + } while (0) + +/* + * An OSAL-specific check macro for object name strings. + * + * Returns OS_ERR_NAME_TOO_LONG if length is exceeded. + */ +#define OS_CHECK_APINAME(str) OS_CHECK_STRING(str, OS_MAX_API_NAME, OS_ERR_NAME_TOO_LONG) + +/* + * An OSAL specific argument check macro for path names + * + * Returns OS_FS_ERR_PATH_TOO_LONG if length is exceeded. + */ +#define OS_CHECK_PATHNAME(str) OS_CHECK_STRING(str, OS_MAX_PATH_LEN, OS_FS_ERR_PATH_TOO_LONG) + +#endif /* OS_SHARED_GLOBALDEFS_H */ diff --git a/src/os/shared/inc/os-shared-heap.h b/src/os/shared/inc/os-shared-heap.h index 510eb432c..d419d7d4a 100644 --- a/src/os/shared/inc/os-shared-heap.h +++ b/src/os/shared/inc/os-shared-heap.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_HEAP_H_ -#define INCLUDE_OS_SHARED_HEAP_H_ +#ifndef OS_SHARED_HEAP_H +#define OS_SHARED_HEAP_H +#include "osapi-heap.h" #include /**************************************************************************************** @@ -47,4 +48,4 @@ ------------------------------------------------------------------*/ int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop); -#endif /* INCLUDE_OS_SHARED_HEAP_H_ */ +#endif /* OS_SHARED_HEAP_H */ diff --git a/src/os/shared/inc/os-shared-idmap.h b/src/os/shared/inc/os-shared-idmap.h index 30f128bc2..9f487c82e 100644 --- a/src/os/shared/inc/os-shared-idmap.h +++ b/src/os/shared/inc/os-shared-idmap.h @@ -25,13 +25,12 @@ * */ -#ifndef INCLUDE_OS_SHARED_IDMAP_H_ -#define INCLUDE_OS_SHARED_IDMAP_H_ +#ifndef OS_SHARED_IDMAP_H +#define OS_SHARED_IDMAP_H +#include "osapi-idmap.h" #include -#define OS_OBJECT_EXCL_REQ_FLAG 0x0001 - #define OS_OBJECT_ID_RESERVED ((osal_id_t) {0xFFFFFFFF}) /* @@ -43,7 +42,6 @@ struct OS_common_record osal_id_t active_id; osal_id_t creator; uint16 refcount; - uint16 flags; }; /* @@ -51,12 +49,50 @@ struct OS_common_record */ typedef enum { - OS_LOCK_MODE_NONE, /**< Do not lock global table at all (use with caution) */ - OS_LOCK_MODE_GLOBAL, /**< Lock during operation, and if successful, leave global table locked */ - OS_LOCK_MODE_EXCLUSIVE, /**< Like OS_LOCK_MODE_GLOBAL but must be exclusive (refcount == zero) */ - OS_LOCK_MODE_REFCOUNT, /**< If operation succeeds, increment refcount and unlock global table */ + OS_LOCK_MODE_NONE, /**< Quick ID validity check, does not lock global table at all (use with caution) */ + OS_LOCK_MODE_GLOBAL, /**< Confirm ID match, and if successful, leave global table locked */ + OS_LOCK_MODE_REFCOUNT, /**< Confirm ID match, increment refcount, and unlock global table. ID is not changed. */ + OS_LOCK_MODE_EXCLUSIVE, /**< Confirm ID match AND refcount equal zero, then change ID to RESERVED value and unlock + global. */ + OS_LOCK_MODE_RESERVED /**< Confirm ID is already set to RESERVED, otherwise like OS_LOCK_MODE_GLOBAL. */ } OS_lock_mode_t; +/* + * A unique key value issued when obtaining a table lock, based on a + * the a combination of the requesting task ID and a transaction ID + */ +typedef struct +{ + uint32 key_value; +} osal_key_t; + +/* + * Actual (non-abstract) definition of "OS_object_token_t" + */ +struct OS_object_token +{ + OS_lock_mode_t lock_mode; + osal_key_t lock_key; + osal_objtype_t obj_type; + osal_index_t obj_idx; + osal_id_t obj_id; +}; + +/* + * Macro to retrieve an entry from an object table, based on a token + */ +#define OS_OBJECT_TABLE_GET(tbl, tok) (&tbl[OS_ObjectIndexFromToken(&(tok))]) + +/* + * Macro to clear a table entry and reset its name + */ +#define OS_OBJECT_INIT(tok, ref, namefield, nameval) \ + { \ + memset(ref, 0, sizeof(*ref)); \ + strncpy(ref->namefield, nameval, sizeof(ref->namefield) - 1); \ + OS_ObjectIdGlobalFromToken(&tok)->name_entry = ref->namefield; \ + } + /* * A function to perform arbitrary record matching. * @@ -65,7 +101,19 @@ typedef enum * * Returns true if the id/obj matches the reference, false otherwise. */ -typedef bool (*OS_ObjectMatchFunc_t)(void *ref, uint32 local_id, const OS_common_record_t *obj); +typedef bool (*OS_ObjectMatchFunc_t)(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); + +/* + * State object associated with an object iterator + */ +typedef struct +{ + OS_common_record_t * base; + OS_ObjectMatchFunc_t match; + void * arg; + osal_index_t limit; + OS_object_token_t token; +} OS_object_iter_t; /* * Global instantiations @@ -109,7 +157,7 @@ int32 OS_ObjectIdInit(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -void OS_Lock_Global(uint32 idtype); +void OS_Lock_Global(OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_Lock_Global @@ -118,7 +166,7 @@ void OS_Lock_Global(uint32 idtype); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_Lock_Global_Impl(uint32 idtype); +void OS_Lock_Global_Impl(osal_objtype_t idtype); /*---------------------------------------------------------------- Function: OS_Unlock_Global @@ -127,7 +175,7 @@ int32 OS_Lock_Global_Impl(uint32 idtype); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -void OS_Unlock_Global(uint32 idtype); +void OS_Unlock_Global(OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_Unlock_Global @@ -136,7 +184,36 @@ void OS_Unlock_Global(uint32 idtype); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_Unlock_Global_Impl(uint32 idtype); +void OS_Unlock_Global_Impl(osal_objtype_t idtype); + +/*---------------------------------------------------------------- + + Function: OS_WaitForStateChange + + Purpose: Waits for a change in the global table identified by "idtype" + + NOTE: The table must be already "owned" (via OS_Lock_Global) by the calling + at the time this function is invoked. The lock is released and re-acquired + before returning from this function. + + -----------------------------------------------------------------*/ +void OS_WaitForStateChange(OS_object_token_t *token, uint32 attempts); + +/*---------------------------------------------------------------- + + Function: OS_WaitForStateChange_Impl + + Purpose: Block the caller until some sort of change event + has occurred for the given object type, such as a record changing + state i.e. the acquisition or release of a lock/refcount from + another thread. + + It is not guaranteed what, if any, state change has actually + occured when this function returns. This may be implement as + a simple OS_TaskDelay(). + + ------------------------------------------------------------------*/ +void OS_WaitForStateChange_Impl(osal_objtype_t objtype, uint32 attempts); /* Function prototypes for routines implemented in common layers but private to OSAL @@ -161,7 +238,7 @@ static inline uint32 OS_ObjectIdToSerialNumber_Impl(osal_id_t id) Purpose: Obtain the object type component of a generic OSAL Object ID ------------------------------------------------------------------*/ -static inline uint32 OS_ObjectIdToType_Impl(osal_id_t id) +static inline osal_objtype_t OS_ObjectIdToType_Impl(osal_id_t id) { return (OS_ObjectIdToInteger(id) >> OS_OBJECT_TYPE_SHIFT); } @@ -171,11 +248,31 @@ static inline uint32 OS_ObjectIdToType_Impl(osal_id_t id) Purpose: Convert an object serial number and resource type into an external 32-bit OSAL ID ------------------------------------------------------------------*/ -static inline void OS_ObjectIdCompose_Impl(uint32 idtype, uint32 idserial, osal_id_t *result) +static inline void OS_ObjectIdCompose_Impl(osal_objtype_t idtype, uint32 idserial, osal_id_t *result) { *result = OS_ObjectIdFromInteger((idtype << OS_OBJECT_TYPE_SHIFT) | idserial); } +/*-------------------------------------------------------------------------------------*/ +/** + * @brief Check if an object ID represents a valid/active value. + * + * This tests that the ID value is within the range specifically used by + * valid OSAL IDs. This is smaller than the set of defined IDs. + * + * For example, the value of OS_OBJECT_ID_RESERVED is defined but not valid. + * So while OS_ObjectIdDefined() will match entries being actively created or + * deleted, OS_ObjectIdIsValid() will not. + * + * @param[in] object_id The object ID + * @returns true if table entry is valid + */ +static inline bool OS_ObjectIdIsValid(osal_id_t object_id) +{ + osal_objtype_t objtype = OS_ObjectIdToType_Impl(object_id); + return (objtype > OS_OBJECT_TYPE_UNDEFINED && objtype < OS_OBJECT_TYPE_USER); +} + /*---------------------------------------------------------------- Function: OS_GetMaxForObjectType @@ -183,7 +280,7 @@ static inline void OS_ObjectIdCompose_Impl(uint32 idtype, uint32 idserial, osal_ Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -uint32 OS_GetMaxForObjectType(uint32 idtype); +uint32 OS_GetMaxForObjectType(osal_objtype_t idtype); /*---------------------------------------------------------------- Function: OS_GetBaseForObjectType @@ -192,7 +289,92 @@ uint32 OS_GetMaxForObjectType(uint32 idtype); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -uint32 OS_GetBaseForObjectType(uint32 idtype); +uint32 OS_GetBaseForObjectType(osal_objtype_t idtype); + +/*---------------------------------------------------------------- + Function: OS_ObjectIndexFromToken + + Purpose: Gets the index referenced by the token + + Returns: None + ------------------------------------------------------------------*/ +static inline osal_objtype_t OS_ObjectTypeFromToken(const OS_object_token_t *token) +{ + return token->obj_type; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIndexFromToken + + Purpose: Gets the index referenced by the token + + Returns: None + ------------------------------------------------------------------*/ +static inline osal_index_t OS_ObjectIndexFromToken(const OS_object_token_t *token) +{ + return token->obj_idx; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdFromToken + + Purpose: Gets the object ID referenced by the token + + Returns: None + ------------------------------------------------------------------*/ +static inline osal_id_t OS_ObjectIdFromToken(const OS_object_token_t *token) +{ + return token->obj_id; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdGlobalFromToken + + Purpose: Obtains the global record corresponding to the token + + Returns: Pointer to global object + ------------------------------------------------------------------*/ +OS_common_record_t *OS_ObjectIdGlobalFromToken(const OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransactionInit + + Purpose: Initiates a transaction by obtaining the global table lock + and preparing the object token value + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdTransactionInit(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransactionCancel + + Purpose: Cancels/Releases the lock obtained by OS_ObjectIdTransactionInit() + without making any modification to global IDs. + + Returns: None + ------------------------------------------------------------------*/ +void OS_ObjectIdTransactionCancel(OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransactionFinish + + Purpose: Releases the lock obtained by OS_ObjectIdTransactionInit() + with an optional synchronized ID update for new/deleted IDs. + + Returns: None + ------------------------------------------------------------------*/ +void OS_ObjectIdTransactionFinish(OS_object_token_t *token, osal_id_t *final_id); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdConvertToken + + Purpose: Converts a token from OS_ObjectIdTransactionInit() to the + type that was requested by the user. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdConvertToken(OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ObjectIdFindByName @@ -201,7 +383,7 @@ uint32 OS_GetBaseForObjectType(uint32 idtype); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdFindByName(uint32 idtype, const char *name, osal_id_t *object_id); +int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t *object_id); /*---------------------------------------------------------------- Function: OS_ObjectIdGetBySearch @@ -212,8 +394,8 @@ int32 OS_ObjectIdFindByName(uint32 idtype, const char *name, osal_id_t *object_i Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, - OS_common_record_t **record); +int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, + OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ObjectIdGetByName @@ -223,7 +405,7 @@ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, OS_ObjectM Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, uint32 idtype, const char *name, OS_common_record_t **record); +int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ObjectIdGetById @@ -233,8 +415,27 @@ int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, uint32 idtype, const char * Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, uint32 idtype, osal_id_t id, uint32 *array_index, - OS_common_record_t **record); +int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdRelease + + Purpose: Releases (unlocks) the object token previously obtained using + OS_ObjectIdGetById() or OS_ObjectIdGetBySearch(). + + Returns: none + ------------------------------------------------------------------*/ +void OS_ObjectIdRelease(OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransferToken + + Purpose: Transfers ownership of a object token without unlocking/releasing. + The original token will become benign and the new token becomes active. + + Returns: none + ------------------------------------------------------------------*/ +void OS_ObjectIdTransferToken(OS_object_token_t *token_from, OS_object_token_t *token_to); /*---------------------------------------------------------------- Function: OS_ObjectIdAllocateNew @@ -246,7 +447,7 @@ int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, uint32 idtype, osal_id_t id, Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_index, OS_common_record_t **record); +int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ObjectIdFinalizeNew @@ -258,7 +459,7 @@ int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_inde Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, osal_id_t *outid); +int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_object_token_t *token, osal_id_t *outid); /*---------------------------------------------------------------- Function: OS_ObjectIdFinalizeDelete @@ -270,27 +471,78 @@ int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *record); +int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_object_token_t *token); /*---------------------------------------------------------------- - Function: OS_ObjectIdRefcountDecr + Function: OS_ObjectIdIteratorInit - Purpose: Decrement the reference count - This releases objects obtained with OS_LOCK_MODE_REFCOUNT mode + Purpose: Initialize a generic object iterator of the given type. + Note This obtains and holds a global lock on the internal table, so + this call must be followed by a call to OS_ObjectIdIteratorDestroy() - Returns: OS_SUCCESS on success, or relevant error code + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIteratorInit(OS_ObjectMatchFunc_t matchfunc, void *matcharg, osal_objtype_t objtype, + OS_object_iter_t *iter); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIterateActive + + Purpose: Initialize a object iterator of the given type that will + return only active/valid OSAL objects. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIterateActive(osal_objtype_t objtype, OS_object_iter_t *iter); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorGetNext + + Purpose: Move then token to the next matching iterator entry + + Returns: true if successful, false if at last entry/end of table + ------------------------------------------------------------------*/ +bool OS_ObjectIdIteratorGetNext(OS_object_iter_t *iter); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorDestroy + + Purpose: Releases an iterator from OS_ObjectIdIteratorInit() + + Returns: None + ------------------------------------------------------------------*/ +void OS_ObjectIdIteratorDestroy(OS_object_iter_t *iter); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorRef + + Purpose: Gets the token indicating current iterator position + The returned token can be used to access the relevant entry + + Returns: None + ------------------------------------------------------------------*/ +static inline const OS_object_token_t *OS_ObjectIdIteratorRef(OS_object_iter_t *iter) +{ + return &iter->token; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorProcessEntry + + Purpose: Calls a function using the ID of the entry from the iterator + + Returns: None ------------------------------------------------------------------*/ -int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record); +int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t, void *)); /* * Internal helper functions * These are not normally called outside this unit, but need * to be exposed for unit testing. */ -bool OS_ObjectNameMatch(void *ref, uint32 local_id, const OS_common_record_t *obj); -void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, uint32 idtype); -int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, osal_id_t reference_id, OS_common_record_t *obj); -int32 OS_ObjectIdSearch(uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record); -int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record); +bool OS_ObjectFilterActive(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); +bool OS_ObjectNameMatch(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); +int32 OS_ObjectIdFindNextMatch(OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_object_token_t *token); +int32 OS_ObjectIdFindNextFree(OS_object_token_t *token); -#endif /* INCLUDE_OS_SHARED_IDMAP_H_ */ +#endif /* OS_SHARED_IDMAP_H */ diff --git a/src/os/shared/inc/os-shared-module.h b/src/os/shared/inc/os-shared-module.h index 3c93c2345..5f0e53adb 100644 --- a/src/os/shared/inc/os-shared-module.h +++ b/src/os/shared/inc/os-shared-module.h @@ -25,17 +25,26 @@ * */ -#ifndef INCLUDE_OS_SHARED_MODULE_H_ -#define INCLUDE_OS_SHARED_MODULE_H_ +#ifndef OS_SHARED_MODULE_H +#define OS_SHARED_MODULE_H +#include "osapi-module.h" #include +typedef enum +{ + OS_MODULE_TYPE_UNKNOWN = 0, /**< Default/unspecified (reserved value) */ + OS_MODULE_TYPE_DYNAMIC = 1, /**< Module is dynamically loaded via the OS loader */ + OS_MODULE_TYPE_STATIC = 2 /**< Module is statically linked and is a placeholder */ +} OS_module_type_t; + typedef struct { - char module_name[OS_MAX_API_NAME]; - char file_name[OS_MAX_PATH_LEN]; - uint32 flags; - cpuaddr entry_point; + char module_name[OS_MAX_API_NAME]; + char file_name[OS_MAX_PATH_LEN]; + OS_module_type_t module_type; + uint32 flags; + cpuaddr entry_point; } OS_module_internal_record_t; /* @@ -64,7 +73,7 @@ int32 OS_ModuleAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path); +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path); /*---------------------------------------------------------------- @@ -74,7 +83,7 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(uint32 module_id); +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ModuleGetInfo_Impl @@ -83,17 +92,27 @@ int32 OS_ModuleUnload_Impl(uint32 module_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(uint32 module_id, OS_module_prop_t *module_prop); +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop); + +/*---------------------------------------------------------------- + Function: OS_GlobalSymbolLookup_Impl + + Purpose: Find the Address of a Symbol in the global symbol table. + The address of the symbol will be stored in the pointer that is passed in. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName); /*---------------------------------------------------------------- Function: OS_SymbolLookup_Impl - Purpose: Find the Address of a Symbol + Purpose: Find the Address of a Symbol within a specific module. The address of the symbol will be stored in the pointer that is passed in. Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName); +int32 OS_ModuleSymbolLookup_Impl(const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName); /*---------------------------------------------------------------- Function: OS_SymbolTableDump_Impl @@ -102,13 +121,13 @@ int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SymbolTableDump_Impl(const char *filename, uint32 size_limit); +int32 OS_SymbolTableDump_Impl(const char *filename, size_t size_limit); /* * Helper functions within the shared layer that are not normally invoked outside the local module * These need to be exposed for unit testing */ int32 OS_ModuleLoad_Static(const char *ModuleName); -int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName); +int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName, const char *ModuleName); -#endif /* INCLUDE_OS_SHARED_MODULE_H_ */ +#endif /* OS_SHARED_MODULE_H */ diff --git a/src/os/shared/inc/os-shared-mutex.h b/src/os/shared/inc/os-shared-mutex.h index 218c60343..524f9fcde 100644 --- a/src/os/shared/inc/os-shared-mutex.h +++ b/src/os/shared/inc/os-shared-mutex.h @@ -25,15 +25,16 @@ * */ -#ifndef INCLUDE_OS_SHARED_MUTEX_H_ -#define INCLUDE_OS_SHARED_MUTEX_H_ +#ifndef OS_SHARED_MUTEX_H +#define OS_SHARED_MUTEX_H +#include "osapi-mutex.h" #include typedef struct { - char obj_name[OS_MAX_API_NAME]; - osal_id_t last_owner; + char obj_name[OS_MAX_API_NAME]; + osal_id_t last_owner; } OS_mutex_internal_record_t; /* @@ -58,7 +59,7 @@ int32 OS_MutexAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options); +int32 OS_MutSemCreate_Impl(const OS_object_token_t *token, uint32 options); /*---------------------------------------------------------------- Function: OS_MutSemGive_Impl @@ -67,7 +68,7 @@ int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl(uint32 sem_id); +int32 OS_MutSemGive_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_MutSemTake_Impl @@ -76,7 +77,7 @@ int32 OS_MutSemGive_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl(uint32 sem_id); +int32 OS_MutSemTake_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_MutSemDelete_Impl @@ -85,7 +86,7 @@ int32 OS_MutSemTake_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl(uint32 sem_id); +int32 OS_MutSemDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_MutSemGetInfo_Impl @@ -94,6 +95,6 @@ int32 OS_MutSemDelete_Impl(uint32 sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl(uint32 sem_id, OS_mut_sem_prop_t *mut_prop); +int32 OS_MutSemGetInfo_Impl(const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop); -#endif /* INCLUDE_OS_SHARED_MUTEX_H_ */ +#endif /* OS_SHARED_MUTEX_H */ diff --git a/src/os/shared/inc/os-shared-network.h b/src/os/shared/inc/os-shared-network.h index 818f8ea84..19fd03d79 100644 --- a/src/os/shared/inc/os-shared-network.h +++ b/src/os/shared/inc/os-shared-network.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_NETWORK_H_ -#define INCLUDE_OS_SHARED_NETWORK_H_ +#ifndef OS_SHARED_NETWORK_H +#define OS_SHARED_NETWORK_H +#include "osapi-network.h" #include /**************************************************************************************** @@ -51,7 +52,7 @@ int32 OS_NetworkAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_NetworkGetHostName_Impl(char *host_name, uint32 name_len); +int32 OS_NetworkGetHostName_Impl(char *host_name, size_t name_len); /*---------------------------------------------------------------- Function: OS_NetworkGetID_Impl @@ -62,4 +63,4 @@ int32 OS_NetworkGetHostName_Impl(char *host_name, uint32 name_len); ------------------------------------------------------------------*/ int32 OS_NetworkGetID_Impl(int32 *IdBuf); -#endif /* INCLUDE_OS_SHARED_NETWORK_H_ */ +#endif /* OS_SHARED_NETWORK_H */ diff --git a/src/os/shared/inc/os-shared-printf.h b/src/os/shared/inc/os-shared-printf.h index b4f0e3d86..43393a154 100644 --- a/src/os/shared/inc/os-shared-printf.h +++ b/src/os/shared/inc/os-shared-printf.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_PRINTF_H_ -#define INCLUDE_OS_SHARED_PRINTF_H_ +#ifndef OS_SHARED_PRINTF_H +#define OS_SHARED_PRINTF_H +#include "osapi-printf.h" #include /* @@ -45,9 +46,9 @@ typedef struct char device_name[OS_MAX_API_NAME]; char * BufBase; /**< Start of the buffer memory */ - uint32 BufSize; /**< Total size of the buffer */ - volatile uint32 ReadPos; /**< Offset of next byte to read */ - volatile uint32 WritePos; /**< Offset of next byte to write */ + size_t BufSize; /**< Total size of the buffer */ + volatile size_t ReadPos; /**< Offset of next byte to read */ + volatile size_t WritePos; /**< Offset of next byte to write */ uint32 OverflowEvents; /**< Number of lines dropped due to overflow */ } OS_console_internal_record_t; @@ -73,7 +74,7 @@ int32 OS_ConsoleAPI_Init(void); Purpose: Prepare a console device for use For Async devices, this sets up the background writer task ------------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(uint32 local_id); +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ConsoleOutput_Impl @@ -85,7 +86,7 @@ int32 OS_ConsoleCreate_Impl(uint32 local_id); The data is already formatted, this just writes the characters. ------------------------------------------------------------------*/ -void OS_ConsoleOutput_Impl(uint32 local_id); +void OS_ConsoleOutput_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ConsoleOutput_Impl @@ -100,6 +101,6 @@ void OS_ConsoleOutput_Impl(uint32 local_id); service, this should wakeup the actual console servicing thread. ------------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(uint32 local_id); +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token); -#endif /* INCLUDE_OS_SHARED_PRINTF_H_ */ +#endif /* OS_SHARED_PRINTF_H */ diff --git a/src/os/shared/inc/os-shared-queue.h b/src/os/shared/inc/os-shared-queue.h index b60e4a279..d0d123989 100644 --- a/src/os/shared/inc/os-shared-queue.h +++ b/src/os/shared/inc/os-shared-queue.h @@ -25,16 +25,17 @@ * */ -#ifndef INCLUDE_OS_SHARED_QUEUE_H_ -#define INCLUDE_OS_SHARED_QUEUE_H_ +#ifndef OS_SHARED_QUEUE_H +#define OS_SHARED_QUEUE_H +#include "osapi-queue.h" #include typedef struct { - char queue_name[OS_MAX_API_NAME]; - uint32 max_size; - uint32 max_depth; + char queue_name[OS_MAX_API_NAME]; + size_t max_size; + osal_blockcount_t max_depth; } OS_queue_internal_record_t; /* @@ -63,7 +64,7 @@ int32 OS_QueueAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags); +int32 OS_QueueCreate_Impl(const OS_object_token_t *token, uint32 flags); /*---------------------------------------------------------------- Function: OS_QueueDelete_Impl @@ -72,7 +73,7 @@ int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl(uint32 queue_id); +int32 OS_QueueDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_QueueGet_Impl @@ -85,7 +86,7 @@ int32 OS_QueueDelete_Impl(uint32 queue_id); OS_QUEUE_EMPTY must be returned if the queue is empty when polled (OS_CHECK) OS_QUEUE_INVALID_SIZE must be returned if the supplied buffer is too small ------------------------------------------------------------------*/ -int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout); +int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout); /*---------------------------------------------------------------- Function: OS_QueuePut_Impl @@ -95,7 +96,7 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co Returns: OS_SUCCESS on success, or relevant error code OS_QUEUE_FULL must be returned if the queue is full. ------------------------------------------------------------------*/ -int32 OS_QueuePut_Impl(uint32 queue_id, const void *data, uint32 size, uint32 flags); +int32 OS_QueuePut_Impl(const OS_object_token_t *token, const void *data, size_t size, uint32 flags); /*---------------------------------------------------------------- Function: OS_QueueGetInfo_Impl @@ -104,6 +105,6 @@ int32 OS_QueuePut_Impl(uint32 queue_id, const void *data, uint32 size, uint32 fl Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_QueueGetInfo_Impl(uint32 queue_id, OS_queue_prop_t *queue_prop); +int32 OS_QueueGetInfo_Impl(const OS_object_token_t *token, OS_queue_prop_t *queue_prop); -#endif /* INCLUDE_OS_SHARED_QUEUE_H_ */ +#endif /* OS_SHARED_QUEUE_H */ diff --git a/src/os/shared/inc/os-shared-select.h b/src/os/shared/inc/os-shared-select.h index b2bc847a5..051bf4a50 100644 --- a/src/os/shared/inc/os-shared-select.h +++ b/src/os/shared/inc/os-shared-select.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_SELECT_H_ -#define INCLUDE_OS_SHARED_SELECT_H_ +#ifndef OS_SHARED_SELECT_H +#define OS_SHARED_SELECT_H +#include "osapi-select.h" #include /* @@ -50,7 +51,7 @@ Returns: OS_SUCCESS on success, or relevant error code OS_ERR_OPERATION_NOT_SUPPORTED if the specified file handle does not support select ------------------------------------------------------------------*/ -int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs); +int32 OS_SelectSingle_Impl(const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs); /*---------------------------------------------------------------- @@ -77,4 +78,4 @@ int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs); ------------------------------------------------------------------*/ int32 OS_SelectMultiple_Impl(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs); -#endif /* INCLUDE_OS_SHARED_SELECT_H_ */ +#endif /* OS_SHARED_SELECT_H */ diff --git a/src/os/shared/inc/os-shared-shell.h b/src/os/shared/inc/os-shared-shell.h index 582f1e3fa..db58583b7 100644 --- a/src/os/shared/inc/os-shared-shell.h +++ b/src/os/shared/inc/os-shared-shell.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_SHELL_H_ -#define INCLUDE_OS_SHARED_SHELL_H_ +#ifndef OS_SHARED_SHELL_H +#define OS_SHARED_SHELL_H +#include "osapi-shell.h" #include /**************************************************************************************** @@ -41,6 +42,6 @@ Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 stream_id, const char *Cmd); +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd); -#endif /* INCLUDE_OS_SHARED_SHELL_H_ */ +#endif /* OS_SHARED_SHELL_H */ diff --git a/src/os/shared/inc/os-shared-sockets.h b/src/os/shared/inc/os-shared-sockets.h index a50e0a45c..7c3175753 100644 --- a/src/os/shared/inc/os-shared-sockets.h +++ b/src/os/shared/inc/os-shared-sockets.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_SOCKETS_H_ -#define INCLUDE_OS_SHARED_SOCKETS_H_ +#ifndef OS_SHARED_SOCKETS_H +#define OS_SHARED_SOCKETS_H +#include "osapi-sockets.h" #include /* @@ -50,7 +51,7 @@ int32 OS_SocketAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketOpen_Impl(uint32 sock_id); +int32 OS_SocketOpen_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_SocketBind_Impl @@ -59,7 +60,7 @@ int32 OS_SocketOpen_Impl(uint32 sock_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr); +int32 OS_SocketBind_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr); /*---------------------------------------------------------------- Function: OS_SocketAccept_Impl @@ -70,7 +71,8 @@ int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Addr, int32 timeout); +int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_token_t *conn_token, + OS_SockAddr_t *Addr, int32 timeout); /*---------------------------------------------------------------- Function: OS_SocketConnect_Impl @@ -80,7 +82,7 @@ int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Ad Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 timeout); +int32 OS_SocketConnect_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr, int32 timeout); /*---------------------------------------------------------------- Function: OS_SocketRecvFrom_Impl @@ -93,7 +95,8 @@ int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 tim Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout); +int32 OS_SocketRecvFrom_Impl(const OS_object_token_t *token, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, + int32 timeout); /*---------------------------------------------------------------- Function: OS_SocketSendTo_Impl @@ -104,7 +107,8 @@ int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_Soc Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr); +int32 OS_SocketSendTo_Impl(const OS_object_token_t *token, const void *buffer, size_t buflen, + const OS_SockAddr_t *RemoteAddr); /*---------------------------------------------------------------- @@ -114,7 +118,7 @@ int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, co Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketGetInfo_Impl(uint32 sock_id, OS_socket_prop_t *sock_prop); +int32 OS_SocketGetInfo_Impl(const OS_object_token_t *token, OS_socket_prop_t *sock_prop); /*---------------------------------------------------------------- @@ -134,7 +138,7 @@ int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketAddrToString_Impl(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr); +int32 OS_SocketAddrToString_Impl(char *buffer, size_t buflen, const OS_SockAddr_t *Addr); /*---------------------------------------------------------------- Function: OS_SocketAddrFromString_Impl @@ -174,6 +178,6 @@ int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum); * Internal helper functions * Not normally called outside the local unit, except during unit test */ -void OS_CreateSocketName(uint32 local_id, const OS_SockAddr_t *Addr, const char *parent_name); +void OS_CreateSocketName(const OS_object_token_t *token, const OS_SockAddr_t *Addr, const char *parent_name); -#endif /* INCLUDE_OS_SHARED_SOCKETS_H_ */ +#endif /* OS_SHARED_SOCKETS_H */ diff --git a/src/os/shared/inc/os-shared-task.h b/src/os/shared/inc/os-shared-task.h index 4adb87fe2..29f45fcbe 100644 --- a/src/os/shared/inc/os-shared-task.h +++ b/src/os/shared/inc/os-shared-task.h @@ -25,21 +25,22 @@ * */ -#ifndef INCLUDE_OS_SHARED_TASK_H_ -#define INCLUDE_OS_SHARED_TASK_H_ +#ifndef OS_SHARED_TASK_H +#define OS_SHARED_TASK_H +#include "osapi-task.h" #include /*tasks */ typedef struct { char task_name[OS_MAX_API_NAME]; - uint32 stack_size; - uint32 priority; + size_t stack_size; + osal_priority_t priority; osal_task_entry entry_function_pointer; osal_task_entry delete_hook_pointer; void * entry_arg; - uint32 * stack_pointer; + osal_stackptr_t stack_pointer; } OS_task_internal_record_t; /* @@ -81,7 +82,7 @@ void OS_TaskEntryPoint(osal_id_t global_task_id); Returns: OS_SUCCESS on match, any other code on non-match ------------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(uint32 task_id); +int32 OS_TaskMatch_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- @@ -92,7 +93,17 @@ int32 OS_TaskMatch_Impl(uint32 task_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags); +int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags); + +/*---------------------------------------------------------------- + Function: OS_TaskDetach_Impl + + Purpose: Sets the thread so that the OS resources associated with the task + will be released when the thread exits itself + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TaskDetach_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_TaskDelete_Impl @@ -101,7 +112,7 @@ int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl(uint32 task_id); +int32 OS_TaskDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_TaskExit_Impl @@ -128,7 +139,7 @@ int32 OS_TaskDelay_Impl(uint32 millisecond); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl(uint32 task_id, uint32 new_priority); +int32 OS_TaskSetPriority_Impl(const OS_object_token_t *token, osal_priority_t new_priority); /*---------------------------------------------------------------- Function: OS_TaskGetId_Impl @@ -146,7 +157,7 @@ osal_id_t OS_TaskGetId_Impl(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl(uint32 task_id, OS_task_prop_t *task_prop); +int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_prop); /*---------------------------------------------------------------- @@ -169,7 +180,7 @@ int32 OS_TaskRegister_Impl(osal_id_t global_task_id); Compatible with the "OS_ObjectIdFindBySearch" routine ------------------------------------------------------------------*/ -bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj); +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); /*---------------------------------------------------------------- @@ -179,6 +190,6 @@ bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_r compatible/reasonable for the underlying OS. ------------------------------------------------------------------*/ -int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size); +int32 OS_TaskValidateSystemData_Impl(const void *sysdata, size_t sysdata_size); -#endif /* INCLUDE_OS_SHARED_TASK_H_ */ +#endif /* OS_SHARED_TASK_H */ diff --git a/src/os/shared/inc/os-shared-time.h b/src/os/shared/inc/os-shared-time.h index f8397cd54..1cf14a15e 100644 --- a/src/os/shared/inc/os-shared-time.h +++ b/src/os/shared/inc/os-shared-time.h @@ -25,25 +25,28 @@ * */ -#ifndef INCLUDE_OS_SHARED_TIME_H_ -#define INCLUDE_OS_SHARED_TIME_H_ +#ifndef OS_SHARED_TIME_H +#define OS_SHARED_TIME_H + +#include "osapi-timer.h" #include +#include #define TIMECB_FLAG_DEDICATED_TIMEBASE 0x1 typedef struct { - char timer_name[OS_MAX_API_NAME]; - uint32 flags; - uint32 timebase_ref; - uint32 prev_ref; - uint32 next_ref; - uint32 backlog_resets; - int32 wait_time; - int32 interval_time; - OS_ArgCallback_t callback_ptr; - void * callback_arg; + char timer_name[OS_MAX_API_NAME]; + uint32 flags; + OS_object_token_t timebase_token; + osal_id_t prev_cb; + osal_id_t next_cb; + uint32 backlog_resets; + int32 wait_time; + int32 interval_time; + OS_ArgCallback_t callback_ptr; + void * callback_arg; } OS_timecb_internal_record_t; /* @@ -61,4 +64,4 @@ extern OS_timecb_internal_record_t OS_timecb_table[OS_MAX_TIMERS]; ---------------------------------------------------------------------------------------*/ int32 OS_TimerCbAPI_Init(void); -#endif /* INCLUDE_OS_SHARED_TIME_H_ */ +#endif /* OS_SHARED_TIME_H */ diff --git a/src/os/shared/inc/os-shared-timebase.h b/src/os/shared/inc/os-shared-timebase.h index cf88e82a2..4e838d227 100644 --- a/src/os/shared/inc/os-shared-timebase.h +++ b/src/os/shared/inc/os-shared-timebase.h @@ -25,9 +25,10 @@ * */ -#ifndef INCLUDE_OS_SHARED_TIMEBASE_H_ -#define INCLUDE_OS_SHARED_TIMEBASE_H_ +#ifndef OS_SHARED_TIMEBASE_H +#define OS_SHARED_TIMEBASE_H +#include "osapi-timebase.h" #include typedef struct @@ -73,7 +74,7 @@ int32 OS_TimeBaseAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TimeBaseCreate_Impl(uint32 timebase_id); +int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_TimeBaseSet_Impl @@ -82,7 +83,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timebase_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TimeBaseSet_Impl(uint32 timebase_id, int32 start_time, int32 interval_time); +int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uint32 interval_time); /*---------------------------------------------------------------- Function: OS_TimeBaseDelete_Impl @@ -91,7 +92,7 @@ int32 OS_TimeBaseSet_Impl(uint32 timebase_id, int32 start_time, int32 interval_t Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TimeBaseDelete_Impl(uint32 timebase_id); +int32 OS_TimeBaseDelete_Impl(const OS_object_token_t *token); /**************************************************************************************** INTERNAL FUNCTIONS @@ -103,7 +104,7 @@ int32 OS_TimeBaseDelete_Impl(uint32 timebase_id); Purpose: Get exclusive access to the given timebase Add/remove of application callbacks is prevented ------------------------------------------------------------------*/ -void OS_TimeBaseLock_Impl(uint32 timebase_id); +void OS_TimeBaseLock_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_TimeBaseLock_Impl @@ -111,7 +112,7 @@ void OS_TimeBaseLock_Impl(uint32 timebase_id); Purpose: Release exclusive access to the given timebase Add/remove of application callbacks is allowed ------------------------------------------------------------------*/ -void OS_TimeBaseUnlock_Impl(uint32 timebase_id); +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_TimeBaseGetInfo_Impl @@ -120,7 +121,7 @@ void OS_TimeBaseUnlock_Impl(uint32 timebase_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TimeBaseGetInfo_Impl(uint32 timer_id, OS_timebase_prop_t *timer_prop); +int32 OS_TimeBaseGetInfo_Impl(const OS_object_token_t *token, OS_timebase_prop_t *timer_prop); /*---------------------------------------------------------------- Function: OS_TimeBase_CallbackThread @@ -137,4 +138,4 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id); ------------------------------------------------------------------*/ int32 OS_Milli2Ticks(uint32 milli_seconds, int *ticks); -#endif /* INCLUDE_OS_SHARED_TIMEBASE_H_ */ +#endif /* OS_SHARED_TIMEBASE_H */ diff --git a/src/os/shared/src/osapi-binsem.c b/src/os/shared/src/osapi-binsem.c index 3cb6dbfc6..e498db02f 100644 --- a/src/os/shared/src/osapi-binsem.c +++ b/src/os/shared/src/osapi-binsem.c @@ -96,34 +96,28 @@ int32 OS_BinSemAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + int32 return_code; + OS_object_token_t token; + OS_bin_sem_internal_record_t *binsem; - /* Check for NULL pointers */ - if (sem_id == NULL || sem_name == NULL) - { - return OS_INVALID_POINTER; - } - - if (strlen(sem_name) >= OS_MAX_API_NAME) - { - return OS_ERR_NAME_TOO_LONG; - } + /* Check parameters */ + OS_CHECK_POINTER(sem_id); + OS_CHECK_APINAME(sem_name); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - strcpy(OS_bin_sem_table[local_id].obj_name, sem_name); - record->name_entry = OS_bin_sem_table[local_id].obj_name; + binsem = OS_OBJECT_TABLE_GET(OS_bin_sem_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, binsem, obj_name, sem_name); /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_BinSemCreate_Impl(local_id, sem_initial_value, options); + return_code = OS_BinSemCreate_Impl(&token, sem_initial_value, options); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, sem_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, sem_id); } return return_code; @@ -140,17 +134,16 @@ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initia *-----------------------------------------------------------------*/ int32 OS_BinSemDelete(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemDelete_Impl(local_id); + return_code = OS_BinSemDelete_Impl(&token); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -167,15 +160,14 @@ int32 OS_BinSemDelete(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_BinSemGive(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemGive_Impl(local_id); + return_code = OS_BinSemGive_Impl(&token); } return return_code; @@ -192,15 +184,14 @@ int32 OS_BinSemGive(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_BinSemFlush(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemFlush_Impl(local_id); + return_code = OS_BinSemFlush_Impl(&token); } return return_code; @@ -216,15 +207,14 @@ int32 OS_BinSemFlush(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_BinSemTake(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemTake_Impl(local_id); + return_code = OS_BinSemTake_Impl(&token); } return return_code; @@ -240,15 +230,14 @@ int32 OS_BinSemTake(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_BinSemTimedWait(osal_id_t sem_id, uint32 msecs) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemTimedWait_Impl(local_id, msecs); + return_code = OS_BinSemTimedWait_Impl(&token, msecs); } return return_code; @@ -266,10 +255,9 @@ int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name) { int32 return_code; - if (sem_id == NULL || sem_name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(sem_id); + OS_CHECK_POINTER(sem_name); return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, sem_name, sem_id); @@ -287,25 +275,25 @@ int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name) int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop) { OS_common_record_t *record; - uint32 local_id; + OS_object_token_t token; int32 return_code; /* Check parameters */ - if (bin_prop == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(bin_prop); memset(bin_prop, 0, sizeof(OS_bin_sem_prop_t)); /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - strncpy(bin_prop->name, record->name_entry, OS_MAX_API_NAME - 1); + record = OS_OBJECT_TABLE_GET(OS_global_bin_sem_table, token); + + strncpy(bin_prop->name, record->name_entry, sizeof(bin_prop->name) - 1); bin_prop->creator = record->creator; - return_code = OS_BinSemGetInfo_Impl(local_id, bin_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + return_code = OS_BinSemGetInfo_Impl(&token, bin_prop); + + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-clock.c b/src/os/shared/src/osapi-clock.c index 7cd2c8c17..d5a844376 100644 --- a/src/os/shared/src/osapi-clock.c +++ b/src/os/shared/src/osapi-clock.c @@ -50,10 +50,8 @@ *-----------------------------------------------------------------*/ int32 OS_GetLocalTime(OS_time_t *time_struct) { - if (time_struct == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(time_struct); return OS_GetLocalTime_Impl(time_struct); @@ -67,12 +65,10 @@ int32 OS_GetLocalTime(OS_time_t *time_struct) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_SetLocalTime(OS_time_t *time_struct) +int32 OS_SetLocalTime(const OS_time_t *time_struct) { - if (time_struct == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(time_struct); return OS_SetLocalTime_Impl(time_struct); diff --git a/src/os/shared/src/osapi-common.c b/src/os/shared/src/osapi-common.c index c6f317625..2848228c8 100644 --- a/src/os/shared/src/osapi-common.c +++ b/src/os/shared/src/osapi-common.c @@ -108,9 +108,9 @@ int32 OS_NotifyEvent(OS_Event_t event, osal_id_t object_id, void *data) *-----------------------------------------------------------------*/ int32 OS_API_Init(void) { - int32 return_code = OS_SUCCESS; - uint32 idtype; - uint32 microSecPerSec; + int32 return_code = OS_SUCCESS; + osal_objtype_t idtype; + uint32 microSecPerSec; if (OS_SharedGlobalVars.Initialized != false) { @@ -229,10 +229,7 @@ int32 OS_API_Init(void) *-----------------------------------------------------------------*/ int32 OS_RegisterEventHandler(OS_EventHandler_t handler) { - if (handler == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(handler); OS_SharedGlobalVars.EventHandler = handler; return OS_SUCCESS; @@ -340,7 +337,15 @@ void OS_DeleteAllObjects(void) { ObjectCount = 0; ++TryCount; + + /* Delete timers and tasks first, as they could be actively using other object types */ + OS_ForEachObjectOfType(OS_OBJECT_TYPE_OS_TIMECB, OS_OBJECT_CREATOR_ANY, OS_CleanUpObject, &ObjectCount); + OS_ForEachObjectOfType(OS_OBJECT_TYPE_OS_TIMEBASE, OS_OBJECT_CREATOR_ANY, OS_CleanUpObject, &ObjectCount); + OS_ForEachObjectOfType(OS_OBJECT_TYPE_OS_TASK, OS_OBJECT_CREATOR_ANY, OS_CleanUpObject, &ObjectCount); + + /* Then try to delete all other remaining objects of any type */ OS_ForEachObject(OS_OBJECT_CREATOR_ANY, OS_CleanUpObject, &ObjectCount); + if (ObjectCount == 0 || TryCount > 4) { break; diff --git a/src/os/shared/src/osapi-countsem.c b/src/os/shared/src/osapi-countsem.c index 00cd9d930..9eebafc84 100644 --- a/src/os/shared/src/osapi-countsem.c +++ b/src/os/shared/src/osapi-countsem.c @@ -88,34 +88,28 @@ int32 OS_CountSemAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; - - /* Check for NULL pointers */ - if (sem_id == NULL || sem_name == NULL) - { - return OS_INVALID_POINTER; - } + int32 return_code; + OS_object_token_t token; + OS_count_sem_internal_record_t *countsem; - if (strlen(sem_name) >= OS_MAX_API_NAME) - { - return OS_ERR_NAME_TOO_LONG; - } + /* Check parameters */ + OS_CHECK_POINTER(sem_id); + OS_CHECK_APINAME(sem_name); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - strcpy(OS_count_sem_table[local_id].obj_name, sem_name); - record->name_entry = OS_count_sem_table[local_id].obj_name; + countsem = OS_OBJECT_TABLE_GET(OS_count_sem_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, countsem, obj_name, sem_name); /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_CountSemCreate_Impl(local_id, sem_initial_value, options); + return_code = OS_CountSemCreate_Impl(&token, sem_initial_value, options); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, sem_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, sem_id); } return return_code; @@ -132,17 +126,16 @@ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_init *-----------------------------------------------------------------*/ int32 OS_CountSemDelete(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemDelete_Impl(local_id); + return_code = OS_CountSemDelete_Impl(&token); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -159,15 +152,14 @@ int32 OS_CountSemDelete(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_CountSemGive(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemGive_Impl(local_id); + return_code = OS_CountSemGive_Impl(&token); } return return_code; @@ -184,15 +176,14 @@ int32 OS_CountSemGive(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_CountSemTake(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemTake_Impl(local_id); + return_code = OS_CountSemTake_Impl(&token); } return return_code; @@ -208,15 +199,14 @@ int32 OS_CountSemTake(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_CountSemTimedWait(osal_id_t sem_id, uint32 msecs) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemTimedWait_Impl(local_id, msecs); + return_code = OS_CountSemTimedWait_Impl(&token, msecs); } return return_code; @@ -234,10 +224,9 @@ int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name) { int32 return_code; - if (sem_id == NULL || sem_name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(sem_id); + OS_CHECK_POINTER(sem_name); return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, sem_name, sem_id); @@ -255,26 +244,26 @@ int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name) int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop) { OS_common_record_t *record; - uint32 local_id; + OS_object_token_t token; int32 return_code; /* Check parameters */ - if (count_prop == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(count_prop); memset(count_prop, 0, sizeof(OS_count_sem_prop_t)); /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - strncpy(count_prop->name, record->name_entry, OS_MAX_API_NAME - 1); + record = OS_OBJECT_TABLE_GET(OS_global_count_sem_table, token); + + strncpy(count_prop->name, record->name_entry, sizeof(count_prop->name) - 1); count_prop->creator = record->creator; - return_code = OS_CountSemGetInfo_Impl(local_id, count_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + return_code = OS_CountSemGetInfo_Impl(&token, count_prop); + + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-dir.c b/src/os/shared/src/osapi-dir.c index 42153431e..7566aa606 100644 --- a/src/os/shared/src/osapi-dir.c +++ b/src/os/shared/src/osapi-dir.c @@ -35,6 +35,8 @@ #include #include +#include "osapi-filesys.h" + /* * User defined include files */ @@ -111,32 +113,31 @@ int32 OS_mkdir(const char *path, uint32 access) *-----------------------------------------------------------------*/ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) { - char local_path[OS_MAX_LOCAL_PATH_LEN]; - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + char local_path[OS_MAX_LOCAL_PATH_LEN]; + OS_object_token_t token; + OS_dir_internal_record_t *dir; + int32 return_code; - if (dir_id == NULL || path == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(dir_id); return_code = OS_TranslatePath(path, local_path); if (return_code == OS_SUCCESS) { /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - memset(&OS_dir_table[local_id], 0, sizeof(OS_dir_internal_record_t)); - strncpy(OS_dir_table[local_id].dir_name, path, OS_MAX_PATH_LEN - 1); + dir = OS_OBJECT_TABLE_GET(OS_dir_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, dir, dir_name, path); /* Now call the OS-specific implementation. */ - return_code = OS_DirOpen_Impl(local_id, local_path); + return_code = OS_DirOpen_Impl(&token, local_path); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, dir_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, dir_id); } } @@ -153,18 +154,17 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) *-----------------------------------------------------------------*/ int32 OS_DirectoryClose(osal_id_t dir_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, dir_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, dir_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_DirClose_Impl(local_id); + return_code = OS_DirClose_Impl(&token); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -180,17 +180,14 @@ int32 OS_DirectoryClose(osal_id_t dir_id) *-----------------------------------------------------------------*/ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; - if (dirent == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(dirent); /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, dir_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, dir_id, &token); if (return_code == OS_SUCCESS) { /* @@ -203,9 +200,9 @@ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) * reads the "/" directory, the application will see the * real name (eeprom) and not the virtualized name (cf). */ - return_code = OS_DirRead_Impl(local_id, dirent); + return_code = OS_DirRead_Impl(&token, dirent); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -222,15 +219,14 @@ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) *-----------------------------------------------------------------*/ int32 OS_DirectoryRewind(osal_id_t dir_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, dir_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, dir_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_DirRewind_Impl(local_id); + return_code = OS_DirRewind_Impl(&token); } return return_code; diff --git a/src/os/shared/src/osapi-errors.c b/src/os/shared/src/osapi-errors.c index a8e077fb3..a7abfa09a 100644 --- a/src/os/shared/src/osapi-errors.c +++ b/src/os/shared/src/osapi-errors.c @@ -98,13 +98,11 @@ static const OS_ErrorTable_Entry_t OS_GLOBAL_ERROR_NAME_TABLE[] = { *-----------------------------------------------------------------*/ int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name) { - uint32 return_code; + int32 return_code; const OS_ErrorTable_Entry_t *Error; - if (err_name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(err_name); Error = OS_GLOBAL_ERROR_NAME_TABLE; while (Error->Name != NULL && Error->Number != error_num) @@ -123,8 +121,9 @@ int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name) if (Error->Number == error_num && Error->Name != NULL) { - strncpy(*err_name, Error->Name, OS_ERROR_NAME_LENGTH - 1); - return_code = OS_SUCCESS; + strncpy(*err_name, Error->Name, sizeof(*err_name) - 1); + *err_name[sizeof(*err_name) - 1] = 0; + return_code = OS_SUCCESS; } else { diff --git a/src/os/shared/src/osapi-file.c b/src/os/shared/src/osapi-file.c index 37837b9e2..6781985d1 100644 --- a/src/os/shared/src/osapi-file.c +++ b/src/os/shared/src/osapi-file.c @@ -41,6 +41,12 @@ #include "os-shared-file.h" #include "os-shared-idmap.h" +/* + * Other OSAL public APIs used by this module + */ +#include "osapi-filesys.h" +#include "osapi-sockets.h" + /* * Sanity checks on the user-supplied configuration * The relevent OS_MAX limit should be defined and greater than zero @@ -60,6 +66,16 @@ enum OS_stream_internal_record_t OS_stream_table[OS_MAX_NUM_OPEN_FILES]; +/*---------------------------------------------------------------- + * + * Helper function to close a file from an iterator + * + *-----------------------------------------------------------------*/ +int32 OS_FileIteratorClose(osal_id_t filedes, void *arg) +{ + return OS_close(filedes); +} + /**************************************************************************************** FILE API ***************************************************************************************/ @@ -89,15 +105,13 @@ int32 OS_FileAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access) { - int32 return_code; - uint32 local_id; - OS_common_record_t *record; - char local_path[OS_MAX_LOCAL_PATH_LEN]; + int32 return_code; + char local_path[OS_MAX_LOCAL_PATH_LEN]; + OS_object_token_t token; + OS_stream_internal_record_t *stream; - if (filedes == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(filedes); /* ** Check for a valid access mode @@ -115,19 +129,19 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc if (return_code == OS_SUCCESS) { /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - memset(&OS_stream_table[local_id], 0, sizeof(OS_stream_internal_record_t)); - strcpy(OS_stream_table[local_id].stream_name, path); - record->name_entry = OS_stream_table[local_id].stream_name; + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, stream, stream_name, path); /* Now call the OS-specific implementation. */ - return_code = OS_FileOpen_Impl(local_id, local_path, flags, access); + return_code = OS_FileOpen_Impl(&token, local_path, flags, access); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, filedes); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, filedes); } } @@ -227,18 +241,17 @@ int32 OS_open(const char *path, int32 access, uint32 mode) *-----------------------------------------------------------------*/ int32 OS_close(osal_id_t filedes) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericClose_Impl(local_id); + return_code = OS_GenericClose_Impl(&token); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -253,23 +266,21 @@ int32 OS_close(osal_id_t filedes) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_TimedRead(osal_id_t filedes, void *buffer, uint32 nbytes, int32 timeout) +int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - if (buffer == NULL || nbytes == 0) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(buffer); + OS_CHECK_SIZE(nbytes); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericRead_Impl(local_id, buffer, nbytes, timeout); - OS_ObjectIdRefcountDecr(record); + return_code = OS_GenericRead_Impl(&token, buffer, nbytes, timeout); + + OS_ObjectIdRelease(&token); } return return_code; @@ -283,23 +294,20 @@ int32 OS_TimedRead(osal_id_t filedes, void *buffer, uint32 nbytes, int32 timeout * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, uint32 nbytes, int32 timeout) +int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - if (buffer == NULL || nbytes == 0) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(buffer); + OS_CHECK_SIZE(nbytes); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericWrite_Impl(local_id, buffer, nbytes, timeout); - OS_ObjectIdRefcountDecr(record); + return_code = OS_GenericWrite_Impl(&token, buffer, nbytes, timeout); + OS_ObjectIdRelease(&token); } return return_code; @@ -313,7 +321,7 @@ int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, uint32 nbytes, int32 * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_read(osal_id_t filedes, void *buffer, uint32 nbytes) +int32 OS_read(osal_id_t filedes, void *buffer, size_t nbytes) { return OS_TimedRead(filedes, buffer, nbytes, OS_PEND); } /* end OS_read */ @@ -326,7 +334,7 @@ int32 OS_read(osal_id_t filedes, void *buffer, uint32 nbytes) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_write(osal_id_t filedes, const void *buffer, uint32 nbytes) +int32 OS_write(osal_id_t filedes, const void *buffer, size_t nbytes) { return OS_TimedWrite(filedes, buffer, nbytes, OS_PEND); } /* end OS_write */ @@ -367,10 +375,8 @@ int32 OS_stat(const char *path, os_fstat_t *filestats) int32 return_code; char local_path[OS_MAX_LOCAL_PATH_LEN]; - if (filestats == NULL) - { - return OS_INVALID_POINTER; - } + /* Check Parameters */ + OS_CHECK_POINTER(filestats); memset(filestats, 0, sizeof(*filestats)); @@ -393,16 +399,15 @@ int32 OS_stat(const char *path, os_fstat_t *filestats) *-----------------------------------------------------------------*/ int32 OS_lseek(osal_id_t filedes, int32 offset, uint32 whence) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericSeek_Impl(local_id, offset, whence); - OS_ObjectIdRefcountDecr(record); + return_code = OS_GenericSeek_Impl(&token, offset, whence); + OS_ObjectIdRelease(&token); } return return_code; @@ -441,10 +446,11 @@ int32 OS_remove(const char *path) *-----------------------------------------------------------------*/ int32 OS_rename(const char *old, const char *new) { - int i; - int32 return_code; - char old_path[OS_MAX_LOCAL_PATH_LEN]; - char new_path[OS_MAX_LOCAL_PATH_LEN]; + OS_object_iter_t iter; + OS_stream_internal_record_t *stream; + int32 return_code; + char old_path[OS_MAX_LOCAL_PATH_LEN]; + char new_path[OS_MAX_LOCAL_PATH_LEN]; return_code = OS_TranslatePath(old, old_path); if (return_code == OS_SUCCESS) @@ -459,17 +465,20 @@ int32 OS_rename(const char *old, const char *new) if (return_code == OS_SUCCESS) { - OS_Lock_Global(LOCAL_OBJID_TYPE); - for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) + OS_ObjectIdIterateActive(LOCAL_OBJID_TYPE, &iter); + + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (OS_ObjectIdDefined(OS_global_stream_table[i].active_id) && - OS_stream_table[i].socket_domain == OS_SocketDomain_INVALID && - strcmp(OS_stream_table[i].stream_name, old) == 0) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, iter.token); + + if (stream->socket_domain == OS_SocketDomain_INVALID && strcmp(stream->stream_name, old) == 0) { - strcpy(OS_stream_table[i].stream_name, new); + strncpy(stream->stream_name, new, sizeof(stream->stream_name) - 1); + stream->stream_name[sizeof(stream->stream_name) - 1] = 0; } } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + + OS_ObjectIdIteratorDestroy(&iter); } return return_code; @@ -494,10 +503,9 @@ int32 OS_cp(const char *src, const char *dest) osal_id_t file2; uint8 copyblock[512]; - if (src == NULL || dest == NULL) - { - return OS_INVALID_POINTER; - } + /* Check Parameters */ + OS_CHECK_POINTER(src); + OS_CHECK_POINTER(dest); file1 = OS_OBJECT_ID_UNDEFINED; file2 = OS_OBJECT_ID_UNDEFINED; @@ -583,25 +591,25 @@ int32 OS_mv(const char *src, const char *dest) int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) { OS_common_record_t *record; - uint32 local_id; + OS_object_token_t token; int32 return_code; /* Check parameters */ - if (fd_prop == NULL) - { - return (OS_INVALID_POINTER); - } + OS_CHECK_POINTER(fd_prop); memset(fd_prop, 0, sizeof(OS_file_prop_t)); /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - strncpy(fd_prop->Path, record->name_entry, OS_MAX_PATH_LEN - 1); + record = OS_OBJECT_TABLE_GET(OS_global_stream_table, token); + + strncpy(fd_prop->Path, record->name_entry, sizeof(fd_prop->Path) - 1); fd_prop->User = record->creator; fd_prop->IsValid = true; - OS_Unlock_Global(LOCAL_OBJID_TYPE); + + OS_ObjectIdRelease(&token); } return return_code; @@ -618,30 +626,28 @@ int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) *-----------------------------------------------------------------*/ int32 OS_FileOpenCheck(const char *Filename) { - int32 return_code; - uint32 i; + int32 return_code; + OS_object_iter_t iter; + OS_stream_internal_record_t *stream; - if (Filename == NULL) - { - return (OS_INVALID_POINTER); - } + /* Check parameters */ + OS_CHECK_POINTER(Filename); return_code = OS_ERROR; - OS_Lock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIterateActive(LOCAL_OBJID_TYPE, &iter); - for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (OS_ObjectIdDefined(OS_global_stream_table[i].active_id) && - OS_stream_table[i].socket_domain == OS_SocketDomain_INVALID && - (strcmp(OS_stream_table[i].stream_name, Filename) == 0)) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, iter.token); + if (stream->socket_domain == OS_SocketDomain_INVALID && (strcmp(stream->stream_name, Filename) == 0)) { return_code = OS_SUCCESS; break; } - } /* end for */ + } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIteratorDestroy(&iter); return return_code; } /* end OS_FileOpenCheck */ @@ -656,38 +662,35 @@ int32 OS_FileOpenCheck(const char *Filename) *-----------------------------------------------------------------*/ int32 OS_CloseFileByName(const char *Filename) { - int32 return_code; - int32 close_code; - uint32 i; + int32 return_code; + int32 close_code; + OS_object_iter_t iter; + OS_stream_internal_record_t *stream; - if (Filename == NULL) - { - return (OS_INVALID_POINTER); - } + /* Check parameters */ + OS_CHECK_POINTER(Filename); return_code = OS_FS_ERR_PATH_INVALID; - OS_Lock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIterateActive(LOCAL_OBJID_TYPE, &iter); - for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (OS_ObjectIdDefined(OS_global_stream_table[i].active_id) && - OS_stream_table[i].socket_domain == OS_SocketDomain_INVALID && - (strcmp(OS_stream_table[i].stream_name, Filename) == 0)) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, iter.token); + + if (stream->socket_domain == OS_SocketDomain_INVALID && (strcmp(stream->stream_name, Filename) == 0)) { - close_code = OS_GenericClose_Impl(i); - if (close_code == OS_SUCCESS) - { - OS_global_stream_table[i].active_id = OS_OBJECT_ID_UNDEFINED; - } + /* call OS_close() on the entry referred to by the iterator */ + close_code = OS_ObjectIdIteratorProcessEntry(&iter, OS_FileIteratorClose); + if (return_code == OS_FS_ERR_PATH_INVALID || close_code != OS_SUCCESS) { return_code = close_code; } } - } /* end for */ + } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIteratorDestroy(&iter); return (return_code); @@ -703,31 +706,25 @@ int32 OS_CloseFileByName(const char *Filename) *-----------------------------------------------------------------*/ int32 OS_CloseAllFiles(void) { - int32 return_code; - int32 close_code; - uint32 i; + int32 return_code; + int32 close_code; + OS_object_iter_t iter; return_code = OS_SUCCESS; - OS_Lock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIterateActive(LOCAL_OBJID_TYPE, &iter); - for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (OS_ObjectIdDefined(OS_global_stream_table[i].active_id)) + /* call OS_close() on the entry referred to by the iterator */ + close_code = OS_ObjectIdIteratorProcessEntry(&iter, OS_FileIteratorClose); + if (close_code != OS_SUCCESS) { - close_code = OS_GenericClose_Impl(i); - if (close_code == OS_SUCCESS) - { - OS_global_stream_table[i].active_id = OS_OBJECT_ID_UNDEFINED; - } - if (close_code != OS_SUCCESS) - { - return_code = close_code; - } + return_code = close_code; } - } /* end for */ + } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIteratorDestroy(&iter); return (return_code); diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index 30d562aa4..9eb01c768 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -42,6 +42,7 @@ */ #include "os-shared-filesys.h" #include "os-shared-idmap.h" +#include "os-shared-common.h" enum { @@ -63,6 +64,21 @@ OS_filesys_internal_record_t OS_filesys_table[LOCAL_NUM_OBJECTS]; */ const char OS_FILESYS_RAMDISK_VOLNAME_PREFIX[] = "RAM"; +/*---------------------------------------------------------------- + * + * Function: OS_FileSysFilterFree + * + * Purpose: Local helper routine, not part of OSAL API. + * Iterator function to match only the free/open entries + * + * Returns: true if the entry is free, false if it is in use + * + *-----------------------------------------------------------------*/ +bool OS_FileSysFilterFree(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) +{ + return !OS_ObjectIdDefined(obj->active_id); +} + /*---------------------------------------------------------------- * * Function: OS_FileSys_FindVirtMountPoint @@ -74,20 +90,22 @@ const char OS_FILESYS_RAMDISK_VOLNAME_PREFIX[] = "RAM"; * Returns: true if the entry matches, false if it does not match * *-----------------------------------------------------------------*/ -bool OS_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_common_record_t *obj) +bool OS_FileSys_FindVirtMountPoint(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { - OS_filesys_internal_record_t *rec = &OS_filesys_table[local_id]; + OS_filesys_internal_record_t *filesys; const char * target = (const char *)ref; size_t mplen; - if ((rec->flags & OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL) == 0) + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + + if ((filesys->flags & OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL) == 0) { return false; } - mplen = strlen(rec->virtual_mountpt); - return (mplen > 0 && strncmp(target, rec->virtual_mountpt, mplen) == 0 && - (target[mplen] == '/' || target[mplen] == 0)); + mplen = OS_strnlen(filesys->virtual_mountpt, sizeof(filesys->virtual_mountpt)); + return (mplen > 0 && mplen < sizeof(filesys->virtual_mountpt) && + strncmp(target, filesys->virtual_mountpt, mplen) == 0 && (target[mplen] == '/' || target[mplen] == 0)); } /* end OS_FileSys_FindVirtMountPoint */ /*---------------------------------------------------------------- @@ -101,21 +119,20 @@ bool OS_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_common_r * Returns: OS_SUCCESS on creating the disk, or appropriate error code. * *-----------------------------------------------------------------*/ -int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fsvolname, uint32 blocksize, - uint32 numblocks, bool should_format) +int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fsvolname, size_t blocksize, + osal_blockcount_t numblocks, bool should_format) { - OS_common_record_t * global; - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; int32 return_code; - uint32 local_id; + OS_object_token_t token; /* - ** Check parameters - */ - if (fsdevname == NULL || fsvolname == NULL) - { - return OS_INVALID_POINTER; - } + * Check parameters + * + * Note "address" is not checked, because in certain configurations it can be validly null. + */ + OS_CHECK_STRING(fsdevname, sizeof(filesys->device_name), OS_FS_ERR_PATH_TOO_LONG); + OS_CHECK_STRING(fsvolname, sizeof(filesys->volume_name), OS_FS_ERR_PATH_TOO_LONG); /* check names are not empty strings */ if (fsdevname[0] == 0 || fsvolname[0] == 0) @@ -123,27 +140,20 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs return OS_FS_ERR_PATH_INVALID; } - /* check names are not excessively long strings */ - if (strlen(fsdevname) >= sizeof(local->device_name) || strlen(fsvolname) >= sizeof(local->volume_name)) - { - return OS_FS_ERR_PATH_TOO_LONG; - } - - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, fsdevname, &local_id, &global); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, fsdevname, &token); if (return_code == OS_SUCCESS) { - local = &OS_filesys_table[local_id]; + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); - memset(local, 0, sizeof(*local)); - global->name_entry = local->device_name; - strcpy(local->device_name, fsdevname); + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, filesys, device_name, fsdevname); /* populate the VolumeName and BlockSize ahead of the Impl call, * so the implementation can reference this info if necessary */ - local->blocksize = blocksize; - local->numblocks = numblocks; - local->address = address; - strcpy(local->volume_name, fsvolname); + filesys->blocksize = blocksize; + filesys->numblocks = numblocks; + filesys->address = address; + strncpy(filesys->volume_name, fsvolname, sizeof(filesys->volume_name) - 1); /* * Determine basic type of filesystem, if not already known @@ -152,14 +162,14 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs * contains the string "RAM" then it is a RAM disk. Otherwise * leave the type as UNKNOWN and let the implementation decide. */ - if (local->fstype == OS_FILESYS_TYPE_UNKNOWN && - (local->address != NULL || strncmp(local->volume_name, OS_FILESYS_RAMDISK_VOLNAME_PREFIX, - sizeof(OS_FILESYS_RAMDISK_VOLNAME_PREFIX) - 1) == 0)) + if (filesys->fstype == OS_FILESYS_TYPE_UNKNOWN && + (filesys->address != NULL || strncmp(filesys->volume_name, OS_FILESYS_RAMDISK_VOLNAME_PREFIX, + sizeof(OS_FILESYS_RAMDISK_VOLNAME_PREFIX) - 1) == 0)) { - local->fstype = OS_FILESYS_TYPE_VOLATILE_DISK; + filesys->fstype = OS_FILESYS_TYPE_VOLATILE_DISK; } - return_code = OS_FileSysStartVolume_Impl(local_id); + return_code = OS_FileSysStartVolume_Impl(&token); if (return_code == OS_SUCCESS) { @@ -169,27 +179,27 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs */ if (should_format) { - return_code = OS_FileSysFormatVolume_Impl(local_id); + return_code = OS_FileSysFormatVolume_Impl(&token); } if (return_code == OS_SUCCESS) { - local->flags |= OS_FILESYS_FLAG_IS_READY; + filesys->flags |= OS_FILESYS_FLAG_IS_READY; } else { - /* + /* * To avoid leaving in an intermediate state, * this also stops the volume if formatting failed. * Cast to void to repress analysis warnings for * ignored return value. */ - (void)OS_FileSysStopVolume_Impl(local_id); + (void)OS_FileSysStopVolume_Impl(&token); } } /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, global, NULL); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, NULL); } return return_code; @@ -226,24 +236,16 @@ int32 OS_FileSysAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const char *virt_path) { - OS_common_record_t * global; - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; int32 return_code; - uint32 local_id; + OS_object_token_t token; const char * dev_name; /* * Validate inputs */ - if (phys_path == NULL || virt_path == NULL) - { - return OS_INVALID_POINTER; - } - - if (strlen(phys_path) >= OS_MAX_LOCAL_PATH_LEN || strlen(virt_path) >= OS_MAX_PATH_LEN) - { - return OS_ERR_NAME_TOO_LONG; - } + OS_CHECK_STRING(phys_path, sizeof(filesys->system_mountpt), OS_FS_ERR_PATH_TOO_LONG); + OS_CHECK_PATHNAME(virt_path); /* * Generate a dev name by taking the basename of the phys_path. @@ -258,39 +260,39 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const ++dev_name; } - if (strlen(dev_name) >= OS_FS_DEV_NAME_LEN) + if (memchr(dev_name, 0, sizeof(filesys->volume_name)) == NULL) { return OS_ERR_NAME_TOO_LONG; } - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, dev_name, &local_id, &global); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, dev_name, &token); if (return_code == OS_SUCCESS) { - local = &OS_filesys_table[local_id]; + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); - memset(local, 0, sizeof(*local)); - global->name_entry = local->device_name; - strncpy(local->device_name, dev_name, sizeof(local->device_name) - 1); - strncpy(local->volume_name, dev_name, sizeof(local->volume_name) - 1); - strncpy(local->system_mountpt, phys_path, sizeof(local->system_mountpt) - 1); - strncpy(local->virtual_mountpt, virt_path, sizeof(local->virtual_mountpt) - 1); + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, filesys, device_name, dev_name); + + strncpy(filesys->volume_name, dev_name, sizeof(filesys->volume_name) - 1); + strncpy(filesys->system_mountpt, phys_path, sizeof(filesys->system_mountpt) - 1); + strncpy(filesys->virtual_mountpt, virt_path, sizeof(filesys->virtual_mountpt) - 1); /* * mark the entry that it is a fixed disk */ - local->fstype = OS_FILESYS_TYPE_FS_BASED; - local->flags = OS_FILESYS_FLAG_IS_FIXED; + filesys->fstype = OS_FILESYS_TYPE_FS_BASED; + filesys->flags = OS_FILESYS_FLAG_IS_FIXED; /* * The "mount" implementation is required as it will * create the mountpoint if it does not already exist */ - return_code = OS_FileSysStartVolume_Impl(local_id); + return_code = OS_FileSysStartVolume_Impl(&token); if (return_code == OS_SUCCESS) { - local->flags |= OS_FILESYS_FLAG_IS_READY; - return_code = OS_FileSysMountVolume_Impl(local_id); + filesys->flags |= OS_FILESYS_FLAG_IS_READY; + return_code = OS_FileSysMountVolume_Impl(&token); } if (return_code == OS_SUCCESS) @@ -298,11 +300,11 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const /* * mark the entry that it is a fixed disk */ - local->flags |= OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + filesys->flags |= OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; } /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, global, filesys_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, filesys_id); } return return_code; @@ -316,7 +318,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_mkfs(char *address, const char *devname, const char *volname, uint32 blocksize, uint32 numblocks) +int32 OS_mkfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks) { int32 return_code; @@ -348,25 +350,15 @@ int32 OS_mkfs(char *address, const char *devname, const char *volname, uint32 bl *-----------------------------------------------------------------*/ int32 OS_rmfs(const char *devname) { - int32 return_code; - uint32 local_id; - OS_common_record_t *global; - - if (devname == NULL) - { - return OS_INVALID_POINTER; - } + int32 return_code; + OS_object_token_t token; - if (strlen(devname) >= OS_MAX_API_NAME) - { - return OS_FS_ERR_PATH_TOO_LONG; - } + /* Check parameters */ + OS_CHECK_PATHNAME(devname); - return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, devname, &global); + return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, devname, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - /* * NOTE: It is likely that if the file system is mounted, * this call to stop the volume will fail. @@ -375,16 +367,10 @@ int32 OS_rmfs(const char *devname) * the filesystem is unmounted first, but this would break * compatibility with the existing unit tests. */ - return_code = OS_FileSysStopVolume_Impl(local_id); - - /* Free the entry in the master table now while still locked */ - if (return_code == OS_SUCCESS) - { - /* Only need to clear the ID as zero is the "unused" flag */ - global->active_id = OS_OBJECT_ID_UNDEFINED; - } + return_code = OS_FileSysStopVolume_Impl(&token); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + /* Free the entry in the master table */ + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } else { @@ -402,7 +388,7 @@ int32 OS_rmfs(const char *devname) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_initfs(char *address, const char *devname, const char *volname, uint32 blocksize, uint32 numblocks) +int32 OS_initfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks) { int32 return_code; @@ -435,26 +421,17 @@ int32 OS_initfs(char *address, const char *devname, const char *volname, uint32 int32 OS_mount(const char *devname, const char *mountpoint) { int32 return_code; - uint32 local_id; - OS_common_record_t * global; - OS_filesys_internal_record_t *local; + OS_object_token_t token; + OS_filesys_internal_record_t *filesys; /* Check parameters */ - if (devname == NULL || mountpoint == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_STRING(devname, sizeof(filesys->device_name), OS_FS_ERR_PATH_TOO_LONG); + OS_CHECK_STRING(mountpoint, sizeof(filesys->virtual_mountpt), OS_FS_ERR_PATH_TOO_LONG); - if (strlen(devname) >= sizeof(local->device_name) || strlen(mountpoint) >= sizeof(local->virtual_mountpt)) - { - return OS_FS_ERR_PATH_TOO_LONG; - } - - return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, devname, &global); + return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, devname, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - local = &OS_filesys_table[local_id]; + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); /* * READY flag should be set (mkfs/initfs must have been called on this FS) @@ -463,12 +440,12 @@ int32 OS_mount(const char *devname, const char *mountpoint) * FIXED flag _should_ always be unset (these don't support mount/unmount) * but to support abstraction this is not enforced. */ - if ((local->flags & ~OS_FILESYS_FLAG_IS_FIXED) != OS_FILESYS_FLAG_IS_READY) + if ((filesys->flags & ~OS_FILESYS_FLAG_IS_FIXED) != OS_FILESYS_FLAG_IS_READY) { /* mount() cannot be used on this file system at this time */ return_code = OS_ERR_INCORRECT_OBJ_STATE; } - else if (local->system_mountpt[0] == 0) + else if (filesys->system_mountpt[0] == 0) { /* * The system mount point should be a non-empty string. @@ -477,18 +454,19 @@ int32 OS_mount(const char *devname, const char *mountpoint) } else { - return_code = OS_FileSysMountVolume_Impl(local_id); + return_code = OS_FileSysMountVolume_Impl(&token); } if (return_code == OS_SUCCESS) { /* mark as mounted in the local table. * For now this does both sides (system and virtual) */ - local->flags |= OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - strcpy(local->virtual_mountpt, mountpoint); + filesys->flags |= OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + strncpy(filesys->virtual_mountpt, mountpoint, sizeof(filesys->virtual_mountpt) - 1); + filesys->virtual_mountpt[sizeof(filesys->virtual_mountpt) - 1] = 0; } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } if (return_code != OS_SUCCESS) @@ -511,28 +489,18 @@ int32 OS_mount(const char *devname, const char *mountpoint) int32 OS_unmount(const char *mountpoint) { int32 return_code; - uint32 local_id; - OS_common_record_t * global; - OS_filesys_internal_record_t *local; + OS_object_token_t token; + OS_filesys_internal_record_t *filesys; /* Check parameters */ - if (mountpoint == NULL) - { - return OS_INVALID_POINTER; - } - - if (strlen(mountpoint) >= sizeof(local->virtual_mountpt)) - { - return OS_FS_ERR_PATH_TOO_LONG; - } + OS_CHECK_STRING(mountpoint, sizeof(filesys->virtual_mountpt), OS_FS_ERR_PATH_TOO_LONG); - return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)mountpoint, &global); + return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, + (void *)mountpoint, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - local = &OS_filesys_table[local_id]; + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); /* * FIXED flag should always be unset (these don't support mount/unmount at all) @@ -541,7 +509,7 @@ int32 OS_unmount(const char *mountpoint) * * The FIXED flag is not enforced to support abstraction. */ - if ((local->flags & ~OS_FILESYS_FLAG_IS_FIXED) != + if ((filesys->flags & ~OS_FILESYS_FLAG_IS_FIXED) != (OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL)) { /* unmount() cannot be used on this file system at this time */ @@ -549,17 +517,17 @@ int32 OS_unmount(const char *mountpoint) } else { - return_code = OS_FileSysUnmountVolume_Impl(local_id); + return_code = OS_FileSysUnmountVolume_Impl(&token); } if (return_code == OS_SUCCESS) { /* mark as mounted in the local table. * For now this does both sides (system and virtual) */ - local->flags &= ~(OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL); + filesys->flags &= ~(OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL); } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } if (return_code != OS_SUCCESS) @@ -570,6 +538,8 @@ int32 OS_unmount(const char *mountpoint) return return_code; } /* end OS_unmount */ +#ifndef OSAL_OMIT_DEPRECATED + /*---------------------------------------------------------------- * * Function: OS_fsBlocksFree @@ -580,31 +550,21 @@ int32 OS_unmount(const char *mountpoint) *-----------------------------------------------------------------*/ int32 OS_fsBlocksFree(const char *name) { - int32 return_code; - OS_statvfs_t statfs; - uint32 local_id; - OS_common_record_t *global; - - if (name == NULL) - { - return (OS_INVALID_POINTER); - } + int32 return_code; + OS_statvfs_t statfs; + OS_object_token_t token; - if (strlen(name) >= OS_MAX_PATH_LEN) - { - return OS_FS_ERR_PATH_TOO_LONG; - } + /* Check parameters */ + OS_CHECK_PATHNAME(name); return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)name, &global); + (void *)name, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); + return_code = OS_FileSysStatVolume_Impl(&token, &statfs); - return_code = OS_FileSysStatVolume_Impl(local_id, &statfs); - - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); if (return_code == OS_SUCCESS) { @@ -631,31 +591,22 @@ int32 OS_fsBlocksFree(const char *name) *-----------------------------------------------------------------*/ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) { - int32 return_code; - OS_statvfs_t statfs; - uint32 local_id; - OS_common_record_t *global; + int32 return_code; + OS_statvfs_t statfs; + OS_object_token_t token; - if (name == NULL || bytes_free == NULL) - { - return (OS_INVALID_POINTER); - } - - if (strlen(name) >= OS_MAX_PATH_LEN) - { - return OS_FS_ERR_PATH_TOO_LONG; - } + /* Check parameters */ + OS_CHECK_PATHNAME(name); + OS_CHECK_POINTER(bytes_free); return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)name, &global); + (void *)name, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - - return_code = OS_FileSysStatVolume_Impl(local_id, &statfs); + return_code = OS_FileSysStatVolume_Impl(&token, &statfs); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); if (return_code == OS_SUCCESS) { @@ -672,47 +623,64 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) } /* end OS_fsBytesFree */ +#endif /* OSAL_OMIT_DEPRECATED */ + /*---------------------------------------------------------------- * - * Function: OS_chkfs + * Function: OS_FileSysStatVolume * * Purpose: Implemented per public OSAL API * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_chkfs(const char *name, bool repair) +int32 OS_FileSysStatVolume(const char *name, OS_statvfs_t *statbuf) { - uint32 local_id; - int32 return_code; - OS_common_record_t *global; + int32 return_code; + OS_object_token_t token; - /* - ** Check for a null pointer - */ - if (name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_PATHNAME(name); + OS_CHECK_POINTER(statbuf); - /* - ** Check the length of the volume name - */ - if (strlen(name) >= OS_MAX_PATH_LEN) + return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, + (void *)name, &token); + + if (return_code == OS_SUCCESS) { - return (OS_FS_ERR_PATH_TOO_LONG); + return_code = OS_FileSysStatVolume_Impl(&token, statbuf); + + OS_ObjectIdRelease(&token); } + return return_code; + +} /* end OS_FileSysStatVolume */ + +/*---------------------------------------------------------------- + * + * Function: OS_chkfs + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_chkfs(const char *name, bool repair) +{ + OS_object_token_t token; + int32 return_code; + + /* Check parameters */ + OS_CHECK_PATHNAME(name); + /* Get a reference lock, as a filesystem check could take some time. */ return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)name, &global); + (void *)name, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); + return_code = OS_FileSysCheckVolume_Impl(&token, repair); - return_code = OS_FileSysCheckVolume_Impl(local_id, repair); - - OS_ObjectIdRefcountDecr(global); + OS_ObjectIdRelease(&token); } return return_code; @@ -729,33 +697,25 @@ int32 OS_chkfs(const char *name, bool repair) *-----------------------------------------------------------------*/ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) { - uint32 local_id; + OS_object_token_t token; int32 return_code; - OS_common_record_t * global; - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; - if (MountPoint == NULL || PhysDriveName == NULL) - { - return OS_INVALID_POINTER; - } - - if (strlen(MountPoint) >= OS_MAX_PATH_LEN) - { - return OS_FS_ERR_PATH_TOO_LONG; - } + /* Check parameters */ + OS_CHECK_PATHNAME(MountPoint); + OS_CHECK_POINTER(PhysDriveName); /* Get a reference lock, as a filesystem check could take some time. */ return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)MountPoint, &global); + (void *)MountPoint, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - local = &OS_filesys_table[local_id]; + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); - if ((local->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) + if ((filesys->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) { - strncpy(PhysDriveName, local->system_mountpt, OS_FS_PHYS_NAME_LEN - 1); + strncpy(PhysDriveName, filesys->system_mountpt, OS_FS_PHYS_NAME_LEN - 1); PhysDriveName[OS_FS_PHYS_NAME_LEN - 1] = 0; } else @@ -763,7 +723,7 @@ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) return_code = OS_ERR_INCORRECT_OBJ_STATE; } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } else { @@ -783,44 +743,29 @@ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) *-----------------------------------------------------------------*/ int32 OS_GetFsInfo(os_fsinfo_t *filesys_info) { - int i; + OS_object_iter_t iter; - /* - ** Check to see if the file pointers are NULL - */ - if (filesys_info == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(filesys_info); memset(filesys_info, 0, sizeof(*filesys_info)); filesys_info->MaxFds = OS_MAX_NUM_OPEN_FILES; filesys_info->MaxVolumes = OS_MAX_FILE_SYSTEMS; - OS_Lock_Global(OS_OBJECT_TYPE_OS_STREAM); - - for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) + OS_ObjectIdIteratorInit(OS_FileSysFilterFree, NULL, OS_OBJECT_TYPE_OS_STREAM, &iter); + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (!OS_ObjectIdDefined(OS_global_stream_table[i].active_id)) - { - filesys_info->FreeFds++; - } + ++filesys_info->FreeFds; } + OS_ObjectIdIteratorDestroy(&iter); - OS_Unlock_Global(OS_OBJECT_TYPE_OS_STREAM); - - OS_Lock_Global(OS_OBJECT_TYPE_OS_FILESYS); - - for (i = 0; i < OS_MAX_FILE_SYSTEMS; i++) + OS_ObjectIdIteratorInit(OS_FileSysFilterFree, NULL, OS_OBJECT_TYPE_OS_FILESYS, &iter); + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (!OS_ObjectIdDefined(OS_global_filesys_table[i].active_id)) - { - filesys_info->FreeVolumes++; - } + ++filesys_info->FreeVolumes; } - - OS_Unlock_Global(OS_OBJECT_TYPE_OS_FILESYS); + OS_ObjectIdIteratorDestroy(&iter); return (OS_SUCCESS); } /* end OS_GetFsInfo */ @@ -835,11 +780,10 @@ int32 OS_GetFsInfo(os_fsinfo_t *filesys_info) *-----------------------------------------------------------------*/ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) { - uint32 local_id; + OS_object_token_t token; int32 return_code; const char * name_ptr; - OS_common_record_t * global; - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; size_t SysMountPointLen; size_t VirtPathLen; size_t VirtPathBegin; @@ -847,15 +791,14 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) /* ** Check to see if the path pointers are NULL */ - if (VirtualPath == NULL || LocalPath == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(VirtualPath); + OS_CHECK_POINTER(LocalPath); /* ** Check length */ - VirtPathLen = strlen(VirtualPath); + VirtPathLen = OS_strnlen(VirtualPath, OS_MAX_PATH_LEN); if (VirtPathLen >= OS_MAX_PATH_LEN) { return OS_FS_ERR_PATH_TOO_LONG; @@ -870,7 +813,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) /* strrchr returns a pointer to the last '/' char, so we advance one char */ name_ptr = name_ptr + 1; - if (strlen(name_ptr) >= OS_MAX_FILE_NAME) + if (memchr(name_ptr, 0, OS_MAX_FILE_NAME) == NULL) { return OS_FS_ERR_NAME_TOO_LONG; } @@ -888,7 +831,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) /* Get a reference lock, as a filesystem check could take some time. */ return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)VirtualPath, &global); + (void *)VirtualPath, &token); if (return_code != OS_SUCCESS) { @@ -896,16 +839,15 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) } else { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - local = &OS_filesys_table[local_id]; + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); - if ((local->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) + if ((filesys->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) { - SysMountPointLen = strlen(local->system_mountpt); - VirtPathBegin = strlen(local->virtual_mountpt); + SysMountPointLen = OS_strnlen(filesys->system_mountpt, sizeof(filesys->system_mountpt)); + VirtPathBegin = OS_strnlen(filesys->virtual_mountpt, sizeof(filesys->virtual_mountpt)); if (SysMountPointLen < OS_MAX_LOCAL_PATH_LEN) { - memcpy(LocalPath, local->system_mountpt, SysMountPointLen); + memcpy(LocalPath, filesys->system_mountpt, SysMountPointLen); } } else @@ -913,7 +855,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) return_code = OS_ERR_INCORRECT_OBJ_STATE; } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } if (return_code == OS_SUCCESS) diff --git a/src/os/shared/src/osapi-heap.c b/src/os/shared/src/osapi-heap.c index ed833f814..888d0d7ec 100644 --- a/src/os/shared/src/osapi-heap.c +++ b/src/os/shared/src/osapi-heap.c @@ -50,10 +50,8 @@ *-----------------------------------------------------------------*/ int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop) { - if (heap_prop == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(heap_prop); return OS_HeapGetInfo_Impl(heap_prop); } /* end OS_HeapGetInfo */ diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index 0c0bf1af7..1e2496662 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -56,6 +56,13 @@ #include "os-shared-idmap.h" #include "os-shared-task.h" +/* + * A fixed nonzero value to put into the upper 8 bits + * of lock keys. + */ +#define OS_LOCK_KEY_FIXED_VALUE 0x4D000000 +#define OS_LOCK_KEY_INVALID ((osal_key_t) {0}) + typedef enum { OS_TASK_BASE = 0, @@ -73,6 +80,17 @@ typedef enum OS_MAX_TOTAL_RECORDS = OS_CONSOLE_BASE + OS_MAX_CONSOLES } OS_ObjectIndex_t; +/* + * A structure containing the user-specified + * details of a "foreach" iteration request + */ +typedef struct +{ + osal_id_t creator_id; + OS_ArgCallback_t user_callback; + void * user_arg; +} OS_creator_filter_t; + /* * Global ID storage tables */ @@ -85,8 +103,12 @@ typedef struct /* Keep track of the last successfully-issued object ID of each type */ osal_id_t last_id_issued; - /* The last task to lock/own this global table */ - osal_id_t table_owner; + /* The number of individual transactions (lock/unlock cycles) on this type */ + uint32 transaction_count; + + /* The key required to unlock this table */ + osal_key_t owner_key; + } OS_objtype_state_t; OS_objtype_state_t OS_objtype_state[OS_OBJECT_TYPE_USER]; @@ -132,7 +154,7 @@ int32 OS_ObjectIdInit(void) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -uint32 OS_GetMaxForObjectType(uint32 idtype) +uint32 OS_GetMaxForObjectType(osal_objtype_t idtype) { switch (idtype) { @@ -172,7 +194,7 @@ uint32 OS_GetMaxForObjectType(uint32 idtype) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -uint32 OS_GetBaseForObjectType(uint32 idtype) +uint32 OS_GetBaseForObjectType(osal_objtype_t idtype) { switch (idtype) { @@ -210,6 +232,59 @@ uint32 OS_GetBaseForObjectType(uint32 idtype) * (not used outside of this unit) **************************************************************/ +/*---------------------------------------------------------------- + * + * Function: OS_ForEachFilterCreator + * + * Purpose: Local helper routine, not part of OSAL API. + * Determine if the object is a match for "foreach" operations + * + *-----------------------------------------------------------------*/ +bool OS_ForEachFilterCreator(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) +{ + OS_creator_filter_t *filter = ref; + + /* + * Check if the obj_id is both valid and matches + * the specified creator_id + */ + return (OS_ObjectIdIsValid(obj->active_id) && (OS_ObjectIdEqual(filter->creator_id, OS_OBJECT_CREATOR_ANY) || + OS_ObjectIdEqual(obj->creator, filter->creator_id))); +} + +/*---------------------------------------------------------------- + * + * Function: OS_ForEachDoCallback + * + * Purpose: Local helper routine, not part of OSAL API. + * Invoke the user-specified callback routine + * + *-----------------------------------------------------------------*/ +int32 OS_ForEachDoCallback(osal_id_t obj_id, void *ref) +{ + OS_creator_filter_t *filter = ref; + + /* Just invoke the user callback */ + filter->user_callback(obj_id, filter->user_arg); + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_ObjectIdGlobalFromToken + * + * Purpose: Local helper routine, not part of OSAL API. + * Gets the global/common record associated with the token + * + * returns: pointer to record (never NULL - token MUST be valid) + * + *-----------------------------------------------------------------*/ +OS_common_record_t *OS_ObjectIdGlobalFromToken(const OS_object_token_t *token) +{ + uint32 base_idx = OS_GetBaseForObjectType(token->obj_type); + return &OS_common_table[base_idx + token->obj_idx]; +} + /*---------------------------------------------------------------- * * Function: OS_ObjectNameMatch @@ -219,19 +294,19 @@ uint32 OS_GetBaseForObjectType(uint32 idtype) * a reference value (which must be a const char* string). * * This allows OS_ObjectIdFindByName() to be implemented using the - * generic OS_ObjectIdSearch() routine. + * generic OS_ObjectIdFindNextMatch() routine. * * returns: true if match, false otherwise * *-----------------------------------------------------------------*/ -bool OS_ObjectNameMatch(void *ref, uint32 local_id, const OS_common_record_t *obj) +bool OS_ObjectNameMatch(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { return (obj->name_entry != NULL && strcmp((const char *)ref, obj->name_entry) == 0); } /* end OS_ObjectNameMatch */ /*---------------------------------------------------------------- * - * Function: OS_ObjectIdInitiateLock + * Function: OS_ObjectIdTransactionInit * * Purpose: Local helper routine, not part of OSAL API. * Initiate the locking process for the given mode and ID type, prior @@ -240,22 +315,71 @@ bool OS_ObjectNameMatch(void *ref, uint32 local_id, const OS_common_record_t *ob * For any lock_mode other than OS_LOCK_MODE_NONE, this acquires the * global table lock for that ID type. * - * Once the lookup operation is completed, the OS_ObjectIdConvertLock() + * Once the lookup operation is completed, the OS_ObjectIdConvertToken() * routine should be used to convert this global lock into the actual * lock type requested (lock_mode). * *-----------------------------------------------------------------*/ -void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, uint32 idtype) +int32 OS_ObjectIdTransactionInit(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_object_token_t *token) { + memset(token, 0, sizeof(*token)); + + if (OS_SharedGlobalVars.Initialized == false) + { + return OS_ERROR; + } + + /* + * only "exclusive" locks allowed after shutdown request (this is mode used for delete). + * All regular ops will be blocked. + */ + if (OS_SharedGlobalVars.ShutdownFlag == OS_SHUTDOWN_MAGIC_NUMBER && lock_mode != OS_LOCK_MODE_EXCLUSIVE) + { + return OS_ERR_INCORRECT_OBJ_STATE; + } + + /* + * Transactions cannot be started on an object type for which + * there are no actual objects + */ + if (OS_GetMaxForObjectType(idtype) == 0) + { + return OS_ERR_INCORRECT_OBJ_TYPE; + } + + token->lock_mode = lock_mode; + token->obj_type = idtype; + token->obj_idx = OSAL_INDEX_C(-1); + if (lock_mode != OS_LOCK_MODE_NONE) { - OS_Lock_Global(idtype); + OS_Lock_Global(token); + } + + return OS_SUCCESS; + +} /* end OS_ObjectIdTransactionInit */ + +/*---------------------------------------------------------------- + * + * Function: OS_ObjectIdTransactionInit + * + * Purpose: Local helper routine, not part of OSAL API. + * Cancels/aborts a previously initialized transaction + * + *-----------------------------------------------------------------*/ +void OS_ObjectIdTransactionCancel(OS_object_token_t *token) +{ + if (token->lock_mode != OS_LOCK_MODE_NONE) + { + OS_Unlock_Global(token); + token->lock_mode = OS_LOCK_MODE_NONE; } -} /* end OS_ObjectIdInitiateLock */ +} /*---------------------------------------------------------------- * - * Function: OS_ObjectIdConvertLock + * Function: OS_ObjectIdConvertToken * * Purpose: Local helper routine, not part of OSAL API. * @@ -291,74 +415,89 @@ void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, uint32 idtype) * all lock modes other than OS_LOCK_MODE_NONE. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, osal_id_t reference_id, OS_common_record_t *obj) +int32 OS_ObjectIdConvertToken(OS_object_token_t *token) { - int32 return_code = OS_ERROR; - uint32 exclusive_bits = 0; - uint32 attempts = 0; + int32 return_code = OS_ERROR; + uint32 attempts = 0; + OS_common_record_t *obj; + osal_id_t expected_id; + + obj = OS_ObjectIdGlobalFromToken(token); + expected_id = OS_ObjectIdFromToken(token); + + /* + * Upon entry the ID from the token must be valid + */ + if (!OS_ObjectIdIsValid(expected_id)) + { + return OS_ERR_INCORRECT_OBJ_STATE; + } + + /* + * If lock mode is RESERVED, then the ID in the record should + * already be set to OS_OBJECT_ID_RESERVED. This is for very + * specific use cases where a secondary task needs to access an + * object during its creation/deletion. + * + * For all typical modes the ID in the record should be equal + * to the token ID. + */ + if (token->lock_mode == OS_LOCK_MODE_RESERVED) + { + expected_id = OS_OBJECT_ID_RESERVED; + } while (true) { /* Validate the integrity of the ID. As the "active_id" is a single * integer, we can do this check regardless of whether global is locked or not. */ - if (!OS_ObjectIdEqual(obj->active_id, reference_id)) - { - /* The ID does not match, so unlock and return error. - * This basically means the ID was stale or otherwise no longer invalid */ - return_code = OS_ERR_INVALID_ID; - break; - } - - /* - * The REFCOUNT and EXCLUSIVE lock modes require additional - * conditions on before they can be successful. - */ - if (lock_mode == OS_LOCK_MODE_REFCOUNT) - { - /* As long as no exclusive request is pending, we can increment the - * refcount and good to go. */ - if ((obj->flags & OS_OBJECT_EXCL_REQ_FLAG) == 0) - { - ++obj->refcount; - return_code = OS_SUCCESS; - break; - } - } - else if (lock_mode == OS_LOCK_MODE_EXCLUSIVE) + if (OS_ObjectIdEqual(obj->active_id, expected_id)) { /* - * Set the exclusive request flag -- this will prevent anyone else from - * incrementing the refcount while we are waiting. However we can only - * do this if there are no OTHER exclusive requests. + * Got an ID match... */ - if (exclusive_bits != 0 || (obj->flags & OS_OBJECT_EXCL_REQ_FLAG) == 0) + if (token->lock_mode == OS_LOCK_MODE_EXCLUSIVE) { /* - * As long as nothing is referencing this object, we are good to go. - * The global table will be left in a locked state in this case. + * For EXCLUSIVE mode, overwrite the ID to be RESERVED now -- this + * makes any future ID checks or lock attempts in other tasks fail to match. + */ + if (!OS_ObjectIdEqual(expected_id, OS_OBJECT_ID_RESERVED)) + { + expected_id = OS_OBJECT_ID_RESERVED; + obj->active_id = expected_id; + } + + /* + * Also confirm that reference count is zero + * If not zero, will need to wait for other tasks to release. */ if (obj->refcount == 0) { return_code = OS_SUCCESS; break; } - - exclusive_bits = OS_OBJECT_EXCL_REQ_FLAG; - obj->flags |= exclusive_bits; + } + else + { + /* + * Nothing else to test for this lock type + */ + return_code = OS_SUCCESS; + break; } } - else + else if (token->lock_mode == OS_LOCK_MODE_NONE || !OS_ObjectIdEqual(obj->active_id, OS_OBJECT_ID_RESERVED)) { - /* No fanciness required - move on. */ - return_code = OS_SUCCESS; + /* Not an ID match and not RESERVED - fail out */ + return_code = OS_ERR_INVALID_ID; break; } /* * If we get this far, it means there is contention for access to the object. - * a) we want to increment refcount but an exclusive is pending - * b) we want exclusive but refcount is nonzero - * c) we want exclusive but another exclusive is pending + * a) we want to some type of lock but the ID is currently RESERVED + * b) the refcount is too high - need to wait for release * * In this case we will UNLOCK the global object again so that the holder * can relinquish it. We'll try again a few times before giving up hope. @@ -370,9 +509,10 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, osal_id_t break; } - OS_Unlock_Global(idtype); - OS_TaskDelay_Impl(attempts); - OS_Lock_Global(idtype); + /* + * Call the impl layer to wait for some sort of change to occur. + */ + OS_WaitForStateChange(token, attempts); } /* @@ -381,34 +521,48 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, osal_id_t * If lock_mode is OS_LOCK_MODE_NONE, then the table was never locked * to begin with, and therefore never needs to be unlocked. */ - if (lock_mode != OS_LOCK_MODE_NONE) + if (token->lock_mode != OS_LOCK_MODE_NONE) { - /* - * In case any exclusive bits were set locally, unset them now - * before the lock is (maybe) released. - */ - obj->flags &= ~exclusive_bits; + if (return_code == OS_SUCCESS) + { + /* always increment the refcount, which means a task is actively + * using or modifying this record. */ + ++obj->refcount; - /* - * If the operation failed, then we always unlock the global table. - * - * On a successful operation, the global is unlocked if it is a REFCOUNT - * style lock. For other styles (GLOBAL or EXCLUSIVE) the global lock - * should be maintained and returned to the caller. - */ - if (return_code != OS_SUCCESS || lock_mode == OS_LOCK_MODE_REFCOUNT) + /* + * On a successful operation, the global is unlocked if it is + * a REFCOUNT or EXCLUSIVE lock. Note for EXCLUSIVE, because the ID + * was overwritten to OS_OBJECT_ID_RESERVED, other tasks will not be + * able to access the object because the ID will not match, so the + * table can be unlocked while the remainder of the create/delete process + * continues. + * + * For OS_LOCK_MODE_GLOBAL the global lock should be maintained and + * returned to the caller. + */ + if (token->lock_mode == OS_LOCK_MODE_REFCOUNT || token->lock_mode == OS_LOCK_MODE_EXCLUSIVE) + { + OS_Unlock_Global(token); + } + } + else if (token->lock_mode == OS_LOCK_MODE_EXCLUSIVE && OS_ObjectIdEqual(expected_id, OS_OBJECT_ID_RESERVED)) { - OS_Unlock_Global(idtype); + /* + * On failure, if the active_id was overwritten, then set + * it back to the original value which is in the token. + * (note it had to match initially before overwrite) + */ + obj->active_id = OS_ObjectIdFromToken(token); } } return return_code; -} /* end OS_ObjectIdConvertLock */ +} /* end OS_ObjectIdConvertToken */ /*---------------------------------------------------------------- * - * Function: OS_ObjectIdSearch + * Function: OS_ObjectIdFindNextMatch * * Purpose: Local helper routine, not part of OSAL API. * Locate an existing object using the supplied Match function. @@ -420,47 +574,43 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, osal_id_t * returns: OS_ERR_NAME_NOT_FOUND if not found, OS_SUCCESS if match is found * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdSearch(uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record) +int32 OS_ObjectIdFindNextMatch(OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_object_token_t *token) { int32 return_code; uint32 obj_count; - uint32 local_id; - OS_common_record_t *obj; + OS_common_record_t *base; + OS_common_record_t *record; - return_code = OS_ERR_NAME_NOT_FOUND; - obj = &OS_common_table[OS_GetBaseForObjectType(idtype)]; - obj_count = OS_GetMaxForObjectType(idtype); - local_id = 0; + return_code = OS_ERR_NAME_NOT_FOUND; + base = &OS_common_table[OS_GetBaseForObjectType(token->obj_type)]; + obj_count = OS_GetMaxForObjectType(token->obj_type); + token->obj_id = OS_OBJECT_ID_UNDEFINED; while (true) { - if (obj_count == 0) + ++token->obj_idx; + + if (token->obj_idx >= obj_count) { - obj = NULL; break; } - --obj_count; - if (OS_ObjectIdDefined(obj->active_id) && MatchFunc(arg, local_id, obj)) + record = OS_OBJECT_TABLE_GET(base, *token); + + if (OS_ObjectIdDefined(record->active_id) && MatchFunc(arg, token, record)) { - return_code = OS_SUCCESS; + return_code = OS_SUCCESS; + token->obj_id = record->active_id; break; } - ++obj; - ++local_id; - } - - if (record != NULL) - { - *record = obj; } return return_code; -} /* end OS_ObjectIdSearch */ +} /* end OS_ObjectIdFindNextMatch */ /*---------------------------------------------------------------- * - * Function: OS_ObjectIdFindNext + * Function: OS_ObjectIdFindNextFree * * Purpose: Local helper routine, not part of OSAL API. * Find the next available Object ID of the given type @@ -475,18 +625,20 @@ int32 OS_ObjectIdSearch(uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg * * returns: OS_SUCCESS if an empty location was found. *-----------------------------------------------------------------*/ -int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record) +int32 OS_ObjectIdFindNextFree(OS_object_token_t *token) { uint32 max_id; uint32 base_id; uint32 local_id = 0; - uint32 idvalue; + uint32 serial; uint32 i; int32 return_code; OS_common_record_t *obj = NULL; + OS_objtype_state_t *objtype_state; - base_id = OS_GetBaseForObjectType(idtype); - max_id = OS_GetMaxForObjectType(idtype); + base_id = OS_GetBaseForObjectType(token->obj_type); + max_id = OS_GetMaxForObjectType(token->obj_type); + objtype_state = &OS_objtype_state[token->obj_type]; if (max_id == 0) { @@ -495,21 +647,21 @@ int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t * Return the "not implemented" to differentiate between * this case vs. running out of valid slots */ return_code = OS_ERR_NOT_IMPLEMENTED; - idvalue = 0; + serial = 0; } else { return_code = OS_ERR_NO_FREE_IDS; - idvalue = OS_ObjectIdToSerialNumber_Impl(OS_objtype_state[idtype].last_id_issued); + serial = OS_ObjectIdToSerialNumber_Impl(objtype_state->last_id_issued); } for (i = 0; i < max_id; ++i) { - local_id = (++idvalue) % max_id; - if (idvalue >= OS_OBJECT_INDEX_MASK) + local_id = (++serial) % max_id; + if (serial >= OS_OBJECT_INDEX_MASK) { /* reset to beginning of ID space */ - idvalue = local_id; + serial = local_id; } obj = &OS_common_table[local_id + base_id]; if (!OS_ObjectIdDefined(obj->active_id)) @@ -521,31 +673,27 @@ int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t if (return_code == OS_SUCCESS) { - OS_ObjectIdCompose_Impl(idtype, idvalue, &obj->active_id); + token->obj_idx = OSAL_INDEX_C(local_id); + OS_ObjectIdCompose_Impl(token->obj_type, serial, &token->obj_id); /* Ensure any data in the record has been cleared */ + obj->active_id = token->obj_id; obj->name_entry = NULL; obj->creator = OS_TaskGetId(); obj->refcount = 0; - } - if (return_code != OS_SUCCESS) - { - obj = NULL; - local_id = 0; + /* preemptively update the last id issued */ + objtype_state->last_id_issued = token->obj_id; } - if (array_index != NULL) - { - *array_index = local_id; - } - if (record != NULL) + if (return_code != OS_SUCCESS) { - *record = obj; + token->obj_idx = OSAL_INDEX_C(-1); + token->obj_id = OS_OBJECT_ID_UNDEFINED; } return return_code; -} /* end OS_ObjectIdFindNext */ +} /* end OS_ObjectIdFindNextFree */ /* ********************************************************************************* @@ -561,59 +709,63 @@ int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t Purpose: Locks the global table identified by "idtype" ------------------------------------------------------------------*/ -void OS_Lock_Global(uint32 idtype) +void OS_Lock_Global(OS_object_token_t *token) { - int32 return_code; osal_id_t self_task_id; OS_objtype_state_t *objtype; - if (idtype < OS_OBJECT_TYPE_USER) + if (token->obj_type < OS_OBJECT_TYPE_USER && token->lock_mode != OS_LOCK_MODE_NONE) { - objtype = &OS_objtype_state[idtype]; + objtype = &OS_objtype_state[token->obj_type]; self_task_id = OS_TaskGetId_Impl(); - return_code = OS_Lock_Global_Impl(idtype); - if (return_code == OS_SUCCESS) + OS_Lock_Global_Impl(token->obj_type); + + /* + * Track ownership of this table. It should only be owned by one + * task at a time, and this aids in recovery if the owning task is + * deleted or experiences an exception causing it to not be freed. + * + * This is done after successfully locking, so this has exclusive access + * to the state object. + */ + if (!OS_ObjectIdIsValid(self_task_id)) { /* - * Track ownership of this table. It should only be owned by one - * task at a time, and this aids in recovery if the owning task is - * deleted or experiences an exception causing it to not be freed. - * - * This is done after successfully locking, so this has exclusive access - * to the state object. + * This just means the calling context is not an OSAL-created task. + * This is not necessarily an error, but it should be tracked. + * Also note that the root/initial task also does not have an ID. */ - if (!OS_ObjectIdDefined(self_task_id)) - { - /* - * This just means the calling context is not an OSAL-created task. - * This is not necessarily an error, but it should be tracked. - * Also note that the root/initial task also does not have an ID. - */ - self_task_id = OS_OBJECT_ID_RESERVED; /* nonzero, but also won't alias a known task */ - } + self_task_id = OS_OBJECT_ID_RESERVED; /* nonzero, but also won't alias a known task */ + } - if (OS_ObjectIdDefined(objtype->table_owner)) - { - /* this is almost certainly a bug */ - OS_DEBUG("ERROR: global %u acquired by task 0x%lx when already owned by task 0x%lx\n", - (unsigned int)idtype, OS_ObjectIdToInteger(self_task_id), - OS_ObjectIdToInteger(objtype->table_owner)); - } - else - { - objtype->table_owner = self_task_id; - } + /* + * The key value is computed with fixed/nonzero flag bits combined + * with the lower 24 bits of the task ID xor'ed with transaction id. + * This makes it different for every operation, and different depending + * on what task is calling the function. + */ + token->lock_key.key_value = + OS_LOCK_KEY_FIXED_VALUE | ((OS_ObjectIdToInteger(self_task_id) ^ objtype->transaction_count) & 0xFFFFFF); + + ++objtype->transaction_count; + + if (objtype->owner_key.key_value != 0) + { + /* this is almost certainly a bug */ + OS_DEBUG("ERROR: global %u acquired by task 0x%lx when already assigned key 0x%lx\n", + (unsigned int)token->obj_type, OS_ObjectIdToInteger(self_task_id), + (unsigned long)objtype->owner_key.key_value); + } + else + { + objtype->owner_key = token->lock_key; } } else { - return_code = OS_ERR_INCORRECT_OBJ_TYPE; - } - - if (return_code != OS_SUCCESS) - { - OS_DEBUG("ERROR: unable to lock global %u, error=%d\n", (unsigned int)idtype, (int)return_code); + OS_DEBUG("ERROR: cannot lock global %u for mode %u\n", (unsigned int)token->obj_type, + (unsigned int)token->lock_mode); } } @@ -622,16 +774,13 @@ void OS_Lock_Global(uint32 idtype) Purpose: Unlocks the global table identified by "idtype" ------------------------------------------------------------------*/ -void OS_Unlock_Global(uint32 idtype) +void OS_Unlock_Global(OS_object_token_t *token) { - int32 return_code; - osal_id_t self_task_id; OS_objtype_state_t *objtype; - if (idtype < OS_OBJECT_TYPE_USER) + if (token->obj_type < OS_OBJECT_TYPE_USER && token->lock_mode != OS_LOCK_MODE_NONE) { - objtype = &OS_objtype_state[idtype]; - self_task_id = OS_TaskGetId_Impl(); + objtype = &OS_objtype_state[token->obj_type]; /* * Un-track ownership of this table. It should only be owned by one @@ -641,38 +790,68 @@ void OS_Unlock_Global(uint32 idtype) * This is done before unlocking, while this has exclusive access * to the state object. */ - if (!OS_ObjectIdDefined(self_task_id)) - { - /* - * This just means the calling context is not an OSAL-created task. - * This is not necessarily an error, but it should be tracked. - * Also note that the root/initial task also does not have an ID. - */ - self_task_id = OS_OBJECT_ID_RESERVED; /* nonzero, but also won't alias a known task */ - } - - if (!OS_ObjectIdEqual(objtype->table_owner, self_task_id)) + if ((objtype->owner_key.key_value & 0xFF000000) != OS_LOCK_KEY_FIXED_VALUE || + objtype->owner_key.key_value != token->lock_key.key_value) { /* this is almost certainly a bug */ - OS_DEBUG("ERROR: global %u released by task 0x%lx when owned by task 0x%lx\n", (unsigned int)idtype, - OS_ObjectIdToInteger(self_task_id), OS_ObjectIdToInteger(objtype->table_owner)); - } - else - { - objtype->table_owner = OS_OBJECT_ID_UNDEFINED; + OS_DEBUG("ERROR: global %u released using mismatched key=0x%lx expected=0x%lx\n", + (unsigned int)token->obj_type, (unsigned long)token->lock_key.key_value, + (unsigned long)objtype->owner_key.key_value); } - return_code = OS_Unlock_Global_Impl(idtype); + objtype->owner_key = OS_LOCK_KEY_INVALID; + token->lock_key = OS_LOCK_KEY_INVALID; + + OS_Unlock_Global_Impl(token->obj_type); } else { - return_code = OS_ERR_INCORRECT_OBJ_TYPE; + OS_DEBUG("ERROR: cannot unlock global %u for mode %u\n", (unsigned int)token->obj_type, + (unsigned int)token->lock_mode); } +} - if (return_code != OS_SUCCESS) - { - OS_DEBUG("ERROR: unable to unlock global %u, error=%d\n", (unsigned int)idtype, (int)return_code); - } +/*---------------------------------------------------------------- + * + * Function: OS_WaitForStateChange + * + * Purpose: Local helper routine, not part of OSAL API. + * Waits for a change in the global table identified by "idtype" + * + * NOTE: this must be called while the table is _LOCKED_ + * The "OS_WaitForStateChange_Impl" function should unlock + relock + * + *-----------------------------------------------------------------*/ +void OS_WaitForStateChange(OS_object_token_t *token, uint32 attempts) +{ + osal_key_t saved_unlock_key; + OS_objtype_state_t *objtype; + + /* + * This needs to release the lock, to allow other + * tasks to make a change to the table. But to avoid + * ownership warnings the key must also be temporarily + * cleared too, and restored after waiting. + */ + + objtype = &OS_objtype_state[token->obj_type]; + saved_unlock_key = objtype->owner_key; + + /* temporarily release the table */ + objtype->owner_key = OS_LOCK_KEY_INVALID; + + /* + * The implementation layer takes care of the actual unlock + wait. + * This permits use of condition variables where these two actions + * are done atomically. + */ + OS_WaitForStateChange_Impl(token->obj_type, attempts); + + /* + * After return, this task owns the table again + */ + /* cppcheck-suppress redundantAssignment */ + objtype->owner_key = saved_unlock_key; } /*---------------------------------------------------------------- @@ -693,10 +872,9 @@ void OS_Unlock_Global(uint32 idtype) * were detected while validating the ID. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, osal_id_t *outid) +int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_object_token_t *token, osal_id_t *outid) { - uint32 idtype = OS_ObjectIdToType_Impl(record->active_id); - osal_id_t callback_id; + osal_id_t final_id; /* if operation was unsuccessful, then clear * the active_id field within the record, so @@ -705,42 +883,32 @@ int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, * Otherwise, ensure that the record_id to be * exported is sane (it always should be) */ - if (operation_status != OS_SUCCESS) - { - record->active_id = OS_OBJECT_ID_UNDEFINED; - } - else if (idtype == 0 || idtype >= OS_OBJECT_TYPE_USER) + if (operation_status == OS_SUCCESS) { - /* should never happen - indicates a bug. */ - operation_status = OS_ERR_INVALID_ID; - record->active_id = OS_OBJECT_ID_UNDEFINED; + final_id = token->obj_id; } else { - /* success */ - OS_objtype_state[idtype].last_id_issued = record->active_id; + final_id = OS_OBJECT_ID_UNDEFINED; } - /* snapshot the ID for callback - will be needed after unlock */ - callback_id = record->active_id; + /* Either way we must unlock the object type */ + OS_ObjectIdTransactionFinish(token, &final_id); - if (outid != NULL) + /* Give event callback to the application */ + if (operation_status == OS_SUCCESS) { - /* always write the final value to the output buffer */ - *outid = record->active_id; + OS_NotifyEvent(OS_EVENT_RESOURCE_CREATED, token->obj_id, NULL); } - /* Either way we must unlock the object type */ - OS_Unlock_Global(idtype); - - /* Give event callback to the application */ - if (OS_ObjectIdDefined(callback_id)) + if (outid != NULL) { - OS_NotifyEvent(OS_EVENT_RESOURCE_CREATED, callback_id, NULL); + /* always write the final value to the output buffer */ + *outid = final_id; } return operation_status; -} /* end OS_ObjectIdFinalizeNew */ +} /* end OS_ObjectIdFinalizeNew(, &token, ) */ /*---------------------------------------------------------------- Function: OS_ObjectIdFinalizeDelete @@ -748,29 +916,28 @@ int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, Purpose: Helper routine, not part of OSAL public API. See description in prototype ------------------------------------------------------------------*/ -int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *record) +int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_object_token_t *token) { - uint32 idtype = OS_ObjectIdToType_Impl(record->active_id); - osal_id_t callback_id; + osal_id_t final_id; /* Clear the OSAL ID if successful - this returns the record to the pool */ if (operation_status == OS_SUCCESS) { - callback_id = record->active_id; - record->active_id = OS_OBJECT_ID_UNDEFINED; + final_id = OS_OBJECT_ID_UNDEFINED; } else { - callback_id = OS_OBJECT_ID_UNDEFINED; + /* this restores the original ID */ + final_id = token->obj_id; } /* Either way we must unlock the object type */ - OS_Unlock_Global(idtype); + OS_ObjectIdTransactionFinish(token, &final_id); /* Give event callback to the application */ - if (OS_ObjectIdDefined(callback_id)) + if (operation_status == OS_SUCCESS) { - OS_NotifyEvent(OS_EVENT_RESOURCE_DELETED, callback_id, NULL); + OS_NotifyEvent(OS_EVENT_RESOURCE_DELETED, token->obj_id, NULL); } return operation_status; @@ -790,33 +957,27 @@ int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *reco * returns: OS_ERR_NAME_NOT_FOUND if not found, OS_SUCCESS if match is found * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, - OS_common_record_t **record) +int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, + OS_object_token_t *token) { - int32 return_code; - OS_common_record_t *obj; + int32 return_code; - OS_ObjectIdInitiateLock(lock_mode, idtype); + OS_ObjectIdTransactionInit(lock_mode, idtype, token); - return_code = OS_ObjectIdSearch(idtype, MatchFunc, arg, &obj); + return_code = OS_ObjectIdFindNextMatch(MatchFunc, arg, token); if (return_code == OS_SUCCESS) { /* - * The "ConvertLock" routine will return with the global lock + * The "ConvertToken" routine will return with the global lock * in a state appropriate for returning to the caller, as indicated * by the "check_mode" parameter. */ - return_code = OS_ObjectIdConvertLock(lock_mode, idtype, obj->active_id, obj); + return_code = OS_ObjectIdConvertToken(token); } - else if (lock_mode != OS_LOCK_MODE_NONE) - { - OS_Unlock_Global(idtype); - } - - if (record != NULL) + else { - *record = obj; + OS_ObjectIdTransactionCancel(token); } return return_code; @@ -836,9 +997,9 @@ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, OS_ObjectM * returns: OS_ERR_NAME_NOT_FOUND if not found, OS_SUCCESS if match is found * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, uint32 idtype, const char *name, OS_common_record_t **record) +int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, OS_object_token_t *token) { - return OS_ObjectIdGetBySearch(lock_mode, idtype, OS_ObjectNameMatch, (void *)name, record); + return OS_ObjectIdGetBySearch(lock_mode, idtype, OS_ObjectNameMatch, (void *)name, token); } /* end OS_ObjectIdGetByName */ @@ -853,31 +1014,25 @@ int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, uint32 idtype, const char * * returns: OS_ERR_NAME_NOT_FOUND if not found, OS_SUCCESS if match is found * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdFindByName(uint32 idtype, const char *name, osal_id_t *object_id) +int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t *object_id) { - int32 return_code; - OS_common_record_t *global; + int32 return_code; + OS_object_token_t token; /* * As this is an internal-only function, calling it will NULL is allowed. * This is required by the file/dir/socket API since these DO allow multiple * instances of the same name. */ - if (name == NULL) - { - return OS_ERR_NAME_NOT_FOUND; - } - - if (strlen(name) >= OS_MAX_API_NAME) - { - return OS_ERR_NAME_TOO_LONG; - } + ARGCHECK(name, OS_ERR_NAME_NOT_FOUND); + LENGTHCHECK(name, OS_MAX_API_NAME, OS_ERR_NAME_TOO_LONG); - return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_GLOBAL, idtype, name, &global); + return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_GLOBAL, idtype, name, &token); if (return_code == OS_SUCCESS) { - *object_id = global->active_id; - OS_Unlock_Global(idtype); + *object_id = token.obj_id; + + OS_ObjectIdRelease(&token); } return return_code; @@ -900,87 +1055,127 @@ int32 OS_ObjectIdFindByName(uint32 idtype, const char *name, osal_id_t *object_i * If this returns something other than OS_SUCCESS then the global is NOT locked. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, uint32 idtype, osal_id_t id, uint32 *array_index, - OS_common_record_t **record) +int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, OS_object_token_t *token) { int32 return_code; - if (OS_SharedGlobalVars.Initialized == false) + return_code = OS_ObjectIdTransactionInit(lock_mode, idtype, token); + if (return_code != OS_SUCCESS) { - return OS_ERROR; + return return_code; } - /* - * Special case to allow only OS_LOCK_MODE_EXCLUSIVE during shutdowns - * (This is the lock mode used to delete objects) - */ - if (OS_SharedGlobalVars.ShutdownFlag == OS_SHUTDOWN_MAGIC_NUMBER && lock_mode != OS_LOCK_MODE_EXCLUSIVE) + return_code = OS_ObjectIdToArrayIndex(idtype, id, &token->obj_idx); + if (return_code == OS_SUCCESS) { - return OS_ERR_INCORRECT_OBJ_STATE; + token->obj_id = id; + + /* + * The "ConvertToken" routine will return with the global lock + * in a state appropriate for returning to the caller, as indicated + * by the "check_mode" paramter. + * + * Note If this operation fails, then it always unlocks the global for + * all check_mode's other than NONE. + */ + return_code = OS_ObjectIdConvertToken(token); } - return_code = OS_ObjectIdToArrayIndex(idtype, id, array_index); if (return_code != OS_SUCCESS) { - return return_code; + OS_ObjectIdTransactionCancel(token); } - *record = &OS_common_table[*array_index + OS_GetBaseForObjectType(idtype)]; - - OS_ObjectIdInitiateLock(lock_mode, idtype); - - /* - * The "ConvertLock" routine will return with the global lock - * in a state appropriate for returning to the caller, as indicated - * by the "check_mode" paramter. - * - * Note If this operation fails, then it always unlocks the global for - * all check_mode's other than NONE. - */ - return_code = OS_ObjectIdConvertLock(lock_mode, idtype, id, *record); - return return_code; } /* end OS_ObjectIdGetById */ /*---------------------------------------------------------------- * - * Function: OS_ObjectIdRefcountDecr + * Function: OS_ObjectIdTransactionFinish * - * Purpose: Local helper routine, not part of OSAL API. - * Decrement the reference count on the resource record, which must have been - * acquired (incremented) by the caller prior to this. + * Purpose: Complete a transaction which was previously obtained via + * OS_ObjectIdGetById() or OS_ObjectIdGetBySearch(). + * + * This also updates the ID from the value in the final_id parameter, which + * is used for create/delete. * - * returns: OS_SUCCESS if decremented successfully. + * If no ID update is pending, then NULL may be passed and the ID will not + * be changed. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record) +void OS_ObjectIdTransactionFinish(OS_object_token_t *token, osal_id_t *final_id) { - int32 return_code; - uint32 idtype = OS_ObjectIdToType_Impl(record->active_id); + OS_common_record_t *record; - if (idtype == 0 || !OS_ObjectIdDefined(record->active_id)) + if (token->lock_mode == OS_LOCK_MODE_NONE) { - return_code = OS_ERR_INVALID_ID; + /* nothing to do */ + return; } - else + + record = OS_ObjectIdGlobalFromToken(token); + + /* re-acquire global table lock to adjust refcount */ + if (token->lock_mode == OS_LOCK_MODE_EXCLUSIVE || token->lock_mode == OS_LOCK_MODE_REFCOUNT) { - OS_Lock_Global(idtype); + OS_Lock_Global(token); + } - if (record->refcount > 0) - { - --record->refcount; - return_code = OS_SUCCESS; - } - else - { - return_code = OS_ERR_INCORRECT_OBJ_STATE; - } + if (record->refcount > 0) + { + --record->refcount; + } - OS_Unlock_Global(idtype); + /* + * at this point the global mutex is always held, either + * from re-acquiring it above or it is still held from + * the original lock when using OS_LOCK_MODE_GLOBAL. + * + * If an ID update was pending (i.e. for a create/delete op) + * then do the ID update now while holding the mutex. + */ + if (final_id != NULL) + { + record->active_id = *final_id; + } + else if (token->lock_mode == OS_LOCK_MODE_EXCLUSIVE) + { + /* + * If the lock type was EXCLUSIVE, it means that the ID in the record + * was reset to OS_OBJECT_ID_RESERVED. This must restore the original + * object ID from the token. + */ + record->active_id = token->obj_id; } - return return_code; -} /* end OS_ObjectIdRefcountDecr */ + /* always unlock (this also covers OS_LOCK_MODE_GLOBAL case) */ + OS_Unlock_Global(token); + + /* + * Setting to "NONE" indicates that this token has been + * released, and should not be released again. + */ + token->lock_mode = OS_LOCK_MODE_NONE; +} + +/*---------------------------------------------------------------- + * + * Function: OS_ObjectIdRelease + * + * Purpose: Release/Unlock a transaction token which was previously obtained via + * OS_ObjectIdGetById() or OS_ObjectIdGetBySearch(). + * + * This is used for completing normal operations other than create/delete - + * that is where the same ID exists before and after the transaction without + * change. + * + * (There is a dedicated routine for finalization of create and delete ops) + * + *-----------------------------------------------------------------*/ +void OS_ObjectIdRelease(OS_object_token_t *token) +{ + OS_ObjectIdTransactionFinish(token, NULL); +} /*---------------------------------------------------------------- * @@ -1012,29 +1207,28 @@ int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record) * manipulate the global lock at all. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_index, OS_common_record_t **record) +int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token) { int32 return_code; - if (OS_SharedGlobalVars.Initialized == false || OS_SharedGlobalVars.ShutdownFlag == OS_SHUTDOWN_MAGIC_NUMBER) + if (OS_SharedGlobalVars.ShutdownFlag == OS_SHUTDOWN_MAGIC_NUMBER) { - return OS_ERROR; + return OS_ERR_INCORRECT_OBJ_STATE; } - if (idtype >= OS_OBJECT_TYPE_USER) + return_code = OS_ObjectIdTransactionInit(OS_LOCK_MODE_EXCLUSIVE, idtype, token); + if (return_code != OS_SUCCESS) { - return OS_ERR_INCORRECT_OBJ_TYPE; + return return_code; } - OS_Lock_Global(idtype); - /* * Check if an object of the same name already exits. * If so, a new object cannot be allocated. */ if (name != NULL) { - return_code = OS_ObjectIdSearch(idtype, OS_ObjectNameMatch, (void *)name, record); + return_code = OS_ObjectIdFindNextMatch(OS_ObjectNameMatch, (void *)name, token); } else { @@ -1047,24 +1241,152 @@ int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_inde } else { - return_code = OS_ObjectIdFindNext(idtype, array_index, record); + return_code = OS_ObjectIdFindNextFree(token); + } + + /* If allocation failed, abort the operation now - no ID was allocated. + * After this point, if a future step fails, the allocated ID must be + * released. */ + if (return_code != OS_SUCCESS) + { + OS_ObjectIdTransactionCancel(token); + return return_code; + } + + if (return_code == OS_SUCCESS) + { + return_code = OS_NotifyEvent(OS_EVENT_RESOURCE_ALLOCATED, token->obj_id, NULL); } if (return_code == OS_SUCCESS) { - return_code = OS_NotifyEvent(OS_EVENT_RESOURCE_ALLOCATED, (*record)->active_id, NULL); + return_code = OS_ObjectIdConvertToken(token); } - /* If allocation failed for any reason, unlock the global. - * otherwise the global should stay locked so remaining initialization can be done */ if (return_code != OS_SUCCESS) { - OS_Unlock_Global(idtype); + return_code = OS_ObjectIdFinalizeNew(return_code, token, NULL); } return return_code; } /* end OS_ObjectIdAllocateNew */ +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransferToken + + Purpose: Transfer ownership of a token to another buffer + ------------------------------------------------------------------*/ +void OS_ObjectIdTransferToken(OS_object_token_t *token_from, OS_object_token_t *token_to) +{ + /* start with a simple copy */ + *token_to = *token_from; + + /* + * nullify the old token, such that if release/cancel + * is invoked it will have no effect (the real lock is + * now on token_to). + */ + token_from->lock_mode = OS_LOCK_MODE_NONE; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorInit + + Purpose: Start the process of iterating through OSAL objects + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIteratorInit(OS_ObjectMatchFunc_t matchfunc, void *matcharg, osal_objtype_t objtype, + OS_object_iter_t *iter) +{ + iter->match = matchfunc; + iter->arg = matcharg; + iter->limit = OS_GetMaxForObjectType(objtype); + iter->base = &OS_common_table[OS_GetBaseForObjectType(objtype)]; + + return OS_ObjectIdTransactionInit(OS_LOCK_MODE_GLOBAL, objtype, &iter->token); +} + +/*---------------------------------------------------------------- + Function: OS_ObjectFilterActive + + Purpose: Match function to iterate only active objects + ------------------------------------------------------------------*/ +bool OS_ObjectFilterActive(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) +{ + return OS_ObjectIdDefined(obj->active_id); +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIterateActive + + Purpose: Start the process of iterating through OSAL objects + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIterateActive(osal_objtype_t objtype, OS_object_iter_t *iter) +{ + return OS_ObjectIdIteratorInit(OS_ObjectFilterActive, NULL, objtype, iter); +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorGetNext + + Purpose: Move iterator to the next entry + ------------------------------------------------------------------*/ +bool OS_ObjectIdIteratorGetNext(OS_object_iter_t *iter) +{ + OS_common_record_t *record; + bool got_next; + + got_next = false; + iter->token.obj_id = OS_OBJECT_ID_UNDEFINED; + + do + { + ++iter->token.obj_idx; + if (iter->token.obj_idx >= iter->limit) + { + break; + } + + record = OS_OBJECT_TABLE_GET(iter->base, iter->token); + if (iter->match == NULL || iter->match(iter->arg, &iter->token, record)) + { + iter->token.obj_id = record->active_id; + got_next = true; + } + } while (!got_next); + + return got_next; +} /* end OS_ObjectIdIteratorGetNext */ + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorDestroy + + Purpose: Release iterator resources + ------------------------------------------------------------------*/ +void OS_ObjectIdIteratorDestroy(OS_object_iter_t *iter) +{ + OS_ObjectIdTransactionCancel(&iter->token); +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorProcessEntry + + Purpose: Call a handler function on an iterator object ID + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t, void *)) +{ + int32 status; + + /* + * This needs to temporarily unlock the global, + * call the handler function, then re-lock. + */ + OS_Unlock_Global(&iter->token); + status = func(OS_ObjectIdFromToken(&iter->token), iter->arg); + OS_Lock_Global(&iter->token); + + return status; +} + /* ********************************************************************************* * PUBLIC API (these functions may be called externally) @@ -1079,7 +1401,7 @@ int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_inde * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_ConvertToArrayIndex(osal_id_t object_id, uint32 *ArrayIndex) +int32 OS_ConvertToArrayIndex(osal_id_t object_id, osal_index_t *ArrayIndex) { /* just pass to the generic internal conversion routine */ return OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_UNDEFINED, object_id, ArrayIndex); @@ -1095,7 +1417,7 @@ int32 OS_ConvertToArrayIndex(osal_id_t object_id, uint32 *ArrayIndex) *-----------------------------------------------------------------*/ void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg) { - uint32 idtype; + osal_objtype_t idtype; for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype) { @@ -1111,54 +1433,24 @@ void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void * See description in API and header file for detail * *-----------------------------------------------------------------*/ -void OS_ForEachObjectOfType(uint32 idtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg) +void OS_ForEachObjectOfType(osal_objtype_t idtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, + void *callback_arg) { - uint32 obj_index; - uint32 obj_max; - osal_id_t obj_id; + OS_object_iter_t iter; + OS_creator_filter_t filter; - obj_max = OS_GetMaxForObjectType(idtype); - if (obj_max > 0) + filter.creator_id = creator_id; + filter.user_callback = callback_ptr; + filter.user_arg = callback_arg; + + if (OS_ObjectIdIteratorInit(OS_ForEachFilterCreator, &filter, idtype, &iter) == OS_SUCCESS) { - obj_index = OS_GetBaseForObjectType(idtype); - OS_Lock_Global(idtype); - while (obj_max > 0) + while (OS_ObjectIdIteratorGetNext(&iter)) { - /* - * Check if the obj_id is both valid and matches - * the specified creator_id - */ - obj_id = OS_common_table[obj_index].active_id; - if (OS_ObjectIdDefined(obj_id) && !OS_ObjectIdEqual(creator_id, OS_OBJECT_CREATOR_ANY) && - !OS_ObjectIdEqual(OS_common_table[obj_index].creator, creator_id)) - { - /* valid object but not a creator match - - * skip the callback for this object */ - obj_id = OS_OBJECT_ID_UNDEFINED; - } - - if (OS_ObjectIdDefined(obj_id)) - { - /* - * Invoke Callback for the object, which must be done - * while the global table is unlocked. - * - * Note this means by the time the callback is done, - * the object could have been deleted by another task. - * - * But this must not invoke a callback with a locked table, - * as the callback function might call other OSAL functions, - * which could deadlock. - */ - OS_Unlock_Global(idtype); - (*callback_ptr)(obj_id, callback_arg); - OS_Lock_Global(idtype); - } - - ++obj_index; - --obj_max; + OS_ObjectIdIteratorProcessEntry(&iter, OS_ForEachDoCallback); } - OS_Unlock_Global(idtype); + + OS_ObjectIdIteratorDestroy(&iter); } } /* end OS_ForEachObjectOfType */ @@ -1170,7 +1462,7 @@ void OS_ForEachObjectOfType(uint32 idtype, osal_id_t creator_id, OS_ArgCallback_ * See description in API and header file for detail * *-----------------------------------------------------------------*/ -uint32 OS_IdentifyObject(osal_id_t object_id) +osal_objtype_t OS_IdentifyObject(osal_id_t object_id) { return OS_ObjectIdToType_Impl(object_id); } /* end OS_IdentifyObject */ @@ -1183,13 +1475,12 @@ uint32 OS_IdentifyObject(osal_id_t object_id) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_GetResourceName(osal_id_t object_id, char *buffer, uint32 buffer_size) +int32 OS_GetResourceName(osal_id_t object_id, char *buffer, size_t buffer_size) { - uint32 idtype; OS_common_record_t *record; int32 return_code; - uint32 name_len; - uint32 local_id; + size_t name_len; + OS_object_token_t token; /* sanity check the passed-in buffer and size */ if (buffer == NULL || buffer_size == 0) @@ -1204,13 +1495,14 @@ int32 OS_GetResourceName(osal_id_t object_id, char *buffer, uint32 buffer_size) */ buffer[0] = 0; - idtype = OS_ObjectIdToType_Impl(object_id); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, idtype, object_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_ObjectIdToType_Impl(object_id), object_id, &token); if (return_code == OS_SUCCESS) { + record = OS_ObjectIdGlobalFromToken(&token); + if (record->name_entry != NULL) { - name_len = strlen(record->name_entry); + name_len = OS_strnlen(record->name_entry, buffer_size); if (buffer_size <= name_len) { /* indicates the name does not fit into supplied buffer */ @@ -1220,7 +1512,8 @@ int32 OS_GetResourceName(osal_id_t object_id, char *buffer, uint32 buffer_size) memcpy(buffer, record->name_entry, name_len); buffer[name_len] = 0; } - OS_Unlock_Global(idtype); + + OS_ObjectIdRelease(&token); } return return_code; @@ -1241,12 +1534,15 @@ int32 OS_GetResourceName(osal_id_t object_id, char *buffer, uint32 buffer_size) * Otherwise OS_SUCCESS is returned. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdToArrayIndex(uint32 idtype, osal_id_t object_id, uint32 *ArrayIndex) +int32 OS_ObjectIdToArrayIndex(osal_objtype_t idtype, osal_id_t object_id, osal_index_t *ArrayIndex) { - uint32 max_id; - uint32 obj_index; - uint32 actual_type; - int32 return_code; + uint32 max_id; + uint32 obj_index; + osal_objtype_t actual_type; + int32 return_code; + + /* Check Parameters */ + OS_CHECK_POINTER(ArrayIndex); obj_index = OS_ObjectIdToSerialNumber_Impl(object_id); actual_type = OS_ObjectIdToType_Impl(object_id); @@ -1269,7 +1565,7 @@ int32 OS_ObjectIdToArrayIndex(uint32 idtype, osal_id_t object_id, uint32 *ArrayI else { return_code = OS_SUCCESS; - *ArrayIndex = obj_index % max_id; + *ArrayIndex = OSAL_INDEX_C(obj_index % max_id); } } diff --git a/src/os/shared/src/osapi-module.c b/src/os/shared/src/osapi-module.c index 8b690e7d4..fd24962d1 100644 --- a/src/os/shared/src/osapi-module.c +++ b/src/os/shared/src/osapi-module.c @@ -41,6 +41,11 @@ #include "os-shared-module.h" #include "os-shared-idmap.h" +/* + * Other OSAL public APIs used by this module + */ +#include "osapi-filesys.h" + /* * Sanity checks on the user-supplied configuration * The relevent OS_MAX limit should be defined @@ -90,7 +95,7 @@ extern OS_static_symbol_record_t OS_STATIC_SYMTABLE_SOURCE[]; * Checks for a symbol name in the static symbol table * *-----------------------------------------------------------------*/ -int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName, const char *ModuleName) { int32 return_code = OS_ERR_NOT_IMPLEMENTED; OS_static_symbol_record_t *StaticSym = OS_STATIC_SYMTABLE_SOURCE; @@ -105,7 +110,8 @@ int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName) return_code = OS_ERROR; break; } - if (strcmp(StaticSym->Name, SymbolName) == 0) + if (strcmp(StaticSym->Name, SymbolName) == 0 && + (ModuleName == NULL || strcmp(StaticSym->Module, ModuleName) == 0)) { /* found matching symbol */ *SymbolAddress = (cpuaddr)StaticSym->Address; @@ -178,29 +184,22 @@ int32 OS_ModuleAPI_Init(void) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *filename) +int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *filename, uint32 flags) { - char translated_path[OS_MAX_LOCAL_PATH_LEN]; - int32 return_code; - int32 filename_status; - uint32 local_id; - OS_common_record_t *record; + char translated_path[OS_MAX_LOCAL_PATH_LEN]; + int32 return_code; + int32 filename_status; + OS_object_token_t token; + OS_module_internal_record_t *module; /* - ** Check parameters - ** - ** Note "filename" is not checked, because in certain configurations it can be validly - ** null. filename is checked for NULL-ness by the OS_TranslatePath() later. + * Check parameters + * + * Note "filename" is not checked, because in certain configurations it can be validly + * null. filename is checked for NULL-ness by the OS_TranslatePath() later. */ - if ((module_id == NULL) || (module_name == NULL)) - { - return (OS_INVALID_POINTER); - } - - if (strlen(module_name) >= OS_MAX_API_NAME) - { - return (OS_ERR_NAME_TOO_LONG); - } + OS_CHECK_POINTER(module_id); + OS_CHECK_APINAME(module_name); /* * Preemptively translate the filename, and hold it in a temporary buffer. @@ -214,12 +213,15 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f filename_status = OS_TranslatePath(filename, translated_path); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, module_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, module_name, &token); if (return_code == OS_SUCCESS) { - memset(&OS_module_table[local_id], 0, sizeof(OS_module_internal_record_t)); - strncpy(OS_module_table[local_id].module_name, module_name, OS_MAX_API_NAME); - record->name_entry = OS_module_table[local_id].module_name; + module = OS_OBJECT_TABLE_GET(OS_module_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, module, module_name, module_name); + + module->flags = flags; /* save user-supplied flags */ /* * Check the statically-linked module list. @@ -232,7 +234,12 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f * returns OS_ERR_NAME_NOT_FOUND. */ return_code = OS_ModuleLoad_Static(module_name); - if (return_code != OS_SUCCESS) + if (return_code == OS_SUCCESS) + { + /* mark this as a statically loaded module */ + module->module_type = OS_MODULE_TYPE_STATIC; + } + else { /* * If this is NOT a static module, then the module file must be loaded by normal @@ -247,15 +254,16 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f else { /* supplied filename was valid, so store a copy for future reference */ - strncpy(OS_module_table[local_id].file_name, filename, OS_MAX_PATH_LEN); + strncpy(module->file_name, filename, sizeof(module->file_name) - 1); + module->module_type = OS_MODULE_TYPE_DYNAMIC; /* Now call the OS-specific implementation. This reads info from the module table. */ - return_code = OS_ModuleLoad_Impl(local_id, translated_path); + return_code = OS_ModuleLoad_Impl(&token, translated_path); } } /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, module_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, module_id); } return (return_code); @@ -272,20 +280,27 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f *-----------------------------------------------------------------*/ int32 OS_ModuleUnload(osal_id_t module_id) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + OS_module_internal_record_t *module; + int32 return_code; + OS_object_token_t token; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, module_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, module_id, &token); if (return_code == OS_SUCCESS) { + module = OS_OBJECT_TABLE_GET(OS_module_table, token); + /* - * Only call the implementation if the loader is enabled + * Only call the implementation if the file was actually loaded. + * If this is a static module, then this is just a placeholder and + * it means there was no file actually loaded. */ - return_code = OS_ModuleUnload_Impl(local_id); + if (module->module_type == OS_MODULE_TYPE_DYNAMIC) + { + return_code = OS_ModuleUnload_Impl(&token); + } /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -301,27 +316,28 @@ int32 OS_ModuleUnload(osal_id_t module_id) *-----------------------------------------------------------------*/ int32 OS_ModuleInfo(osal_id_t module_id, OS_module_prop_t *module_prop) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + OS_common_record_t * record; + OS_module_internal_record_t *module; + int32 return_code; + OS_object_token_t token; /* Check parameters */ - if (module_prop == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(module_prop); memset(module_prop, 0, sizeof(OS_module_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, module_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, module_id, &token); if (return_code == OS_SUCCESS) { - strncpy(module_prop->name, record->name_entry, OS_MAX_API_NAME - 1); - strncpy(module_prop->filename, OS_module_table[local_id].file_name, OS_MAX_API_NAME - 1); + record = OS_OBJECT_TABLE_GET(OS_global_module_table, token); + module = OS_OBJECT_TABLE_GET(OS_module_table, token); + + strncpy(module_prop->name, record->name_entry, sizeof(module_prop->name) - 1); + strncpy(module_prop->filename, module->file_name, sizeof(module_prop->filename) - 1); - return_code = OS_ModuleGetInfo_Impl(local_id, module_prop); + return_code = OS_ModuleGetInfo_Impl(&token, module_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -339,21 +355,18 @@ int32 OS_ModuleInfo(osal_id_t module_id, OS_module_prop_t *module_prop) int32 OS_SymbolLookup(cpuaddr *SymbolAddress, const char *SymbolName) { int32 return_code; - int32 status; + int32 staticsym_status; /* ** Check parameters */ - if ((SymbolAddress == NULL) || (SymbolName == NULL)) - { - return (OS_INVALID_POINTER); - } + OS_CHECK_POINTER(SymbolAddress); + OS_CHECK_POINTER(SymbolName); /* - * if the module loader is included, then call the - * OS symbol lookup implementation function first. + * attempt to find the symbol in the global symbol table. */ - return_code = OS_SymbolLookup_Impl(SymbolAddress, SymbolName); + return_code = OS_GlobalSymbolLookup_Impl(SymbolAddress, SymbolName); /* * If the OS call did not find the symbol or the loader is @@ -361,20 +374,15 @@ int32 OS_SymbolLookup(cpuaddr *SymbolAddress, const char *SymbolName) */ if (return_code != OS_SUCCESS) { - status = OS_SymbolLookup_Static(SymbolAddress, SymbolName); + staticsym_status = OS_SymbolLookup_Static(SymbolAddress, SymbolName, NULL); /* - * NOTE: - * The OS_ERR_NOT_IMPLEMENTED code should only be returned - * if _neither_ the SymbolLookup_Impl _nor_ the static table - * lookup capabilities are implemented. - * - * If either of these are implemented then the returned - * value should be OS_ERROR for a not-found result. + * Only overwrite the return code if static lookup was successful. + * Otherwise keep the error code from the low level implementation. */ - if (status == OS_SUCCESS || return_code == OS_ERR_NOT_IMPLEMENTED) + if (staticsym_status == OS_SUCCESS) { - return_code = status; + return_code = staticsym_status; } } @@ -384,25 +392,70 @@ int32 OS_SymbolLookup(cpuaddr *SymbolAddress, const char *SymbolName) /*---------------------------------------------------------------- * - * Function: OS_SymbolTableDump + * Function: OS_ModuleSymbolLookup * * Purpose: Implemented per public OSAL API * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_SymbolTableDump(const char *filename, uint32 SizeLimit) +int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const char *symbol_name) { - int32 return_code; - char translated_path[OS_MAX_LOCAL_PATH_LEN]; + int32 return_code; + int32 staticsym_status; + OS_common_record_t *record; + OS_object_token_t token; /* ** Check parameters */ - if (filename == NULL) + OS_CHECK_POINTER(symbol_address); + OS_CHECK_POINTER(symbol_name); + + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, module_id, &token); + if (return_code == OS_SUCCESS) { - return (OS_INVALID_POINTER); + record = OS_OBJECT_TABLE_GET(OS_global_module_table, token); + + return_code = OS_ModuleSymbolLookup_Impl(&token, symbol_address, symbol_name); + if (return_code != OS_SUCCESS) + { + /* look for a static symbol that also matches this module name */ + staticsym_status = OS_SymbolLookup_Static(symbol_address, symbol_name, record->name_entry); + + /* + * Only overwrite the return code if static lookup was successful. + * Otherwise keep the error code from the low level implementation. + */ + if (staticsym_status == OS_SUCCESS) + { + return_code = staticsym_status; + } + } + + OS_ObjectIdRelease(&token); } + return (return_code); + +} /* end OS_ModuleSymbolLookup */ + +/*---------------------------------------------------------------- + * + * Function: OS_SymbolTableDump + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_SymbolTableDump(const char *filename, size_t SizeLimit) +{ + int32 return_code; + char translated_path[OS_MAX_LOCAL_PATH_LEN]; + OS_object_token_t token; + + /* Check parameters */ + OS_CHECK_POINTER(filename); + /* ** Translate the filename to the Host System */ @@ -421,11 +474,15 @@ int32 OS_SymbolTableDump(const char *filename, uint32 SizeLimit) * underlying implementation may safely use globals for * state storage. */ - OS_Lock_Global(LOCAL_OBJID_TYPE); + return_code = OS_ObjectIdTransactionInit(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, &token); + if (return_code != OS_SUCCESS) + { + return (return_code); + } return_code = OS_SymbolTableDump_Impl(translated_path, SizeLimit); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdTransactionCancel(&token); return (return_code); diff --git a/src/os/shared/src/osapi-mutex.c b/src/os/shared/src/osapi-mutex.c index 28cbc73ee..93cc0e92f 100644 --- a/src/os/shared/src/osapi-mutex.c +++ b/src/os/shared/src/osapi-mutex.c @@ -41,6 +41,11 @@ #include "os-shared-idmap.h" #include "os-shared-mutex.h" +/* + * Other OSAL public APIs used by this module + */ +#include "osapi-task.h" + /* * Sanity checks on the user-supplied configuration * The relevent OS_MAX limit should be defined and greater than zero @@ -88,34 +93,28 @@ int32 OS_MutexAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + int32 return_code; + OS_object_token_t token; + OS_mutex_internal_record_t *mutex; - /* Check for NULL pointers */ - if (sem_id == NULL || sem_name == NULL) - { - return OS_INVALID_POINTER; - } - - if (strlen(sem_name) >= OS_MAX_API_NAME) - { - return OS_ERR_NAME_TOO_LONG; - } + /* Check parameters */ + OS_CHECK_POINTER(sem_id); + OS_CHECK_APINAME(sem_name); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - strcpy(OS_mutex_table[local_id].obj_name, sem_name); - record->name_entry = OS_mutex_table[local_id].obj_name; + mutex = OS_OBJECT_TABLE_GET(OS_mutex_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, mutex, obj_name, sem_name); /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_MutSemCreate_Impl(local_id, options); + return_code = OS_MutSemCreate_Impl(&token, options); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, sem_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, sem_id); } return return_code; @@ -132,17 +131,16 @@ int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) *-----------------------------------------------------------------*/ int32 OS_MutSemDelete(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_MutSemDelete_Impl(local_id); + return_code = OS_MutSemDelete_Impl(&token); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -159,28 +157,28 @@ int32 OS_MutSemDelete(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_MutSemGive(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; - osal_id_t self_task; + OS_mutex_internal_record_t *mutex; + OS_object_token_t token; + int32 return_code; + osal_id_t self_task; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { + mutex = OS_OBJECT_TABLE_GET(OS_mutex_table, token); + self_task = OS_TaskGetId(); - if (!OS_ObjectIdEqual(OS_mutex_table[local_id].last_owner, self_task)) + if (!OS_ObjectIdEqual(mutex->last_owner, self_task)) { - OS_DEBUG("WARNING: Task %lu giving mutex %lu while owned by task %lu\n", - OS_ObjectIdToInteger(self_task), - OS_ObjectIdToInteger(sem_id), - OS_ObjectIdToInteger(OS_mutex_table[local_id].last_owner)); + OS_DEBUG("WARNING: Task %lu giving mutex %lu while owned by task %lu\n", OS_ObjectIdToInteger(self_task), + OS_ObjectIdToInteger(sem_id), OS_ObjectIdToInteger(mutex->last_owner)); } - OS_mutex_table[local_id].last_owner = OS_OBJECT_ID_UNDEFINED; + mutex->last_owner = OS_OBJECT_ID_UNDEFINED; - return_code = OS_MutSemGive_Impl(local_id); + return_code = OS_MutSemGive_Impl(&token); } return return_code; @@ -197,29 +195,30 @@ int32 OS_MutSemGive(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_MutSemTake(osal_id_t sem_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; - osal_id_t self_task; + OS_mutex_internal_record_t *mutex; + OS_object_token_t token; + int32 return_code; + osal_id_t self_task; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_MutSemTake_Impl(local_id); + mutex = OS_OBJECT_TABLE_GET(OS_mutex_table, token); + + return_code = OS_MutSemTake_Impl(&token); if (return_code == OS_SUCCESS) { self_task = OS_TaskGetId(); - if (OS_ObjectIdDefined(OS_mutex_table[local_id].last_owner)) + if (OS_ObjectIdDefined(mutex->last_owner)) { OS_DEBUG("WARNING: Task %lu taking mutex %lu while owned by task %lu\n", - OS_ObjectIdToInteger(self_task), - OS_ObjectIdToInteger(sem_id), - OS_ObjectIdToInteger(OS_mutex_table[local_id].last_owner)); + OS_ObjectIdToInteger(self_task), OS_ObjectIdToInteger(sem_id), + OS_ObjectIdToInteger(mutex->last_owner)); } - OS_mutex_table[local_id].last_owner = self_task; + mutex->last_owner = self_task; } } @@ -239,10 +238,9 @@ int32 OS_MutSemGetIdByName(osal_id_t *sem_id, const char *sem_name) { int32 return_code; - if (sem_id == NULL || sem_name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(sem_id); + OS_CHECK_POINTER(sem_name); return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, sem_name, sem_id); @@ -262,25 +260,24 @@ int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop) { OS_common_record_t *record; int32 return_code; - uint32 local_id; + OS_object_token_t token; /* Check parameters */ - if (mut_prop == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(mut_prop); memset(mut_prop, 0, sizeof(OS_mut_sem_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - strncpy(mut_prop->name, record->name_entry, OS_MAX_API_NAME - 1); + record = OS_OBJECT_TABLE_GET(OS_global_mutex_table, token); + + strncpy(mut_prop->name, record->name_entry, sizeof(mut_prop->name) - 1); mut_prop->creator = record->creator; - return_code = OS_MutSemGetInfo_Impl(local_id, mut_prop); + return_code = OS_MutSemGetInfo_Impl(&token, mut_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-network.c b/src/os/shared/src/osapi-network.c index 3864288e3..70367fa16 100644 --- a/src/os/shared/src/osapi-network.c +++ b/src/os/shared/src/osapi-network.c @@ -63,28 +63,20 @@ int32 OS_NetworkAPI_Init(void) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_NetworkGetHostName(char *host_name, uint32 name_len) +int32 OS_NetworkGetHostName(char *host_name, size_t name_len) { - uint32 return_code; + int32 return_code; - if (host_name == NULL) - { - return_code = OS_INVALID_POINTER; - } - else if (name_len == 0) - { - return_code = OS_ERROR; - } - else - { - /* delegate to low-level API */ - return_code = OS_NetworkGetHostName_Impl(host_name, name_len); + /* Check parameters */ + OS_CHECK_POINTER(host_name); + OS_CHECK_SIZE(name_len); - if (return_code != OS_SUCCESS) - { - /* return an empty string on failure, just in case */ - host_name[0] = 0; - } + /* delegate to low-level API */ + return_code = OS_NetworkGetHostName_Impl(host_name, name_len); + if (return_code != OS_SUCCESS) + { + /* return an empty string on failure, just in case */ + host_name[0] = 0; } return (return_code); diff --git a/src/os/shared/src/osapi-printf.c b/src/os/shared/src/osapi-printf.c index e420dfeab..f3bcac68c 100644 --- a/src/os/shared/src/osapi-printf.c +++ b/src/os/shared/src/osapi-printf.c @@ -47,6 +47,7 @@ #include #include #include +#include /* * User defined include files @@ -78,22 +79,20 @@ int32 OS_ConsoleAPI_Init(void) { OS_console_internal_record_t *console; int32 return_code; - uint32 local_id; - OS_common_record_t * record; + OS_object_token_t token; memset(&OS_console_table, 0, sizeof(OS_console_table)); /* * Configure a console device to be used for OS_printf() calls. */ - return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_CONSOLE, OS_PRINTF_CONSOLE_NAME, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_CONSOLE, OS_PRINTF_CONSOLE_NAME, &token); if (return_code == OS_SUCCESS) { - console = &OS_console_table[local_id]; + console = OS_OBJECT_TABLE_GET(OS_console_table, token); - record->name_entry = console->device_name; - strncpy(console->device_name, OS_PRINTF_CONSOLE_NAME, sizeof(console->device_name) - 1); - console->device_name[sizeof(console->device_name) - 1] = 0; + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, console, device_name, OS_PRINTF_CONSOLE_NAME); /* * Initialize the ring buffer pointers @@ -101,10 +100,10 @@ int32 OS_ConsoleAPI_Init(void) console->BufBase = OS_printf_buffer_mem; console->BufSize = sizeof(OS_printf_buffer_mem); - return_code = OS_ConsoleCreate_Impl(local_id); + return_code = OS_ConsoleCreate_Impl(&token); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, &OS_SharedGlobalVars.PrintfConsoleId); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, &OS_SharedGlobalVars.PrintfConsoleId); /* * Printf can be enabled by default now that the buffer is configured. @@ -112,7 +111,7 @@ int32 OS_ConsoleAPI_Init(void) OS_SharedGlobalVars.PrintfEnabled = true; } - return OS_SUCCESS; + return return_code; } /* end OS_ConsoleAPI_Init */ /* @@ -137,10 +136,10 @@ int32 OS_ConsoleAPI_Init(void) * Either the entire string should be written, or none of it. * *-----------------------------------------------------------------*/ -static int32 OS_Console_CopyOut(OS_console_internal_record_t *console, const char *Str, uint32 *NextWritePos) +static int32 OS_Console_CopyOut(OS_console_internal_record_t *console, const char *Str, size_t *NextWritePos) { const char *pmsg; - uint32 WriteOffset; + size_t WriteOffset; int32 return_code; return_code = OS_ERROR; @@ -192,15 +191,14 @@ static int32 OS_Console_CopyOut(OS_console_internal_record_t *console, const cha int32 OS_ConsoleWrite(osal_id_t console_id, const char *Str) { int32 return_code; - OS_common_record_t * record; - uint32 local_id; + OS_object_token_t token; OS_console_internal_record_t *console; - uint32 PendingWritePos; + size_t PendingWritePos; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_CONSOLE, console_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_CONSOLE, console_id, &token); if (return_code == OS_SUCCESS) { - console = &OS_console_table[local_id]; + console = OS_OBJECT_TABLE_GET(OS_console_table, token); /* * The entire string should be put to the ring buffer, @@ -236,9 +234,9 @@ int32 OS_ConsoleWrite(osal_id_t console_id, const char *Str) * This is done while still locked, so it can support * either a synchronous or asynchronous implementation. */ - OS_ConsoleWakeup_Impl(local_id); + OS_ConsoleWakeup_Impl(&token); - OS_Unlock_Global(OS_OBJECT_TYPE_OS_CONSOLE); + OS_ObjectIdRelease(&token); } return return_code; @@ -258,6 +256,8 @@ void OS_printf(const char *String, ...) char msg_buffer[OS_BUFFER_SIZE]; int actualsz; + BUGCHECK((String) != NULL, ) + if (!OS_SharedGlobalVars.Initialized) { /* diff --git a/src/os/shared/src/osapi-queue.c b/src/os/shared/src/osapi-queue.c index 9400f0f3b..f50278f8e 100644 --- a/src/os/shared/src/osapi-queue.c +++ b/src/os/shared/src/osapi-queue.c @@ -87,42 +87,36 @@ int32 OS_QueueAPI_Init(void) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, uint32 queue_depth, uint32 data_size, uint32 flags) +int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcount_t queue_depth, size_t data_size, + uint32 flags) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; - - if (queue_name == NULL || queue_id == NULL) - { - return OS_INVALID_POINTER; - } + int32 return_code; + OS_object_token_t token; + OS_queue_internal_record_t *queue; - if (strlen(queue_name) >= OS_MAX_API_NAME) - { - return OS_ERR_NAME_TOO_LONG; - } - - if (queue_depth > OS_QUEUE_MAX_DEPTH) - { - return OS_QUEUE_INVALID_SIZE; - } + /* validate inputs */ + OS_CHECK_POINTER(queue_id); + OS_CHECK_APINAME(queue_name); + OS_CHECK_SIZE(data_size); + ARGCHECK(queue_depth <= OS_QUEUE_MAX_DEPTH, OS_QUEUE_INVALID_SIZE); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, queue_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, queue_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal queue table */ - strcpy(OS_queue_table[local_id].queue_name, queue_name); - record->name_entry = OS_queue_table[local_id].queue_name; - OS_queue_table[local_id].max_depth = queue_depth; - OS_queue_table[local_id].max_size = data_size; + queue = OS_OBJECT_TABLE_GET(OS_queue_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, queue, queue_name, queue_name); + + queue->max_depth = queue_depth; + queue->max_size = data_size; /* Now call the OS-specific implementation. This reads info from the queue table. */ - return_code = OS_QueueCreate_Impl(local_id, flags); + return_code = OS_QueueCreate_Impl(&token, flags); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, queue_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, queue_id); } return return_code; @@ -139,17 +133,16 @@ int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, uint32 queue_d *-----------------------------------------------------------------*/ int32 OS_QueueDelete(osal_id_t queue_id) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, queue_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, queue_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_QueueDelete_Impl(local_id); + return_code = OS_QueueDelete_Impl(&token); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -164,34 +157,32 @@ int32 OS_QueueDelete(osal_id_t queue_id) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGet(osal_id_t queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) +int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; + OS_queue_internal_record_t *queue; /* Check Parameters */ - if (data == NULL || size_copied == NULL) - { - return_code = OS_INVALID_POINTER; - } - else + OS_CHECK_POINTER(data); + OS_CHECK_POINTER(size_copied); + + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &token); + if (return_code == OS_SUCCESS) { - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &local_id, &record); - if (return_code == OS_SUCCESS) + queue = OS_OBJECT_TABLE_GET(OS_queue_table, token); + + if (size < queue->max_size) { - if (size < OS_queue_table[local_id].max_size) - { - /* - ** The buffer that the user is passing in is potentially too small - */ - *size_copied = 0; - return_code = OS_QUEUE_INVALID_SIZE; - } - else - { - return_code = OS_QueueGet_Impl(local_id, data, size, size_copied, timeout); - } + /* + ** The buffer that the user is passing in is potentially too small + */ + *size_copied = 0; + return_code = OS_QUEUE_INVALID_SIZE; + } + else + { + return_code = OS_QueueGet_Impl(&token, data, size, size_copied, timeout); } } @@ -206,23 +197,30 @@ int32 OS_QueueGet(osal_id_t queue_id, void *data, uint32 size, uint32 *size_copi * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_QueuePut(osal_id_t queue_id, const void *data, uint32 size, uint32 flags) +int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flags) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; + OS_queue_internal_record_t *queue; /* Check Parameters */ - if (data == NULL) - { - return_code = OS_INVALID_POINTER; - } - else + OS_CHECK_POINTER(data); + + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &token); + if (return_code == OS_SUCCESS) { - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &local_id, &record); - if (return_code == OS_SUCCESS) + queue = OS_OBJECT_TABLE_GET(OS_queue_table, token); + + if (size > queue->max_size) + { + /* + ** The buffer that the user is passing in is too large + */ + return_code = OS_QUEUE_INVALID_SIZE; + } + else { - return_code = OS_QueuePut_Impl(local_id, data, size, flags); + return_code = OS_QueuePut_Impl(&token, data, size, flags); } } @@ -241,10 +239,9 @@ int32 OS_QueueGetIdByName(osal_id_t *queue_id, const char *queue_name) { int32 return_code; - if (queue_id == NULL || queue_name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check Parameters */ + OS_CHECK_POINTER(queue_id); + OS_CHECK_POINTER(queue_name); return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, queue_name, queue_id); @@ -264,20 +261,19 @@ int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop) { OS_common_record_t *record; int32 return_code; - uint32 local_id; + OS_object_token_t token; /* Check parameters */ - if (queue_prop == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(queue_prop); memset(queue_prop, 0, sizeof(OS_queue_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, queue_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, queue_id, &token); if (return_code == OS_SUCCESS) { - strncpy(queue_prop->name, record->name_entry, OS_MAX_API_NAME - 1); + record = OS_OBJECT_TABLE_GET(OS_global_queue_table, token); + + strncpy(queue_prop->name, record->name_entry, sizeof(queue_prop->name) - 1); queue_prop->creator = record->creator; /* @@ -285,7 +281,7 @@ int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop) * But this could be added in the future (i.e. current/max depth, msg size, etc) */ - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-select.c b/src/os/shared/src/osapi-select.c index 5a3fe885f..f74453366 100644 --- a/src/os/shared/src/osapi-select.c +++ b/src/os/shared/src/osapi-select.c @@ -60,18 +60,18 @@ *-----------------------------------------------------------------*/ int32 OS_SelectSingle(osal_id_t objid, uint32 *StateFlags, int32 msecs) { - int32 return_code; - uint32 local_id; - OS_common_record_t *record; + int32 return_code; + OS_object_token_t token; - if (StateFlags == NULL) - return OS_INVALID_POINTER; + /* check parameters */ + OS_CHECK_POINTER(StateFlags); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, objid, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, objid, &token); if (return_code == OS_SUCCESS) { - return_code = OS_SelectSingle_Impl(local_id, StateFlags, msecs); - OS_ObjectIdRefcountDecr(record); + return_code = OS_SelectSingle_Impl(&token, StateFlags, msecs); + + OS_ObjectIdRelease(&token); } return return_code; @@ -89,6 +89,12 @@ int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs) { int32 return_code; + /* + * Check parameters + * + * Note "ReadSet" and "WriteSet" are not checked, because in certain configurations they can be validly null. + */ + /* * This does not currently increment any refcounts. * That means a file/socket can be closed while actively inside a @@ -109,8 +115,8 @@ int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs) *-----------------------------------------------------------------*/ int32 OS_SelectFdZero(OS_FdSet *Set) { - if (Set == NULL) - return OS_INVALID_POINTER; + /* check parameters */ + OS_CHECK_POINTER(Set); memset(Set, 0, sizeof(OS_FdSet)); return OS_SUCCESS; @@ -126,11 +132,11 @@ int32 OS_SelectFdZero(OS_FdSet *Set) *-----------------------------------------------------------------*/ int32 OS_SelectFdAdd(OS_FdSet *Set, osal_id_t objid) { - int32 return_code; - uint32 local_id; + int32 return_code; + osal_index_t local_id; - if (Set == NULL) - return OS_INVALID_POINTER; + /* check parameters */ + OS_CHECK_POINTER(Set); return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id); if (return_code == OS_SUCCESS) @@ -151,11 +157,11 @@ int32 OS_SelectFdAdd(OS_FdSet *Set, osal_id_t objid) *-----------------------------------------------------------------*/ int32 OS_SelectFdClear(OS_FdSet *Set, osal_id_t objid) { - int32 return_code; - uint32 local_id; + int32 return_code; + osal_index_t local_id; - if (Set == NULL) - return OS_INVALID_POINTER; + /* check parameters */ + OS_CHECK_POINTER(Set); return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id); if (return_code == OS_SUCCESS) @@ -176,11 +182,11 @@ int32 OS_SelectFdClear(OS_FdSet *Set, osal_id_t objid) *-----------------------------------------------------------------*/ bool OS_SelectFdIsSet(OS_FdSet *Set, osal_id_t objid) { - int32 return_code; - uint32 local_id; + int32 return_code; + osal_index_t local_id; - if (Set == NULL) - return false; + /* check parameters */ + BUGCHECK(Set != NULL, false); return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id); if (return_code != OS_SUCCESS) diff --git a/src/os/shared/src/osapi-shell.c b/src/os/shared/src/osapi-shell.c index d59668210..0443259c1 100644 --- a/src/os/shared/src/osapi-shell.c +++ b/src/os/shared/src/osapi-shell.c @@ -52,21 +52,17 @@ *-----------------------------------------------------------------*/ int32 OS_ShellOutputToFile(const char *Cmd, osal_id_t filedes) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - if (Cmd == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(Cmd); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_ShellOutputToFile_Impl(local_id, Cmd); - OS_ObjectIdRefcountDecr(record); + return_code = OS_ShellOutputToFile_Impl(&token, Cmd); + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-sockets.c b/src/os/shared/src/osapi-sockets.c index 4a66c5fdb..cdf0fded9 100644 --- a/src/os/shared/src/osapi-sockets.c +++ b/src/os/shared/src/osapi-sockets.c @@ -42,6 +42,12 @@ #include "os-shared-idmap.h" #include "os-shared-file.h" #include "os-shared-sockets.h" +#include "os-shared-common.h" + +/* + * Other OSAL public APIs used by this module + */ +#include "osapi-select.h" /* * Global data for the API @@ -84,11 +90,13 @@ int32 OS_SocketAPI_Init(void) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -void OS_CreateSocketName(uint32 local_id, const OS_SockAddr_t *Addr, const char *parent_name) +void OS_CreateSocketName(const OS_object_token_t *token, const OS_SockAddr_t *Addr, const char *parent_name) { - int32 len; + size_t len; uint16 port; - OS_stream_internal_record_t *sock = &OS_stream_table[local_id]; + OS_stream_internal_record_t *sock; + + sock = OS_OBJECT_TABLE_GET(OS_stream_table, *token); if (OS_SocketAddrToString_Impl(sock->stream_name, OS_MAX_API_NAME, Addr) != OS_SUCCESS) { @@ -96,7 +104,7 @@ void OS_CreateSocketName(uint32 local_id, const OS_SockAddr_t *Addr, const char } if (OS_SocketAddrGetPort_Impl(&port, Addr) == OS_SUCCESS) { - len = strlen(sock->stream_name); + len = OS_strnlen(sock->stream_name, sizeof(sock->stream_name)); snprintf(&sock->stream_name[len], OS_MAX_API_NAME - len, ":%u", (unsigned int)port); } sock->stream_name[OS_MAX_API_NAME - 1] = 0; @@ -104,7 +112,7 @@ void OS_CreateSocketName(uint32 local_id, const OS_SockAddr_t *Addr, const char if (parent_name) { /* Append the name from the parent socket. */ - len = strlen(sock->stream_name); + len = OS_strnlen(sock->stream_name, sizeof(sock->stream_name)); snprintf(&sock->stream_name[len], sizeof(sock->stream_name) - len, "-%s", parent_name); sock->stream_name[sizeof(sock->stream_name) - 1] = 0; } @@ -120,30 +128,29 @@ void OS_CreateSocketName(uint32 local_id, const OS_SockAddr_t *Addr, const char *-----------------------------------------------------------------*/ int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_t Type) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + OS_object_token_t token; + OS_stream_internal_record_t *stream; + int32 return_code; /* Check for NULL pointers */ - if (sock_id == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(sock_id); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &token); if (return_code == OS_SUCCESS) { + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + /* Save all the data to our own internal table */ - memset(&OS_stream_table[local_id], 0, sizeof(OS_stream_internal_record_t)); - OS_stream_table[local_id].socket_domain = Domain; - OS_stream_table[local_id].socket_type = Type; + memset(stream, 0, sizeof(OS_stream_internal_record_t)); + stream->socket_domain = Domain; + stream->socket_type = Type; /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_SocketOpen_Impl(local_id); + return_code = OS_SocketOpen_Impl(&token); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, sock_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, sock_id); } return return_code; @@ -159,43 +166,43 @@ int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_ *-----------------------------------------------------------------*/ int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_common_record_t * record; + OS_stream_internal_record_t *stream; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - if (Addr == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(Addr); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_domain == OS_SocketDomain_INVALID) + record = OS_OBJECT_TABLE_GET(OS_global_stream_table, token); + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + if (stream->socket_domain == OS_SocketDomain_INVALID) { /* Not a socket */ return_code = OS_ERR_INCORRECT_OBJ_TYPE; } - else if (record->refcount != 0 || - (OS_stream_table[local_id].stream_state & (OS_STREAM_STATE_BOUND | OS_STREAM_STATE_CONNECTED)) != 0) + else if ((stream->stream_state & (OS_STREAM_STATE_BOUND | OS_STREAM_STATE_CONNECTED)) != 0) { /* Socket must be neither bound nor connected */ return_code = OS_ERR_INCORRECT_OBJ_STATE; } else { - return_code = OS_SocketBind_Impl(local_id, Addr); + return_code = OS_SocketBind_Impl(&token, Addr); if (return_code == OS_SUCCESS) { - OS_CreateSocketName(local_id, Addr, NULL); - record->name_entry = OS_stream_table[local_id].stream_name; - OS_stream_table[local_id].stream_state |= OS_STREAM_STATE_BOUND; + OS_CreateSocketName(&token, Addr, NULL); + record->name_entry = stream->stream_name; + stream->stream_state |= OS_STREAM_STATE_BOUND; } } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -212,17 +219,17 @@ int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr) *-----------------------------------------------------------------*/ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t *Addr, int32 timeout) { - OS_common_record_t *record; - OS_common_record_t *connrecord; - uint32 local_id; - uint32 conn_id = 0; - int32 return_code; + OS_common_record_t * sock_record; + OS_common_record_t * conn_record; + OS_stream_internal_record_t *sock; + OS_stream_internal_record_t *conn; + OS_object_token_t sock_token; + OS_object_token_t conn_token; + int32 return_code; /* Check Parameters */ - if (Addr == NULL || connsock_id == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(Addr); + OS_CHECK_POINTER(connsock_id); /* * Note: setting "connrecord" here avoids a false warning @@ -231,18 +238,25 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t * * return_code is checked, and return_code is only * set to OS_SUCCESS when connrecord is also initialized) */ - connrecord = NULL; - - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + conn_record = NULL; + sock_record = NULL; + sock = NULL; + conn = NULL; + memset(&sock_token, 0, sizeof(sock_token)); + memset(&conn_token, 0, sizeof(conn_token)); + + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &sock_token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_type != OS_SocketType_STREAM) + sock_record = OS_OBJECT_TABLE_GET(OS_global_stream_table, sock_token); + sock = OS_OBJECT_TABLE_GET(OS_stream_table, sock_token); + + if (sock->socket_type != OS_SocketType_STREAM) { /* Socket must be of the STREAM variety */ return_code = OS_ERR_INCORRECT_OBJ_TYPE; } - else if ((OS_stream_table[local_id].stream_state & (OS_STREAM_STATE_BOUND | OS_STREAM_STATE_CONNECTED)) != - OS_STREAM_STATE_BOUND) + else if ((sock->stream_state & (OS_STREAM_STATE_BOUND | OS_STREAM_STATE_CONNECTED)) != OS_STREAM_STATE_BOUND) { /* Socket must be bound but not connected */ return_code = OS_ERR_INCORRECT_OBJ_STATE; @@ -250,50 +264,35 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t * else { /* Now create a unique ID for the connection */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &conn_id, &connrecord); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &conn_token); if (return_code == OS_SUCCESS) { + conn_record = OS_OBJECT_TABLE_GET(OS_global_stream_table, conn_token); + conn = OS_OBJECT_TABLE_GET(OS_stream_table, sock_token); + /* Incr the refcount to record the fact that an operation is pending on this */ - memset(&OS_stream_table[conn_id], 0, sizeof(OS_stream_internal_record_t)); - OS_stream_table[conn_id].socket_domain = OS_stream_table[local_id].socket_domain; - OS_stream_table[conn_id].socket_type = OS_stream_table[local_id].socket_type; - ++connrecord->refcount; - return_code = OS_ObjectIdFinalizeNew(return_code, connrecord, connsock_id); - } - } + memset(conn, 0, sizeof(OS_stream_internal_record_t)); - /* If failure happened here, decrement the refcount of the listening socket now */ - if (return_code != OS_SUCCESS) - { - OS_ObjectIdRefcountDecr(record); - } - } + conn->socket_domain = sock->socket_domain; + conn->socket_type = sock->socket_type; - if (return_code == OS_SUCCESS) - { - OS_SocketAddrInit_Impl(Addr, OS_stream_table[local_id].socket_domain); + OS_SocketAddrInit_Impl(Addr, sock->socket_domain); - /* The actual accept impl is done without global table lock, only refcount lock */ - return_code = OS_SocketAccept_Impl(local_id, conn_id, Addr, timeout); + return_code = OS_SocketAccept_Impl(&sock_token, &conn_token, Addr, timeout); - OS_Lock_Global(LOCAL_OBJID_TYPE); - if (return_code == OS_SUCCESS) - { - /* Generate an entry name based on the remote address */ - OS_CreateSocketName(conn_id, Addr, record->name_entry); - connrecord->name_entry = OS_stream_table[conn_id].stream_name; - OS_stream_table[conn_id].stream_state |= OS_STREAM_STATE_CONNECTED; - } - else - { - /* Clear the connrecord */ - connrecord->active_id = OS_OBJECT_ID_UNDEFINED; + if (return_code == OS_SUCCESS) + { + /* Generate an entry name based on the remote address */ + OS_CreateSocketName(&conn_token, Addr, sock_record->name_entry); + conn_record->name_entry = conn->stream_name; + conn->stream_state |= OS_STREAM_STATE_CONNECTED; + } + + return_code = OS_ObjectIdFinalizeNew(return_code, &conn_token, connsock_id); + } } - /* Decrement both ref counters that were increased earlier */ - --record->refcount; - --connrecord->refcount; - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&sock_token); } return return_code; @@ -309,48 +308,38 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t * *-----------------------------------------------------------------*/ int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 Timeout) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_stream_internal_record_t *stream; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - if (Addr == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(Addr); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_domain == OS_SocketDomain_INVALID) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + if (stream->socket_domain == OS_SocketDomain_INVALID) { return_code = OS_ERR_INCORRECT_OBJ_TYPE; } - else if (OS_stream_table[local_id].socket_type == OS_SocketType_STREAM && - (OS_stream_table[local_id].stream_state & OS_STREAM_STATE_CONNECTED) != 0) + else if (stream->socket_type == OS_SocketType_STREAM && (stream->stream_state & OS_STREAM_STATE_CONNECTED) != 0) { /* Stream socket must not be connected */ return_code = OS_ERR_INCORRECT_OBJ_STATE; } else { - ++record->refcount; - } - OS_Unlock_Global(LOCAL_OBJID_TYPE); - } - - if (return_code == OS_SUCCESS) - { - return_code = OS_SocketConnect_Impl(local_id, Addr, Timeout); + return_code = OS_SocketConnect_Impl(&token, Addr, Timeout); - OS_Lock_Global(LOCAL_OBJID_TYPE); - if (return_code == OS_SUCCESS) - { - OS_stream_table[local_id].stream_state |= - OS_STREAM_STATE_CONNECTED | OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; + if (return_code == OS_SUCCESS) + { + stream->stream_state |= OS_STREAM_STATE_CONNECTED | OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; + } } - --record->refcount; - OS_Unlock_Global(LOCAL_OBJID_TYPE); + + OS_ObjectIdRelease(&token); } return return_code; @@ -364,36 +353,40 @@ int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 Timeo * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) +int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_stream_internal_record_t *stream; + OS_object_token_t token; + int32 return_code; - /* Check Parameters */ - if (buffer == NULL || buflen == 0) - { - return OS_INVALID_POINTER; - } + /* + * Check parameters + * + * Note "RemoteAddr" is not checked, because in certain configurations it can be validly null. + */ + OS_CHECK_POINTER(buffer); + OS_CHECK_SIZE(buflen); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_type != OS_SocketType_DATAGRAM) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + if (stream->socket_type != OS_SocketType_DATAGRAM) { return_code = OS_ERR_INCORRECT_OBJ_TYPE; } - else if ((OS_stream_table[local_id].stream_state & OS_STREAM_STATE_BOUND) == 0) + else if ((stream->stream_state & OS_STREAM_STATE_BOUND) == 0) { /* Socket needs to be bound first */ return_code = OS_ERR_INCORRECT_OBJ_STATE; } else { - return_code = OS_SocketRecvFrom_Impl(local_id, buffer, buflen, RemoteAddr, timeout); + return_code = OS_SocketRecvFrom_Impl(&token, buffer, buflen, RemoteAddr, timeout); } - OS_ObjectIdRefcountDecr(record); + OS_ObjectIdRelease(&token); } return return_code; @@ -407,31 +400,32 @@ int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, uint32 buflen, OS_SockA * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr) +int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr) { - OS_common_record_t *record; - uint32 local_id; - int32 return_code; + OS_stream_internal_record_t *stream; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - if (buffer == NULL || buflen == 0) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(buffer); + OS_CHECK_SIZE(buflen); + OS_CHECK_POINTER(RemoteAddr); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_type != OS_SocketType_DATAGRAM) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + if (stream->socket_type != OS_SocketType_DATAGRAM) { return_code = OS_ERR_INCORRECT_OBJ_TYPE; } else { - return_code = OS_SocketSendTo_Impl(local_id, buffer, buflen, RemoteAddr); + return_code = OS_SocketSendTo_Impl(&token, buffer, buflen, RemoteAddr); } - OS_ObjectIdRefcountDecr(record); + OS_ObjectIdRelease(&token); } return return_code; @@ -449,10 +443,9 @@ int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name) { int32 return_code; - if (sock_id == NULL || sock_name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check Parameters */ + OS_CHECK_POINTER(sock_id); + OS_CHECK_POINTER(sock_name); return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, sock_name, sock_id); @@ -470,25 +463,25 @@ int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name) int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) { OS_common_record_t *record; - uint32 local_id; + OS_object_token_t token; int32 return_code; /* Check parameters */ - if (sock_prop == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(sock_prop); memset(sock_prop, 0, sizeof(OS_socket_prop_t)); /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { - strncpy(sock_prop->name, record->name_entry, OS_MAX_API_NAME - 1); + record = OS_OBJECT_TABLE_GET(OS_global_stream_table, token); + + strncpy(sock_prop->name, record->name_entry, sizeof(sock_prop->name) - 1); sock_prop->creator = record->creator; - return_code = OS_SocketGetInfo_Impl(local_id, sock_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + return_code = OS_SocketGetInfo_Impl(&token, sock_prop); + + OS_ObjectIdRelease(&token); } return return_code; @@ -504,10 +497,8 @@ int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) *-----------------------------------------------------------------*/ int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) { - if (Addr == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(Addr); return OS_SocketAddrInit_Impl(Addr, Domain); } /* end OS_SocketAddrInit */ @@ -520,12 +511,12 @@ int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_SocketAddrToString(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr) +int32 OS_SocketAddrToString(char *buffer, size_t buflen, const OS_SockAddr_t *Addr) { - if (Addr == NULL || buffer == NULL || buflen == 0) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(Addr); + OS_CHECK_POINTER(buffer); + OS_CHECK_SIZE(buflen); return OS_SocketAddrToString_Impl(buffer, buflen, Addr); } /* end OS_SocketAddrToString */ @@ -540,10 +531,9 @@ int32 OS_SocketAddrToString(char *buffer, uint32 buflen, const OS_SockAddr_t *Ad *-----------------------------------------------------------------*/ int32 OS_SocketAddrFromString(OS_SockAddr_t *Addr, const char *string) { - if (Addr == NULL || string == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(Addr); + OS_CHECK_POINTER(string); return OS_SocketAddrFromString_Impl(Addr, string); } /* end OS_SocketAddrFromString */ @@ -558,10 +548,9 @@ int32 OS_SocketAddrFromString(OS_SockAddr_t *Addr, const char *string) *-----------------------------------------------------------------*/ int32 OS_SocketAddrGetPort(uint16 *PortNum, const OS_SockAddr_t *Addr) { - if (PortNum == NULL || Addr == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(Addr); + OS_CHECK_POINTER(PortNum); return OS_SocketAddrGetPort_Impl(PortNum, Addr); } /* end OS_SocketAddrGetPort */ @@ -576,10 +565,8 @@ int32 OS_SocketAddrGetPort(uint16 *PortNum, const OS_SockAddr_t *Addr) *-----------------------------------------------------------------*/ int32 OS_SocketAddrSetPort(OS_SockAddr_t *Addr, uint16 PortNum) { - if (Addr == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(Addr); return OS_SocketAddrSetPort_Impl(Addr, PortNum); } /* end OS_SocketAddrSetPort */ diff --git a/src/os/shared/src/osapi-task.c b/src/os/shared/src/osapi-task.c index 05817443e..29c60dd4f 100644 --- a/src/os/shared/src/osapi-task.c +++ b/src/os/shared/src/osapi-task.c @@ -81,34 +81,19 @@ OS_task_internal_record_t OS_task_table[LOCAL_NUM_OBJECTS]; *-----------------------------------------------------------------*/ static int32 OS_TaskPrepare(osal_id_t task_id, osal_task_entry *entrypt) { - int32 return_code; - uint32 local_id; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; - return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TASK, task_id, &local_id); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TASK, task_id, &token); if (return_code == OS_SUCCESS) { - /* - * Take our own task table lock. - * - * This ensures that the parent thread's OS_TaskCreate() call is fully completed, - * and that nobody can call OS_TaskDelete() and possibly overwrite this data. - */ - OS_Lock_Global(OS_OBJECT_TYPE_OS_TASK); + task = OS_OBJECT_TABLE_GET(OS_task_table, token); - /* - * Verify that we still appear to own the table entry - */ - if (!OS_ObjectIdEqual(OS_global_task_table[local_id].active_id, task_id)) - { - return_code = OS_ERR_INVALID_ID; - } - else - { - return_code = OS_TaskMatch_Impl(local_id); - *entrypt = OS_task_table[local_id].entry_function_pointer; - } + return_code = OS_TaskMatch_Impl(&token); + *entrypt = task->entry_function_pointer; - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TASK); + OS_ObjectIdRelease(&token); } if (return_code == OS_SUCCESS) @@ -186,58 +171,42 @@ int32 OS_TaskAPI_Init(void) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, uint32 *stack_pointer, - uint32 stack_size, uint32 priority, uint32 flags) +int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, + osal_stackptr_t stack_pointer, size_t stack_size, osal_priority_t priority, uint32 flags) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; - - /* Check for bad priority */ - if (priority > OS_MAX_TASK_PRIORITY) - { - return OS_ERR_INVALID_PRIORITY; - } - - /* Check for NULL pointers */ - if (task_name == NULL || task_id == NULL || function_pointer == NULL) - { - return OS_INVALID_POINTER; - } - - /* Check for bad stack size. Note that NULL stack_pointer is - * OK (impl will allocate) but size must be nonzero. */ - if (stack_size == 0) - { - return OS_ERROR; - } + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; - /* we don't want to allow names too long*/ - /* if truncated, two names might be the same */ - if (strlen(task_name) >= OS_MAX_API_NAME) - { - return OS_ERR_NAME_TOO_LONG; - } + /* + * Check parameters + * + * Note "stack_pointer" is not checked, because in certain configurations it can be validly null. + */ + OS_CHECK_POINTER(task_id); + OS_CHECK_POINTER(function_pointer); + OS_CHECK_APINAME(task_name); + OS_CHECK_SIZE(stack_size); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, task_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, task_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal task table */ - memset(&OS_task_table[local_id], 0, sizeof(OS_task_internal_record_t)); + task = OS_OBJECT_TABLE_GET(OS_task_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, task, task_name, task_name); - strncpy(OS_task_table[local_id].task_name, task_name, OS_MAX_API_NAME); - record->name_entry = OS_task_table[local_id].task_name; - OS_task_table[local_id].stack_size = stack_size; - OS_task_table[local_id].priority = priority; - OS_task_table[local_id].entry_function_pointer = function_pointer; - OS_task_table[local_id].stack_pointer = stack_pointer; + task->stack_size = stack_size; + task->priority = priority; + task->entry_function_pointer = function_pointer; + task->stack_pointer = stack_pointer; /* Now call the OS-specific implementation. This reads info from the task table. */ - return_code = OS_TaskCreate_Impl(local_id, flags); + return_code = OS_TaskCreate_Impl(&token, flags); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, task_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, task_id); } return return_code; @@ -253,22 +222,24 @@ int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry f *-----------------------------------------------------------------*/ int32 OS_TaskDelete(osal_id_t task_id) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; - osal_task_entry delete_hook; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; + osal_task_entry delete_hook; delete_hook = NULL; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, task_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, task_id, &token); if (return_code == OS_SUCCESS) { + task = OS_OBJECT_TABLE_GET(OS_task_table, token); + /* Save the delete hook, as we do not want to call it while locked */ - delete_hook = OS_task_table[local_id].delete_hook_pointer; + delete_hook = task->delete_hook_pointer; - return_code = OS_TaskDelete_Impl(local_id); + return_code = OS_TaskDelete_Impl(&token); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } /* @@ -292,15 +263,16 @@ int32 OS_TaskDelete(osal_id_t task_id) *-----------------------------------------------------------------*/ void OS_TaskExit() { - OS_common_record_t *record; - osal_id_t task_id; - uint32 local_id; + osal_id_t task_id; + OS_object_token_t token; task_id = OS_TaskGetId_Impl(); - if (OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &local_id, &record) == OS_SUCCESS) + if (OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &token) == OS_SUCCESS) { + OS_TaskDetach_Impl(&token); + /* Complete the operation via the common routine */ - OS_ObjectIdFinalizeDelete(OS_SUCCESS, record); + OS_ObjectIdFinalizeDelete(OS_SUCCESS, &token); } /* call the implementation */ @@ -331,33 +303,27 @@ int32 OS_TaskDelay(uint32 millisecond) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority(osal_id_t task_id, uint32 new_priority) +int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; - if (new_priority > OS_MAX_TASK_PRIORITY) - { - return_code = OS_ERR_INVALID_PRIORITY; - } - else + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &token); + if (return_code == OS_SUCCESS) { - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &local_id, &record); - if (return_code == OS_SUCCESS) - { - return_code = OS_TaskSetPriority_Impl(local_id, new_priority); + task = OS_OBJECT_TABLE_GET(OS_task_table, token); - if (return_code == OS_SUCCESS) - { - /* Use the abstracted priority, not the OS one */ - /* Change the priority in the table as well */ - OS_task_table[local_id].priority = new_priority; - } + return_code = OS_TaskSetPriority_Impl(&token, new_priority); - /* Unlock the global from OS_ObjectIdGetAndLock() */ - OS_Unlock_Global(LOCAL_OBJID_TYPE); + if (return_code == OS_SUCCESS) + { + /* Use the abstracted priority, not the OS one */ + /* Change the priority in the table as well */ + task->priority = new_priority; } + + OS_ObjectIdRelease(&token); } return return_code; @@ -373,14 +339,13 @@ int32 OS_TaskSetPriority(osal_id_t task_id, uint32 new_priority) *-----------------------------------------------------------------*/ int32 OS_TaskRegister(void) { - OS_common_record_t *record; - uint32 local_id; + OS_object_token_t token; /* * Just to retain compatibility (really, only the unit test cares) * this will return NON success when called from a non-task context */ - return OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, OS_TaskGetId_Impl(), &local_id, &record); + return OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, OS_TaskGetId_Impl(), &token); } /* end OS_TaskRegister */ /*---------------------------------------------------------------- @@ -393,15 +358,14 @@ int32 OS_TaskRegister(void) *-----------------------------------------------------------------*/ osal_id_t OS_TaskGetId(void) { - OS_common_record_t *record; - uint32 local_id; - osal_id_t task_id; + OS_object_token_t token; + osal_id_t task_id; task_id = OS_TaskGetId_Impl(); /* Confirm the task master table entry matches the expected. * If not it means we have some stale/leftover value */ - if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, task_id, &local_id, &record) != OS_SUCCESS) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, task_id, &token) != OS_SUCCESS) { task_id = OS_OBJECT_ID_UNDEFINED; } @@ -421,10 +385,9 @@ int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name) { int32 return_code; - if (task_id == NULL || task_name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(task_id); + OS_CHECK_POINTER(task_name); return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, task_name, task_id); @@ -442,33 +405,34 @@ int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name) *-----------------------------------------------------------------*/ int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + OS_common_record_t * record; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; /* Check parameters */ - if (task_prop == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(task_prop); memset(task_prop, 0, sizeof(OS_task_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_task_table, token); + task = OS_OBJECT_TABLE_GET(OS_task_table, token); + if (record->name_entry != NULL) { strncpy(task_prop->name, record->name_entry, sizeof(task_prop->name) - 1); task_prop->name[sizeof(task_prop->name) - 1] = 0; } task_prop->creator = record->creator; - task_prop->stack_size = OS_task_table[local_id].stack_size; - task_prop->priority = OS_task_table[local_id].priority; + task_prop->stack_size = task->stack_size; + task_prop->priority = task->priority; - return_code = OS_TaskGetInfo_Impl(local_id, task_prop); + return_code = OS_TaskGetInfo_Impl(&token, task_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -485,21 +449,23 @@ int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) *-----------------------------------------------------------------*/ int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; - osal_id_t task_id; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; + osal_id_t task_id; task_id = OS_TaskGetId_Impl(); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &token); if (return_code == OS_SUCCESS) { + task = OS_OBJECT_TABLE_GET(OS_task_table, token); + /* ** Install the pointer */ - OS_task_table[local_id].delete_hook_pointer = function_pointer; + task->delete_hook_pointer = function_pointer; - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -515,14 +481,11 @@ int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer) *-----------------------------------------------------------------*/ int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t sysdata_size) { - int32 return_code; - OS_common_record_t *record; + int32 return_code; + OS_object_token_t token; /* Check parameters */ - if (task_id == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(task_id); /* The "sysdata" and "sysdata_size" must be passed to the underlying impl for validation */ return_code = OS_TaskValidateSystemData_Impl(sysdata, sysdata_size); @@ -532,11 +495,12 @@ int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t } return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_TaskIdMatchSystemData_Impl, - (void *)sysdata, &record); + (void *)sysdata, &token); if (return_code == OS_SUCCESS) { - *task_id = record->active_id; - OS_Unlock_Global(LOCAL_OBJID_TYPE); + *task_id = OS_ObjectIdFromToken(&token); + + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-time.c b/src/os/shared/src/osapi-time.c index 93b71532f..df92e6a58 100644 --- a/src/os/shared/src/osapi-time.c +++ b/src/os/shared/src/osapi-time.c @@ -56,6 +56,12 @@ OS_timecb_internal_record_t OS_timecb_table[OS_MAX_TIMERS]; +typedef union +{ + OS_TimerCallback_t timer_callback_func; + void * opaque_arg; +} OS_Timer_ArgWrapper_t; + /**************************************************************************************** Timer API ***************************************************************************************/ @@ -90,46 +96,30 @@ int32 OS_TimerCbAPI_Init(void) static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_t timebase_ref_id, OS_ArgCallback_t callback_ptr, void *callback_arg, uint32 flags) { - OS_common_record_t * timebase; - OS_common_record_t * record; - OS_timecb_internal_record_t *local; - int32 return_code; - uint32 local_id; - uint32 timebase_local_id; - osal_id_t cb_list; - uint32 attach_id; - - /* - ** Check Parameters - */ - if (timer_id == NULL || timer_name == NULL) - { - return OS_INVALID_POINTER; - } + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t timebase_token; + OS_object_token_t timecb_token; + OS_object_token_t listcb_token; + OS_timecb_internal_record_t * timecb; + OS_timecb_internal_record_t * list_timecb; + OS_timebase_internal_record_t *timebase; /* - ** we don't want to allow names too long - ** if truncated, two names might be the same - */ - if (strlen(timer_name) >= OS_MAX_API_NAME) - { - return OS_ERR_NAME_TOO_LONG; - } - - /* - ** Verify callback parameter + * Check parameters + * + * Note "callback_arg" is not checked, because in certain configurations it can be validly null. */ - if (callback_ptr == NULL) - { - return OS_TIMER_ERR_INVALID_ARGS; - } + OS_CHECK_POINTER(timer_id); + OS_CHECK_APINAME(timer_name); + OS_CHECK_POINTER(callback_ptr); /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } @@ -139,57 +129,69 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ * If successful, then after this statement, we MUST decrement the refcount * if we leave this routine with an error. */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_ref_id, - &timebase_local_id, &timebase); + return_code = + OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_ref_id, &timebase_token); if (return_code != OS_SUCCESS) { return return_code; } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TIMECB, timer_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TIMECB, timer_name, &timecb_token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal timer table */ - local = &OS_timecb_table[local_id]; + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, timecb_token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, timebase_token); - memset(local, 0, sizeof(OS_timecb_internal_record_t)); + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(timecb_token, timecb, timer_name, timer_name); - strncpy(local->timer_name, timer_name, OS_MAX_API_NAME - 1); - record->name_entry = local->timer_name; - local->callback_ptr = callback_ptr; - local->callback_arg = callback_arg; - local->timebase_ref = timebase_local_id; - local->flags = flags; - local->prev_ref = local_id; - local->next_ref = local_id; + /* + * transfer ownership so the refcount obtained earlier is now + * associated with the timecb object, and will be retained until + * the object is deleted. + */ + OS_ObjectIdTransferToken(&timebase_token, &timecb->timebase_token); + + timecb->callback_ptr = callback_ptr; + timecb->callback_arg = callback_arg; + timecb->flags = flags; + timecb->prev_cb = OS_ObjectIdFromToken(&timecb_token); + timecb->next_cb = OS_ObjectIdFromToken(&timecb_token); /* * Now we need to add it to the time base callback ring, so take the * timebase-specific lock to prevent a tick from being processed at this moment. */ - OS_TimeBaseLock_Impl(timebase_local_id); - - cb_list = OS_timebase_table[timebase_local_id].first_cb; - OS_timebase_table[timebase_local_id].first_cb = record->active_id; + OS_TimeBaseLock_Impl(&timebase_token); - if (OS_ObjectIdDefined(cb_list)) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timebase->first_cb, &listcb_token) == + OS_SUCCESS) { - OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TIMECB, cb_list, &attach_id); - local->next_ref = attach_id; - local->prev_ref = OS_timecb_table[attach_id].prev_ref; - OS_timecb_table[local->prev_ref].next_ref = local_id; - OS_timecb_table[local->next_ref].prev_ref = local_id; + list_timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, listcb_token); + + timecb->next_cb = OS_ObjectIdFromToken(&listcb_token); + timecb->prev_cb = list_timecb->prev_cb; + + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timecb->prev_cb, &listcb_token) == + OS_SUCCESS) + { + list_timecb->prev_cb = OS_ObjectIdFromToken(&timecb_token); + list_timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, listcb_token); + list_timecb->next_cb = OS_ObjectIdFromToken(&timecb_token); + } } - OS_TimeBaseUnlock_Impl(timebase_local_id); + timebase->first_cb = OS_ObjectIdFromToken(&timecb_token); + + OS_TimeBaseUnlock_Impl(&timebase_token); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, timer_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &timecb_token, timer_id); } else { - OS_ObjectIdRefcountDecr(timebase); + OS_ObjectIdRelease(&timebase_token); } return return_code; @@ -218,7 +220,7 @@ int32 OS_TimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_t timebas *-----------------------------------------------------------------*/ static void OS_Timer_NoArgCallback(osal_id_t objid, void *arg) { - OS_U32ValueWrapper_t Conv; + OS_Timer_ArgWrapper_t Conv; /* * Note - did not write this as simply *((OS_SimpleCallback_t)arg) because @@ -238,27 +240,19 @@ static void OS_Timer_NoArgCallback(osal_id_t objid, void *arg) *-----------------------------------------------------------------*/ int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *accuracy, OS_TimerCallback_t callback_ptr) { - int32 return_code; - osal_id_t timebase_ref_id; - OS_U32ValueWrapper_t Conv; + int32 return_code; + osal_id_t timebase_ref_id; + OS_Timer_ArgWrapper_t Conv; /* ** Check Parameters. Although DoTimerAdd will also ** check this stuff, also doing it here avoids unnecessarily ** creating and deleting a timebase object in case something is bad. */ - if (timer_id == NULL || timer_name == NULL || accuracy == NULL) - { - return OS_INVALID_POINTER; - } - - /* - ** Verify callback parameter - */ - if (callback_ptr == NULL) - { - return OS_TIMER_ERR_INVALID_ARGS; - } + OS_CHECK_POINTER(timer_id); + OS_CHECK_APINAME(timer_name); + OS_CHECK_POINTER(accuracy); + OS_CHECK_POINTER(callback_ptr); /* * Create our dedicated time base object to drive this timer @@ -281,6 +275,7 @@ int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *accura */ Conv.opaque_arg = NULL; Conv.timer_callback_func = callback_ptr; + return_code = OS_DoTimerAdd(timer_id, timer_name, timebase_ref_id, OS_Timer_NoArgCallback, Conv.opaque_arg, TIMECB_FLAG_DEDICATED_TIMEBASE); @@ -310,53 +305,46 @@ int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *accura *-----------------------------------------------------------------*/ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) { - OS_common_record_t * record; - OS_timecb_internal_record_t *local; + OS_timecb_internal_record_t *timecb; int32 return_code; - uint32 local_id; + osal_objtype_t objtype; osal_id_t dedicated_timebase_id; + OS_object_token_t token; dedicated_timebase_id = OS_OBJECT_ID_UNDEFINED; - if (start_time >= (UINT32_MAX / 2) || interval_time >= (UINT32_MAX / 2)) - { - return OS_TIMER_ERR_INVALID_ARGS; - } - - if (start_time == 0 && interval_time == 0) - { - return OS_ERROR; - } + ARGCHECK(start_time < (UINT32_MAX / 2), OS_TIMER_ERR_INVALID_ARGS); + ARGCHECK(interval_time < (UINT32_MAX / 2), OS_TIMER_ERR_INVALID_ARGS); + ARGCHECK(start_time != 0 || interval_time != 0, OS_ERROR); /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &token); if (return_code == OS_SUCCESS) { - local = &OS_timecb_table[local_id]; + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, token); - OS_TimeBaseLock_Impl(local->timebase_ref); + OS_TimeBaseLock_Impl(&timecb->timebase_token); - if ((local->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) + if ((timecb->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) { - dedicated_timebase_id = OS_global_timebase_table[local->timebase_ref].active_id; + dedicated_timebase_id = OS_ObjectIdFromToken(&timecb->timebase_token); } - local->wait_time = (int32)start_time; - local->interval_time = (int32)interval_time; + timecb->wait_time = (int32)start_time; + timecb->interval_time = (int32)interval_time; - OS_TimeBaseUnlock_Impl(local->timebase_ref); + OS_TimeBaseUnlock_Impl(&timecb->timebase_token); - /* Unlock the global from OS_ObjectIdCheck() */ - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TIMECB); + OS_ObjectIdRelease(&token); } /* @@ -389,85 +377,95 @@ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) *-----------------------------------------------------------------*/ int32 OS_TimerDelete(osal_id_t timer_id) { - OS_timecb_internal_record_t *local; - OS_common_record_t * record; - OS_common_record_t * timebase = NULL; - int32 return_code; - uint32 local_id; - osal_id_t dedicated_timebase_id; + int32 return_code; + osal_objtype_t objtype; + osal_id_t dedicated_timebase_id; + OS_object_token_t timecb_token; + OS_object_token_t timebase_token; + OS_object_token_t listcb_token; + OS_timebase_internal_record_t *timebase; + OS_timecb_internal_record_t * timecb; + OS_timecb_internal_record_t * list_timecb; dedicated_timebase_id = OS_OBJECT_ID_UNDEFINED; + memset(&timebase_token, 0, sizeof(timebase_token)); /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &timecb_token); if (return_code == OS_SUCCESS) { - local = &OS_timecb_table[local_id]; - timebase = &OS_global_timebase_table[local->timebase_ref]; + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, timecb_token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, timecb->timebase_token); + + OS_ObjectIdTransferToken(&timecb->timebase_token, &timebase_token); - OS_TimeBaseLock_Impl(local->timebase_ref); + OS_TimeBaseLock_Impl(&timecb->timebase_token); /* * If the timer uses a dedicated time base, then also delete that. */ - if ((local->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) + if ((timecb->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) { - dedicated_timebase_id = timebase->active_id; + dedicated_timebase_id = OS_ObjectIdFromToken(&timecb->timebase_token); } /* * Now we need to remove it from the time base callback ring */ - if (OS_ObjectIdEqual(OS_timebase_table[local->timebase_ref].first_cb, timer_id)) + if (OS_ObjectIdEqual(timebase->first_cb, OS_ObjectIdFromToken(&timecb_token))) { - if (local->next_ref != local_id) + if (OS_ObjectIdEqual(OS_ObjectIdFromToken(&timecb_token), timecb->next_cb)) { - OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TIMEBASE, local->next_ref, - &OS_timebase_table[local->timebase_ref].first_cb); + timebase->first_cb = OS_OBJECT_ID_UNDEFINED; } else { - /* - * consider the list empty - */ - OS_timebase_table[local->timebase_ref].first_cb = OS_OBJECT_ID_UNDEFINED; + timebase->first_cb = timecb->next_cb; } } - OS_timecb_table[local->prev_ref].next_ref = local->next_ref; - OS_timecb_table[local->next_ref].prev_ref = local->prev_ref; - local->next_ref = local_id; - local->prev_ref = local_id; + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timecb->prev_cb, &listcb_token) == + OS_SUCCESS) + { + list_timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, listcb_token); + list_timecb->next_cb = timecb->next_cb; + } + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timecb->next_cb, &listcb_token) == + OS_SUCCESS) + { + list_timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, listcb_token); + list_timecb->prev_cb = timecb->prev_cb; + } + + timecb->next_cb = OS_ObjectIdFromToken(&timecb_token); + timecb->prev_cb = OS_ObjectIdFromToken(&timecb_token); - OS_TimeBaseUnlock_Impl(local->timebase_ref); + OS_TimeBaseUnlock_Impl(&timecb->timebase_token); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &timecb_token); } /* * Remove the reference count against the timebase */ + OS_ObjectIdRelease(&timebase_token); /* * If the timer uses a dedicated time base, then also delete it. */ - if (return_code == OS_SUCCESS) + if (return_code == OS_SUCCESS && OS_ObjectIdDefined(dedicated_timebase_id)) { - OS_ObjectIdRefcountDecr(timebase); - if (OS_ObjectIdDefined(dedicated_timebase_id)) - { - OS_TimeBaseDelete(dedicated_timebase_id); - } + OS_TimeBaseDelete(dedicated_timebase_id); } return return_code; @@ -483,20 +481,19 @@ int32 OS_TimerDelete(osal_id_t timer_id) *-----------------------------------------------------------------*/ int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name) { - int32 return_code; - uint32 local_id; + int32 return_code; + osal_objtype_t objtype; - if (timer_id == NULL || timer_name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(timer_id); + OS_CHECK_POINTER(timer_name); /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } @@ -516,37 +513,41 @@ int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name) *-----------------------------------------------------------------*/ int32 OS_TimerGetInfo(osal_id_t timer_id, OS_timer_prop_t *timer_prop) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + OS_common_record_t * record; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; + OS_timecb_internal_record_t * timecb; + OS_timebase_internal_record_t *timebase; /* Check parameters */ - if (timer_prop == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(timer_prop); /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } memset(timer_prop, 0, sizeof(OS_timer_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &token); if (return_code == OS_SUCCESS) { - strncpy(timer_prop->name, record->name_entry, OS_MAX_API_NAME - 1); + record = OS_OBJECT_TABLE_GET(OS_global_timecb_table, token); + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, timecb->timebase_token); + + strncpy(timer_prop->name, record->name_entry, sizeof(timer_prop->name) - 1); timer_prop->creator = record->creator; - timer_prop->interval_time = (uint32)OS_timecb_table[local_id].interval_time; - timer_prop->accuracy = OS_timebase_table[OS_timecb_table[local_id].timebase_ref].accuracy_usec; + timer_prop->interval_time = (uint32)timecb->interval_time; + timer_prop->accuracy = timebase->accuracy_usec; - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TIMECB); + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-timebase.c b/src/os/shared/src/osapi-timebase.c index e881954b7..a7918852a 100644 --- a/src/os/shared/src/osapi-timebase.c +++ b/src/os/shared/src/osapi-timebase.c @@ -98,9 +98,10 @@ int32 OS_TimeBaseAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_TimeBaseCreate(osal_id_t *timer_id, const char *timebase_name, OS_TimerSync_t external_sync) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; + OS_timebase_internal_record_t *timebase; /* * Specifying a NULL sync function means the timebase is not externally synchronized. @@ -110,54 +111,43 @@ int32 OS_TimeBaseCreate(osal_id_t *timer_id, const char *timebase_name, OS_Timer /* ** Check Parameters */ - if (timer_id == NULL || timebase_name == NULL) - { - return OS_INVALID_POINTER; - } - - /* - ** we don't want to allow names too long - ** if truncated, two names might be the same - */ - if (strlen(timebase_name) >= OS_MAX_API_NAME) - { - return OS_ERR_NAME_TOO_LONG; - } + OS_CHECK_POINTER(timer_id); + OS_CHECK_APINAME(timebase_name); /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TIMEBASE, timebase_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TIMEBASE, timebase_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal timer table */ - memset(&OS_timebase_table[local_id], 0, sizeof(OS_timebase_internal_record_t)); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, timebase, timebase_name, timebase_name); - strncpy(OS_timebase_table[local_id].timebase_name, timebase_name, OS_MAX_API_NAME - 1); - record->name_entry = OS_timebase_table[local_id].timebase_name; - OS_timebase_table[local_id].external_sync = external_sync; + timebase->external_sync = external_sync; if (external_sync == NULL) { - OS_timebase_table[local_id].accuracy_usec = OS_SharedGlobalVars.MicroSecPerTick; + timebase->accuracy_usec = OS_SharedGlobalVars.MicroSecPerTick; } else { - OS_timebase_table[local_id].accuracy_usec = 0; + timebase->accuracy_usec = 0; } /* Now call the OS-specific implementation. This reads info from the timer table. */ - return_code = OS_TimeBaseCreate_Impl(local_id); + return_code = OS_TimeBaseCreate_Impl(&token); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, timer_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, timer_id); } return return_code; @@ -173,9 +163,10 @@ int32 OS_TimeBaseCreate(osal_id_t *timer_id, const char *timebase_name, OS_Timer *-----------------------------------------------------------------*/ int32 OS_TimeBaseSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; + OS_timebase_internal_record_t *timebase; /* * Internally the implementation represents the interval as a @@ -185,39 +176,39 @@ int32 OS_TimeBaseSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time * Note that the units are intentionally left unspecified. The external sync period * could be measured in microseconds or hours -- it is whatever the application requires. */ - if (interval_time >= 1000000000 || start_time >= 1000000000) - { - return OS_TIMER_ERR_INVALID_ARGS; - } + ARGCHECK(start_time < 1000000000, OS_TIMER_ERR_INVALID_ARGS); + ARGCHECK(interval_time < 1000000000, OS_TIMER_ERR_INVALID_ARGS); /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMEBASE, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMEBASE, timer_id, &token); if (return_code == OS_SUCCESS) { + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + /* Need to take the time base lock to ensure that no ticks are currently being processed */ - OS_TimeBaseLock_Impl(local_id); + OS_TimeBaseLock_Impl(&token); - return_code = OS_TimeBaseSet_Impl(local_id, start_time, interval_time); + return_code = OS_TimeBaseSet_Impl(&token, start_time, interval_time); if (return_code == OS_SUCCESS) { /* Save the value since we were successful */ - OS_timebase_table[local_id].nominal_start_time = start_time; - OS_timebase_table[local_id].nominal_interval_time = interval_time; + timebase->nominal_start_time = start_time; + timebase->nominal_interval_time = interval_time; } - OS_TimeBaseUnlock_Impl(local_id); + OS_TimeBaseUnlock_Impl(&token); - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TIMEBASE); + OS_ObjectIdRelease(&token); } return return_code; @@ -233,27 +224,27 @@ int32 OS_TimeBaseSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time *-----------------------------------------------------------------*/ int32 OS_TimeBaseDelete(osal_id_t timer_id) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMEBASE, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMEBASE, timer_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_TimeBaseDelete_Impl(local_id); + return_code = OS_TimeBaseDelete_Impl(&token); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -269,20 +260,19 @@ int32 OS_TimeBaseDelete(osal_id_t timer_id) *-----------------------------------------------------------------*/ int32 OS_TimeBaseGetIdByName(osal_id_t *timer_id, const char *timebase_name) { - int32 return_code; - uint32 local_id; + int32 return_code; + osal_objtype_t objtype; - if (timer_id == NULL || timebase_name == NULL) - { - return OS_INVALID_POINTER; - } + /* Check parameters */ + OS_CHECK_POINTER(timer_id); + OS_CHECK_APINAME(timebase_name); /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } @@ -302,40 +292,42 @@ int32 OS_TimeBaseGetIdByName(osal_id_t *timer_id, const char *timebase_name) *-----------------------------------------------------------------*/ int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_prop) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + OS_common_record_t * record; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; + OS_timebase_internal_record_t *timebase; /* Check parameters */ - if (timebase_prop == NULL) - { - return OS_INVALID_POINTER; - } + OS_CHECK_POINTER(timebase_prop); /* * Check our context. Not allowed to use the timer API from a timer callback. * Just interested in the object type returned. */ - local_id = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); - if (local_id == OS_OBJECT_TYPE_OS_TIMEBASE) + objtype = OS_ObjectIdToType_Impl(OS_TaskGetId_Impl()); + if (objtype == OS_OBJECT_TYPE_OS_TIMEBASE) { return OS_ERR_INCORRECT_OBJ_STATE; } memset(timebase_prop, 0, sizeof(OS_timebase_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, timebase_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, timebase_id, &token); if (return_code == OS_SUCCESS) { - strncpy(timebase_prop->name, record->name_entry, OS_MAX_API_NAME - 1); + record = OS_OBJECT_TABLE_GET(OS_global_timebase_table, token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + + strncpy(timebase_prop->name, record->name_entry, sizeof(timebase_prop->name) - 1); timebase_prop->creator = record->creator; - timebase_prop->nominal_interval_time = OS_timebase_table[local_id].nominal_interval_time; - timebase_prop->freerun_time = OS_timebase_table[local_id].freerun_time; - timebase_prop->accuracy = OS_timebase_table[local_id].accuracy_usec; + timebase_prop->nominal_interval_time = timebase->nominal_interval_time; + timebase_prop->freerun_time = timebase->freerun_time; + timebase_prop->accuracy = timebase->accuracy_usec; - return_code = OS_TimeBaseGetInfo_Impl(local_id, timebase_prop); + return_code = OS_TimeBaseGetInfo_Impl(&token, timebase_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -351,15 +343,19 @@ int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_pro *-----------------------------------------------------------------*/ int32 OS_TimeBaseGetFreeRun(osal_id_t timebase_id, uint32 *freerun_val) { - OS_common_record_t *record; - int32 return_code; - uint32 local_id; + int32 return_code; + OS_object_token_t token; + OS_timebase_internal_record_t *timebase; /* Check parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, timebase_id, &local_id, &record); + OS_CHECK_POINTER(freerun_val); + + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, timebase_id, &token); if (return_code == OS_SUCCESS) { - *freerun_val = OS_timebase_table[local_id].freerun_time; + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + + *freerun_val = timebase->freerun_time; } return return_code; @@ -390,10 +386,8 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) OS_timebase_internal_record_t *timebase; OS_timecb_internal_record_t * timecb; OS_common_record_t * record; - uint32 local_id; - uint32 timer_id; - uint32 curr_cb_local_id; - osal_id_t curr_cb_public_id; + OS_object_token_t token; + OS_object_token_t cb_token; uint32 tick_time; uint32 spin_cycles; int32 saved_wait_time; @@ -407,17 +401,19 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) OS_TaskRegister_Impl(timebase_id); /* Grab the relevant info from the global structure */ - if (OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &local_id, &record) != 0) + if (OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &token) != 0) { /* Something went wrong - abort this thread */ return; } - timebase = &OS_timebase_table[local_id]; + record = OS_OBJECT_TABLE_GET(OS_global_timebase_table, token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + syncfunc = timebase->external_sync; spin_cycles = 0; - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TIMEBASE); + OS_ObjectIdRelease(&token); while (1) { @@ -425,7 +421,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) * Call the sync function - this will pend for some period of time * and return the amount of elapsed time in units of "timebase ticks" */ - tick_time = (*syncfunc)(local_id); + tick_time = (*syncfunc)(timebase_id); /* * The returned tick_time should be nonzero. If the sync function @@ -467,7 +463,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) } } - OS_TimeBaseLock_Impl(local_id); + OS_TimeBaseLock_Impl(&token); /* * After waiting, check that our ID still matches @@ -475,19 +471,17 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) */ if (!OS_ObjectIdEqual(timebase_id, record->active_id)) { - OS_TimeBaseUnlock_Impl(local_id); + OS_TimeBaseUnlock_Impl(&token); break; } timebase->freerun_time += tick_time; - if (OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TIMECB, timebase->first_cb, &timer_id) == 0) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timebase->first_cb, &cb_token) == 0) { - curr_cb_local_id = timer_id; do { - curr_cb_public_id = OS_global_timecb_table[curr_cb_local_id].active_id; - timecb = &OS_timecb_table[curr_cb_local_id]; - saved_wait_time = timecb->wait_time; + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, cb_token); + saved_wait_time = timecb->wait_time; timecb->wait_time -= tick_time; while (timecb->wait_time <= 0) { @@ -512,7 +506,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) */ if (saved_wait_time > 0 && timecb->callback_ptr != NULL) { - (*timecb->callback_ptr)(curr_cb_public_id, timecb->callback_arg); + (*timecb->callback_ptr)(OS_ObjectIdFromToken(&cb_token), timecb->callback_arg); } /* @@ -523,11 +517,13 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) break; } } - curr_cb_local_id = timecb->next_ref; - } while (curr_cb_local_id != timer_id); + + } while (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timecb->next_cb, &cb_token) == + OS_SUCCESS && + !OS_ObjectIdEqual(OS_ObjectIdFromToken(&cb_token), timebase->first_cb)); } - OS_TimeBaseUnlock_Impl(local_id); + OS_TimeBaseUnlock_Impl(&token); } } /* end OS_TimeBase_CallbackThread */ diff --git a/src/os/vxworks/CMakeLists.txt b/src/os/vxworks/CMakeLists.txt index 9a510d041..912f3e74c 100644 --- a/src/os/vxworks/CMakeLists.txt +++ b/src/os/vxworks/CMakeLists.txt @@ -14,7 +14,7 @@ set(VXWORKS_BASE_SRCLIST src/os-impl-console.c src/os-impl-countsem.c src/os-impl-errors.c - src/os-impl-dirs.c + src/os-impl-dirs-globals.c src/os-impl-files.c src/os-impl-filesys.c src/os-impl-heap.c @@ -33,6 +33,7 @@ set(VXWORKS_IMPL_SRCLIST ../portable/os-impl-bsd-select.c ../portable/os-impl-posix-io.c ../portable/os-impl-posix-files.c + ../portable/os-impl-posix-dirs.c ) if (OSAL_CONFIG_INCLUDE_SHELL) @@ -77,3 +78,8 @@ add_library(osal_vxworks_impl OBJECT ${VXWORKS_BASE_SRCLIST} ${VXWORKS_IMPL_SRCLIST} ) + +if (CMAKE_SYSTEM_VERSION VERSION_LESS 7.0) + target_compile_definitions(osal_vxworks_impl PRIVATE OSAL_VXWORKS6_COMPATIBILITY) +endif () + diff --git a/src/os/vxworks/inc/os-impl-binsem.h b/src/os/vxworks/inc/os-impl-binsem.h index 3da1e1a97..d18aa9a61 100644 --- a/src/os/vxworks/inc/os-impl-binsem.h +++ b/src/os/vxworks/inc/os-impl-binsem.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_BINSEM_H_ -#define INCLUDE_OS_IMPL_BINSEM_H_ +#ifndef OS_IMPL_BINSEM_H +#define OS_IMPL_BINSEM_H -#include +#include "osconfig.h" #include /* Binary Semaphores */ @@ -41,4 +41,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_binsem_internal_record_t OS_impl_bin_sem_table[OS_MAX_BIN_SEMAPHORES]; -#endif /* INCLUDE_OS_IMPL_BINSEM_H_ */ +#endif /* OS_IMPL_BINSEM_H */ diff --git a/src/os/vxworks/inc/os-impl-console.h b/src/os/vxworks/inc/os-impl-console.h index e10f88534..56d44993c 100644 --- a/src/os/vxworks/inc/os-impl-console.h +++ b/src/os/vxworks/inc/os-impl-console.h @@ -25,11 +25,11 @@ * */ -#ifndef INCLUDE_OS_IMPL_CONSOLE_H_ -#define INCLUDE_OS_IMPL_CONSOLE_H_ +#ifndef OS_IMPL_CONSOLE_H +#define OS_IMPL_CONSOLE_H #include -#include +#include "osconfig.h" #include #include @@ -44,4 +44,4 @@ typedef struct extern OS_impl_console_internal_record_t OS_impl_console_table[OS_MAX_CONSOLES]; -#endif /* INCLUDE_OS_IMPL_CONSOLE_H_ */ +#endif /* OS_IMPL_CONSOLE_H */ diff --git a/src/os/vxworks/inc/os-impl-countsem.h b/src/os/vxworks/inc/os-impl-countsem.h index 4698756c3..4d14393a2 100644 --- a/src/os/vxworks/inc/os-impl-countsem.h +++ b/src/os/vxworks/inc/os-impl-countsem.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_COUNTSEM_H_ -#define INCLUDE_OS_IMPL_COUNTSEM_H_ +#ifndef OS_IMPL_COUNTSEM_H +#define OS_IMPL_COUNTSEM_H -#include +#include "osconfig.h" #include /* Counting & Binary Semaphores */ @@ -41,4 +41,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_countsem_internal_record_t OS_impl_count_sem_table[OS_MAX_COUNT_SEMAPHORES]; -#endif /* INCLUDE_OS_IMPL_COUNTSEM_H_ */ +#endif /* OS_IMPL_COUNTSEM_H */ diff --git a/src/os/vxworks/inc/os-impl-dirs.h b/src/os/vxworks/inc/os-impl-dirs.h index e391792c1..5ae902ee2 100644 --- a/src/os/vxworks/inc/os-impl-dirs.h +++ b/src/os/vxworks/inc/os-impl-dirs.h @@ -25,14 +25,26 @@ * */ -#ifndef INCLUDE_OS_IMPL_DIRS_H_ -#define INCLUDE_OS_IMPL_DIRS_H_ +#ifndef OS_IMPL_DIRS_H +#define OS_IMPL_DIRS_H -#include +#include "osconfig.h" #include #include +#include #include +/* + * In VxWorks 6.x the system mkdir() function only has a path argument + * In VxWorks 7 it is now POSIX compilant and adds a mode argument + * + * This macro simply discards the second argument, allowing code to use + * mkdir() in a consistent, POSIX compliant fashion. + */ +#ifdef OSAL_VXWORKS6_COMPATIBILITY +#define mkdir(path, mode) mkdir(path) +#endif + typedef struct { DIR *dp; @@ -43,4 +55,4 @@ typedef struct */ extern OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; -#endif /* INCLUDE_OS_IMPL_DIRS_H_ */ +#endif /* OS_IMPL_DIRS_H */ diff --git a/src/os/vxworks/inc/os-impl-files.h b/src/os/vxworks/inc/os-impl-files.h index d32892dec..64378a043 100644 --- a/src/os/vxworks/inc/os-impl-files.h +++ b/src/os/vxworks/inc/os-impl-files.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_IMPL_FILES_H_ -#define INCLUDE_OS_IMPL_FILES_H_ +#ifndef OS_IMPL_FILES_H +#define OS_IMPL_FILES_H #include "os-impl-io.h" @@ -47,4 +47,4 @@ */ #define OS_IMPL_REGULAR_FILE_FLAGS 0 -#endif /* INCLUDE_OS_IMPL_FILES_H_ */ +#endif /* OS_IMPL_FILES_H */ diff --git a/src/os/vxworks/inc/os-impl-filesys.h b/src/os/vxworks/inc/os-impl-filesys.h index d0649d348..b376ef0fa 100644 --- a/src/os/vxworks/inc/os-impl-filesys.h +++ b/src/os/vxworks/inc/os-impl-filesys.h @@ -25,11 +25,11 @@ * */ -#ifndef INCLUDE_OS_IMPL_FILESYS_H_ -#define INCLUDE_OS_IMPL_FILESYS_H_ +#ifndef OS_IMPL_FILESYS_H +#define OS_IMPL_FILESYS_H -#include -#include +#include "osconfig.h" +#include "common_types.h" #include #include @@ -42,4 +42,4 @@ typedef struct extern OS_impl_filesys_internal_record_t OS_impl_filesys_table[OS_MAX_FILE_SYSTEMS]; -#endif /* INCLUDE_OS_IMPL_FILESYS_H_ */ +#endif /* OS_IMPL_FILESYS_H */ diff --git a/src/os/vxworks/inc/os-impl-gettime.h b/src/os/vxworks/inc/os-impl-gettime.h index c0e7a5f44..5a66cabd9 100644 --- a/src/os/vxworks/inc/os-impl-gettime.h +++ b/src/os/vxworks/inc/os-impl-gettime.h @@ -25,12 +25,12 @@ * */ -#ifndef INCLUDE_OS_IMPL_GETTIME_H_ -#define INCLUDE_OS_IMPL_GETTIME_H_ +#ifndef OS_IMPL_GETTIME_H +#define OS_IMPL_GETTIME_H -#include +#include "osconfig.h" #include #define OSAL_GETTIME_SOURCE_CLOCK CLOCK_MONOTONIC -#endif /* INCLUDE_OS_IMPL_GETTIME_H_ */ +#endif /* OS_IMPL_GETTIME_H */ diff --git a/src/os/vxworks/inc/os-impl-idmap.h b/src/os/vxworks/inc/os-impl-idmap.h new file mode 100644 index 000000000..2e2098a31 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-idmap.h @@ -0,0 +1,44 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file os-impl-idmap.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef OS_IMPL_IDMAP_H +#define OS_IMPL_IDMAP_H + +#include "osconfig.h" +#include "osapi-idmap.h" +#include + +typedef struct +{ + void *const mem; + SEM_ID vxid; +} OS_impl_objtype_lock_t; + +/* Tables where the lock state information is stored */ +extern OS_impl_objtype_lock_t *const OS_impl_objtype_lock_table[OS_OBJECT_TYPE_USER]; + +#endif /* OS_IMPL_IDMAP_H */ diff --git a/src/os/vxworks/inc/os-impl-io.h b/src/os/vxworks/inc/os-impl-io.h index 0bf73c3bc..0968588f6 100644 --- a/src/os/vxworks/inc/os-impl-io.h +++ b/src/os/vxworks/inc/os-impl-io.h @@ -25,11 +25,11 @@ * */ -#ifndef INCLUDE_OS_IMPL_IO_H_ -#define INCLUDE_OS_IMPL_IO_H_ +#ifndef OS_IMPL_IO_H +#define OS_IMPL_IO_H -#include -#include +#include "osconfig.h" +#include "common_types.h" #include #include #include @@ -38,7 +38,7 @@ typedef struct { int fd; bool selectable; -} OS_VxWorks_filehandle_entry_t; +} OS_impl_file_internal_record_t; /* * The global file handle table. @@ -46,7 +46,7 @@ typedef struct * This table is shared across multiple units (files, sockets, etc) and they will share * the same file handle table from the basic file I/O. */ -extern OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; +extern OS_impl_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; /* * VxWorks needs to cast the argument to "write()" to avoid a warning. @@ -55,4 +55,4 @@ extern OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FI */ #define GENERIC_IO_CONST_DATA_CAST (void *) -#endif /* INCLUDE_OS_IMPL_IO_H_ */ +#endif /* OS_IMPL_IO_H */ diff --git a/src/os/vxworks/inc/os-impl-loader.h b/src/os/vxworks/inc/os-impl-loader.h index 05da9da70..3093c6e5d 100644 --- a/src/os/vxworks/inc/os-impl-loader.h +++ b/src/os/vxworks/inc/os-impl-loader.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_LOADER_H_ -#define INCLUDE_OS_IMPL_LOADER_H_ +#ifndef OS_IMPL_LOADER_H +#define OS_IMPL_LOADER_H -#include +#include "osconfig.h" #include /* @@ -51,4 +51,4 @@ typedef struct */ extern OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; -#endif /* INCLUDE_OS_IMPL_LOADER_H_ */ +#endif /* OS_IMPL_LOADER_H */ diff --git a/src/os/vxworks/inc/os-impl-mutex.h b/src/os/vxworks/inc/os-impl-mutex.h index 91c1d93a6..08bb6b388 100644 --- a/src/os/vxworks/inc/os-impl-mutex.h +++ b/src/os/vxworks/inc/os-impl-mutex.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_MUTEX_H_ -#define INCLUDE_OS_IMPL_MUTEX_H_ +#ifndef OS_IMPL_MUTEX_H +#define OS_IMPL_MUTEX_H -#include +#include "osconfig.h" #include typedef struct @@ -40,4 +40,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_mutsem_internal_record_t OS_impl_mutex_table[OS_MAX_MUTEXES]; -#endif /* INCLUDE_OS_IMPL_MUTEX_H_ */ +#endif /* OS_IMPL_MUTEX_H */ diff --git a/src/os/vxworks/inc/os-impl-network.h b/src/os/vxworks/inc/os-impl-network.h index 5f7943edf..4b473c856 100644 --- a/src/os/vxworks/inc/os-impl-network.h +++ b/src/os/vxworks/inc/os-impl-network.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_IMPL_NETWORK_H_ -#define INCLUDE_OS_IMPL_NETWORK_H_ +#ifndef OS_IMPL_NETWORK_H +#define OS_IMPL_NETWORK_H #include #include @@ -36,4 +36,4 @@ #include #include -#endif /* INCLUDE_OS_IMPL_NETWORK_H_ */ +#endif /* OS_IMPL_NETWORK_H */ diff --git a/src/os/vxworks/inc/os-impl-queues.h b/src/os/vxworks/inc/os-impl-queues.h index 48a47269a..d82a7affe 100644 --- a/src/os/vxworks/inc/os-impl-queues.h +++ b/src/os/vxworks/inc/os-impl-queues.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_QUEUES_H_ -#define INCLUDE_OS_IMPL_QUEUES_H_ +#ifndef OS_IMPL_QUEUES_H +#define OS_IMPL_QUEUES_H -#include +#include "osconfig.h" #include typedef struct @@ -39,4 +39,4 @@ typedef struct /* Tables where the OS object information is stored */ extern OS_impl_queue_internal_record_t OS_impl_queue_table[OS_MAX_QUEUES]; -#endif /* INCLUDE_OS_IMPL_QUEUES_H_ */ +#endif /* OS_IMPL_QUEUES_H */ diff --git a/src/os/vxworks/inc/os-impl-select.h b/src/os/vxworks/inc/os-impl-select.h index fd88d6e8e..d29b5d8e5 100644 --- a/src/os/vxworks/inc/os-impl-select.h +++ b/src/os/vxworks/inc/os-impl-select.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_OS_IMPL_SELECT_H_ -#define INCLUDE_OS_IMPL_SELECT_H_ +#ifndef OS_IMPL_SELECT_H +#define OS_IMPL_SELECT_H #include "os-impl-io.h" #include -#endif /* INCLUDE_OS_IMPL_SELECT_H_ */ +#endif /* OS_IMPL_SELECT_H */ diff --git a/src/os/vxworks/inc/os-impl-sockets.h b/src/os/vxworks/inc/os-impl-sockets.h index 8c17d2254..32dbabea2 100644 --- a/src/os/vxworks/inc/os-impl-sockets.h +++ b/src/os/vxworks/inc/os-impl-sockets.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_IMPL_SOCKETS_H_ -#define INCLUDE_OS_IMPL_SOCKETS_H_ +#ifndef OS_IMPL_SOCKETS_H +#define OS_IMPL_SOCKETS_H #include "os-impl-io.h" @@ -46,4 +46,4 @@ /* The "in.h" header file supplied in VxWorks 6.9 is missing the "in_port_t" typedef */ typedef u_short in_port_t; -#endif /* INCLUDE_OS_IMPL_SOCKETS_H_ */ +#endif /* OS_IMPL_SOCKETS_H */ diff --git a/src/os/vxworks/inc/os-impl-symtab.h b/src/os/vxworks/inc/os-impl-symtab.h index 373d9b60c..037207385 100644 --- a/src/os/vxworks/inc/os-impl-symtab.h +++ b/src/os/vxworks/inc/os-impl-symtab.h @@ -25,16 +25,16 @@ * */ -#ifndef INCLUDE_OS_IMPL_SYMTAB_H_ -#define INCLUDE_OS_IMPL_SYMTAB_H_ +#ifndef OS_IMPL_SYMTAB_H +#define OS_IMPL_SYMTAB_H -#include +#include "osconfig.h" #include typedef struct { - uint32 Sizelimit; - uint32 CurrSize; + size_t Sizelimit; + size_t CurrSize; int32 StatusCode; int fd; } SymbolDumpState_t; @@ -44,4 +44,4 @@ extern SymbolDumpState_t OS_VxWorks_SymbolDumpState; BOOL OS_SymTableIterator_Impl(char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_arg_t arg, SYM_GROUP group); -#endif /* INCLUDE_OS_IMPL_SYMTAB_H_ */ +#endif /* OS_IMPL_SYMTAB_H */ diff --git a/src/os/vxworks/inc/os-impl-tasks.h b/src/os/vxworks/inc/os-impl-tasks.h index 87cb15818..12ef8f726 100644 --- a/src/os/vxworks/inc/os-impl-tasks.h +++ b/src/os/vxworks/inc/os-impl-tasks.h @@ -25,22 +25,30 @@ * */ -#ifndef INCLUDE_OS_IMPL_TASKS_H_ -#define INCLUDE_OS_IMPL_TASKS_H_ +#ifndef OS_IMPL_TASKS_H +#define OS_IMPL_TASKS_H -#include +#include "osconfig.h" #include +#if defined(VX_WIND_TCB_SIZE) +/* vxworks >= 7.0 should provide this symbol via taskLib.h. WIND_TCB is an opaque type */ +typedef char OS_VxWorks_TCB_t[VX_WIND_TCB_SIZE]; +#else +/* older vxworks expose the definition of VX_WIND_TCB_SIZE */ +typedef WIND_TCB OS_VxWorks_TCB_t; +#endif /* !defined(VX_WIND_TCB_SIZE) */ + /*tasks */ typedef struct { - WIND_TCB tcb; /* Must be first */ - TASK_ID vxid; - void * heap_block; /* set non-null if the stack was obtained with malloc() */ - long heap_block_size; + OS_VxWorks_TCB_t tcb; /* Must be first */ + TASK_ID vxid; + void * heap_block; /* set non-null if the stack was obtained with malloc() */ + size_t heap_block_size; } OS_impl_task_internal_record_t; /* Tables where the OS object information is stored */ extern OS_impl_task_internal_record_t OS_impl_task_table[OS_MAX_TASKS]; -#endif /* INCLUDE_OS_IMPL_TASKS_H_ */ +#endif /* OS_IMPL_TASKS_H */ diff --git a/src/os/vxworks/inc/os-impl-timebase.h b/src/os/vxworks/inc/os-impl-timebase.h index 2c3afab8b..72dbd22ba 100644 --- a/src/os/vxworks/inc/os-impl-timebase.h +++ b/src/os/vxworks/inc/os-impl-timebase.h @@ -25,11 +25,11 @@ * */ -#ifndef INCLUDE_OS_IMPL_TIMEBASE_H_ -#define INCLUDE_OS_IMPL_TIMEBASE_H_ +#ifndef OS_IMPL_TIMEBASE_H +#define OS_IMPL_TIMEBASE_H -#include -#include +#include "osconfig.h" +#include "common_types.h" #include #include #include @@ -61,4 +61,4 @@ typedef struct extern OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; -#endif /* INCLUDE_OS_IMPL_TIMEBASE_H_ */ +#endif /* OS_IMPL_TIMEBASE_H */ diff --git a/src/os/vxworks/inc/os-vxworks.h b/src/os/vxworks/inc/os-vxworks.h index 9b993db96..da6b8da22 100644 --- a/src/os/vxworks/inc/os-vxworks.h +++ b/src/os/vxworks/inc/os-vxworks.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_VXWORKS_H_ -#define INCLUDE_OS_VXWORKS_H_ +#ifndef OS_VXWORKS_H +#define OS_VXWORKS_H /**************************************************************************************** COMMON INCLUDE FILES @@ -51,30 +51,10 @@ TYPEDEFS ****************************************************************************************/ -typedef struct -{ - void *const mem; - SEM_ID vxid; -} VxWorks_GlobalMutex_t; - -/* - * Union to facilitate passing an osal_id_t through - * a function/api designed to take an "int" - * - * This relies on sizeof(int) >= sizeof(osal_id_t) - */ -typedef union -{ - osal_id_t id; - int arg; -} VxWorks_ID_Buffer_t; - /**************************************************************************************** GLOBAL DATA ****************************************************************************************/ -extern VxWorks_GlobalMutex_t VX_MUTEX_TABLE[]; - /**************************************************************************************** VXWORKS IMPLEMENTATION FUNCTION PROTOTYPES ****************************************************************************************/ @@ -92,14 +72,14 @@ int32 OS_VxWorks_DirAPI_Impl_Init(void); int OS_VxWorks_TaskEntry(int arg); int OS_VxWorks_ConsoleTask_Entry(int arg); -uint32 OS_VxWorks_SigWait(uint32 local_id); +uint32 OS_VxWorks_SigWait(osal_id_t timebase_id); int OS_VxWorks_TimeBaseTask(int arg); -void OS_VxWorks_RegisterTimer(uint32 local_id); +void OS_VxWorks_RegisterTimer(osal_id_t obj_id); void OS_VxWorks_UsecToTimespec(uint32 usecs, struct timespec *time_spec); int32 OS_VxWorks_GenericSemTake(SEM_ID vxid, int sys_ticks); int32 OS_VxWorks_GenericSemGive(SEM_ID vxid); -int32 OS_VxWorks_TableMutex_Init(uint32 idtype); +int32 OS_VxWorks_TableMutex_Init(osal_objtype_t idtype); -#endif /* INCLUDE_OS_VXWORKS_H_ */ +#endif /* OS_VXWORKS_H */ diff --git a/src/os/vxworks/src/os-impl-binsem.c b/src/os/vxworks/src/os-impl-binsem.c index c2c0c4e96..4c9a1acd4 100644 --- a/src/os/vxworks/src/os-impl-binsem.c +++ b/src/os/vxworks/src/os-impl-binsem.c @@ -33,6 +33,7 @@ #include "os-impl-binsem.h" #include "os-shared-binsem.h" #include "os-shared-timebase.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -70,13 +71,16 @@ int32 OS_VxWorks_BinSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { - SEM_ID tmp_sem_id; + SEM_ID tmp_sem_id; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* Initialize VxWorks Semaphore. * The memory for this sem is statically allocated. */ - tmp_sem_id = semBInitialize(OS_impl_bin_sem_table[sem_id].bmem, SEM_Q_PRIORITY, sem_initial_value); + tmp_sem_id = semBInitialize(impl->bmem, SEM_Q_PRIORITY, sem_initial_value); /* check if semBInitialize failed */ if (tmp_sem_id == (SEM_ID)0) @@ -85,7 +89,7 @@ int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 optio return OS_SEM_FAILURE; } - OS_impl_bin_sem_table[sem_id].vxid = tmp_sem_id; + impl->vxid = tmp_sem_id; return OS_SUCCESS; } /* end OS_BinSemCreate_Impl */ @@ -98,12 +102,16 @@ int32 OS_BinSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 optio * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl(uint32 sem_id) +int32 OS_BinSemDelete_Impl(const OS_object_token_t *token) { + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* * As the memory for the sem is statically allocated, delete is a no-op. */ - OS_impl_bin_sem_table[sem_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_BinSemDelete_Impl */ @@ -116,10 +124,14 @@ int32 OS_BinSemDelete_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl(uint32 sem_id) +int32 OS_BinSemGive_Impl(const OS_object_token_t *token) { + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* Use common routine */ - return OS_VxWorks_GenericSemGive(OS_impl_bin_sem_table[sem_id].vxid); + return OS_VxWorks_GenericSemGive(impl->vxid); } /* end OS_BinSemGive_Impl */ /*---------------------------------------------------------------- @@ -130,10 +142,14 @@ int32 OS_BinSemGive_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl(uint32 sem_id) +int32 OS_BinSemFlush_Impl(const OS_object_token_t *token) { + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* Flush VxWorks Semaphore */ - if (semFlush(OS_impl_bin_sem_table[sem_id].vxid) != OK) + if (semFlush(impl->vxid) != OK) { OS_DEBUG("semFlush() - vxWorks errno %d\n", errno); return OS_SEM_FAILURE; @@ -150,10 +166,14 @@ int32 OS_BinSemFlush_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl(uint32 sem_id) +int32 OS_BinSemTake_Impl(const OS_object_token_t *token) { + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* Use common routine */ - return OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, WAIT_FOREVER); + return OS_VxWorks_GenericSemTake(impl->vxid, WAIT_FOREVER); } /* end OS_BinSemTake_Impl */ @@ -165,16 +185,19 @@ int32 OS_BinSemTake_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl(uint32 sem_id, uint32 msecs) +int32 OS_BinSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - int ticks; - int32 status; + int ticks; + int32 status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); status = OS_Milli2Ticks(msecs, &ticks); if (status == OS_SUCCESS) { - status = OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, ticks); + status = OS_VxWorks_GenericSemTake(impl->vxid, ticks); } return status; @@ -188,7 +211,7 @@ int32 OS_BinSemTimedWait_Impl(uint32 sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl(uint32 sem_id, OS_bin_sem_prop_t *bin_prop) +int32 OS_BinSemGetInfo_Impl(const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop) { /* VxWorks has no API for obtaining the current value of a semaphore */ return OS_SUCCESS; diff --git a/src/os/vxworks/src/os-impl-common.c b/src/os/vxworks/src/os-impl-common.c index 6c3dc4aa8..acf2a2896 100644 --- a/src/os/vxworks/src/os-impl-common.c +++ b/src/os/vxworks/src/os-impl-common.c @@ -31,6 +31,7 @@ #include "os-vxworks.h" #include "os-shared-common.h" +#include "os-shared-idmap.h" #include #include @@ -60,7 +61,7 @@ static TASK_ID OS_idle_task_id; * about objects * *-----------------------------------------------------------------*/ -int32 OS_API_Impl_Init(uint32 idtype) +int32 OS_API_Impl_Init(osal_objtype_t idtype) { int32 return_code; @@ -184,8 +185,11 @@ int32 OS_VxWorks_GenericSemTake(SEM_ID vxid, int sys_ticks) * check for the timeout condition, * which has a different return code and * not necessarily an error of concern. + * + * vxworks7: if sys_ticks == 0, then if the semaphore can + * not be taken S_objLib_OBJ_UNAVAILABLE will be returned */ - if (errno == S_objLib_OBJ_TIMEOUT) + if ((errno == S_objLib_OBJ_TIMEOUT) || (!sys_ticks && (errno == S_objLib_OBJ_UNAVAILABLE))) { return OS_SEM_TIMEOUT; } diff --git a/src/os/vxworks/src/os-impl-console.c b/src/os/vxworks/src/os-impl-console.c index 52f82aa64..f5d44dc69 100644 --- a/src/os/vxworks/src/os-impl-console.c +++ b/src/os/vxworks/src/os-impl-console.c @@ -32,6 +32,8 @@ #include "os-impl-console.h" #include "os-shared-printf.h" +#include "os-shared-idmap.h" +#include "os-shared-common.h" /**************************************************************************************** DEFINES @@ -66,9 +68,11 @@ OS_impl_console_internal_record_t OS_impl_console_table[OS_MAX_CONSOLES]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(uint32 local_id) +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; + + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); if (local->is_async) { @@ -81,7 +85,7 @@ void OS_ConsoleWakeup_Impl(uint32 local_id) else { /* output directly */ - OS_ConsoleOutput_Impl(local_id); + OS_ConsoleOutput_Impl(token); } } /* end OS_ConsoleWakeup_Impl */ @@ -94,18 +98,25 @@ void OS_ConsoleWakeup_Impl(uint32 local_id) *-----------------------------------------------------------------*/ int OS_VxWorks_ConsoleTask_Entry(int arg) { - uint32 local_id = arg; OS_impl_console_internal_record_t *local; + OS_object_token_t token; - local = &OS_impl_console_table[local_id]; - while (true) + if (OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_CONSOLE, OS_ObjectIdFromInteger(arg), &token) == + OS_SUCCESS) { - OS_ConsoleOutput_Impl(local_id); - if (semTake(local->datasem, WAIT_FOREVER) == ERROR) + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, token); + + /* Loop forever (unless shutdown is set) */ + while (OS_SharedGlobalVars.ShutdownFlag != OS_SHUTDOWN_MAGIC_NUMBER) { - OS_DEBUG("semTake() - vxWorks errno %d\n", errno); - break; + OS_ConsoleOutput_Impl(&token); + if (semTake(local->datasem, WAIT_FOREVER) == ERROR) + { + OS_DEBUG("semTake() - vxWorks errno %d\n", errno); + break; + } } + OS_ObjectIdRelease(&token); } return OK; @@ -119,12 +130,16 @@ int OS_VxWorks_ConsoleTask_Entry(int arg) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(uint32 local_id) +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; int32 return_code; + OS_console_internal_record_t * console; + + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); + console = OS_OBJECT_TABLE_GET(OS_console_table, *token); - if (local_id == 0) + if (OS_ObjectIndexFromToken(token) == 0) { return_code = OS_SUCCESS; local->is_async = OS_CONSOLE_ASYNC; @@ -145,9 +160,9 @@ int32 OS_ConsoleCreate_Impl(uint32 local_id) } /* spawn the async output helper task */ - local->taskid = taskSpawn(OS_console_table[local_id].device_name, OS_CONSOLE_TASK_PRIORITY, 0, - OS_CONSOLE_TASK_STACKSIZE, (FUNCPTR)OS_VxWorks_ConsoleTask_Entry, local_id, 0, 0, - 0, 0, 0, 0, 0, 0, 0); + local->taskid = taskSpawn(console->device_name, OS_CONSOLE_TASK_PRIORITY, 0, OS_CONSOLE_TASK_STACKSIZE, + (FUNCPTR)OS_VxWorks_ConsoleTask_Entry, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), 0, 0, 0, 0, 0, 0, 0, 0, 0); if (local->taskid == (TASK_ID)ERROR) { diff --git a/src/os/vxworks/src/os-impl-countsem.c b/src/os/vxworks/src/os-impl-countsem.c index c22f847d4..3f4ef65e7 100644 --- a/src/os/vxworks/src/os-impl-countsem.c +++ b/src/os/vxworks/src/os-impl-countsem.c @@ -32,6 +32,7 @@ #include "os-impl-countsem.h" #include "os-shared-countsem.h" #include "os-shared-timebase.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -69,13 +70,16 @@ int32 OS_VxWorks_CountSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_CountSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { - SEM_ID tmp_sem_id; + SEM_ID tmp_sem_id; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); /* Initialize VxWorks Semaphore. * The memory for this sem is statically allocated. */ - tmp_sem_id = semCInitialize(OS_impl_count_sem_table[sem_id].cmem, SEM_Q_PRIORITY, sem_initial_value); + tmp_sem_id = semCInitialize(impl->cmem, SEM_Q_PRIORITY, sem_initial_value); /* check if semCInitialize failed */ if (tmp_sem_id == (SEM_ID)0) @@ -84,7 +88,7 @@ int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 opt return OS_SEM_FAILURE; } - OS_impl_count_sem_table[sem_id].vxid = tmp_sem_id; + impl->vxid = tmp_sem_id; return OS_SUCCESS; } /* end OS_CountSemCreate_Impl */ @@ -97,12 +101,16 @@ int32 OS_CountSemCreate_Impl(uint32 sem_id, uint32 sem_initial_value, uint32 opt * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl(uint32 sem_id) +int32 OS_CountSemDelete_Impl(const OS_object_token_t *token) { + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + /* * As the memory for the sem is statically allocated, delete is a no-op. */ - OS_impl_count_sem_table[sem_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_CountSemDelete_Impl */ @@ -115,10 +123,14 @@ int32 OS_CountSemDelete_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl(uint32 sem_id) +int32 OS_CountSemGive_Impl(const OS_object_token_t *token) { + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + /* Give VxWorks Semaphore */ - return OS_VxWorks_GenericSemGive(OS_impl_count_sem_table[sem_id].vxid); + return OS_VxWorks_GenericSemGive(impl->vxid); } /* end OS_CountSemGive_Impl */ /*---------------------------------------------------------------- @@ -129,9 +141,13 @@ int32 OS_CountSemGive_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl(uint32 sem_id) +int32 OS_CountSemTake_Impl(const OS_object_token_t *token) { - return OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, WAIT_FOREVER); + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + return OS_VxWorks_GenericSemTake(impl->vxid, WAIT_FOREVER); } /* end OS_CountSemTake_Impl */ /*---------------------------------------------------------------- @@ -142,16 +158,19 @@ int32 OS_CountSemTake_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl(uint32 sem_id, uint32 msecs) +int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - int ticks; - int32 status; + int ticks; + int32 status; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); status = OS_Milli2Ticks(msecs, &ticks); if (status == OS_SUCCESS) { - status = OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, ticks); + status = OS_VxWorks_GenericSemTake(impl->vxid, ticks); } return status; @@ -165,7 +184,7 @@ int32 OS_CountSemTimedWait_Impl(uint32 sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl(uint32 sem_id, OS_count_sem_prop_t *count_prop) +int32 OS_CountSemGetInfo_Impl(const OS_object_token_t *token, OS_count_sem_prop_t *count_prop) { /* VxWorks does not provide an API to get the value */ return OS_SUCCESS; diff --git a/src/unit-tests/osprintf-test/ut_osprintf_printf.c b/src/os/vxworks/src/os-impl-dirs-globals.c similarity index 51% rename from src/unit-tests/osprintf-test/ut_osprintf_printf.c rename to src/os/vxworks/src/os-impl-dirs-globals.c index 182261db2..aa53a3585 100644 --- a/src/unit-tests/osprintf-test/ut_osprintf_printf.c +++ b/src/os/vxworks/src/os-impl-dirs-globals.c @@ -18,32 +18,35 @@ * limitations under the License. */ -/* - * UT_osprintf_printf.c +/** + * \file os-impl-dirs.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov * - * Created on: May 22, 2013 - * Author: Kevin McCluney */ -#ifdef OS_USE_EMBEDDED_PRINTF +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ -#include "ut_osprintf.h" +#include "os-vxworks.h" +#include "os-impl-dirs.h" +#include "os-shared-dir.h" -extern unsigned OS_printf_enabled; +/* + * The directory handle table. + */ +OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; -/***************************************************************************** - * Tests of embedded printf to get complete osprintf.c code coverage - *****************************************************************************/ -void UT_osprintf_printf(void) +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_DirAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_DirAPI_Impl_Init(void) { - /* Perform printf enabled test */ - OS_printf("%s", "printf_test_string\n"); - UT_Report(UT_PASS, "PRINTF", "Output to console", "%s", "01"); - - /* Perform printf disabled test */ - OS_printf_enabled = 0; - OS_printf("%s", "printf_test_string_disabled\n"); - UT_Report(UT_PASS, "PRINTF", "Output to console disabled", "%s", "02"); - OS_printf_enabled = 1; -} -#endif + memset(OS_impl_dir_table, 0, sizeof(OS_impl_dir_table)); + return OS_SUCCESS; +} /* end OS_VxWorks_DirAPI_Impl_Init */ diff --git a/src/os/vxworks/src/os-impl-dirs.c b/src/os/vxworks/src/os-impl-dirs.c deleted file mode 100644 index 9e6cff52f..000000000 --- a/src/os/vxworks/src/os-impl-dirs.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file os-impl-dirs.c - * \ingroup vxworks - * \author joseph.p.hickey@nasa.gov - * - */ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ - -#include "os-vxworks.h" -#include "os-impl-dirs.h" -#include "os-shared-dir.h" - -/* - * The directory handle table. - */ -OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_DirAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_VxWorks_DirAPI_Impl_Init(void) -{ - memset(OS_impl_dir_table, 0, sizeof(OS_impl_dir_table)); - return OS_SUCCESS; -} /* end OS_VxWorks_DirAPI_Impl_Init */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirCreate_Impl(const char *local_path, uint32 access) -{ - int32 return_code; - - if (mkdir(local_path) != OK) - { - return_code = OS_ERROR; - } - else - { - return_code = OS_SUCCESS; - } - - return return_code; -} /* end OS_DirCreate_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirOpen_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) -{ - OS_impl_dir_table[local_id].dp = opendir(local_path); - if (OS_impl_dir_table[local_id].dp == NULL) - { - return OS_ERROR; - } - return OS_SUCCESS; -} /* end OS_DirOpen_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirClose_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirClose_Impl(uint32 local_id) -{ - closedir(OS_impl_dir_table[local_id].dp); - OS_impl_dir_table[local_id].dp = NULL; - return OS_SUCCESS; -} /* end OS_DirClose_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirRead_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) -{ - struct dirent *de; - - /* NOTE - the readdir() call is non-reentrant .... - * However, this is performed while the global dir table lock is taken. - * Therefore this ensures that only one such call can occur at any given time. - * - * Static analysis tools may warn about this because they do not know - * this function is externally serialized via the global lock. - */ - /* cppcheck-suppress readdirCalled */ - /* cppcheck-suppress nonreentrantFunctionsreaddir */ - de = readdir(OS_impl_dir_table[local_id].dp); - if (de == NULL) - { - return OS_ERROR; - } - - strncpy(dirent->FileName, de->d_name, sizeof(dirent->FileName) - 1); - dirent->FileName[sizeof(dirent->FileName) - 1] = 0; - - return OS_SUCCESS; -} /* end OS_DirRead_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirRewind_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirRewind_Impl(uint32 local_id) -{ - rewinddir(OS_impl_dir_table[local_id].dp); - return OS_SUCCESS; -} /* end OS_DirRewind_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirRemove_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirRemove_Impl(const char *local_path) -{ - if (rmdir(local_path) < 0) - { - return OS_ERROR; - } - - return OS_SUCCESS; -} /* end OS_DirRemove_Impl */ diff --git a/src/os/vxworks/src/os-impl-files.c b/src/os/vxworks/src/os-impl-files.c index cb024ebd1..c839fe469 100644 --- a/src/os/vxworks/src/os-impl-files.c +++ b/src/os/vxworks/src/os-impl-files.c @@ -38,7 +38,7 @@ * * This is shared by all OSAL entities that perform low-level I/O. */ -OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; +OS_impl_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; /*---------------------------------------------------------------- * @@ -49,7 +49,7 @@ OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; *-----------------------------------------------------------------*/ int32 OS_VxWorks_StreamAPI_Impl_Init(void) { - uint32 local_id; + osal_index_t local_id; /* * init all filehandles to -1, which is always invalid. diff --git a/src/os/vxworks/src/os-impl-filesys.c b/src/os/vxworks/src/os-impl-filesys.c index 1a3a3ff32..5352e8563 100644 --- a/src/os/vxworks/src/os-impl-filesys.c +++ b/src/os/vxworks/src/os-impl-filesys.c @@ -32,6 +32,7 @@ #include "os-vxworks.h" #include "os-impl-filesys.h" +#include "os-impl-dirs.h" #include "os-shared-filesys.h" #include "os-shared-idmap.h" @@ -76,12 +77,15 @@ OS_impl_filesys_internal_record_t OS_impl_filesys_table[OS_MAX_FILE_SYSTEMS]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStartVolume_Impl(uint32 filesys_id) +int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; int32 return_code; + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + memset(impl, 0, sizeof(*impl)); return_code = OS_ERR_NOT_IMPLEMENTED; switch (local->fstype) @@ -192,10 +196,13 @@ int32 OS_FileSysStartVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStopVolume_Impl(uint32 filesys_id) +int32 OS_FileSysStopVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); switch (local->fstype) { @@ -231,12 +238,14 @@ int32 OS_FileSysStopVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysFormatVolume_Impl(uint32 filesys_id) +int32 OS_FileSysFormatVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; int32 return_code = OS_ERR_NOT_IMPLEMENTED; int status; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + switch (local->fstype) { case OS_FILESYS_TYPE_FS_BASED: @@ -282,25 +291,67 @@ int32 OS_FileSysFormatVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysMountVolume_Impl(uint32 filesys_id) +int32 OS_FileSysMountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; int32 status; int fd; + struct stat stat_buf; + + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); /* - * Calling open() on the physical device path - * mounts the device. + * For FS-based mounts, these are just a map to a some other + * directory in the filesystem. + * + * If it does exist then make sure it is actually a directory. + * If it does not exist then attempt to create it. */ - fd = open(local->system_mountpt, O_RDONLY, 0644); - if (fd < 0) + if (local->fstype == OS_FILESYS_TYPE_FS_BASED) { - status = OS_ERROR; + if (stat(local->system_mountpt, &stat_buf) == 0) + { + if (S_ISDIR(stat_buf.st_mode)) + { + /* mount point exists */ + status = OS_SUCCESS; + } + else + { + OS_DEBUG("%s is not a directory\n", local->system_mountpt); + status = OS_FS_ERR_PATH_INVALID; + } + } + else + { + if (mkdir(local->system_mountpt, 0775) == 0) + { + /* directory created OK */ + status = OS_SUCCESS; + } + else + { + OS_DEBUG("mkdir(%s): errno=%d\n", local->system_mountpt, errnoGet()); + status = OS_FS_ERR_DRIVE_NOT_CREATED; + } + } } else { - status = OS_SUCCESS; - close(fd); + /* + * For all other (non-FS_BASED) filesystem types, + * Calling open() on the physical device path mounts the device. + */ + fd = open(local->system_mountpt, O_RDONLY, 0644); + if (fd < 0) + { + status = OS_ERROR; + } + else + { + status = OS_SUCCESS; + close(fd); + } } return status; @@ -315,32 +366,42 @@ int32 OS_FileSysMountVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysUnmountVolume_Impl(uint32 filesys_id) +int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; int32 status; int fd; - /* - ** vxWorks uses an ioctl to unmount - */ - fd = open(local->system_mountpt, O_RDONLY, 0644); - if (fd < 0) + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + + if (local->fstype == OS_FILESYS_TYPE_FS_BASED) { - status = OS_ERROR; + /* unmount is a no-op on FS-based mounts - it is just a directory map */ + status = OS_SUCCESS; } else { - if (ioctl(fd, FIOUNMOUNT, 0) < 0) + /* + ** vxWorks uses an ioctl to unmount + */ + fd = open(local->system_mountpt, O_RDONLY, 0644); + if (fd < 0) { status = OS_ERROR; } else { - status = OS_SUCCESS; - } + if (ioctl(fd, FIOUNMOUNT, 0) < 0) + { + status = OS_ERROR; + } + else + { + status = OS_SUCCESS; + } - close(fd); + close(fd); + } } return status; @@ -355,12 +416,14 @@ int32 OS_FileSysUnmountVolume_Impl(uint32 filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result) +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct statfs stat_buf; int return_code; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + if (statfs(local->system_mountpt, &stat_buf) != 0) { return_code = OS_ERROR; @@ -368,9 +431,9 @@ int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result) } else { - result->block_size = stat_buf.f_bsize; - result->blocks_free = stat_buf.f_bfree; - result->total_blocks = stat_buf.f_blocks; + result->block_size = OSAL_SIZE_C(stat_buf.f_bsize); + result->blocks_free = OSAL_BLOCKCOUNT_C(stat_buf.f_bfree); + result->total_blocks = OSAL_BLOCKCOUNT_C(stat_buf.f_blocks); return_code = OS_SUCCESS; } @@ -386,13 +449,15 @@ int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysCheckVolume_Impl(uint32 filesys_id, bool repair) +int32 OS_FileSysCheckVolume_Impl(const OS_object_token_t *token, bool repair) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; STATUS chk_status; int flags; int fd; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + fd = open(local->system_mountpt, O_RDONLY, 0); if (fd < 0) { diff --git a/src/os/vxworks/src/os-impl-heap.c b/src/os/vxworks/src/os-impl-heap.c index fb46f0780..8931130c0 100644 --- a/src/os/vxworks/src/os-impl-heap.c +++ b/src/os/vxworks/src/os-impl-heap.c @@ -57,9 +57,9 @@ int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop) return OS_ERROR; } - heap_prop->free_bytes = stats.numBytesFree; - heap_prop->free_blocks = stats.numBlocksFree; - heap_prop->largest_free_block = stats.maxBlockSizeFree; + heap_prop->free_bytes = OSAL_SIZE_C(stats.numBytesFree); + heap_prop->free_blocks = OSAL_BLOCKCOUNT_C(stats.numBlocksFree); + heap_prop->largest_free_block = OSAL_SIZE_C(stats.maxBlockSizeFree); return (OS_SUCCESS); } /* end OS_HeapGetInfo_Impl */ diff --git a/src/os/vxworks/src/os-impl-idmap.c b/src/os/vxworks/src/os-impl-idmap.c index 41752a387..a8da5bd2d 100644 --- a/src/os/vxworks/src/os-impl-idmap.c +++ b/src/os/vxworks/src/os-impl-idmap.c @@ -29,12 +29,15 @@ ****************************************************************************************/ #include "os-vxworks.h" +#include "os-impl-idmap.h" #include "os-shared-idmap.h" +#include #include #include #include #include +#include /**************************************************************************************** DEFINES @@ -55,28 +58,35 @@ VX_MUTEX_SEMAPHORE(OS_timebase_table_mut_mem); VX_MUTEX_SEMAPHORE(OS_timecb_table_mut_mem); VX_MUTEX_SEMAPHORE(OS_module_table_mut_mem); VX_MUTEX_SEMAPHORE(OS_filesys_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_console_mut_mem); - -VxWorks_GlobalMutex_t VX_MUTEX_TABLE[] = { - [OS_OBJECT_TYPE_UNDEFINED] = {NULL}, - [OS_OBJECT_TYPE_OS_TASK] = {.mem = OS_task_table_mut_mem}, - [OS_OBJECT_TYPE_OS_QUEUE] = {.mem = OS_queue_table_mut_mem}, - [OS_OBJECT_TYPE_OS_COUNTSEM] = {.mem = OS_count_sem_table_mut_mem}, - [OS_OBJECT_TYPE_OS_BINSEM] = {.mem = OS_bin_sem_table_mut_mem}, - [OS_OBJECT_TYPE_OS_MUTEX] = {.mem = OS_mutex_table_mut_mem}, - [OS_OBJECT_TYPE_OS_STREAM] = {.mem = OS_stream_table_mut_mem}, - [OS_OBJECT_TYPE_OS_DIR] = {.mem = OS_dir_table_mut_mem}, - [OS_OBJECT_TYPE_OS_TIMEBASE] = {.mem = OS_timebase_table_mut_mem}, - [OS_OBJECT_TYPE_OS_TIMECB] = {.mem = OS_timecb_table_mut_mem}, - [OS_OBJECT_TYPE_OS_MODULE] = {.mem = OS_module_table_mut_mem}, - [OS_OBJECT_TYPE_OS_FILESYS] = {.mem = OS_filesys_table_mut_mem}, - [OS_OBJECT_TYPE_OS_CONSOLE] = {.mem = OS_console_mut_mem}, -}; - -enum -{ - VX_MUTEX_TABLE_SIZE = (sizeof(VX_MUTEX_TABLE) / sizeof(VX_MUTEX_TABLE[0])) -}; +VX_MUTEX_SEMAPHORE(OS_console_table_mut_mem); + +static OS_impl_objtype_lock_t OS_task_table_lock = {.mem = OS_task_table_mut_mem}; +static OS_impl_objtype_lock_t OS_queue_table_lock = {.mem = OS_queue_table_mut_mem}; +static OS_impl_objtype_lock_t OS_bin_sem_table_lock = {.mem = OS_bin_sem_table_mut_mem}; +static OS_impl_objtype_lock_t OS_mutex_table_lock = {.mem = OS_mutex_table_mut_mem}; +static OS_impl_objtype_lock_t OS_count_sem_table_lock = {.mem = OS_count_sem_table_mut_mem}; +static OS_impl_objtype_lock_t OS_stream_table_lock = {.mem = OS_stream_table_mut_mem}; +static OS_impl_objtype_lock_t OS_dir_table_lock = {.mem = OS_dir_table_mut_mem}; +static OS_impl_objtype_lock_t OS_timebase_table_lock = {.mem = OS_timebase_table_mut_mem}; +static OS_impl_objtype_lock_t OS_timecb_table_lock = {.mem = OS_timecb_table_mut_mem}; +static OS_impl_objtype_lock_t OS_module_table_lock = {.mem = OS_module_table_mut_mem}; +static OS_impl_objtype_lock_t OS_filesys_table_lock = {.mem = OS_filesys_table_mut_mem}; +static OS_impl_objtype_lock_t OS_console_table_lock = {.mem = OS_console_table_mut_mem}; + +OS_impl_objtype_lock_t *const OS_impl_objtype_lock_table[OS_OBJECT_TYPE_USER] = { + [OS_OBJECT_TYPE_UNDEFINED] = NULL, + [OS_OBJECT_TYPE_OS_TASK] = &OS_task_table_lock, + [OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_lock, + [OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_lock, + [OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_lock, + [OS_OBJECT_TYPE_OS_MUTEX] = &OS_mutex_table_lock, + [OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_lock, + [OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_lock, + [OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_lock, + [OS_OBJECT_TYPE_OS_TIMECB] = &OS_timecb_table_lock, + [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_lock, + [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_lock, + [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_table_lock}; /*---------------------------------------------------------------- * @@ -86,28 +96,17 @@ enum * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_Lock_Global_Impl(uint32 idtype) +void OS_Lock_Global_Impl(osal_objtype_t idtype) { - VxWorks_GlobalMutex_t *mut; - - if (idtype >= VX_MUTEX_TABLE_SIZE) - { - return OS_ERROR; - } + OS_impl_objtype_lock_t *impl; - mut = &VX_MUTEX_TABLE[idtype]; - if (mut->vxid == (SEM_ID)0) - { - return OS_ERROR; - } + impl = OS_impl_objtype_lock_table[idtype]; - if (semTake(mut->vxid, WAIT_FOREVER) != OK) + if (semTake(impl->vxid, WAIT_FOREVER) != OK) { OS_DEBUG("semTake() - vxWorks errno %d\n", errno); - return OS_ERROR; } - return OS_SUCCESS; } /* end OS_Lock_Global_Impl */ /*---------------------------------------------------------------- @@ -118,29 +117,44 @@ int32 OS_Lock_Global_Impl(uint32 idtype) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_Unlock_Global_Impl(uint32 idtype) +void OS_Unlock_Global_Impl(osal_objtype_t idtype) { - VxWorks_GlobalMutex_t *mut; + OS_impl_objtype_lock_t *impl; - if (idtype >= VX_MUTEX_TABLE_SIZE) + impl = OS_impl_objtype_lock_table[idtype]; + + if (semGive(impl->vxid) != OK) { - return OS_ERROR; + OS_DEBUG("semGive() - vxWorks errno %d\n", errno); } - mut = &VX_MUTEX_TABLE[idtype]; - if (mut->vxid == (SEM_ID)0) +} /* end OS_Unlock_Global_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_WaitForStateChange_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_WaitForStateChange_Impl(osal_objtype_t idtype, uint32 attempts) +{ + int wait_ticks; + + if (attempts <= 10) { - return OS_ERROR; + wait_ticks = attempts * attempts; } - - if (semGive(mut->vxid) != OK) + else { - OS_DEBUG("semGive() - vxWorks errno %d\n", errno); - return OS_ERROR; + wait_ticks = 100; } - return OS_SUCCESS; -} /* end OS_Unlock_Global_Impl */ + OS_Unlock_Global_Impl(idtype); + taskDelay(wait_ticks); + OS_Lock_Global_Impl(idtype); +} /**************************************************************************************** INITIALIZATION FUNCTION @@ -154,26 +168,28 @@ int32 OS_Unlock_Global_Impl(uint32 idtype) * about objects * *-----------------------------------------------------------------*/ -int32 OS_VxWorks_TableMutex_Init(uint32 idtype) +int32 OS_VxWorks_TableMutex_Init(osal_objtype_t idtype) { - int32 return_code = OS_SUCCESS; - SEM_ID semid; + OS_impl_objtype_lock_t *impl; + SEM_ID semid; + + impl = OS_impl_objtype_lock_table[idtype]; + if (impl == NULL) + { + return OS_SUCCESS; + } /* Initialize the table mutex for the given idtype */ - if (idtype < VX_MUTEX_TABLE_SIZE && VX_MUTEX_TABLE[idtype].mem != NULL) + semid = semMInitialize(impl->mem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); + + if (semid == (SEM_ID)0) { - semid = semMInitialize(VX_MUTEX_TABLE[idtype].mem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); - - if (semid == (SEM_ID)0) - { - OS_DEBUG("Error: semMInitialize() failed - vxWorks errno %d\n", errno); - return_code = OS_ERROR; - } - else - { - VX_MUTEX_TABLE[idtype].vxid = semid; - } + OS_DEBUG("Error: semMInitialize() failed - vxWorks errno %d\n", errno); + return OS_ERROR; } - return (return_code); + impl->vxid = semid; + + return OS_SUCCESS; + } /* end OS_VxWorks_TableMutex_Init */ diff --git a/src/os/vxworks/src/os-impl-loader.c b/src/os/vxworks/src/os-impl-loader.c index 7ab65fae6..49e693be4 100644 --- a/src/os/vxworks/src/os-impl-loader.c +++ b/src/os/vxworks/src/os-impl-loader.c @@ -32,6 +32,7 @@ #include "os-vxworks.h" #include "os-impl-loader.h" #include "os-shared-module.h" +#include "os-shared-idmap.h" #include #include @@ -71,11 +72,14 @@ int32 OS_VxWorks_ModuleAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(uint32 local_id, const char *translated_path) +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) { - int32 return_code; - int fd; - MODULE_ID vxModuleId; + int32 return_code; + int fd; + MODULE_ID vxModuleId; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); /* ** File is ready to load @@ -104,8 +108,8 @@ int32 OS_ModuleLoad_Impl(uint32 local_id, const char *translated_path) } else { - OS_impl_module_table[local_id].moduleID = vxModuleId; - return_code = OS_SUCCESS; + impl->moduleID = vxModuleId; + return_code = OS_SUCCESS; } /* @@ -126,14 +130,17 @@ int32 OS_ModuleLoad_Impl(uint32 local_id, const char *translated_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(uint32 local_id) +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) { - STATUS vxStatus; + STATUS vxStatus; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); /* ** Attempt to close/unload the module */ - vxStatus = unldByModuleId(OS_impl_module_table[local_id].moduleID, 0); + vxStatus = unldByModuleId(impl->moduleID, 0); if (vxStatus == ERROR) { OS_DEBUG("OSAL: Error, Cannot Close/Unload application file: %d\n", vxStatus); @@ -152,17 +159,20 @@ int32 OS_ModuleUnload_Impl(uint32 local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(uint32 local_id, OS_module_prop_t *module_prop) +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop) { - MODULE_INFO vxModuleInfo; - STATUS vxStatus; + MODULE_INFO vxModuleInfo; + STATUS vxStatus; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); - module_prop->host_module_id = (cpuaddr)OS_impl_module_table[local_id].moduleID; + module_prop->host_module_id = (cpuaddr)impl->moduleID; /* ** Get the module info from vxWorks */ - vxStatus = moduleInfoGet(OS_impl_module_table[local_id].moduleID, &vxModuleInfo); + vxStatus = moduleInfoGet(impl->moduleID, &vxModuleInfo); if (vxStatus == ERROR) { OS_DEBUG("OSAL: OS_ModuleInfoGet Error from vxWorks: %d\n", vxStatus); diff --git a/src/os/vxworks/src/os-impl-mutex.c b/src/os/vxworks/src/os-impl-mutex.c index 54273f14e..d044e5bed 100644 --- a/src/os/vxworks/src/os-impl-mutex.c +++ b/src/os/vxworks/src/os-impl-mutex.c @@ -32,6 +32,7 @@ #include "os-impl-mutex.h" #include "os-shared-mutex.h" +#include "os-shared-idmap.h" #include @@ -67,13 +68,16 @@ int32 OS_VxWorks_MutexAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) +int32 OS_MutSemCreate_Impl(const OS_object_token_t *token, uint32 options) { - SEM_ID tmp_sem_id; + SEM_ID tmp_sem_id; + OS_impl_mutsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* Initialize VxWorks Semaphore. * The memory for this sem is statically allocated. */ - tmp_sem_id = semMInitialize(OS_impl_mutex_table[sem_id].mmem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); + tmp_sem_id = semMInitialize(impl->mmem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); if (tmp_sem_id == (SEM_ID)0) { @@ -81,7 +85,7 @@ int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) return OS_SEM_FAILURE; } - OS_impl_mutex_table[sem_id].vxid = tmp_sem_id; + impl->vxid = tmp_sem_id; return OS_SUCCESS; } /* end OS_MutSemCreate_Impl */ @@ -93,12 +97,16 @@ int32 OS_MutSemCreate_Impl(uint32 sem_id, uint32 options) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl(uint32 sem_id) +int32 OS_MutSemDelete_Impl(const OS_object_token_t *token) { + OS_impl_mutsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); + /* * As the memory for the sem is statically allocated, delete is a no-op. */ - OS_impl_mutex_table[sem_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_MutSemDelete_Impl */ @@ -111,10 +119,14 @@ int32 OS_MutSemDelete_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl(uint32 sem_id) +int32 OS_MutSemGive_Impl(const OS_object_token_t *token) { + OS_impl_mutsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); + /* Give VxWorks Semaphore */ - return OS_VxWorks_GenericSemGive(OS_impl_mutex_table[sem_id].vxid); + return OS_VxWorks_GenericSemGive(impl->vxid); } /* end OS_MutSemGive_Impl */ /*---------------------------------------------------------------- @@ -125,10 +137,14 @@ int32 OS_MutSemGive_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl(uint32 sem_id) +int32 OS_MutSemTake_Impl(const OS_object_token_t *token) { + OS_impl_mutsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); + /* Take VxWorks Semaphore */ - return OS_VxWorks_GenericSemTake(OS_impl_mutex_table[sem_id].vxid, WAIT_FOREVER); + return OS_VxWorks_GenericSemTake(impl->vxid, WAIT_FOREVER); } /* end OS_MutSemTake_Impl */ /*---------------------------------------------------------------- @@ -139,7 +155,7 @@ int32 OS_MutSemTake_Impl(uint32 sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl(uint32 sem_id, OS_mut_sem_prop_t *mut_prop) +int32 OS_MutSemGetInfo_Impl(const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop) { /* VxWorks provides no additional info */ return OS_SUCCESS; diff --git a/src/os/vxworks/src/os-impl-network.c b/src/os/vxworks/src/os-impl-network.c index 63c526be6..6180c1439 100644 --- a/src/os/vxworks/src/os-impl-network.c +++ b/src/os/vxworks/src/os-impl-network.c @@ -43,7 +43,7 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_NetworkGetHostName_Impl(char *host_name, uint32 name_len) +int32 OS_NetworkGetHostName_Impl(char *host_name, size_t name_len) { int32 return_code; diff --git a/src/os/vxworks/src/os-impl-queues.c b/src/os/vxworks/src/os-impl-queues.c index 319d5e1dd..99e8a3002 100644 --- a/src/os/vxworks/src/os-impl-queues.c +++ b/src/os/vxworks/src/os-impl-queues.c @@ -32,6 +32,7 @@ #include "os-impl-queues.h" #include "os-shared-queue.h" #include "os-shared-timebase.h" +#include "os-shared-idmap.h" /**************************************************************************************** GLOBAL DATA @@ -63,11 +64,19 @@ int32 OS_VxWorks_QueueAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) +int32 OS_QueueCreate_Impl(const OS_object_token_t *token, uint32 flags) { - MSG_Q_ID tmp_msgq_id; - int queue_depth = OS_queue_table[queue_id].max_depth; /* maximum number of messages in queue (queue depth) */ - int data_size = OS_queue_table[queue_id].max_size; /* maximum size in bytes of a message */ + MSG_Q_ID tmp_msgq_id; + int queue_depth; + int data_size; + OS_impl_queue_internal_record_t *impl; + OS_queue_internal_record_t * queue; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + queue = OS_OBJECT_TABLE_GET(OS_queue_table, *token); + + queue_depth = queue->max_depth; /* maximum number of messages in queue (queue depth) */ + data_size = queue->max_size; /* maximum size in bytes of a message */ /* Create VxWorks Message Queue */ tmp_msgq_id = msgQCreate(queue_depth, data_size, MSG_Q_FIFO); @@ -79,7 +88,7 @@ int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) return OS_ERROR; } - OS_impl_queue_table[queue_id].vxid = tmp_msgq_id; + impl->vxid = tmp_msgq_id; return OS_SUCCESS; } /* end OS_QueueCreate_Impl */ @@ -92,16 +101,20 @@ int32 OS_QueueCreate_Impl(uint32 queue_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl(uint32 queue_id) +int32 OS_QueueDelete_Impl(const OS_object_token_t *token) { + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + /* Try to delete the queue */ - if (msgQDelete(OS_impl_queue_table[queue_id].vxid) != OK) + if (msgQDelete(impl->vxid) != OK) { OS_DEBUG("msgQDelete() - vxWorks errno %d\n", errno); return OS_ERROR; } - OS_impl_queue_table[queue_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_QueueDelete_Impl */ @@ -114,11 +127,14 @@ int32 OS_QueueDelete_Impl(uint32 queue_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) +int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout) { - int32 return_code; - STATUS status; - int ticks; + int32 return_code; + STATUS status; + int ticks; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* Get Message From Message Queue */ if (timeout == OS_PEND) @@ -138,7 +154,7 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co } } - status = msgQReceive(OS_impl_queue_table[queue_id].vxid, data, size, ticks); + status = msgQReceive(impl->vxid, data, size, ticks); if (status == ERROR) { @@ -159,7 +175,7 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co } else { - *size_copied = status; + *size_copied = OSAL_SIZE_C(status); return_code = OS_SUCCESS; } @@ -174,11 +190,14 @@ int32 OS_QueueGet_Impl(uint32 queue_id, void *data, uint32 size, uint32 *size_co * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueuePut_Impl(uint32 queue_id, const void *data, uint32 size, uint32 flags) +int32 OS_QueuePut_Impl(const OS_object_token_t *token, const void *data, size_t size, uint32 flags) { - int32 return_code; + int32 return_code; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); - if (msgQSend(OS_impl_queue_table[queue_id].vxid, (void *)data, size, NO_WAIT, MSG_PRI_NORMAL) == OK) + if (msgQSend(impl->vxid, (void *)data, size, NO_WAIT, MSG_PRI_NORMAL) == OK) { return_code = OS_SUCCESS; } @@ -204,7 +223,7 @@ int32 OS_QueuePut_Impl(uint32 queue_id, const void *data, uint32 size, uint32 fl * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGetInfo_Impl(uint32 queue_id, OS_queue_prop_t *queue_prop) +int32 OS_QueueGetInfo_Impl(const OS_object_token_t *token, OS_queue_prop_t *queue_prop) { /* No extra info for queues in the OS implementation */ return OS_SUCCESS; diff --git a/src/os/vxworks/src/os-impl-shell.c b/src/os/vxworks/src/os-impl-shell.c index a43fce496..4401c9867 100644 --- a/src/os/vxworks/src/os-impl-shell.c +++ b/src/os/vxworks/src/os-impl-shell.c @@ -33,6 +33,8 @@ #include "os-impl-io.h" #include "os-shared-shell.h" #include "os-shared-file.h" +#include "os-shared-idmap.h" +#include "os-shared-common.h" #include #include @@ -52,13 +54,15 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) { - int32 ReturnCode = OS_ERROR; - int32 Result; - osal_id_t fdCmd; - uint32 cmdidx; - char * shellName; + int32 ReturnCode = OS_ERROR; + int32 Result; + osal_id_t fdCmd; + char * shellName; + OS_impl_file_internal_record_t *out_impl; + OS_impl_file_internal_record_t *cmd_impl; + OS_object_token_t cmd_token; /* Create a file to write the command to (or write over the old one) */ Result = @@ -69,16 +73,18 @@ int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) return Result; } - if (OS_ConvertToArrayIndex(fdCmd, &cmdidx) == OS_SUCCESS) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_STREAM, fdCmd, &cmd_token) == OS_SUCCESS) { + out_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + cmd_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, cmd_token); + /* copy the command to the file, and then seek back to the beginning of the file */ - OS_write(fdCmd, Cmd, strlen(Cmd)); + OS_write(fdCmd, Cmd, OS_strnlen(Cmd, OS_MAX_CMD_LEN)); OS_lseek(fdCmd, 0, OS_SEEK_SET); /* Create a shell task the will run the command in the file, push output to OS_fd */ - Result = - shellGenericInit("INTERPRETER=Cmd", 0, NULL, &shellName, false, false, OS_impl_filehandle_table[cmdidx].fd, - OS_impl_filehandle_table[file_id].fd, OS_impl_filehandle_table[file_id].fd); + Result = shellGenericInit("INTERPRETER=Cmd", 0, NULL, &shellName, false, false, cmd_impl->fd, out_impl->fd, + out_impl->fd); } if (Result == OK) diff --git a/src/os/vxworks/src/os-impl-symtab.c b/src/os/vxworks/src/os-impl-symtab.c index d3ebaf85a..ed4244761 100644 --- a/src/os/vxworks/src/os-impl-symtab.c +++ b/src/os/vxworks/src/os-impl-symtab.c @@ -64,13 +64,13 @@ extern SYMTAB_ID sysSymTbl; /*---------------------------------------------------------------- * - * Function: OS_SymbolLookup_Impl + * Function: OS_GenericSymbolLookup_Impl * * Purpose: Implemented per internal OSAL API * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_GenericSymbolLookup_Impl(SYMTAB_ID SymTab, cpuaddr *SymbolAddress, const char *SymbolName) { STATUS vxStatus; SYMBOL_DESC SymDesc; @@ -94,7 +94,7 @@ int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) SymDesc.mask = SYM_FIND_BY_NAME; SymDesc.name = (char *)SymbolName; - vxStatus = symFind(sysSymTbl, &SymDesc); + vxStatus = symFind(SymTab, &SymDesc); *SymbolAddress = (cpuaddr)SymDesc.value; if (vxStatus == ERROR) @@ -104,7 +104,40 @@ int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) return (OS_SUCCESS); -} /* end OS_SymbolLookup_Impl */ +} /* end OS_GenericSymbolLookup_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_GlobalSymbolLookup_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +{ + return OS_GenericSymbolLookup_Impl(sysSymTbl, SymbolAddress, SymbolName); +} /* end OS_GlobalSymbolLookup_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleSymbolLookup_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleSymbolLookup_Impl(const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName) +{ + /* + * NOTE: this is currently exactly the same as OS_GlobalSymbolLookup_Impl(). + * + * Ideally this should get a SYMTAB_ID from the MODULE_ID and search only + * for the symbols provided by that module - but it is not clear if vxWorks + * offers this capability. + */ + return OS_GenericSymbolLookup_Impl(sysSymTbl, SymbolAddress, SymbolName); +} /* end OS_ModuleSymbolLookup_Impl */ /*---------------------------------------------------------------- * @@ -129,7 +162,7 @@ int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) BOOL OS_SymTableIterator_Impl(char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_arg_t arg, SYM_GROUP group) { SymbolRecord_t symRecord; - uint32 NextSize; + size_t NextSize; int status; SymbolDumpState_t *state; @@ -139,7 +172,7 @@ BOOL OS_SymTableIterator_Impl(char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_ */ state = &OS_VxWorks_SymbolDumpState; - if (strlen(name) >= OS_MAX_SYM_LEN) + if (memchr(name, 0, OS_MAX_SYM_LEN) == NULL) { OS_DEBUG("%s(): symbol name too long\n", __func__); state->StatusCode = OS_ERROR; @@ -163,7 +196,8 @@ BOOL OS_SymTableIterator_Impl(char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_ /* ** Copy symbol name */ - strncpy(symRecord.SymbolName, name, OS_MAX_SYM_LEN); + strncpy(symRecord.SymbolName, name, sizeof(symRecord.SymbolName) - 1); + symRecord.SymbolName[sizeof(symRecord.SymbolName) - 1] = 0; /* ** Save symbol address @@ -198,7 +232,7 @@ BOOL OS_SymTableIterator_Impl(char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SymbolTableDump_Impl(const char *local_filename, uint32 SizeLimit) +int32 OS_SymbolTableDump_Impl(const char *filename, size_t size_limit) { SymbolDumpState_t *state; @@ -209,15 +243,15 @@ int32 OS_SymbolTableDump_Impl(const char *local_filename, uint32 SizeLimit) state = &OS_VxWorks_SymbolDumpState; memset(state, 0, sizeof(*state)); - state->Sizelimit = SizeLimit; + state->Sizelimit = size_limit; /* ** Open file */ - state->fd = open(local_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); + state->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (state->fd < 0) { - OS_DEBUG("open(%s): error: %s\n", local_filename, strerror(errno)); + OS_DEBUG("open(%s): error: %s\n", filename, strerror(errno)); state->StatusCode = OS_ERROR; } else diff --git a/src/os/vxworks/src/os-impl-tasks.c b/src/os/vxworks/src/os-impl-tasks.c index fac9ae90e..2f6ebfed4 100644 --- a/src/os/vxworks/src/os-impl-tasks.c +++ b/src/os/vxworks/src/os-impl-tasks.c @@ -51,7 +51,7 @@ #if defined(_STACK_ALIGN_SIZE) #define VX_IMPL_STACK_ALIGN_SIZE _STACK_ALIGN_SIZE #else -#define VX_IMPL_STACK_ALIGN_SIZE 16 +#define VX_IMPL_STACK_ALIGN_SIZE ((size_t)16) #endif #if defined(STACK_ROUND_DOWN) @@ -83,11 +83,7 @@ OS_impl_task_internal_record_t OS_impl_task_table[OS_MAX_TASKS]; ---------------------------------------------------------------------------------------*/ int OS_VxWorks_TaskEntry(int arg) { - VxWorks_ID_Buffer_t id; - - id.arg = arg; - - OS_TaskEntryPoint(id.id); + OS_TaskEntryPoint(OS_ObjectIdFromInteger(arg)); return 0; } /* end OS_VxWorksEntry */ @@ -117,18 +113,19 @@ int32 OS_VxWorks_TaskAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) +int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags) { STATUS status; int vxflags; int vxpri; - long actualsz; - long userstackbase; - long actualstackbase; + size_t actualsz; + unsigned long userstackbase; + unsigned long actualstackbase; OS_impl_task_internal_record_t *lrec; - VxWorks_ID_Buffer_t id; + OS_task_internal_record_t * task; - lrec = &OS_impl_task_table[task_id]; + lrec = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + task = OS_OBJECT_TABLE_GET(OS_task_table, *token); /* Create VxWorks Task */ @@ -145,9 +142,9 @@ int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) * Get priority/stack specs from main struct * priority should be a direct passthru */ - vxpri = OS_task_table[task_id].priority; - actualsz = OS_task_table[task_id].stack_size; - userstackbase = (long)OS_task_table[task_id].stack_pointer; + vxpri = task->priority; + actualsz = task->stack_size; + userstackbase = (unsigned long)task->stack_pointer; /* * NOTE: Using taskInit() here rather than taskSpawn() allows us @@ -213,7 +210,7 @@ int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) } } - userstackbase = (long)lrec->heap_block; + userstackbase = (unsigned long)lrec->heap_block; } if (userstackbase == 0) @@ -237,14 +234,13 @@ int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) actualstackbase += actualsz; /* move to last byte of stack block */ #endif - id.id = OS_global_task_table[task_id].active_id; - status = taskInit(&lrec->tcb, /* address of new task's TCB */ - (char *)OS_global_task_table[task_id].name_entry, vxpri, /* priority of new task */ - vxflags, /* task option word */ - (char *)actualstackbase, /* base of new task's stack */ - actualsz, /* size (bytes) of stack needed */ - (FUNCPTR)OS_VxWorks_TaskEntry, /* entry point of new task */ - id.arg, /* 1st arg is ID */ + status = taskInit((WIND_TCB *)&lrec->tcb, /* address of new task's TCB */ + (char *)task->task_name, vxpri, /* priority of new task */ + vxflags, /* task option word */ + (char *)actualstackbase, /* base of new task's stack */ + actualsz, /* size (bytes) of stack needed */ + (FUNCPTR)OS_VxWorks_TaskEntry, /* entry point of new task */ + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), /* 1st arg is ID */ 0, 0, 0, 0, 0, 0, 0, 0, 0); if (status != OK) @@ -268,25 +264,43 @@ int32 OS_TaskCreate_Impl(uint32 task_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl(uint32 task_id) +int32 OS_TaskDelete_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Try to delete the task ** If this fails, not much recourse - the only potential cause of failure ** to cancel here is that the thread ID is invalid because it already exited itself, ** and if that is true there is nothing wrong - everything is OK to continue normally. */ - if (taskDelete(OS_impl_task_table[task_id].vxid) != OK) + if (taskDelete(impl->vxid) != OK) { OS_DEBUG("taskDelete() - vxWorks errno %d\n", errno); return OS_ERROR; } - OS_impl_task_table[task_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_TaskDelete_Impl */ +/*---------------------------------------------------------------- + * + * Function: OS_TaskDetach_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskDetach_Impl(const OS_object_token_t *token) +{ + /* No-op on VxWorks */ + return OS_SUCCESS; +} + /*---------------------------------------------------------------- * * Function: OS_TaskExit_Impl @@ -336,10 +350,14 @@ int32 OS_TaskDelay_Impl(uint32 milli_second) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl(uint32 task_id, uint32 new_priority) +int32 OS_TaskSetPriority_Impl(const OS_object_token_t *token, osal_priority_t new_priority) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* Set VxWorks Task Priority */ - if (taskPrioritySet(OS_impl_task_table[task_id].vxid, new_priority) != OK) + if (taskPrioritySet(impl->vxid, new_priority) != OK) { return OS_ERROR; } @@ -356,12 +374,16 @@ int32 OS_TaskSetPriority_Impl(uint32 task_id, uint32 new_priority) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(uint32 task_id) +int32 OS_TaskMatch_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Get VxWorks Task Id */ - if (taskIdSelf() != OS_impl_task_table[task_id].vxid) + if (taskIdSelf() != impl->vxid) { return (OS_ERROR); } @@ -392,19 +414,19 @@ int32 OS_TaskRegister_Impl(osal_id_t global_task_id) *-----------------------------------------------------------------*/ osal_id_t OS_TaskGetId_Impl(void) { - OS_impl_task_internal_record_t *lrec; - size_t index; - osal_id_t id; + void * lrec; + size_t idx; + osal_id_t id; id = OS_OBJECT_ID_UNDEFINED; - lrec = (OS_impl_task_internal_record_t *)taskTcb(taskIdSelf()); + lrec = taskTcb(taskIdSelf()); if (lrec != NULL) { - index = lrec - &OS_impl_task_table[0]; - if (index < OS_MAX_TASKS) + idx = (OS_impl_task_internal_record_t *)lrec - &OS_impl_task_table[0]; + if (idx < OS_MAX_TASKS) { - id = OS_global_task_table[index].active_id; + id = OS_global_task_table[idx].active_id; } } @@ -420,7 +442,7 @@ osal_id_t OS_TaskGetId_Impl(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl(uint32 task_id, OS_task_prop_t *task_prop) +int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_prop) { return OS_SUCCESS; @@ -434,7 +456,7 @@ int32 OS_TaskGetInfo_Impl(uint32 task_id, OS_task_prop_t *task_prop) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size) +int32 OS_TaskValidateSystemData_Impl(const void *sysdata, size_t sysdata_size) { if (sysdata == NULL || sysdata_size != sizeof(TASK_ID)) { @@ -451,9 +473,12 @@ int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj) +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { - const TASK_ID *target = (const TASK_ID *)ref; + const TASK_ID * target = (const TASK_ID *)ref; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); - return (*target == OS_impl_task_table[local_id].vxid); + return (*target == impl->vxid); } diff --git a/src/os/vxworks/src/os-impl-timebase.c b/src/os/vxworks/src/os-impl-timebase.c index 28955632e..235413179 100644 --- a/src/os/vxworks/src/os-impl-timebase.c +++ b/src/os/vxworks/src/os-impl-timebase.c @@ -42,6 +42,8 @@ #include #include +#include "osapi-task.h" + /**************************************************************************************** DEFINES ****************************************************************************************/ @@ -93,9 +95,13 @@ static uint32 OS_ClockAccuracyNsec; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseLock_Impl(uint32 local_id) +void OS_TimeBaseLock_Impl(const OS_object_token_t *token) { - semTake(OS_impl_timebase_table[local_id].handler_mutex, WAIT_FOREVER); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + semTake(impl->handler_mutex, WAIT_FOREVER); } /* end OS_TimeBaseLock_Impl */ /*---------------------------------------------------------------- @@ -106,9 +112,13 @@ void OS_TimeBaseLock_Impl(uint32 local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseUnlock_Impl(uint32 local_id) +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) { - semGive(OS_impl_timebase_table[local_id].handler_mutex); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + semGive(impl->handler_mutex); } /* end OS_TimeBaseUnlock_Impl */ /*---------------------------------------------------------------- @@ -140,26 +150,24 @@ void OS_VxWorks_UsecToTimespec(uint32 usecs, struct timespec *time_spec) * Blocks the calling task until the timer tick arrives * *-----------------------------------------------------------------*/ -uint32 OS_VxWorks_SigWait(uint32 local_id) +uint32 OS_VxWorks_SigWait(osal_id_t timebase_id) { - OS_impl_timebase_internal_record_t *local; - OS_common_record_t * global; - osal_id_t active_id; + OS_object_token_t token; + OS_impl_timebase_internal_record_t *impl; uint32 tick_time; int signo; int ret; - local = &OS_impl_timebase_table[local_id]; - global = &OS_global_timebase_table[local_id]; - active_id = global->active_id; tick_time = 0; - if (OS_ObjectIdDefined(active_id) && local->assigned_signal > 0) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &token) == OS_SUCCESS) { + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); + /* * Pend for the tick arrival */ - ret = sigwait(&local->timer_sigset, &signo); + ret = sigwait(&impl->timer_sigset, &signo); /* * The sigwait() can be interrupted.... @@ -179,17 +187,17 @@ uint32 OS_VxWorks_SigWait(uint32 local_id) * conditions. Samples from before/after a reconfig * are generally not comparable. */ - if (ret == OK && signo == local->assigned_signal && OS_ObjectIdEqual(global->active_id, active_id)) + if (ret == OK && signo == impl->assigned_signal) { - if (local->reset_flag) + if (impl->reset_flag) { /* first interval after reset, use start time */ - tick_time = local->configured_start_time; - local->reset_flag = false; + tick_time = impl->configured_start_time; + impl->reset_flag = false; } else { - tick_time = local->configured_interval_time; + tick_time = impl->configured_interval_time; } } } @@ -204,38 +212,50 @@ uint32 OS_VxWorks_SigWait(uint32 local_id) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -void OS_VxWorks_RegisterTimer(uint32 local_id) +void OS_VxWorks_RegisterTimer(osal_id_t obj_id) { OS_impl_timebase_internal_record_t *local; + OS_object_token_t token; struct sigevent evp; int status; + int32 retcode; - local = &OS_impl_timebase_table[local_id]; + retcode = OS_ObjectIdGetById(OS_LOCK_MODE_RESERVED, OS_OBJECT_TYPE_OS_TIMEBASE, obj_id, &token); + if (retcode == OS_SUCCESS) + { + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); - memset(&evp, 0, sizeof(evp)); - evp.sigev_notify = SIGEV_SIGNAL; - evp.sigev_signo = local->assigned_signal; + memset(&evp, 0, sizeof(evp)); + evp.sigev_notify = SIGEV_SIGNAL; + evp.sigev_signo = local->assigned_signal; - /* - ** Create the timer - ** - ** The result is not returned from this function, because - ** this is a different task context from the original creator. - ** - ** The registration status is returned through the OS_impl_timebase_table entry, - ** which is checked by the creator before returning. - ** - ** If set to ERROR, then this task will be subsequently deleted. - */ - status = timer_create(OS_PREFERRED_CLOCK, &evp, &local->host_timerid); - if (status < 0) - { - OS_DEBUG("timer_create() failed: errno=%d\n", errno); - local->timer_state = OS_TimerRegState_ERROR; + /* + ** Create the timer + ** + ** The result is not returned from this function, because + ** this is a different task context from the original creator. + ** + ** The registration status is returned through the OS_impl_timebase_table entry, + ** which is checked by the creator before returning. + ** + ** If set to ERROR, then this task will be subsequently deleted. + */ + status = timer_create(OS_PREFERRED_CLOCK, &evp, &local->host_timerid); + if (status < 0) + { + OS_DEBUG("timer_create() failed: errno=%d\n", errno); + local->timer_state = OS_TimerRegState_ERROR; + } + else + { + local->timer_state = OS_TimerRegState_SUCCESS; + } + + OS_ObjectIdRelease(&token); } else { - local->timer_state = OS_TimerRegState_SUCCESS; + OS_DEBUG("OS_VxWorks_RegisterTimer() bad ID, code=%d\n", (int)retcode); } } /* end OS_VxWorks_RegisterTimer */ @@ -252,15 +272,11 @@ void OS_VxWorks_RegisterTimer(uint32 local_id) *-----------------------------------------------------------------*/ int OS_VxWorks_TimeBaseTask(int arg) { - VxWorks_ID_Buffer_t id; - uint32 local_id; + osal_id_t obj_id; - id.arg = arg; - if (OS_ConvertToArrayIndex(id.id, &local_id) == OS_SUCCESS) - { - OS_VxWorks_RegisterTimer(local_id); - OS_TimeBase_CallbackThread(id.id); - } + obj_id = OS_ObjectIdFromInteger(arg); + OS_VxWorks_RegisterTimer(obj_id); + OS_TimeBase_CallbackThread(obj_id); return 0; } /* end OS_VxWorks_TimeBaseTask */ @@ -323,7 +339,7 @@ int32 OS_VxWorks_TimeBaseAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseCreate_Impl(uint32 timer_id) +int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token) { /* * The tick_sem is a simple semaphore posted by the ISR and taken by the @@ -331,15 +347,16 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) */ int32 return_code; OS_impl_timebase_internal_record_t *local; - OS_common_record_t * global; + OS_timebase_internal_record_t * timebase; int signo; sigset_t inuse; + osal_index_t idx; uint32 i; - VxWorks_ID_Buffer_t idbuf; return_code = OS_SUCCESS; - local = &OS_impl_timebase_table[timer_id]; - global = &OS_global_timebase_table[timer_id]; + + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); sigemptyset(&local->timer_sigset); local->assigned_signal = 0; @@ -358,7 +375,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * If no external sync function is provided then this will set up a VxWorks * timer to locally simulate the timer tick using the CPU clock. */ - if (OS_timebase_table[timer_id].external_sync == NULL) + if (timebase->external_sync == NULL) { /* * find an RT signal that is not used by another time base object. @@ -367,13 +384,13 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) */ sigemptyset(&inuse); - for (i = 0; i < OS_MAX_TIMEBASES; ++i) + for (idx = 0; idx < OS_MAX_TIMEBASES; ++idx) { - if (OS_ObjectIdDefined(OS_global_timebase_table[i].active_id) && - OS_impl_timebase_table[i].assigned_signal > 0) + if (OS_ObjectIdIsValid(OS_global_timebase_table[idx].active_id) && + OS_impl_timebase_table[idx].assigned_signal > 0) { /* mark signal as in-use */ - sigaddset(&inuse, OS_impl_timebase_table[i].assigned_signal); + sigaddset(&inuse, OS_impl_timebase_table[idx].assigned_signal); } } @@ -410,7 +427,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) /* * Use local sigwait() wrapper as a sync function for the local task. */ - OS_timebase_table[timer_id].external_sync = OS_VxWorks_SigWait; + timebase->external_sync = OS_VxWorks_SigWait; } } @@ -443,11 +460,11 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) */ if (return_code == OS_SUCCESS) { - idbuf.id = global->active_id; - local->handler_task = taskSpawn((char *)global->name_entry, OSAL_TIMEBASE_TASK_PRIORITY, /* priority */ - OSAL_TIMEBASE_TASK_OPTION_WORD, /* task option word */ - OSAL_TIMEBASE_TASK_STACK_SIZE, /* size (bytes) of stack needed */ - (FUNCPTR)OS_VxWorks_TimeBaseTask, idbuf.arg, /* 1st arg is ID */ + local->handler_task = taskSpawn(timebase->timebase_name, OSAL_TIMEBASE_TASK_PRIORITY, /* priority */ + OSAL_TIMEBASE_TASK_OPTION_WORD, /* task option word */ + OSAL_TIMEBASE_TASK_STACK_SIZE, /* size (bytes) of stack needed */ + (FUNCPTR)OS_VxWorks_TimeBaseTask, /* Timebase helper task entry point */ + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), /* 1st arg is ID */ 0, 0, 0, 0, 0, 0, 0, 0, 0); /* check if taskSpawn failed */ @@ -500,14 +517,14 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time) +int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uint32 interval_time) { OS_impl_timebase_internal_record_t *local; struct itimerspec timeout; int32 return_code; int status; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); /* There is only something to do here if we are generating a simulated tick */ if (local->assigned_signal <= 0) @@ -555,13 +572,13 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time if (local->configured_start_time != start_time) { OS_DEBUG("WARNING: timer %lu start_time requested=%luus, configured=%luus\n", - (unsigned long)timer_id, (unsigned long)start_time, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), (unsigned long)start_time, (unsigned long)local->configured_start_time); } if (local->configured_interval_time != interval_time) { OS_DEBUG("WARNING: timer %lu interval_time requested=%luus, configured=%luus\n", - (unsigned long)timer_id, (unsigned long)interval_time, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), (unsigned long)interval_time, (unsigned long)local->configured_interval_time); } } @@ -588,12 +605,12 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseDelete_Impl(uint32 timer_id) +int32 OS_TimeBaseDelete_Impl(const OS_object_token_t *token) { OS_impl_timebase_internal_record_t *local; int32 return_code; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); return_code = OS_SUCCESS; /* An assigned_signal value indicates the OS timer needs deletion too */ @@ -622,7 +639,7 @@ int32 OS_TimeBaseDelete_Impl(uint32 timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseGetInfo_Impl(uint32 timer_id, OS_timebase_prop_t *timer_prop) +int32 OS_TimeBaseGetInfo_Impl(const OS_object_token_t *token, OS_timebase_prop_t *timer_prop) { return OS_SUCCESS; diff --git a/src/tests/bin-sem-flush-test/bin-sem-flush-test.c b/src/tests/bin-sem-flush-test/bin-sem-flush-test.c index 12c6b1ac8..67bf0a553 100644 --- a/src/tests/bin-sem-flush-test/bin-sem-flush-test.c +++ b/src/tests/bin-sem-flush-test/bin-sem-flush-test.c @@ -222,13 +222,16 @@ void BinSemFlushSetup(void) /* ** Create the tasks */ - status = OS_TaskCreate(&task_1_id, "Task 1", task_1, task_1_stack, TASK_STACK_SIZE, TASK_1_PRIORITY, 0); + status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_STACKPTR_C(task_1_stack), sizeof(task_1_stack), + OSAL_PRIORITY_C(TASK_1_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status); - status = OS_TaskCreate(&task_2_id, "Task 2", task_2, task_2_stack, TASK_STACK_SIZE, TASK_2_PRIORITY, 0); + status = OS_TaskCreate(&task_2_id, "Task 2", task_2, OSAL_STACKPTR_C(task_2_stack), sizeof(task_2_stack), + OSAL_PRIORITY_C(TASK_2_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 2 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_2_id), (int)status); - status = OS_TaskCreate(&task_3_id, "Task 3", task_3, task_3_stack, TASK_STACK_SIZE, TASK_3_PRIORITY, 0); + status = OS_TaskCreate(&task_3_id, "Task 3", task_3, OSAL_STACKPTR_C(task_3_stack), sizeof(task_3_stack), + OSAL_PRIORITY_C(TASK_3_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 3 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_3_id), (int)status); /* diff --git a/src/tests/bin-sem-test/bin-sem-test.c b/src/tests/bin-sem-test/bin-sem-test.c index 0e645c6ea..4f6b6557c 100644 --- a/src/tests/bin-sem-test/bin-sem-test.c +++ b/src/tests/bin-sem-test/bin-sem-test.c @@ -224,7 +224,8 @@ void BinSemSetup(void) /* ** Create the "consumer" task. */ - status = OS_TaskCreate(&task_1_id, "Task 1", task_1, task_1_stack, TASK_1_STACK_SIZE, TASK_1_PRIORITY, 0); + status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_STACKPTR_C(task_1_stack), sizeof(task_1_stack), + OSAL_PRIORITY_C(TASK_1_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status); /* diff --git a/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c b/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c index b368f12d3..54af1b7ef 100644 --- a/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c +++ b/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c @@ -220,7 +220,8 @@ void BinSemTimeoutSetup(void) /* ** Create the "consumer" task. */ - status = OS_TaskCreate(&task_1_id, "Task 1", task_1, task_1_stack, TASK_1_STACK_SIZE, TASK_1_PRIORITY, 0); + status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_STACKPTR_C(task_1_stack), sizeof(task_1_stack), + OSAL_PRIORITY_C(TASK_1_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status); /* diff --git a/src/tests/count-sem-test/count-sem-test.c b/src/tests/count-sem-test/count-sem-test.c index 6ee4c92fb..61239a590 100644 --- a/src/tests/count-sem-test/count-sem-test.c +++ b/src/tests/count-sem-test/count-sem-test.c @@ -191,13 +191,16 @@ void CountSemSetup(void) /* ** Create the tasks */ - status = OS_TaskCreate(&task_1_id, "Task 1", task_1, task_1_stack, TASK_STACK_SIZE, TASK_1_PRIORITY, 0); + status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_STACKPTR_C(task_1_stack), sizeof(task_1_stack), + OSAL_PRIORITY_C(TASK_1_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status); - status = OS_TaskCreate(&task_2_id, "Task 2", task_2, task_2_stack, TASK_STACK_SIZE, TASK_2_PRIORITY, 0); + status = OS_TaskCreate(&task_2_id, "Task 2", task_2, OSAL_STACKPTR_C(task_2_stack), sizeof(task_2_stack), + OSAL_PRIORITY_C(TASK_2_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 2 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_2_id), (int)status); - status = OS_TaskCreate(&task_3_id, "Task 3", task_3, task_3_stack, TASK_STACK_SIZE, TASK_3_PRIORITY, 0); + status = OS_TaskCreate(&task_3_id, "Task 3", task_3, OSAL_STACKPTR_C(task_3_stack), sizeof(task_3_stack), + OSAL_PRIORITY_C(TASK_3_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 3 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_3_id), (int)status); /* diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index 8bfda6ea0..b82867782 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -33,6 +33,7 @@ void TestMkfsMount(void); void TestCreatRemove(void); void TestOpenClose(void); +void TestChmod(void); void TestReadWriteLseek(void); void TestMkRmDirFreeBytes(void); void TestOpenReadCloseDir(void); @@ -75,6 +76,7 @@ void UtTest_Setup(void) UtTest_Add(TestMkfsMount, NULL, NULL, "TestMkfsMount"); UtTest_Add(TestCreatRemove, NULL, NULL, "TestCreatRemove"); UtTest_Add(TestOpenClose, NULL, NULL, "TestOpenClose"); + UtTest_Add(TestChmod, NULL, NULL, "TestChmod"); UtTest_Add(TestReadWriteLseek, NULL, NULL, "TestReadWriteLseek"); UtTest_Add(TestMkRmDirFreeBytes, NULL, NULL, "TestMkRmDirFreeBytes"); UtTest_Add(TestOpenReadCloseDir, NULL, NULL, "TestOpenReadCloseDir"); @@ -89,7 +91,7 @@ void TestMkfsMount(void) int32 status; /* Make the file system */ - status = OS_mkfs(0, "/ramdev0", "RAM", 512, 200); + status = OS_mkfs(0, "/ramdev0", "RAM", OSAL_SIZE_C(512), OSAL_BLOCKCOUNT_C(200)); UtAssert_True(status == OS_SUCCESS, "status after mkfs = %d", (int)status); status = OS_mount("/ramdev0", "/drive0"); @@ -238,10 +240,77 @@ void TestOpenClose(void) status = OS_remove(filename); UtAssert_True(status == OS_SUCCESS, "status after remove = %d", (int)status); } + /*--------------------------------------------------------------------------------------- - * Name TestReadWriteLseek + * Name TestChmod ---------------------------------------------------------------------------------------*/ +void TestChmod(void) +{ + char filename[OS_MAX_PATH_LEN]; + int32 status; + osal_id_t fd; + + /*Make a file to test on. Start in Read only mode */ + strncpy(filename, "/drive0/Filename1", sizeof(filename) - 1); + filename[sizeof(filename) - 1] = 0; + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE, OS_READ_WRITE); + UtAssert_True(status >= OS_SUCCESS, "status after creat = %d", (int)status); + status = OS_close(fd); + UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status); + + /*Testing Write Only */ + status = OS_chmod(filename, OS_WRITE_ONLY); + if (status != OS_ERR_NOT_IMPLEMENTED) + { + UtAssert_True(status == OS_SUCCESS, "status after chmod = %d", (int)status); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_NONE, OS_WRITE_ONLY); + UtAssert_True(status >= OS_SUCCESS, "status after reopen = %d", (int)status); + status = OS_close(fd); + UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status); + } + else + { + UtPrintf("OS_chmod not implemented for write only\n"); + } + + /*Testing Read Only */ + status = OS_chmod(filename, OS_READ_ONLY); + if (status != OS_ERR_NOT_IMPLEMENTED) + { + UtAssert_True(status == OS_SUCCESS, "status after chmod = %d", (int)status); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_NONE, OS_READ_ONLY); + UtAssert_True(status >= OS_SUCCESS, "status after reopen = %d", (int)status); + status = OS_close(fd); + UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status); + } + else + { + UtPrintf("OS_chmod not implemented for read only\n"); + } + /*Testing Read Write */ + status = OS_chmod(filename, OS_READ_WRITE); + if (status != OS_ERR_NOT_IMPLEMENTED) + { + UtAssert_True(status == OS_SUCCESS, "status after chmod = %d", (int)status); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_NONE, OS_READ_WRITE); + UtAssert_True(status >= OS_SUCCESS, "status after reopen = %d", (int)status); + status = OS_close(fd); + UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status); + } + else + { + UtPrintf("OS_chmod not implemented for read write\n"); + } + + /*Removing the file */ + status = OS_remove(filename); + UtAssert_True(status == OS_SUCCESS, "status after remove = %d", (int)status); +} + +/*--------------------------------------------------------------------------------------- + * Name TestReadWriteLseek +---------------------------------------------------------------------------------------*/ void TestReadWriteLseek(void) { char filename[OS_MAX_PATH_LEN]; @@ -249,8 +318,8 @@ void TestReadWriteLseek(void) char copyofbuffer[30]; char seekbuffer[30]; char newbuffer[30]; - int offset; - int size; + size_t offset; + size_t size; int32 status; osal_id_t fd; @@ -270,11 +339,12 @@ void TestReadWriteLseek(void) status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat = %d", (int)status); - size = strlen(buffer); + /* Write the string including null character */ + size = strlen(buffer) + 1; /* test write portion of R/W mode */ status = OS_write(fd, (void *)buffer, size); - UtAssert_True(status == size, "status after write = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after write = %d size = %lu", (int)status, (unsigned long)size); strcpy(buffer, ""); @@ -284,7 +354,7 @@ void TestReadWriteLseek(void) /*Read what we wrote to the file */ status = OS_read(fd, (void *)buffer, size); - UtAssert_True(status == size, "status after read = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after read = %d size = %lu", (int)status, (unsigned long)size); if (status >= OS_SUCCESS) { UtAssert_True(strcmp(buffer, copyofbuffer) == 0, "Read: %s, Written: %s", buffer, copyofbuffer); @@ -305,7 +375,7 @@ void TestReadWriteLseek(void) /* try to read in READ ONLY MODE */ status = OS_read(fd, (void *)buffer, size); - UtAssert_True(status == size, "status after read = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after read = %d size = %lu", (int)status, (unsigned long)size); if (status >= OS_SUCCESS) { UtAssert_True(strcmp(buffer, copyofbuffer) == 0, "Read: %s, Written: %s", buffer, copyofbuffer); @@ -317,8 +387,9 @@ void TestReadWriteLseek(void) /* now try to read out only the last chars of the file */ - status = OS_read(fd, (void *)newbuffer, (size - offset)); - UtAssert_True(status == (size - offset), "status after read = %d size = %d", (int)status, (int)(size - offset)); + status = OS_read(fd, (void *)newbuffer, OSAL_SIZE_C(size - offset)); + UtAssert_True(status == (size - offset), "status after read = %d size = %lu", (int)status, + (unsigned long)(size - offset)); if (status >= OS_SUCCESS) { UtAssert_True(strncmp(newbuffer, seekbuffer, size - offset) == 0, "Read: %s, Written: %s", newbuffer, @@ -335,7 +406,7 @@ void TestReadWriteLseek(void) /* test write in WRITE ONLY mode */ status = OS_write(fd, (void *)buffer, size); - UtAssert_True(status == size, "status after write = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after write = %d size = %lu", (int)status, (unsigned long)size); /* try to read in WRITE ONLY MODE */ status = OS_read(fd, (void *)buffer, size); @@ -346,7 +417,7 @@ void TestReadWriteLseek(void) UtAssert_True(status >= OS_SUCCESS, "status after lseek = %d", (int)status); /* now try to read out only the last chars of the file */ - status = OS_read(fd, (void *)newbuffer, (size - offset)); + status = OS_read(fd, (void *)newbuffer, OSAL_SIZE_C(size - offset)); UtAssert_True(status < OS_SUCCESS, "status after read = %d", (int)status); /* close the file */ @@ -363,18 +434,19 @@ void TestReadWriteLseek(void) ---------------------------------------------------------------------------------------*/ void TestMkRmDirFreeBytes(void) { - int32 status; - char filename1[OS_MAX_PATH_LEN]; - char filename2[OS_MAX_PATH_LEN]; - char dir1[OS_MAX_PATH_LEN]; - char dir2[OS_MAX_PATH_LEN]; - char buffer1[OS_MAX_PATH_LEN]; - char buffer2[OS_MAX_PATH_LEN]; - char copybuffer1[OS_MAX_PATH_LEN]; - char copybuffer2[OS_MAX_PATH_LEN]; - osal_id_t fd1; - osal_id_t fd2; - int size; + int32 status; + char filename1[OS_MAX_PATH_LEN]; + char filename2[OS_MAX_PATH_LEN]; + char dir1[OS_MAX_PATH_LEN]; + char dir2[OS_MAX_PATH_LEN]; + char buffer1[OS_MAX_PATH_LEN]; + char buffer2[OS_MAX_PATH_LEN]; + char copybuffer1[OS_MAX_PATH_LEN]; + char copybuffer2[OS_MAX_PATH_LEN]; + osal_id_t fd1; + osal_id_t fd2; + size_t size; + OS_statvfs_t statbuf; /* make the directory names for testing, as well as the filenames and the buffers * to put in the files */ @@ -389,8 +461,9 @@ void TestMkRmDirFreeBytes(void) /* NOTE: The blocks free call is not necessarily implemented on all filesystems. * So the response of OS_ERR_NOT_IMPLEMENTED is acceptable. */ - status = OS_fsBlocksFree("/drive0"); - UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status >= OS_SUCCESS, "Checking Free Blocks: %d", (int)status); + status = OS_FileSysStatVolume("/drive0", &statbuf); + UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status == OS_SUCCESS, + "Checking Free Blocks: status=%d blocks=%lu", (int)status, (unsigned long)statbuf.blocks_free); /* make the two directories */ status = OS_mkdir(dir1, 0); @@ -410,11 +483,11 @@ void TestMkRmDirFreeBytes(void) /* write the propper buffers into each of the files */ size = strlen(buffer1); status = OS_write(fd1, buffer1, size); - UtAssert_True(status == size, "status after write 1 = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after write 1 = %d size = %lu", (int)status, (unsigned long)size); size = strlen(buffer2); status = OS_write(fd2, buffer2, size); - UtAssert_True(status == size, "status after write 2 = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after write 2 = %d size = %lu", (int)status, (unsigned long)size); /* lseek back to the beginning of the file */ status = OS_lseek(fd1, 0, 0); @@ -425,13 +498,14 @@ void TestMkRmDirFreeBytes(void) memset(buffer1, 0, sizeof(buffer1)); memset(buffer2, 0, sizeof(buffer2)); - status = OS_fsBlocksFree("/drive0"); - UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status >= OS_SUCCESS, "Checking Free Blocks: %d", (int)status); + status = OS_FileSysStatVolume("/drive0", &statbuf); + UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status == OS_SUCCESS, + "Checking Free Blocks: status=%d blocks=%lu", (int)status, (unsigned long)statbuf.blocks_free); /* read back out of the files what we wrote into them */ size = strlen(copybuffer1); status = OS_read(fd1, (void *)buffer1, size); - UtAssert_True(status == size, "status after read 1 = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after read 1 = %d size = %lu", (int)status, (unsigned long)size); if (status >= OS_SUCCESS) { UtAssert_True(strncmp(buffer1, copybuffer1, size) == 0, "Read: %s, Written: %s", buffer1, copybuffer1); @@ -439,7 +513,7 @@ void TestMkRmDirFreeBytes(void) size = strlen(copybuffer2); status = OS_read(fd2, (void *)buffer2, size); - UtAssert_True(status == size, "status after read 2 = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after read 2 = %d size = %lu", (int)status, (unsigned long)size); if (status >= OS_SUCCESS) { UtAssert_True(strncmp(buffer2, copybuffer2, size) == 0, "Read: %s, Written: %s", buffer1, copybuffer1); @@ -465,9 +539,11 @@ void TestMkRmDirFreeBytes(void) status = OS_rmdir(dir2); UtAssert_True(status == OS_SUCCESS, "status after rmdir 2 = %d", (int)status); - status = OS_fsBlocksFree("/drive0"); - UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status >= OS_SUCCESS, "Checking Free Blocks: %d", (int)status); + status = OS_FileSysStatVolume("/drive0", &statbuf); + UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status == OS_SUCCESS, + "Checking Free Blocks: status=%d blocks=%lu", (int)status, (unsigned long)statbuf.blocks_free); } + /*--------------------------------------------------------------------------------------- * Name TestOpenReadCloseDir(); ---------------------------------------------------------------------------------------*/ @@ -481,7 +557,7 @@ void TestOpenReadCloseDir(void) char dir2[OS_MAX_PATH_LEN]; char buffer1[OS_MAX_PATH_LEN]; char buffer2[OS_MAX_PATH_LEN]; - int size; + size_t size; osal_id_t fd1; osal_id_t fd2; osal_id_t dirh; @@ -516,11 +592,11 @@ void TestOpenReadCloseDir(void) /* write the proper buffers into each of the files */ size = strlen(buffer1); status = OS_write(fd1, buffer1, size); - UtAssert_True(status == size, "status after write 1 = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after write 1 = %d size = %lu", (int)status, (unsigned long)size); size = strlen(buffer2); status = OS_write(fd2, buffer2, size); - UtAssert_True(status == size, "status after write 2 = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after write 2 = %d size = %lu", (int)status, (unsigned long)size); /* close the files */ @@ -690,7 +766,7 @@ void TestRename(void) char newfilename1[OS_MAX_PATH_LEN]; osal_id_t fd1; - int size; + size_t size; /* make the directory names for testing, as well as the filenames and the buffers * to put in the files */ @@ -719,7 +795,7 @@ void TestRename(void) size = strlen(buffer1); status = OS_write(fd1, buffer1, size); - UtAssert_True(status == size, "status after write 1 = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after write 1 = %d size = %lu", (int)status, (unsigned long)size); /* close the file */ @@ -745,7 +821,7 @@ void TestRename(void) size = strlen(copybuffer1); status = OS_read(fd1, buffer1, size); - UtAssert_True(status == size, "status after read 1 = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after read 1 = %d size = %lu", (int)status, (unsigned long)size); if (status >= OS_SUCCESS) { UtAssert_True(strncmp(buffer1, copybuffer1, size) == 0, "Read and Written Results are equal"); @@ -762,6 +838,7 @@ void TestRename(void) status = OS_rmdir(newdir1); UtAssert_True(status == OS_SUCCESS, "status after rmdir 1 = %d", (int)status); } + /*--------------------------------------------------------------------------------------- * Name TestStat() ---------------------------------------------------------------------------------------*/ @@ -775,7 +852,7 @@ void TestStat(void) char buffer1[OS_MAX_PATH_LEN]; os_fstat_t StatBuff; osal_id_t fd1; - int size; + size_t size; strcpy(dir1, "/drive0/DirectoryName"); strcpy(dir1slash, dir1); @@ -795,7 +872,7 @@ void TestStat(void) size = strlen(buffer1); status = OS_write(fd1, buffer1, size); - UtAssert_True(status == size, "status after write 1 = %d size = %d", (int)status, (int)size); + UtAssert_True(status == size, "status after write 1 = %d size = %lu", (int)status, (unsigned long)size); status = OS_close(fd1); UtAssert_True(status == OS_SUCCESS, "status after close 1 = %d", (int)status); @@ -875,4 +952,12 @@ void TestOpenFileAPI(void) */ status = OS_CloseFileByName(filename2); UtAssert_True(status < OS_SUCCESS, "status after OS_CloseFileByName 2 = %d", (int)status); + + /* Try removing the files from the drive to end the function */ + status = OS_remove(filename1); + UtAssert_True(status == OS_SUCCESS, "status after remove filename1 = %d", (int)status); + status = OS_remove(filename2); + UtAssert_True(status == OS_SUCCESS, "status after remove filename2 = %d", (int)status); + status = OS_remove(filename3); + UtAssert_True(status == OS_SUCCESS, "status after remove filename3 = %d", (int)status); } diff --git a/src/tests/idmap-api-test/idmap-api-test.c b/src/tests/idmap-api-test/idmap-api-test.c index c91aec89c..3a9ab8327 100644 --- a/src/tests/idmap-api-test/idmap-api-test.c +++ b/src/tests/idmap-api-test/idmap-api-test.c @@ -109,9 +109,10 @@ void TestIdMapApi_Setup(void) /* * Create all allowed objects */ - status = OS_TaskCreate(&task_id, "Task", Test_Void_Fn, NULL, 4096, 50, 0); + status = OS_TaskCreate(&task_id, "Task", Test_Void_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(4096), + OSAL_PRIORITY_C(50), 0); UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); - status = OS_QueueCreate(&queue_id, "Queue", 5, 5, 0); + status = OS_QueueCreate(&queue_id, "Queue", OSAL_BLOCKCOUNT_C(5), OSAL_SIZE_C(5), 0); UtAssert_True(status == OS_SUCCESS, "OS_QueueCreate() (%ld) == OS_SUCCESS", (long)status); status = OS_CountSemCreate(&count_sem_id, "CountSem", 1, 0); UtAssert_True(status == OS_SUCCESS, "OS_CountSemCreate() (%ld) == OS_SUCCESS", (long)status); @@ -141,9 +142,9 @@ void TestIdMapApi(void) { int32 expected; int32 actual; - uint32 TestArrayIndex; - uint32 TestMutex1Index; - uint32 TestMutex2Index; + osal_index_t TestArrayIndex; + osal_index_t TestMutex1Index; + osal_index_t TestMutex2Index; osal_id_t badid; Test_OS_ObjTypeCount_t Count; diff --git a/src/tests/mutex-test/mutex-test.c b/src/tests/mutex-test/mutex-test.c index 67baef8e7..dbe69950d 100644 --- a/src/tests/mutex-test/mutex-test.c +++ b/src/tests/mutex-test/mutex-test.c @@ -259,13 +259,16 @@ void MutexSetup(void) /* ** Create the tasks */ - status = OS_TaskCreate(&task_1_id, "Task 1", task_1, task_1_stack, TASK_STACK_SIZE, TASK_1_PRIORITY, 0); + status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_STACKPTR_C(task_1_stack), sizeof(task_1_stack), + OSAL_PRIORITY_C(TASK_1_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status); - status = OS_TaskCreate(&task_2_id, "Task 2", task_2, task_2_stack, TASK_STACK_SIZE, TASK_2_PRIORITY, 0); + status = OS_TaskCreate(&task_2_id, "Task 2", task_2, OSAL_STACKPTR_C(task_2_stack), sizeof(task_2_stack), + OSAL_PRIORITY_C(TASK_2_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 2 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_2_id), (int)status); - status = OS_TaskCreate(&task_3_id, "Task 3", task_3, task_3_stack, TASK_STACK_SIZE, TASK_3_PRIORITY, 0); + status = OS_TaskCreate(&task_3_id, "Task 3", task_3, OSAL_STACKPTR_C(task_3_stack), sizeof(task_3_stack), + OSAL_PRIORITY_C(TASK_3_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 3 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_3_id), (int)status); /* diff --git a/src/tests/network-api-test/network-api-test.c b/src/tests/network-api-test/network-api-test.c index 5dfee1f34..891bcb6d8 100644 --- a/src/tests/network-api-test/network-api-test.c +++ b/src/tests/network-api-test/network-api-test.c @@ -113,7 +113,14 @@ void TestDatagramNetworkApi_Setup(void) /* OS_SocketOpen */ actual = OS_SocketOpen(&socket_id, OS_SocketDomain_INET6, OS_SocketType_DATAGRAM); - UtAssert_True(actual == OS_SUCCESS || OS_ERR_NOT_IMPLEMENTED, "OS_SocketOpen() (%ld) Passed", (long)actual); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + UtPrintf("INET6 not supported\n"); + } + else + { + UtAssert_True(actual == OS_SUCCESS, "OS_SocketOpen() (%ld) Passed", (long)actual); + } OS_close(socket_id); expected = OS_INVALID_POINTER; @@ -126,12 +133,24 @@ void TestDatagramNetworkApi_Setup(void) /* OS_SocketAddrInit */ actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INET6); - UtAssert_True(actual == OS_SUCCESS || OS_ERR_NOT_IMPLEMENTED, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", - (long)actual); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + UtPrintf("INET6 not supported\n"); + } + else + { + UtAssert_True(actual == OS_SUCCESS, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + } actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INET6); - UtAssert_True(actual == OS_INVALID_POINTER || OS_ERR_NOT_IMPLEMENTED, - "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + UtPrintf("INET6 not supported\n"); + } + else + { + UtAssert_True(actual == OS_INVALID_POINTER, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); + } expected = OS_ERR_NOT_IMPLEMENTED; actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INVALID); @@ -266,43 +285,43 @@ void TestDatagramNetworkApi(void) /* OS_SocketSendTo */ expected = OS_INVALID_POINTER; - actual = OS_SocketSendTo(p1_socket_id, NULL, 0, NULL); + actual = OS_SocketSendTo(p1_socket_id, NULL, OSAL_SIZE_C(0), NULL); UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_SocketSendTo(p1_socket_id, NULL, 1, &p2_addr); + actual = OS_SocketSendTo(p1_socket_id, NULL, OSAL_SIZE_C(1), &p2_addr); UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_INVALID_POINTER", (long)actual); expected = OS_ERR_INVALID_ID; objid = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_SocketSendTo(objid, &Buf1, 1, &p2_addr); + actual = OS_SocketSendTo(objid, &Buf1, sizeof(Buf1), &p2_addr); UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_ERR_INVALID_ID", (long)actual); /* OS_SocketRecvFrom */ expected = OS_INVALID_POINTER; - actual = OS_SocketRecvFrom(p2_socket_id, NULL, 1, NULL, 100); + actual = OS_SocketRecvFrom(p2_socket_id, NULL, OSAL_SIZE_C(1), NULL, 100); UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_INVALID_POINTER", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_SocketRecvFrom(p2_socket_id, NULL, 0, NULL, 0); + actual = OS_SocketRecvFrom(p2_socket_id, NULL, OSAL_SIZE_C(0), NULL, 0); UtAssert_True(actual == expected, "OS_SocketRecvFrom(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); expected = OS_ERR_INVALID_ID; objid = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_SocketRecvFrom(objid, &Buf2, 1, &l_addr, 100); + actual = OS_SocketRecvFrom(objid, &Buf2, sizeof(Buf2), &l_addr, 100); UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_ID", (long)actual); - expected = OS_INVALID_POINTER; - actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, 0, &l_addr, 100); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_INVALID_POINTER", (long)actual); + expected = OS_ERR_INVALID_SIZE; + actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, OSAL_SIZE_C(0), &l_addr, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); - expected = OS_INVALID_POINTER; - actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, 0, NULL, 100); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_INVALID_POINTER", (long)actual); + expected = OS_ERR_INVALID_SIZE; + actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, OSAL_SIZE_C(0), NULL, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); /* OS_SocketAddrToString */ expected = OS_INVALID_POINTER; - actual = OS_SocketAddrToString(NULL, 0, NULL); + actual = OS_SocketAddrToString(NULL, OSAL_SIZE_C(0), NULL); UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); expected = OS_INVALID_POINTER; @@ -310,7 +329,7 @@ void TestDatagramNetworkApi(void) UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_SocketAddrToString(0, 0, &p2_addr); + actual = OS_SocketAddrToString(NULL, OSAL_SIZE_C(0), &p2_addr); UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); /* OS_SocketAddrGetPort */ @@ -319,7 +338,7 @@ void TestDatagramNetworkApi(void) UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_SocketAddrGetPort(0, &l_addr); + actual = OS_SocketAddrGetPort(NULL, &l_addr); UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); expected = OS_INVALID_POINTER; @@ -477,7 +496,8 @@ void TestStreamNetworkApi(void) */ /* Create a server task/thread */ - status = OS_TaskCreate(&s_task_id, "Server", Server_Fn, 0, 16384, 50, 0); + status = OS_TaskCreate(&s_task_id, "Server", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), + OSAL_PRIORITY_C(50), 0); UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); /* Connect to a server */ diff --git a/src/tests/osal-core-test/osal-core-test.c b/src/tests/osal-core-test/osal-core-test.c index d5c04748e..79593e653 100644 --- a/src/tests/osal-core-test/osal-core-test.c +++ b/src/tests/osal-core-test/osal-core-test.c @@ -51,6 +51,32 @@ void TestMutexes(void); void TestGetInfos(void); void TestGenericQueries(void); +/* *************************************** GLOBALS ************************************** */ +osal_id_t task_0_id; +osal_id_t task_1_id; +osal_id_t task_2_id; +osal_id_t task_3_id; + +uint32 task_0_stack[TASK_0_STACK_SIZE]; +uint32 task_1_stack[TASK_1_STACK_SIZE]; +uint32 task_2_stack[TASK_2_STACK_SIZE]; +uint32 task_3_stack[TASK_3_STACK_SIZE]; + +osal_id_t msgq_0; +osal_id_t msgq_1; +osal_id_t msgq_2; +osal_id_t msgq_3; + +osal_id_t bin_0; +osal_id_t bin_1; +osal_id_t bin_2; +osal_id_t bin_3; + +osal_id_t mut_0; +osal_id_t mut_1; +osal_id_t mut_2; +osal_id_t mut_3; + /* helper function for "OS_ForEachObject" test cases */ static void TestForEachCallback(osal_id_t object_id, void *arg) { @@ -116,15 +142,14 @@ void TestTasks(void) OS_task_prop_t taskprop; int loopcnt; - /* OS_TaskRegister(); */ - /* Testing Creating up to OS_MAX_TASKS, plus one more */ memset(TaskData, 0xFF, sizeof(TaskData)); for (tasknum = 0; tasknum < (OS_MAX_TASKS + 1); ++tasknum) { snprintf(taskname, sizeof(taskname), "Task %d", tasknum); - status = OS_TaskCreate(&TaskData[tasknum].task_id, taskname, task_generic_no_exit, TaskData[tasknum].task_stack, - TASK_0_STACK_SIZE, (250 - OS_MAX_TASKS) + tasknum, 0); + status = OS_TaskCreate(&TaskData[tasknum].task_id, taskname, task_generic_no_exit, + OSAL_STACKPTR_C(TaskData[tasknum].task_stack), sizeof(TaskData[tasknum].task_stack), + OSAL_PRIORITY_C(250 - OS_MAX_TASKS + tasknum), 0); UtDebug("Create %s Status = %d, Id = %lx\n", taskname, (int)status, OS_ObjectIdToInteger(TaskData[tasknum].task_id)); @@ -161,7 +186,8 @@ void TestTasks(void) { snprintf(taskname, sizeof(taskname), "Task %d", tasknum); status = OS_TaskCreate(&TaskData[tasknum].task_id, taskname, task_generic_with_exit, - TaskData[tasknum].task_stack, TASK_0_STACK_SIZE, (250 - OS_MAX_TASKS) + tasknum, 0); + OSAL_STACKPTR_C(TaskData[tasknum].task_stack), sizeof(TaskData[tasknum].task_stack), + OSAL_PRIORITY_C((250 - OS_MAX_TASKS) + tasknum), 0); UtDebug("Create %s Status = %d, Id = %lx\n", taskname, (int)status, OS_ObjectIdToInteger(TaskData[tasknum].task_id)); @@ -193,37 +219,34 @@ void TestTasks(void) InitializeTaskIds(); /* Create Task 0 again */ - status = OS_TaskCreate(&task_0_id, "Task 0", task_0, task_0_stack, TASK_0_STACK_SIZE, TASK_0_PRIORITY, 0); - /*UtDebug("Create Status = %d, Id = %d\n",status,task_0_id); */ + status = OS_TaskCreate(&task_0_id, "Task 0", task_generic_no_exit, OSAL_STACKPTR_C(task_0_stack), + sizeof(task_0_stack), OSAL_PRIORITY_C(TASK_0_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate, recreate 0"); /* Try and create another "Task 0", should fail as we already have one named "Task 0" */ - status = OS_TaskCreate(&task_1_id, "Task 0", task_0, task_0_stack, TASK_0_STACK_SIZE, TASK_0_PRIORITY, 0); + status = OS_TaskCreate(&task_1_id, "Task 0", task_generic_no_exit, OSAL_STACKPTR_C(task_0_stack), + sizeof(task_0_stack), OSAL_PRIORITY_C(TASK_0_PRIORITY), 0); UtAssert_True(status != OS_SUCCESS, "OS_TaskCreate, dupe name 0"); - status = OS_TaskCreate(&task_2_id, "Task 2", task_2, task_2_stack, TASK_2_STACK_SIZE, TASK_2_PRIORITY, 0); - /* UtDebug("Create Status = %d, Id = %d\n",status,task_2_id); */ + status = OS_TaskCreate(&task_2_id, "Task 2", task_generic_no_exit, OSAL_STACKPTR_C(task_2_stack), + sizeof(task_2_stack), OSAL_PRIORITY_C(TASK_2_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate, recreate 2"); - status = OS_TaskCreate(&task_3_id, "Task 3", task_3, task_3_stack, TASK_3_STACK_SIZE, TASK_3_PRIORITY, 0); - /* UtDebug("Create Status = %d, Id = %d\n",status,task_3_id); */ + status = OS_TaskCreate(&task_3_id, "Task 3", task_generic_no_exit, OSAL_STACKPTR_C(task_3_stack), + sizeof(task_3_stack), OSAL_PRIORITY_C(TASK_3_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate, recreate 3"); status = OS_TaskGetIdByName(&task_0_id, "Task 0"); - /* UtDebug("Satus after Getting the id of \"Task 0\":%d,%d \n\n",status,task_0_id); */ /*first newly created task should have id == 0*/ UtAssert_True(status == OS_SUCCESS, "OS_TaskGetIdByName, Task 0"); status = OS_TaskGetIdByName(&task_1_id, "Task 1"); - /*UtDebug("Satus after Getting the id of \"Task 1\":%d,%d \n\n",status,task_1_id);*/ UtAssert_True(status != OS_SUCCESS, "OS_TaskGetIdByName, Task 1"); status = OS_TaskGetIdByName(&task_2_id, "Task 2"); - /* UtDebug("Satus after Getting the id of \"Task 2\":%d,%d \n\n",status,task_2_id);*/ UtAssert_True(status == OS_SUCCESS, "OS_TaskGetIdByName, Task 2"); status = OS_TaskGetIdByName(&task_3_id, "Task 3"); - /* UtDebug("Satus after Getting the id of \"Task 3\":%d,%d \n\n",status,task_3_id); */ UtAssert_True(status == OS_SUCCESS, "OS_TaskGetIdByName, Task 3"); /* @@ -255,7 +278,7 @@ void TestQueues(void) for (qnum = 0; qnum < (OS_MAX_QUEUES + 1); ++qnum) { snprintf(qname, sizeof(qname), "q %d", qnum); - status = OS_QueueCreate(&msgq_ids[qnum], qname, MSGQ_DEPTH, MSGQ_SIZE, 0); + status = OS_QueueCreate(&msgq_ids[qnum], qname, OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); UtAssert_True((qnum < OS_MAX_QUEUES && status == OS_SUCCESS) || (qnum >= OS_MAX_QUEUES && status != OS_SUCCESS), "OS_QueueCreate, nominal"); @@ -275,21 +298,17 @@ void TestQueues(void) /* Create Some more Queues for trying to get the id by name */ InitializeQIds(); - status = OS_QueueCreate(&msgq_0, "q 0", MSGQ_DEPTH, MSGQ_SIZE, 0); - /* UtDebug("Status after Creating q 0: %d,%d\n",status,msgq_0);*/ + status = OS_QueueCreate(&msgq_0, "q 0", OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); UtAssert_True(status == OS_SUCCESS, "OS_QueueCreate, recreate 0"); /* This one should fail */ - status = OS_QueueCreate(&msgq_1, "q 0", MSGQ_DEPTH, MSGQ_SIZE, 0); - /* UtDebug("Status after Creating q 0 again: %d,%d\n",status,msgq_1); */ + status = OS_QueueCreate(&msgq_1, "q 0", OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); UtAssert_True(status != OS_SUCCESS, "OS_QueueCreate, dupe name 0"); - status = OS_QueueCreate(&msgq_2, "q 2", MSGQ_DEPTH, MSGQ_SIZE, 0); - /* UtDebug("Status after Creating q 2: %d,%d\n",status,msgq_2); */ + status = OS_QueueCreate(&msgq_2, "q 2", OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); UtAssert_True(status == OS_SUCCESS, "OS_QueueCreate, recreate 2"); - status = OS_QueueCreate(&msgq_3, "q 3", MSGQ_DEPTH, MSGQ_SIZE, 0); - /* UtDebug("Status after Creating q 3: %d,%d\n",status,msgq_3); */ + status = OS_QueueCreate(&msgq_3, "q 3", OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); UtAssert_True(status == OS_SUCCESS, "OS_QueueCreate, recreate 3"); /* @@ -317,19 +336,15 @@ void TestQueues(void) /* Time to Delete the Queues we just created */ status = OS_QueueDelete(msgq_0); - /* UtDebug("Status after Deleting q 0 : %d\n",status); */ UtAssert_True(status == OS_SUCCESS, "OS_QueueDelete, q 0"); status = OS_QueueDelete(msgq_1); - /* UtDebug("Status after Deleting q 1: %d\n",status); */ UtAssert_True(status != OS_SUCCESS, "OS_QueueDelete, q 1"); status = OS_QueueDelete(msgq_2); - /* UtDebug("Status after Deleting q 2: %d\n",status); */ UtAssert_True(status == OS_SUCCESS, "OS_QueueDelete, q 2"); status = OS_QueueDelete(msgq_3); - /* UtDebug("Status after Deleting q 3: %d\n",status); */ UtAssert_True(status == OS_SUCCESS, "OS_QueueDelete, q 3"); } /* end TestQueues */ @@ -372,35 +387,27 @@ void TestBinaries(void) */ InitializeBinIds(); status = OS_BinSemCreate(&bin_0, "Bin 0", OS_SEM_FULL, 0); - /* UtDebug("Status after creating: %d,%d\n",status,bin_0); */ UtAssert_True(status == OS_SUCCESS, "OS_BinSemCreate, recreate 0"); status = OS_BinSemCreate(&bin_1, "Bin 0", OS_SEM_FULL, 0); - /* UtDebug("Status after creating: %d,%d\n",status,bin_1); */ UtAssert_True(status != OS_SUCCESS, "OS_BinSemCreate, dupe name 0"); status = OS_BinSemCreate(&bin_2, "Bin 2", OS_SEM_EMPTY, 0); - /* UtDebug("Status after creating: %d,%d\n",status,bin_2); */ UtAssert_True(status == OS_SUCCESS, "OS_BinSemCreate, recreate 2"); status = OS_BinSemCreate(&bin_3, "Bin 3", OS_SEM_EMPTY, 0); - /* UtDebug("Status after creating: %d,%d\n",status,bin_3); */ UtAssert_True(status == OS_SUCCESS, "OS_BinSemCreate, recreate 3"); status = OS_BinSemGetIdByName(&bin_0, "Bin 0"); - /* UtDebug("Status after GETID: %d,%d\n",status,bin_0); */ UtAssert_True(status == OS_SUCCESS, "OS_BinSemGetIdByName, Bin 0"); status = OS_BinSemGetIdByName(&bin_1, "Bin 1"); - /* UtDebug("Status after GETID: %d,%d\n",status,bin_1); */ UtAssert_True(status != OS_SUCCESS, "OS_BinSemGetIdByName, Bin 1"); status = OS_BinSemGetIdByName(&bin_2, "Bin 2"); - /* UtDebug("Status after GETID: %d,%d\n",status,bin_2); */ UtAssert_True(status == OS_SUCCESS, "OS_BinSemGetIdByName, Bin 2"); status = OS_BinSemGetIdByName(&bin_3, "Bin 3"); - /* UtDebug("Status after GETID: %d,%d\n",status,bin_3); */ UtAssert_True(status == OS_SUCCESS, "OS_BinSemGetIdByName, Bin 3"); /* @@ -410,12 +417,10 @@ void TestBinaries(void) UtAssert_True(status != OS_SUCCESS, "OS_BinSemDelete, Old ID"); status = OS_BinSemDelete(bin_0); - /* UtDebug("Status after deleteing:%d\n",status); */ UtAssert_True(status == OS_SUCCESS, "OS_BinSemDelete, Bin 0"); /* this one was never created */ status = OS_BinSemDelete(bin_1); - /* UtDebug("Status after deleteing:%d\n",status); */ UtAssert_True(status != OS_SUCCESS, "OS_BinSemDelete, Bin 1"); status = OS_BinSemDelete(bin_2); @@ -464,19 +469,15 @@ void TestMutexes(void) */ InitializeMutIds(); status = OS_MutSemCreate(&mut_0, "Mut 0", 0); - /* UtDebug("Status after creating Mut 0: %d,%d\n",status,mut_0); */ UtAssert_True(status == OS_SUCCESS, "OS_MutSemCreate, recreate 0"); status = OS_MutSemCreate(&mut_1, "Mut 0", 0); - /* UtDebug("Status after creating Mut 0 again: %d,%d\n",status,mut_1); */ UtAssert_True(status != OS_SUCCESS, "OS_MutSemCreate, dupe name 0"); status = OS_MutSemCreate(&mut_2, "Mut 2", 0); - /* UtDebug("Status after creating Mut 2: %d,%d\n",status,mut_2); */ UtAssert_True(status == OS_SUCCESS, "OS_MutSemCreate, recreate 2"); status = OS_MutSemCreate(&mut_3, "Mut 3", 0); - /* UtDebug("Status after creating Mut 3: %d,%d\n",status,mut_3); */ UtAssert_True(status == OS_SUCCESS, "OS_MutSemCreate, recreate 3"); status = OS_MutSemGetIdByName(&mut_0, "Mut 0"); @@ -498,20 +499,16 @@ void TestMutexes(void) UtAssert_True(status != OS_SUCCESS, "OS_MutSemDelete, Old ID"); status = OS_MutSemDelete(mut_0); - /* UtDebug("Status after deleteing Mut 0:%d\n",status); */ UtAssert_True(status == OS_SUCCESS, "OS_MutSemDelete, Mut 0"); /* this one was never created*/ status = OS_MutSemDelete(mut_1); - /* UtDebug("Status after deleteing Mut 1:%d\n",status); */ UtAssert_True(status != OS_SUCCESS, "OS_MutSemDelete, Mut 1"); status = OS_MutSemDelete(mut_2); - /* UtDebug("Status after deleteing Mut 2:%d\n",status); */ UtAssert_True(status == OS_SUCCESS, "OS_MutSemDelete, Mut 2"); status = OS_MutSemDelete(mut_3); - /* UtDebug("Status after deleteing Mut 3:%d\n",status); */ UtAssert_True(status == OS_SUCCESS, "OS_MutSemDelete, Mut 3"); } /* end TestMutexes */ @@ -524,84 +521,43 @@ void TestMutexes(void) /* ************************************************************************** */ void InitializeTaskIds(void) { - - task_0_id = OS_OBJECT_ID_UNDEFINED; - task_1_id = OS_OBJECT_ID_UNDEFINED; - task_2_id = OS_OBJECT_ID_UNDEFINED; - task_3_id = OS_OBJECT_ID_UNDEFINED; - task_4_id = OS_OBJECT_ID_UNDEFINED; - task_5_id = OS_OBJECT_ID_UNDEFINED; - task_6_id = OS_OBJECT_ID_UNDEFINED; - task_7_id = OS_OBJECT_ID_UNDEFINED; - task_8_id = OS_OBJECT_ID_UNDEFINED; - task_9_id = OS_OBJECT_ID_UNDEFINED; - task_10_id = OS_OBJECT_ID_UNDEFINED; - task_11_id = OS_OBJECT_ID_UNDEFINED; - task_12_id = OS_OBJECT_ID_UNDEFINED; - task_13_id = OS_OBJECT_ID_UNDEFINED; - task_14_id = OS_OBJECT_ID_UNDEFINED; - task_15_id = OS_OBJECT_ID_UNDEFINED; - task_16_id = OS_OBJECT_ID_UNDEFINED; - task_17_id = OS_OBJECT_ID_UNDEFINED; - task_18_id = OS_OBJECT_ID_UNDEFINED; - task_19_id = OS_OBJECT_ID_UNDEFINED; - task_20_id = OS_OBJECT_ID_UNDEFINED; - + task_0_id = OS_OBJECT_ID_UNDEFINED; + task_1_id = OS_OBJECT_ID_UNDEFINED; + task_2_id = OS_OBJECT_ID_UNDEFINED; + task_3_id = OS_OBJECT_ID_UNDEFINED; return; } /* end InitializeTaskIds */ /* **************************************************************************** */ void InitializeQIds(void) { - msgq_0 = OS_OBJECT_ID_UNDEFINED; - msgq_1 = OS_OBJECT_ID_UNDEFINED; - msgq_2 = OS_OBJECT_ID_UNDEFINED; - msgq_3 = OS_OBJECT_ID_UNDEFINED; - msgq_4 = OS_OBJECT_ID_UNDEFINED; - msgq_5 = OS_OBJECT_ID_UNDEFINED; - msgq_6 = OS_OBJECT_ID_UNDEFINED; - msgq_7 = OS_OBJECT_ID_UNDEFINED; - msgq_8 = OS_OBJECT_ID_UNDEFINED; - msgq_9 = OS_OBJECT_ID_UNDEFINED; - msgq_10 = OS_OBJECT_ID_UNDEFINED; - msgq_id = OS_OBJECT_ID_UNDEFINED; - + msgq_0 = OS_OBJECT_ID_UNDEFINED; + msgq_1 = OS_OBJECT_ID_UNDEFINED; + msgq_2 = OS_OBJECT_ID_UNDEFINED; + msgq_3 = OS_OBJECT_ID_UNDEFINED; return; } /* end InitializeQIds */ /* ***************************************************************************** */ void InitializeBinIds(void) { - bin_0 = OS_OBJECT_ID_UNDEFINED; - bin_1 = OS_OBJECT_ID_UNDEFINED; - bin_2 = OS_OBJECT_ID_UNDEFINED; - bin_3 = OS_OBJECT_ID_UNDEFINED; - bin_4 = OS_OBJECT_ID_UNDEFINED; - bin_5 = OS_OBJECT_ID_UNDEFINED; - bin_6 = OS_OBJECT_ID_UNDEFINED; - bin_7 = OS_OBJECT_ID_UNDEFINED; - bin_8 = OS_OBJECT_ID_UNDEFINED; - bin_9 = OS_OBJECT_ID_UNDEFINED; - bin_10 = OS_OBJECT_ID_UNDEFINED; + bin_0 = OS_OBJECT_ID_UNDEFINED; + bin_1 = OS_OBJECT_ID_UNDEFINED; + bin_2 = OS_OBJECT_ID_UNDEFINED; + bin_3 = OS_OBJECT_ID_UNDEFINED; return; } /* end InitializeBinIds */ /* ***************************************************************************** */ void InitializeMutIds(void) { - mut_0 = OS_OBJECT_ID_UNDEFINED; - mut_1 = OS_OBJECT_ID_UNDEFINED; - mut_2 = OS_OBJECT_ID_UNDEFINED; - mut_3 = OS_OBJECT_ID_UNDEFINED; - mut_4 = OS_OBJECT_ID_UNDEFINED; - mut_5 = OS_OBJECT_ID_UNDEFINED; - mut_6 = OS_OBJECT_ID_UNDEFINED; - mut_7 = OS_OBJECT_ID_UNDEFINED; - mut_8 = OS_OBJECT_ID_UNDEFINED; - mut_9 = OS_OBJECT_ID_UNDEFINED; - mut_10 = OS_OBJECT_ID_UNDEFINED; + mut_0 = OS_OBJECT_ID_UNDEFINED; + mut_1 = OS_OBJECT_ID_UNDEFINED; + mut_2 = OS_OBJECT_ID_UNDEFINED; + mut_3 = OS_OBJECT_ID_UNDEFINED; return; } /* end InitializeMutIds */ + /* ***************************************************************************** */ void TestGetInfos(void) { @@ -613,19 +569,17 @@ void TestGetInfos(void) /* first step is to create an object to to get the properties of */ - status = OS_TaskCreate(&task_0_id, "Task 0", task_0, task_0_stack, TASK_0_STACK_SIZE, TASK_0_PRIORITY, 0); + status = OS_TaskCreate(&task_0_id, "Task 0", task_generic_no_exit, OSAL_STACKPTR_C(task_0_stack), + sizeof(task_0_stack), OSAL_PRIORITY_C(TASK_0_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate"); - status = OS_QueueCreate(&msgq_0, "q 0", MSGQ_DEPTH, MSGQ_SIZE, 0); - /* UtDebug("Status after Creating q 0: %d,%d\n",status,msgq_0); */ + status = OS_QueueCreate(&msgq_0, "q 0", OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); UtAssert_True(status == OS_SUCCESS, "OS_QueueCreate"); status = OS_BinSemCreate(&bin_0, "Bin 0", 1, 0); - /* UtDebug("Status after creating: %d,%d\n",status,bin_0); */ UtAssert_True(status == OS_SUCCESS, "OS_BinSemCreate"); status = OS_MutSemCreate(&mut_0, "Mut 0", 0); - /* UtDebug("Status after creating: %d,%d\n",status,mut_0); */ UtAssert_True(status == OS_SUCCESS, "OS_MutSemCreate"); /* Next Step is to get the properties of the objects */ @@ -647,14 +601,11 @@ void TestGetInfos(void) status = OS_QueueDelete(msgq_0); UtAssert_True(status == OS_SUCCESS, "OS_QueueDelete"); - /* UtDebug("Status after Deleting q 0: %d\n",status); */ status = OS_BinSemDelete(bin_0); - /* UtDebug("Status after deleteing:%d\n",status); */ UtAssert_True(status == OS_SUCCESS, "OS_BinSemDelete"); status = OS_MutSemDelete(mut_0); - /* UtDebug("Status after deleteing:%d\n",status); */ UtAssert_True(status == OS_SUCCESS, "OS_MutSemDelete"); } @@ -668,10 +619,11 @@ void TestGenericQueries(void) TestCallbackState_t State; char ResourceName[OS_MAX_API_NAME]; - status = OS_TaskCreate(&task_0_id, "Task 0", task_0, task_0_stack, TASK_0_STACK_SIZE, TASK_0_PRIORITY, 0); + status = OS_TaskCreate(&task_0_id, "Task 0", task_generic_no_exit, OSAL_STACKPTR_C(task_0_stack), + sizeof(task_0_stack), OSAL_PRIORITY_C(TASK_0_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate (%ld) == OS_SUCCESS", (long)status); - status = OS_QueueCreate(&msgq_0, "q 0", MSGQ_DEPTH, MSGQ_SIZE, 0); + status = OS_QueueCreate(&msgq_0, "q 0", OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); UtAssert_True(status == OS_SUCCESS, "OS_QueueCreate (%ld) == OS_SUCCESS", (long)status); status = OS_BinSemCreate(&bin_0, "Bin 0", 1, 0); @@ -711,7 +663,7 @@ void TestGenericQueries(void) UtAssert_True(State.NumInvocations >= 4, "State.NumInvocations (%lu) >= 4", (unsigned long)State.NumInvocations); /* Test the OS_GetResourceName() API function */ - status = OS_GetResourceName(mut_0, ResourceName, 0); + status = OS_GetResourceName(mut_0, ResourceName, OSAL_SIZE_C(0)); UtAssert_True(status == OS_INVALID_POINTER, "OS_GetResourceName (%lx,%ld) == OS_INVALID_POINTER", OS_ObjectIdToInteger(mut_0), (long)status); @@ -721,10 +673,10 @@ void TestGenericQueries(void) UtAssert_StrCmp(ResourceName, "q 0", "Output value correct"); status = OS_GetResourceName(OS_OBJECT_ID_UNDEFINED, ResourceName, sizeof(ResourceName)); - UtAssert_True(status == OS_ERR_INVALID_ID, "OS_GetResourceName (%lx,%ld) == OS_ERR_INVALID_ID", + UtAssert_True(status == OS_ERR_INCORRECT_OBJ_TYPE, "OS_GetResourceName (%lx,%ld) == OS_ERR_INCORRECT_OBJ_TYPE", OS_ObjectIdToInteger(OS_OBJECT_ID_UNDEFINED), (long)status); - status = OS_GetResourceName(bin_0, ResourceName, 1); + status = OS_GetResourceName(bin_0, ResourceName, OSAL_SIZE_C(1)); UtAssert_True(status == OS_ERR_NAME_TOO_LONG, "OS_GetResourceName (%lx,%ld) == OS_ERR_NAME_TOO_LONG", OS_ObjectIdToInteger(bin_0), (long)status); diff --git a/src/tests/osal-core-test/osal-core-test.h b/src/tests/osal-core-test/osal-core-test.h index 0bc5ea052..b6c7c7099 100644 --- a/src/tests/osal-core-test/osal-core-test.h +++ b/src/tests/osal-core-test/osal-core-test.h @@ -24,496 +24,29 @@ * This is a simple header file used to remove a lot of the task definitions * from the example1.c file so as to make that code easier to read * - * - * - * */ +#ifndef INCLUDE_osal_core_test_h +#define INCLUDE_osal_core_test_h + /* Task 0 */ #define TASK_0_STACK_SIZE 1024 #define TASK_0_PRIORITY 230 -uint32 task_0_stack[TASK_0_STACK_SIZE]; - -void task_0(void); - /* Task 1 */ - #define TASK_1_STACK_SIZE 1024 #define TASK_1_PRIORITY 231 -uint32 task_1_stack[TASK_1_STACK_SIZE]; - -void task_1(void); - /* Task 2 */ - #define TASK_2_STACK_SIZE 1024 #define TASK_2_PRIORITY 232 -uint32 task_2_stack[TASK_2_STACK_SIZE]; - -void task_2(void); - /* Task 3 */ - #define TASK_3_STACK_SIZE 1024 #define TASK_3_PRIORITY 233 -uint32 task_3_stack[TASK_3_STACK_SIZE]; - -void task_3(void); - -/* Task 4 */ - -#define TASK_4_STACK_SIZE 1024 -#define TASK_4_PRIORITY 234 - -uint32 task_4_stack[TASK_4_STACK_SIZE]; - -void task_4(void); - -/* Task 5 */ - -#define TASK_5_STACK_SIZE 1024 -#define TASK_5_PRIORITY 235 - -uint32 task_5_stack[TASK_5_STACK_SIZE]; - -void task_5(void); - -/* Task 6 */ - -#define TASK_6_STACK_SIZE 1024 -#define TASK_6_PRIORITY 236 - -uint32 task_6_stack[TASK_6_STACK_SIZE]; - -void task_6(void); - -/* Task 7 */ - -#define TASK_7_STACK_SIZE 1024 -#define TASK_7_PRIORITY 237 - -uint32 task_7_stack[TASK_7_STACK_SIZE]; - -void task_7(void); - -/* Task 8 */ - -#define TASK_8_STACK_SIZE 1024 -#define TASK_8_PRIORITY 238 - -uint32 task_8_stack[TASK_8_STACK_SIZE]; - -void task_8(void); - -/* Task 9 */ - -#define TASK_9_STACK_SIZE 1024 -#define TASK_9_PRIORITY 239 - -uint32 task_9_stack[TASK_9_STACK_SIZE]; - -void task_9(void); - -/* Task 10 */ - -#define TASK_10_STACK_SIZE 1024 -#define TASK_10_PRIORITY 240 - -uint32 task_10_stack[TASK_10_STACK_SIZE]; - -void task_10(void); - -/* Task 11 */ - -#define TASK_11_STACK_SIZE 1024 -#define TASK_11_PRIORITY 241 - -uint32 task_11_stack[TASK_11_STACK_SIZE]; - -void task_11(void); - -/* Task 12 */ - -#define TASK_12_STACK_SIZE 1024 -#define TASK_12_PRIORITY 242 - -uint32 task_12_stack[TASK_12_STACK_SIZE]; - -void task_12(void); - -/* Task 13 */ - -#define TASK_13_STACK_SIZE 1024 -#define TASK_13_PRIORITY 243 - -uint32 task_13_stack[TASK_13_STACK_SIZE]; - -void task_13(void); - -/* Task 14 */ - -#define TASK_14_STACK_SIZE 1024 -#define TASK_14_PRIORITY 244 - -uint32 task_14_stack[TASK_14_STACK_SIZE]; - -void task_14(void); -/* Task 15 */ - -#define TASK_15_STACK_SIZE 1024 -#define TASK_15_PRIORITY 245 - -uint32 task_15_stack[TASK_15_STACK_SIZE]; - -void task_15(void); - -/* Task 16 */ - -#define TASK_16_STACK_SIZE 1024 -#define TASK_16_PRIORITY 246 - -uint32 task_16_stack[TASK_16_STACK_SIZE]; - -void task_16(void); - -/* Task 17 */ - -#define TASK_17_STACK_SIZE 1024 -#define TASK_17_PRIORITY 247 - -uint32 task_17_stack[TASK_17_STACK_SIZE]; - -void task_17(void); - -/* Task 18 */ - -#define TASK_18_STACK_SIZE 1024 -#define TASK_18_PRIORITY 248 - -uint32 task_18_stack[TASK_18_STACK_SIZE]; - -void task_18(void); - -/* Task 19 */ - -#define TASK_19_STACK_SIZE 1024 -#define TASK_19_PRIORITY 249 - -uint32 task_19_stack[TASK_19_STACK_SIZE]; - -void task_19(void); - -/* Task 20 */ - -#define TASK_20_STACK_SIZE 1024 -#define TASK_20_PRIORITY 250 - -uint32 task_20_stack[TASK_20_STACK_SIZE]; - -void task_20(void); - /* Global Data */ - -/* Task Id's for testing the number of tasks that can be created */ -osal_id_t task_0_id, task_1_id, task_2_id, task_3_id, task_4_id, task_5_id; -osal_id_t task_6_id, task_7_id, task_8_id, task_9_id, task_10_id, task_11_id; -osal_id_t task_12_id, task_13_id, task_14_id, task_15_id, task_16_id, task_17_id; -osal_id_t task_18_id, task_19_id, task_20_id; -/* uint32 extra_id; */ - -osal_id_t mutex_id; - -/* Queue ID for testing the number of queues that can be created */ -osal_id_t msgq_0, msgq_1, msgq_2, msgq_3, msgq_4, msgq_5, msgq_6; -osal_id_t msgq_7, msgq_8, msgq_9; -osal_id_t msgq_10; - -osal_id_t msgq_id; - -osal_id_t bin_0, bin_1, bin_2, bin_3, bin_4, bin_5, bin_6; -osal_id_t bin_7, bin_8, bin_9, bin_10; - -osal_id_t mut_0, mut_1, mut_2, mut_3, mut_4, mut_5, mut_6; -osal_id_t mut_7, mut_8, mut_9, mut_10; -osal_id_t mutex_id; - -uint32 shared_resource_x; - #define MSGQ_DEPTH 50 #define MSGQ_SIZE 4 -#define PASS 0 -#define FAIL 1 - -/* ********************** TASK 0 **************************** */ - -void task_0(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; -} /* end task_0 */ - -/* ********************** TASK 1 **************************** */ - -void task_1(void) -{ - - OS_TaskRegister(); - - while (1) - ; - - return; -} /* end task_1 */ - -/* ********************** TASK 2 **************************** */ - -void task_2(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; -} /* end task_2 */ - -/* ********************** TASK 3 **************************** */ - -void task_3(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; -} /* end task_3 */ - -/* ********************** TASK 4 **************************** */ - -void task_4(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; -} /* end task_4 */ - -/* ********************** TASK 0 **************************** */ - -void task_5(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_5 */ - -/* ********************** TASK 6 **************************** */ - -void task_6(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_6 */ - -/* ********************** TASK 7 **************************** */ - -void task_7(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_7 */ - -/* ********************** TASK 8 **************************** */ - -void task_8(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_8 */ - -/* ********************** TASK 9 **************************** */ - -void task_9(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_9 */ - -/* ********************** TASK 10 **************************** */ - -void task_10(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_10 */ - -/* ********************** TASK 11 **************************** */ - -void task_11(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_11 */ - -/* ********************** TASK 12 **************************** */ - -void task_12(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_12 */ - -/* ********************** TASK 13 **************************** */ - -void task_13(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_13 */ - -/* ********************** TASK 14 **************************** */ - -void task_14(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_14 */ - -/* ********************** TASK 15 **************************** */ - -void task_15(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_15 */ - -/* ********************** TASK 16 **************************** */ - -void task_16(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_16 */ - -/* ********************** TASK 17 **************************** */ - -void task_17(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_17 */ - -/* ********************** TASK 18 **************************** */ - -void task_18(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_18 */ - -/* ********************** TASK 19 **************************** */ - -void task_19(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_19 */ - -/* ********************** TASK 20 **************************** */ - -void task_20(void) -{ - OS_TaskRegister(); - - while (1) - ; - - return; - -} /* end task_20 */ +#endif /* INCLUDE_osal_core_test_h */ diff --git a/src/tests/queue-timeout-test/queue-timeout-test.c b/src/tests/queue-test/queue-test.c similarity index 58% rename from src/tests/queue-timeout-test/queue-timeout-test.c rename to src/tests/queue-test/queue-test.c index 0e05b6d5e..352d8e2a3 100644 --- a/src/tests/queue-timeout-test/queue-timeout-test.c +++ b/src/tests/queue-test/queue-test.c @@ -33,7 +33,9 @@ void QueueTimeoutSetup(void); void QueueTimeoutCheck(void); #define MSGQ_DEPTH 50 -#define MSGQ_SIZE 4 +#define MSGQ_SIZE sizeof(uint32) +#define MSGQ_TOTAL 10 +#define MSGQ_BURST 3 /* Task 1 */ #define TASK_1_STACK_SIZE 1024 @@ -64,8 +66,9 @@ void TimerFunction(osal_id_t timer_id) void task_1(void) { int32 status; + size_t data_size; uint32 data_received; - uint32 data_size; + uint32 expected = 0; OS_printf("Starting task 1\n"); @@ -78,12 +81,15 @@ void task_1(void) while (task_1_failures < 20) { - status = OS_QueueGet(msgq_id, (void *)&data_received, MSGQ_SIZE, &data_size, 1000); + status = OS_QueueGet(msgq_id, (void *)&data_received, OSAL_SIZE_C(MSGQ_SIZE), &data_size, 1000); if (status == OS_SUCCESS) { ++task_1_messages; - OS_printf("TASK 1: Recieved a message on the queue\n"); + UtAssert_True(data_received == expected, "TASK 1: data_received (%u) == expected (%u)", + (unsigned int)data_received, (unsigned int)expected); + + expected++; } else if (status == OS_QUEUE_TIMEOUT) { @@ -108,6 +114,8 @@ void QueueTimeoutCheck(void) UtAssert_True(status == OS_SUCCESS, "Timer delete Rc=%d", (int)status); status = OS_TaskDelete(task_1_id); UtAssert_True(status == OS_SUCCESS, "Task 1 delete Rc=%d", (int)status); + status = OS_QueueDelete(msgq_id); + UtAssert_True(status == OS_SUCCESS, "Queue 1 delete Rc=%d", (int)status); /* None of the tasks should have any failures in their own counters */ UtAssert_True(task_1_failures == 0, "Task 1 failures = %u", (unsigned int)task_1_failures); @@ -127,35 +135,83 @@ void QueueTimeoutCheck(void) (unsigned int)limit); } -void UtTest_Setup(void) +void QueueTimeoutSetup(void) { - if (OS_API_Init() != OS_SUCCESS) + int32 status; + uint32 accuracy; + + task_1_failures = 0; + task_1_messages = 0; + task_1_timeouts = 0; + + status = OS_QueueCreate(&msgq_id, "MsgQ", OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); + UtAssert_True(status == OS_SUCCESS, "MsgQ create Id=%lx Rc=%d", OS_ObjectIdToInteger(msgq_id), (int)status); + + /* + ** Create the "consumer" task. + */ + status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_STACKPTR_C(task_1_stack), sizeof(task_1_stack), + OSAL_PRIORITY_C(TASK_1_PRIORITY), 0); + UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status); + + /* + ** Create a timer + */ + status = OS_TimerCreate(&timer_id, "Timer 1", &accuracy, &(TimerFunction)); + UtAssert_True(status == OS_SUCCESS, "Timer 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(timer_id), (int)status); + UtPrintf("Timer Accuracy = %u microseconds \n", (unsigned int)accuracy); + + /* + ** Start the timer + */ + status = OS_TimerSet(timer_id, timer_start, timer_interval); + UtAssert_True(status == OS_SUCCESS, "Timer 1 set Rc=%d", (int)status); + + /* allow some time for task to run and accrue queue timeouts */ + while (timer_counter < 100) { - UtAssert_Abort("OS_API_Init() failed"); + OS_TaskDelay(100); } +} - /* - * Register the test setup and check routines in UT assert - */ - UtTest_Add(QueueTimeoutCheck, QueueTimeoutSetup, NULL, "QueueTimeoutTest"); +void QueueMessageCheck(void) +{ + int32 status; + + OS_printf("Delay for half a second before checking\n"); + OS_TaskDelay(500); + + status = OS_TimerDelete(timer_id); + UtAssert_True(status == OS_SUCCESS, "Timer delete Rc=%d", (int)status); + status = OS_TaskDelete(task_1_id); + UtAssert_True(status == OS_SUCCESS, "Task 1 delete Rc=%d", (int)status); + status = OS_QueueDelete(msgq_id); + UtAssert_True(status == OS_SUCCESS, "Queue 1 delete Rc=%d", (int)status); + + /* None of the tasks should have any failures in their own counters */ + UtAssert_True(task_1_failures == 0, "Task 1 failures = %u", (unsigned int)task_1_failures); + UtAssert_True(task_1_messages == 10, "Task 1 messages = %u", (unsigned int)task_1_messages); + UtAssert_True(task_1_timeouts == 0, "Task 1 timeouts = %u", (unsigned int)task_1_timeouts); } -void QueueTimeoutSetup(void) +void QueueMessageSetup(void) { int32 status; uint32 accuracy; - + int i; + uint32 Data = 0; task_1_failures = 0; task_1_messages = 0; task_1_timeouts = 0; - status = OS_QueueCreate(&msgq_id, "MsgQ", MSGQ_DEPTH, MSGQ_SIZE, 0); + status = OS_QueueCreate(&msgq_id, "MsgQ", OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); UtAssert_True(status == OS_SUCCESS, "MsgQ create Id=%lx Rc=%d", OS_ObjectIdToInteger(msgq_id), (int)status); /* ** Create the "consumer" task. */ - status = OS_TaskCreate(&task_1_id, "Task 1", task_1, task_1_stack, TASK_1_STACK_SIZE, TASK_1_PRIORITY, 0); + status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_STACKPTR_C(task_1_stack), sizeof(task_1_stack), + OSAL_PRIORITY_C(TASK_1_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status); /* @@ -171,9 +227,31 @@ void QueueTimeoutSetup(void) status = OS_TimerSet(timer_id, timer_start, timer_interval); UtAssert_True(status == OS_SUCCESS, "Timer 1 set Rc=%d", (int)status); - /* allow some time for task to run and accrue queue timeouts */ - while (timer_counter < 100) + /* + * Put 10 messages onto the que with some time inbetween the later messages + * to make sure the que handles both storing and waiting for messages + */ + for (i = 0; i < MSGQ_TOTAL; i++) { - OS_TaskDelay(100); + if (i > MSGQ_BURST) + OS_TaskDelay(400); + + Data = i; + status = OS_QueuePut(msgq_id, (void *)&Data, sizeof(Data), 0); + UtAssert_True(status == OS_SUCCESS, "OS Queue Put Rc=%d", (int)status); } } + +void UtTest_Setup(void) +{ + if (OS_API_Init() != OS_SUCCESS) + { + UtAssert_Abort("OS_API_Init() failed"); + } + + /* + * Register the test setup and check routines in UT assert + */ + UtTest_Add(QueueTimeoutCheck, QueueTimeoutSetup, NULL, "QueueTimeoutTest"); + UtTest_Add(QueueMessageCheck, QueueMessageSetup, NULL, "QueueMessageCheck"); +} diff --git a/src/tests/select-test/select-test.c b/src/tests/select-test/select-test.c new file mode 100644 index 000000000..c9d773a55 --- /dev/null +++ b/src/tests/select-test/select-test.c @@ -0,0 +1,558 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Filename: select-test.c + * + * Purpose: This file contains functional tests for "osapi-select" + * Single select test will create a server and client to stream data between them and the select watches that stream. + * Multi select test will setup a second server and client also streaming data between them so that it can watch + * multiple streams. + * + */ + +#include +#include +#include +#include "common_types.h" +#include "osapi.h" +#include "utassert.h" +#include "uttest.h" +#include "utbsp.h" +#define MAX_BUFFER_LOOP 1000000 + +osal_id_t s_task_id; +osal_id_t s2_task_id; +osal_id_t s_socket_id; +osal_id_t s2_socket_id; +osal_id_t c_socket_id; +osal_id_t c2_socket_id; +OS_SockAddr_t s_addr; +OS_SockAddr_t s2_addr; +OS_SockAddr_t c_addr; +OS_SockAddr_t c2_addr; +osal_id_t bin_sem_id; + +#define OS_TEST_SELECT_FILENAME "/drive0/select_test.txt" + +/* *************************************** MAIN ************************************** */ + +char * fsAddrPtr = NULL; +static osal_id_t setup_file(void) +{ + osal_id_t id; + OS_mkfs(fsAddrPtr, "/ramdev0", "RAM", 512, 20); + OS_mount("/ramdev0", "/drive0"); + OS_OpenCreate(&id, OS_TEST_SELECT_FILENAME, OS_FILE_FLAG_CREATE, OS_READ_WRITE); + return id; +} + +void BinSemSetup(void) +{ + uint32 status; + OS_bin_sem_prop_t bin_sem_prop; + + /* + * Create the binary semaphore + * BinSem1 is used to control when the server can accept connections + */ + status = OS_BinSemCreate(&bin_sem_id, "BinSem1", 0, 0); + UtAssert_True(status == OS_SUCCESS, "BinSem1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(bin_sem_id), (int)status); + + status = OS_BinSemGetInfo(bin_sem_id, &bin_sem_prop); + UtAssert_True(status == OS_SUCCESS, "BinSem1 value=%d Rc=%d", (int)bin_sem_prop.value, (int)status); +} + +void Setup_Server(void) +{ + int32 expected; + int32 actual; + + /* + * Set up a server + */ + + /* Open a server socket */ + s_socket_id = OS_OBJECT_ID_UNDEFINED; + expected = OS_SUCCESS; + actual = OS_SocketOpen(&s_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(s_socket_id), "s_socket_id (%lu) != 0", OS_ObjectIdToInteger(s_socket_id)); + + /* Initialize server address */ + actual = OS_SocketAddrInit(&s_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set server port */ + actual = OS_SocketAddrSetPort(&s_addr, 9994); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set server address */ + actual = OS_SocketAddrFromString(&s_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* Bind server socket to server address */ + actual = OS_SocketBind(s_socket_id, &s_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); +} + +void Setup_Client(void) +{ + int32 expected; + int32 actual; + + /* + * Set up a client + */ + + /* Open a client socket */ + expected = OS_SUCCESS; + c_socket_id = OS_OBJECT_ID_UNDEFINED; + + actual = OS_SocketOpen(&c_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(c_socket_id), "c_socket_id (%lu) != 0", OS_ObjectIdToInteger(c_socket_id)); + + /* Initialize client address */ + actual = OS_SocketAddrInit(&c_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set client port */ + actual = OS_SocketAddrSetPort(&c_addr, 9993); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set client address */ + actual = OS_SocketAddrFromString(&c_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); +} + +void Server_Fn(void) +{ + osal_id_t connsock_id = OS_OBJECT_ID_UNDEFINED; + OS_SockAddr_t addr; + uint32 status; + + /* Accept incoming connections */ + OS_SocketAccept(s_socket_id, &connsock_id, &addr, OS_PEND); + + status = OS_BinSemTake(bin_sem_id); + UtAssert_True(status == OS_SUCCESS, "BinSem1 Server 1 take Rc=%d", (int)status); + + status = OS_close(s_socket_id); + UtAssert_True(status == OS_SUCCESS, "status after close s_socket_id = %d", (int)status); + + status = OS_close(connsock_id); + UtAssert_True(status == OS_SUCCESS, "status after close connsock_id = %d", (int)status); +} /* end Server_Fn */ + +void Setup_Server2(void) +{ + int32 expected; + int32 actual; + + /* + * Set up a server + */ + + /* Open a server socket */ + s2_socket_id = OS_OBJECT_ID_UNDEFINED; + expected = OS_SUCCESS; + actual = OS_SocketOpen(&s2_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(s2_socket_id), "s2_socket_id (%lu) != 0", OS_ObjectIdToInteger(s2_socket_id)); + + /* Initialize server address */ + actual = OS_SocketAddrInit(&s2_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set server port */ + actual = OS_SocketAddrSetPort(&s2_addr, 9995); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set server address */ + actual = OS_SocketAddrFromString(&s2_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* Bind server socket to server address */ + actual = OS_SocketBind(s2_socket_id, &s2_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); +} + +void Setup_Client2(void) +{ + int32 expected; + int32 actual; + + /* + * Set up a client + */ + + /* Open a client socket */ + expected = OS_SUCCESS; + c2_socket_id = OS_OBJECT_ID_UNDEFINED; + + actual = OS_SocketOpen(&c2_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(c2_socket_id), "c2_socket_id (%lu) != 0", OS_ObjectIdToInteger(c2_socket_id)); + + /* Initialize client address */ + actual = OS_SocketAddrInit(&c2_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set client port */ + actual = OS_SocketAddrSetPort(&c2_addr, 9992); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set client address */ + actual = OS_SocketAddrFromString(&c2_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); +} + +void Server_Fn2(void) +{ + osal_id_t connsock_id = OS_OBJECT_ID_UNDEFINED; + OS_SockAddr_t addr; + uint32 status; + + /* Accept incoming connections */ + OS_SocketAccept(s2_socket_id, &connsock_id, &addr, OS_PEND); + + status = OS_close(s2_socket_id); + UtAssert_True(status == OS_SUCCESS, "status after close s2_socket_id = %d", (int)status); + + status = OS_close(connsock_id); + UtAssert_True(status == OS_SUCCESS, "status after close connsock_id = %d", (int)status); +} /* end Server_Fn */ + +void Setup_Single(void) +{ + Setup_Server(); + Setup_Client(); + BinSemSetup(); +} + +void Setup_Multi(void) +{ + Setup_Single(); + Setup_Server2(); + Setup_Client2(); +} + +void Teardown_Single(void) +{ + OS_close(c_socket_id); + OS_BinSemDelete(bin_sem_id); +} + +void Teardown_Multi(void) +{ + // Server 1 is intentionaly left waiting so we close it out here. + OS_close(s_socket_id); + OS_TaskDelete(s_task_id); + + OS_close(c2_socket_id); + Teardown_Single(); +} + +void TestSelectSingleRead(void) +{ + /* + * Test Case For: + * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); + */ + int32 expected = OS_SUCCESS; + int32 actual; + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + int32 status = OS_TaskCreate(&s_task_id, "ServerSingleRead", Server_Fn, OSAL_TASK_STACK_ALLOCATE, + OSAL_SIZE_C(16384), OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + uint32 StateFlags; + expected = OS_ERROR_TIMEOUT; + StateFlags = OS_STREAM_STATE_READABLE; + actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); + + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_ERROR_TIMEOUT", (long)actual); + UtAssert_True(StateFlags == 0, "OS_SelectSingle() (0x%x) == None", (unsigned int)StateFlags); + + status = OS_BinSemGive(bin_sem_id); + + expected = OS_SUCCESS; + StateFlags = OS_STREAM_STATE_READABLE; + actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); + + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(StateFlags == OS_STREAM_STATE_READABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_READABLE", + (unsigned int)StateFlags); +} + +void TestSelectMultipleRead(void) +{ + /* + * Test Case For: + * int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs); + */ + OS_FdSet ReadSet; + OS_FdSet WriteSet; + int32 expected = OS_SUCCESS; + int32 actual; + int32 status; + + OS_SelectFdZero(&ReadSet); + OS_SelectFdZero(&WriteSet); + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + status = OS_TaskCreate(&s_task_id, "ServerMultiRead", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), + OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + status = OS_TaskCreate(&s2_task_id, "ServerMultiRead2", Server_Fn2, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), + OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c2_socket_id, &s2_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + OS_SelectFdAdd(&ReadSet, c_socket_id); + OS_SelectFdAdd(&ReadSet, c2_socket_id); + + UtAssert_True(OS_SelectFdIsSet(&ReadSet, c_socket_id), "OS_SelectFdIsSet(1) == true"); + UtAssert_True(OS_SelectFdIsSet(&ReadSet, c2_socket_id), "OS_SelectFdIsSet(1) == true"); + + actual = OS_SelectMultiple(&ReadSet, &WriteSet, 100); + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectMultiple() (%ld) == OS_SUCCESS", (long)actual); + + UtAssert_True(!OS_SelectFdIsSet(&ReadSet, c_socket_id), "OS_SelectFdIsSet(1) == false"); + UtAssert_True(OS_SelectFdIsSet(&ReadSet, c2_socket_id), "OS_SelectFdIsSet(2) == true"); +} + +void TestSelectSingleWrite(void) +{ + /* + * Test Case For: + * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); + */ + + int32 actual; + uint32 StateFlags; + int32 expected = OS_SUCCESS; + int count = 0; + char Buf_send_c[16834] = {0}; + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + int32 status = OS_TaskCreate(&s_task_id, "ServerSingleWrite", Server_Fn, OSAL_TASK_STACK_ALLOCATE, + OSAL_SIZE_C(16384), OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + while (actual != OS_ERROR_TIMEOUT && count < MAX_BUFFER_LOOP) + { + strcpy(Buf_send_c, "16 KB buffer filler"); + actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); + + StateFlags = OS_STREAM_STATE_WRITABLE; + actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); + + count++; + } + + status = OS_BinSemGive(bin_sem_id); + + if (count >= MAX_BUFFER_LOOP) + { + UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s", + "Unable to cause OS_STREAM_STATE_WRITEABLE timeout with large looped writes, skipping verification"); + } + else + { + expected = OS_ERROR_TIMEOUT; + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_ERROR_TIMEOUT", (long)actual); + UtAssert_True(StateFlags == 0, "OS_SelectSingle() (0x%x) == None", (unsigned int)StateFlags); + + expected = OS_SUCCESS; + StateFlags = OS_STREAM_STATE_WRITABLE; + actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); + + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(StateFlags == OS_STREAM_STATE_WRITABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_WRITABLE", + (unsigned int)StateFlags); + } +} + +void TestSelectMultipleWrite(void) +{ + /* + * Test Case For: + * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); + */ + OS_FdSet ReadSet; + OS_FdSet WriteSet; + int32 expected = OS_SUCCESS; + int32 actual; + int32 status; + uint32 StateFlags; + int count = 0; + char Buf_send_c[16834] = {0}; + + OS_SelectFdZero(&ReadSet); + OS_SelectFdZero(&WriteSet); + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + status = OS_TaskCreate(&s_task_id, "ServerMultiWrite", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), + OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + status = OS_TaskCreate(&s2_task_id, "ServerMultiWrite2", Server_Fn2, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), + OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c2_socket_id, &s2_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + OS_SelectFdAdd(&WriteSet, c_socket_id); + OS_SelectFdAdd(&WriteSet, c2_socket_id); + + UtAssert_True(OS_SelectFdIsSet(&WriteSet, c_socket_id), "OS_SelectFdIsSet(1) == true"); + UtAssert_True(OS_SelectFdIsSet(&WriteSet, c2_socket_id), "OS_SelectFdIsSet(1) == true"); + + while (actual != OS_ERROR_TIMEOUT && count < MAX_BUFFER_LOOP) + { + strcpy(Buf_send_c, "16 KB buffer filler"); + actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); + + StateFlags = OS_STREAM_STATE_WRITABLE; + actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); + + count++; + } + + if (count >= MAX_BUFFER_LOOP) + { + UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s", + "Unable to cause OS_STREAM_STATE_WRITEABLE timeout with large looped writes, skipping verification"); + } + else + { + actual = OS_SelectMultiple(&ReadSet, &WriteSet, 100); + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectMultiple() (%ld) == OS_SUCCESS", (long)actual); + + UtAssert_True(!OS_SelectFdIsSet(&WriteSet, c_socket_id), "OS_SelectFdIsSet(1) == false"); + UtAssert_True(OS_SelectFdIsSet(&WriteSet, c2_socket_id), "OS_SelectFdIsSet(2) == true"); + } +} + +void TestSelectSingleFile(void) +{ + int32 expected = OS_SUCCESS; + int32 actual; + uint32 StateFlags; + osal_id_t fd = setup_file(); + + expected = OS_SUCCESS; + StateFlags = OS_STREAM_STATE_READABLE; + actual = OS_SelectSingle(fd, &StateFlags, 100); + + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(StateFlags == OS_STREAM_STATE_READABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_READABLE", + (unsigned int)StateFlags); + + StateFlags = OS_STREAM_STATE_WRITABLE; + actual = OS_SelectSingle(fd, &StateFlags, 100); + + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(StateFlags == OS_STREAM_STATE_WRITABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_WRITABLE", + (unsigned int)StateFlags); + + expected = OS_ERROR_TIMEOUT; + StateFlags = OS_STREAM_STATE_BOUND; + actual = OS_SelectSingle(fd, &StateFlags, 100); + + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_ERROR_TIMEOUT", (long)actual); + UtAssert_True(StateFlags == 0, "OS_SelectSingle() (0x%x) == None", (unsigned int)StateFlags); + + /* Close and remove file */ + OS_close(fd); + OS_remove(OS_TEST_SELECT_FILENAME); +} + +void UtTest_Setup(void) +{ + if (OS_API_Init() != OS_SUCCESS) + { + UtAssert_Abort("OS_API_Init() failed"); + } + + /* + * Register the test setup and check routines in UT assert + */ + + UtTest_Add(TestSelectSingleRead, Setup_Single, Teardown_Single, "TestSelectSingleRead"); + UtTest_Add(TestSelectMultipleRead, Setup_Multi, Teardown_Multi, "TestSelectMultipleRead"); + UtTest_Add(TestSelectSingleWrite, Setup_Single, Teardown_Single, "TestSelectSingleWrite"); + UtTest_Add(TestSelectMultipleWrite, Setup_Multi, Teardown_Multi, "TestSelectMultipleWrite"); + UtTest_Add(TestSelectSingleFile, NULL, NULL, "TestSelectSingleFile"); +} diff --git a/src/tests/sem-speed-test/sem-speed-test.c b/src/tests/sem-speed-test/sem-speed-test.c index 6a9b59ca3..797ed8af7 100644 --- a/src/tests/sem-speed-test/sem-speed-test.c +++ b/src/tests/sem-speed-test/sem-speed-test.c @@ -176,10 +176,12 @@ void SemSetup(void) /* ** Create the tasks */ - status = OS_TaskCreate(&task_1_id, "Task 1", task_1, NULL, 4096, SEMTEST_TASK_PRIORITY, 0); + status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(4096), + OSAL_PRIORITY_C(SEMTEST_TASK_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status); - status = OS_TaskCreate(&task_2_id, "Task 2", task_2, NULL, 4096, SEMTEST_TASK_PRIORITY, 0); + status = OS_TaskCreate(&task_2_id, "Task 2", task_2, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(4096), + OSAL_PRIORITY_C(SEMTEST_TASK_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Task 2 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_2_id), (int)status); /* A small delay just to allow the tasks diff --git a/src/tests/time-base-api-test/time-base-api-test.c b/src/tests/time-base-api-test/time-base-api-test.c index 95ff39e73..94bc69a9b 100644 --- a/src/tests/time-base-api-test/time-base-api-test.c +++ b/src/tests/time-base-api-test/time-base-api-test.c @@ -35,7 +35,7 @@ #include "uttest.h" #include "utbsp.h" -static uint32 UT_TimerSync(uint32 timer_id) +static uint32 UT_TimerSync(osal_id_t timer_id) { OS_TaskDelay(1); return 1; diff --git a/src/tests/timer-add-api-test/timer-add-api-test.c b/src/tests/timer-add-api-test/timer-add-api-test.c index 608eacdca..5ff9541b4 100644 --- a/src/tests/timer-add-api-test/timer-add-api-test.c +++ b/src/tests/timer-add-api-test/timer-add-api-test.c @@ -130,7 +130,7 @@ void TestTimerAddApi(void) OS_GetLocalTime(&EndTime); - for (i = 0; i < NUMBER_OF_TIMERS; i++) + for (i = NUMBER_OF_TIMERS - 1; i >= 0; --i) { TimerStatus[i] = OS_TimerDelete(TimerID[i]); } @@ -144,15 +144,7 @@ void TestTimerAddApi(void) /* * Time limited test */ - microsecs = 1000000 * (EndTime.seconds - StartTime.seconds); - if (EndTime.microsecs < StartTime.microsecs) - { - microsecs -= StartTime.microsecs - EndTime.microsecs; - } - else - { - microsecs += EndTime.microsecs - StartTime.microsecs; - } + microsecs = OS_TimeGetTotalMicroseconds(OS_TimeSubtract(EndTime, StartTime)); /* Make sure the ratio of the timers are OK */ for (i = 0; i < NUMBER_OF_TIMERS; i++) @@ -186,9 +178,9 @@ void TestTimerAddApi(void) actual = OS_TimerAdd(&timer_id, "Timer", OS_OBJECT_ID_UNDEFINED, null_func, NULL); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERR_INVALID_ID", (long)actual); - expected = OS_TIMER_ERR_INVALID_ARGS; + expected = OS_INVALID_POINTER; actual = OS_TimerAdd(&timer_id, "Timer", time_base_id, NULL, NULL); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); + UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_INVALID_POINTER", (long)actual); expected = OS_ERR_NAME_TAKEN; actual = OS_TimerAdd(&timer_id, "Timer", time_base_id, null_func, NULL); diff --git a/src/tests/timer-test/timer-test.c b/src/tests/timer-test/timer-test.c index 83a58d923..79ba39d5b 100644 --- a/src/tests/timer-test/timer-test.c +++ b/src/tests/timer-test/timer-test.c @@ -33,7 +33,7 @@ #include "uttest.h" #include "utbsp.h" -#define NUMBER_OF_TIMERS 4 +#define NUMBER_OF_TIMERS 5 #define TASK_1_ID 1 #define TASK_1_STACK_SIZE 4096 @@ -45,8 +45,8 @@ void TimerTestCheck(void); OS_time_t StartTime; OS_time_t EndTime; -uint32 TimerStart[NUMBER_OF_TIMERS] = {1000, 2000000, 3000000, 4000000}; -uint32 TimerInterval[NUMBER_OF_TIMERS] = {500000, 400000, 800000, 600000}; +uint32 TimerStart[NUMBER_OF_TIMERS] = {1000, 2000000, 3000000, 4000000, 1000000}; +uint32 TimerInterval[NUMBER_OF_TIMERS] = {500000, 400000, 800000, 600000, 0}; uint32 TimerTestTaskStack[TASK_1_STACK_SIZE]; int32 timer_counter[NUMBER_OF_TIMERS]; @@ -59,9 +59,9 @@ uint32 timer_idlookup[OS_MAX_TIMERS]; */ void test_func(osal_id_t timer_id) { - uint32 indx; - OS_ConvertToArrayIndex(timer_id, &indx); - timer_counter[timer_idlookup[indx]]++; + osal_index_t idx; + OS_ConvertToArrayIndex(timer_id, &idx); + timer_counter[timer_idlookup[idx]]++; } /* ********************** MAIN **************************** */ @@ -89,8 +89,8 @@ void TimerTestSetup(void) * In the new versions of OSAL, timers do NOT work in the "main" thread, * so we must create a task to handle them. */ - status = OS_TaskCreate(&TimerTestTaskId, "Task 1", TimerTestTask, TimerTestTaskStack, TASK_1_STACK_SIZE, - TASK_1_PRIORITY, 0); + status = OS_TaskCreate(&TimerTestTaskId, "Task 1", TimerTestTask, OSAL_STACKPTR_C(TimerTestTaskStack), + sizeof(TimerTestTaskStack), OSAL_PRIORITY_C(TASK_1_PRIORITY), 0); UtAssert_True(status == OS_SUCCESS, "Timer Test Task Created RC=%d", (int)status); /* @@ -111,12 +111,12 @@ void TimerTestSetup(void) void TimerTestTask(void) { - int i = 0; - int32 TimerStatus[NUMBER_OF_TIMERS]; - uint32 TableId; - osal_id_t TimerID[NUMBER_OF_TIMERS]; - char TimerName[NUMBER_OF_TIMERS][20] = {"TIMER1", "TIMER2", "TIMER3", "TIMER4"}; - uint32 ClockAccuracy; + int i = 0; + int32 TimerStatus[NUMBER_OF_TIMERS]; + osal_index_t TableId; + osal_id_t TimerID[NUMBER_OF_TIMERS]; + char TimerName[NUMBER_OF_TIMERS][20] = {"TIMER1", "TIMER2", "TIMER3", "TIMER4", "TIMER5"}; + uint32 ClockAccuracy; for (i = 0; i < NUMBER_OF_TIMERS && i < OS_MAX_TIMERS; i++) { @@ -189,31 +189,34 @@ void TimerTestCheck(void) /* * Time limited test - check and exit */ - microsecs = 1000000 * (EndTime.seconds - StartTime.seconds); - if (EndTime.microsecs < StartTime.microsecs) - { - microsecs -= StartTime.microsecs - EndTime.microsecs; - } - else - { - microsecs += EndTime.microsecs - StartTime.microsecs; - } + microsecs = OS_TimeGetTotalMicroseconds(OS_TimeSubtract(EndTime, StartTime)); /* Make sure the ratio of the timers are OK */ for (i = 0; i < NUMBER_OF_TIMERS && i < OS_MAX_TIMERS; i++) { - /* - * Expect one tick after the start time (i.e. first tick) - * Plus one tick for every interval that occurred during the test - */ - expected = 1 + (microsecs - TimerStart[i]) / TimerInterval[i]; - UtAssert_True(expected > 0, "Expected ticks = %u", (unsigned int)expected); - - /* - * Since all these counts are affected by test system load, - * allow for some fudge factor before declaring failure - */ - UtAssert_True(timer_counter[i] >= (expected - 3), "Timer %d count >= %d", (int)i, (int)(expected - 3)); - UtAssert_True(timer_counter[i] <= (expected + 3), "Timer %d count <= %d", (int)i, (int)(expected + 3)); + if (TimerInterval[i] == 0) + { + /* + * When the Timer Interval is 0, it's a one shot so expect eaxctly 1 tick + */ + expected = 1; + UtAssert_True(timer_counter[i] == (expected), "Timer %d count = %d", (int)i, (int)(expected)); + } + else + { + /* + * Expect one tick after the start time (i.e. first tick) + * Plus one tick for every interval that occurred during the test + */ + expected = 1 + (microsecs - TimerStart[i]) / TimerInterval[i]; + UtAssert_True(expected > 0, "Expected ticks = %u", (unsigned int)expected); + + /* + * Since all these counts are affected by test system load, + * allow for some fudge factor before declaring failure + */ + UtAssert_True(timer_counter[i] >= (expected - 3), "Timer %d count >= %d", (int)i, (int)(expected - 3)); + UtAssert_True(timer_counter[i] <= (expected + 3), "Timer %d count <= %d", (int)i, (int)(expected + 3)); + } } } diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-files.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-files.h index f5f62aceb..a405b68af 100644 --- a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-files.h +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-files.h @@ -25,12 +25,13 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_FILES_H_ -#define INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_FILES_H_ +#ifndef UT_ADAPTOR_PORTABLE_POSIX_FILES_H +#define UT_ADAPTOR_PORTABLE_POSIX_FILES_H -#include +#include "common_types.h" +#include -unsigned int UT_PortablePosixFileTest_GetSelfEUID(void); -unsigned int UT_PortablePosixFileTest_GetSelfEGID(void); +OCS_uid_t UT_PortablePosixFileTest_GetSelfEUID(void); +OCS_gid_t UT_PortablePosixFileTest_GetSelfEGID(void); -#endif /* INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_FILES_H_ */ +#endif /* UT_ADAPTOR_PORTABLE_POSIX_FILES_H */ diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-io.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-io.h index 98f4377b5..a4cadae82 100644 --- a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-io.h +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-io.h @@ -25,20 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_IO_H_ -#define INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_IO_H_ +#ifndef UT_ADAPTOR_PORTABLE_POSIX_IO_H +#define UT_ADAPTOR_PORTABLE_POSIX_IO_H -/** - * \file ut-osfileapi.h - * \ingroup adaptors - * \author joseph.p.hickey@nasa.gov - * - */ - -#ifndef _UT_PPOSFILEAPI_H_ -#define _UT_PPOSFILEAPI_H_ - -#include +#include "common_types.h" /***************************************************** * @@ -48,8 +38,6 @@ * but are not exposed directly through the implementation API. * *****************************************************/ -void UT_PortablePosixIOTest_Set_Selectable(uint32 local_id, bool is_selectable); - -#endif /* _UT_OSFILEAPI_H_ */ +void UT_PortablePosixIOTest_Set_Selectable(osal_index_t local_id, bool is_selectable); -#endif /* INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_IO_H_ */ +#endif /* UT_ADAPTOR_PORTABLE_POSIX_IO_H */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-files.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-files.c index 969dab756..e7a5bc79d 100644 --- a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-files.c +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-files.c @@ -31,12 +31,12 @@ #include -unsigned int UT_PortablePosixFileTest_GetSelfEUID(void) +OCS_uid_t UT_PortablePosixFileTest_GetSelfEUID(void) { return OS_IMPL_SELF_EUID; } -unsigned int UT_PortablePosixFileTest_GetSelfEGID(void) +OCS_gid_t UT_PortablePosixFileTest_GetSelfEGID(void) { return OS_IMPL_SELF_EGID; } diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-io.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-io.c index 0f54a9677..dea9b84d5 100644 --- a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-io.c +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-io.c @@ -31,7 +31,7 @@ #include -void UT_PortablePosixIOTest_Set_Selectable(uint32 local_id, bool is_selectable) +void UT_PortablePosixIOTest_Set_Selectable(osal_index_t local_id, bool is_selectable) { OS_impl_filehandle_table[local_id].selectable = is_selectable; } diff --git a/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c b/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c index 5c0c90acc..fd2f7951c 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c +++ b/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c @@ -26,6 +26,7 @@ #include "os-portable-coveragetest.h" #include "ut-adaptor-portable-posix-io.h" #include "os-shared-select.h" +#include "os-shared-idmap.h" #include @@ -35,22 +36,23 @@ void Test_OS_SelectSingle_Impl(void) * int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs) */ uint32 SelectFlags; - uint32 StreamID; + OS_object_token_t token; struct OCS_timespec nowtime; struct OCS_timespec latertime; - StreamID = 0; - UT_PortablePosixIOTest_Set_Selectable(0, false); + memset(&token, 0, sizeof(token)); + + UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, false); SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 0), OS_ERR_OPERATION_NOT_SUPPORTED); - UT_PortablePosixIOTest_Set_Selectable(0, true); - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 0), OS_ERR_OPERATION_NOT_SUPPORTED); + UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 0), OS_SUCCESS); SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, -1), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, -1), OS_SUCCESS); SelectFlags = 0; - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 0), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_select), 0); + UT_SetDefaultReturnValue(UT_KEY(OCS_select), 0); SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; nowtime.tv_sec = 1; nowtime.tv_nsec = 500000000; @@ -58,9 +60,9 @@ void Test_OS_SelectSingle_Impl(void) latertime.tv_nsec = 0; UT_SetDataBuffer(UT_KEY(OCS_clock_gettime), &nowtime, sizeof(nowtime), false); UT_SetDataBuffer(UT_KEY(OCS_clock_gettime), &latertime, sizeof(latertime), false); - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 999), OS_ERROR_TIMEOUT); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 999), OS_ERROR_TIMEOUT); - UT_SetForceFail(UT_KEY(OCS_select), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_select), -1); SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; nowtime.tv_sec = 1; nowtime.tv_nsec = 0; @@ -68,7 +70,7 @@ void Test_OS_SelectSingle_Impl(void) latertime.tv_nsec = 600000000; UT_SetDataBuffer(UT_KEY(OCS_clock_gettime), &nowtime, sizeof(nowtime), false); UT_SetDataBuffer(UT_KEY(OCS_clock_gettime), &latertime, sizeof(latertime), false); - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 2100), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 2100), OS_ERROR); } /* end OS_SelectSingle_Impl */ void Test_OS_SelectMultiple_Impl(void) @@ -84,7 +86,7 @@ void Test_OS_SelectMultiple_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 0), OS_SUCCESS); memset(&ReadSet, 0xff, sizeof(ReadSet)); memset(&WriteSet, 0, sizeof(WriteSet)); - UT_SetForceFail(UT_KEY(OCS_select), 0); + UT_SetDefaultReturnValue(UT_KEY(OCS_select), 0); OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 1), OS_ERROR_TIMEOUT); } /* end OS_SelectMultiple_Impl */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c b/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c index fc38f97a0..51727f590 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c +++ b/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c @@ -27,6 +27,7 @@ #include "os-portable-coveragetest.h" #include "os-shared-printf.h" +#include "os-shared-idmap.h" #include #include @@ -37,8 +38,11 @@ const char TEST_BUF_INITIALIZER[1 + TEST_BUFFER_LEN] = "abcdefghijklmnop"; void Test_OS_ConsoleOutput_Impl(void) { - char TestConsoleBspBuffer[TEST_BUFFER_LEN]; - char TestOutputBuffer[32]; + char TestConsoleBspBuffer[TEST_BUFFER_LEN]; + char TestOutputBuffer[32]; + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); memcpy(TestConsoleBspBuffer, TEST_BUF_INITIALIZER, sizeof(TestConsoleBspBuffer)); memset(TestOutputBuffer, 0, sizeof(TestOutputBuffer)); @@ -49,11 +53,11 @@ void Test_OS_ConsoleOutput_Impl(void) UT_SetDataBuffer(UT_KEY(OCS_OS_BSP_ConsoleOutput_Impl), TestOutputBuffer, sizeof(TestOutputBuffer), false); OS_console_table[0].WritePos = 4; - OS_ConsoleOutput_Impl(0); + OS_ConsoleOutput_Impl(&token); UtAssert_True(strcmp(TestOutputBuffer, "abcd") == 0, "TestOutputBuffer (%s) == abcd", TestOutputBuffer); OS_console_table[0].WritePos = 2; - OS_ConsoleOutput_Impl(0); + OS_ConsoleOutput_Impl(&token); UtAssert_True(strcmp(TestOutputBuffer, "abcdefghijklmnopab") == 0, "TestOutputBuffer (%s) == abcdefghijklmnopab", TestOutputBuffer); } diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-loader.c b/src/unit-test-coverage/portable/src/coveragetest-no-loader.c index c3df0c998..7d64ed5c1 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-no-loader.c +++ b/src/unit-test-coverage/portable/src/coveragetest-no-loader.c @@ -32,7 +32,7 @@ void Test_OS_ModuleLoad_Impl(void) /* Test Case For: * int32 OS_ModuleLoad_Impl ( uint32 module_id, char *translated_path ) */ - OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl, (0, "local"), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl, (UT_INDEX_0, "local"), OS_ERR_NOT_IMPLEMENTED); } void Test_OS_ModuleUnload_Impl(void) @@ -40,7 +40,7 @@ void Test_OS_ModuleUnload_Impl(void) /* Test Case For: * int32 OS_ModuleUnload_Impl ( uint32 module_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl, (0), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl, (UT_INDEX_0), OS_ERR_NOT_IMPLEMENTED); } void Test_OS_ModuleGetInfo_Impl(void) @@ -51,7 +51,7 @@ void Test_OS_ModuleGetInfo_Impl(void) OS_module_prop_t module_prop; memset(&module_prop, 0, sizeof(module_prop)); - OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl, (0, &module_prop), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl, (UT_INDEX_0, &module_prop), OS_ERR_NOT_IMPLEMENTED); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-shell.c b/src/unit-test-coverage/portable/src/coveragetest-no-shell.c index 1973e407d..776612532 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-no-shell.c +++ b/src/unit-test-coverage/portable/src/coveragetest-no-shell.c @@ -33,7 +33,7 @@ void Test_OS_ShellOutputToFile_Impl(void) /* Test Case For: * int32 OS_ShellOutputToFile_Impl(uint32 stream_id, const char* Cmd) */ - OSAPI_TEST_FUNCTION_RC(OS_ShellOutputToFile_Impl, (0, "ut"), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_ShellOutputToFile_Impl, (UT_INDEX_0, "ut"), OS_ERR_NOT_IMPLEMENTED); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-dirs.c b/src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c similarity index 58% rename from src/unit-test-coverage/vxworks/src/coveragetest-dirs.c rename to src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c index f896cb598..17d581fcd 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-dirs.c +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c @@ -19,31 +19,22 @@ */ /** - * \file coveragetest-dirs.c - * \ingroup vxworks + * \file coveragetest-posix-dirs.c * \author joseph.p.hickey@nasa.gov * */ -#include "os-vxworks-coveragetest.h" -#include "ut-adaptor-dirs.h" +#include "os-portable-coveragetest.h" #include "os-shared-dir.h" +#include "os-shared-idmap.h" #include -#include #include #include +#include #include - -void Test_OS_VxWorks_DirAPI_Impl_Init(void) -{ - /* - * Test Case For: - * int32 OS_VxWorks_DirAPI_Impl_Init(void) - */ - OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_DirAPI_Impl_Init(), OS_SUCCESS); -} +#include void Test_OS_DirCreate_Impl(void) { @@ -51,10 +42,22 @@ void Test_OS_DirCreate_Impl(void) * Test Case For: * int32 OS_DirCreate_Impl(const char *local_path, uint32 access) */ - OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl("dir", 0), OS_SUCCESS); - - UT_SetForceFail(UT_KEY(OCS_mkdir), -1); - OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl("dir", 0), OS_ERROR); + struct OCS_stat statbuf; + + OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl, ("dir", 0), OS_SUCCESS); + + /* With errno other than EEXIST it should return OS_ERROR */ + OCS_errno = OCS_EROFS; + UT_SetDefaultReturnValue(UT_KEY(OCS_mkdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl, ("dir", 0), OS_ERROR); + + /* If the errno is EEXIST it should return success */ + OCS_errno = OCS_EEXIST; + memset(&statbuf, 0, sizeof(statbuf)); + statbuf.st_mode = OCS_S_IFDIR; + UT_SetDataBuffer(UT_KEY(OCS_stat), &statbuf, sizeof(statbuf), false); + UT_SetDefaultReturnValue(UT_KEY(OCS_mkdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl, ("dir", 0), OS_SUCCESS); } void Test_OS_DirOpen_Impl(void) @@ -63,9 +66,13 @@ void Test_OS_DirOpen_Impl(void) * Test Case For: * int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) */ - OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(0, "dir"), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_opendir), -1); - OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(0, "dir"), OS_ERROR); + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl, (&token, "dir"), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OCS_opendir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl, (&token, "dir"), OS_ERROR); } void Test_OS_DirClose_Impl(void) @@ -74,7 +81,11 @@ void Test_OS_DirClose_Impl(void) * Test Case For: * int32 OS_DirClose_Impl(uint32 local_id) */ - OSAPI_TEST_FUNCTION_RC(OS_DirClose_Impl(0), OS_SUCCESS); + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + OSAPI_TEST_FUNCTION_RC(OS_DirClose_Impl, (&token), OS_SUCCESS); } void Test_OS_DirRead_Impl(void) @@ -83,12 +94,15 @@ void Test_OS_DirRead_Impl(void) * Test Case For: * int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) */ - os_dirent_t dirent_buff; + os_dirent_t dirent_buff; + OS_object_token_t token; - OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(0, &dirent_buff), OS_SUCCESS); + memset(&token, 0, sizeof(token)); - UT_SetForceFail(UT_KEY(OCS_readdir), -1); - OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(0, &dirent_buff), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl, (&token, &dirent_buff), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OCS_readdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl, (&token, &dirent_buff), OS_ERROR); } void Test_OS_DirRewind_Impl(void) @@ -97,7 +111,11 @@ void Test_OS_DirRewind_Impl(void) * Test Case For: * int32 OS_DirRewind_Impl(uint32 local_id) */ - OSAPI_TEST_FUNCTION_RC(OS_DirRewind_Impl(0), OS_SUCCESS); + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + OSAPI_TEST_FUNCTION_RC(OS_DirRewind_Impl, (&token), OS_SUCCESS); } void Test_OS_DirRemove_Impl(void) @@ -106,10 +124,10 @@ void Test_OS_DirRemove_Impl(void) * Test Case For: * int32 OS_DirRemove_Impl(const char *local_path) */ - OSAPI_TEST_FUNCTION_RC(OS_DirRemove_Impl("dir"), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_DirRemove_Impl, ("dir"), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_rmdir), -1); - OSAPI_TEST_FUNCTION_RC(OS_DirRemove_Impl("dir"), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_rmdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirRemove_Impl, ("dir"), OS_ERROR); } /* ------------------- End of test cases --------------------------------------*/ @@ -139,7 +157,6 @@ void Osapi_Test_Teardown(void) {} */ void UtTest_Setup(void) { - ADD_TEST(OS_VxWorks_DirAPI_Impl_Init); ADD_TEST(OS_DirCreate_Impl); ADD_TEST(OS_DirOpen_Impl); ADD_TEST(OS_DirClose_Impl); diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-files.c b/src/unit-test-coverage/portable/src/coveragetest-posix-files.c index 7f1080e27..28a03e849 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-posix-files.c +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-files.c @@ -28,12 +28,14 @@ #include "ut-adaptor-portable-posix-files.h" #include "os-shared-file.h" +#include "os-shared-idmap.h" #include #include #include #include #include +#include void Test_OS_FileOpen_Impl(void) { @@ -41,14 +43,18 @@ void Test_OS_FileOpen_Impl(void) * Test Case For: * int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int32 access) */ - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0, "local", OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0, "local", 0, OS_READ_ONLY), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0, "local", OS_FILE_FLAG_CREATE, OS_READ_WRITE), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0, "local", 0, -1234), OS_ERROR); + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", 0, OS_READ_ONLY), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", OS_FILE_FLAG_CREATE, OS_READ_WRITE), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", 0, -1234), OS_ERROR); /* failure mode */ - UT_SetForceFail(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0, "local", 0, OS_READ_ONLY), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", 0, OS_READ_ONLY), OS_ERROR); } void Test_OS_FileStat_Impl(void) @@ -61,9 +67,9 @@ void Test_OS_FileStat_Impl(void) struct OCS_stat RefStat; /* failure mode */ - UT_SetForceFail(UT_KEY(OCS_stat), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_stat), -1); OSAPI_TEST_FUNCTION_RC(OS_FileStat_Impl, ("local", &FileStats), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_stat)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_stat)); /* nominal, no permission bits */ memset(&FileStats, 0, sizeof(FileStats)); @@ -73,9 +79,12 @@ void Test_OS_FileStat_Impl(void) /* all permission bits with uid/gid match */ RefStat.st_uid = UT_PortablePosixFileTest_GetSelfEUID(); RefStat.st_gid = UT_PortablePosixFileTest_GetSelfEGID(); - RefStat.st_mode = ~0; + RefStat.st_mode = ~((OCS_mode_t)0); RefStat.st_size = 1234; RefStat.st_mtime = 5678; + /* Also set the full resolution timespec */ + RefStat.st_mtim.tv_sec = 5678; + RefStat.st_mtim.tv_nsec = 3456; UT_SetDataBuffer(UT_KEY(OCS_stat), &RefStat, sizeof(RefStat), false); OSAPI_TEST_FUNCTION_RC(OS_FileStat_Impl, ("local", &FileStats), OS_SUCCESS); @@ -85,7 +94,7 @@ void Test_OS_FileStat_Impl(void) UtAssert_True(OS_FILESTAT_READ(FileStats), "File Read Bit set"); UtAssert_True(OS_FILESTAT_ISDIR(FileStats), "Directory Bit set"); UtAssert_True(OS_FILESTAT_SIZE(FileStats) == 1234, "Size match"); - UtAssert_True(OS_FILESTAT_TIME(FileStats) == 5678, "Time match"); + UtAssert_True(OS_FILESTAT_TIME(FileStats) == 5678, "Time match (seconds)"); } void Test_OS_FileChmod_Impl(void) @@ -97,26 +106,33 @@ void Test_OS_FileChmod_Impl(void) struct OCS_stat RefStat; /* failure mode 0 (open) */ - UT_SetForceFail(UT_KEY(OCS_open), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); /* failure mode 1 (fstat) */ - UT_SetForceFail(UT_KEY(OCS_fstat), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_fstat), -1); OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_fstat)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_fstat)); /* failure mode 2 (fchmod) */ - UT_SetForceFail(UT_KEY(OCS_fchmod), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_fchmod), -1); OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_fchmod)); + + /* non implemented error, e.g. such as DOS Filesystem with no perms */ + OCS_errno = OCS_ENOTSUP; + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERR_NOT_IMPLEMENTED); + UT_ClearDefaultReturnValue(UT_KEY(OCS_fchmod)); /* all permission bits with uid/gid match */ RefStat.st_uid = UT_PortablePosixFileTest_GetSelfEUID(); RefStat.st_gid = UT_PortablePosixFileTest_GetSelfEGID(); - RefStat.st_mode = ~0; + RefStat.st_mode = ~((OCS_mode_t)0); RefStat.st_size = 1234; RefStat.st_mtime = 5678; + /* Also set the full resolution timespec */ + RefStat.st_mtim.tv_sec = 5678; + RefStat.st_mtim.tv_nsec = 3456; UT_SetDataBuffer(UT_KEY(OCS_fstat), &RefStat, sizeof(RefStat), false); /* nominal 1 - full permissions with file owned by own uid/gid */ @@ -142,7 +158,7 @@ void Test_OS_FileRemove_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_FileRemove_Impl, ("local"), OS_SUCCESS); /* failure mode */ - UT_SetForceFail(UT_KEY(OCS_remove), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_remove), -1); OSAPI_TEST_FUNCTION_RC(OS_FileRemove_Impl, ("local"), OS_ERROR); } @@ -155,7 +171,7 @@ void Test_OS_FileRename_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_FileRename_Impl, ("old", "new"), OS_SUCCESS); /* failure mode */ - UT_SetForceFail(UT_KEY(OCS_rename), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_rename), -1); OSAPI_TEST_FUNCTION_RC(OS_FileRename_Impl, ("old", "new"), OS_ERROR); } diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-gettime.c b/src/unit-test-coverage/portable/src/coveragetest-posix-gettime.c index dc63e8d18..e69cb830a 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-posix-gettime.c +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-gettime.c @@ -35,12 +35,11 @@ void Test_OS_GetLocalTime_Impl(void) * Test Case For: * int32 OS_GetLocalTime_Impl(OS_time_t *time_struct) */ - OS_time_t timeval; - timeval.seconds = 1; - timeval.microsecs = 1; + OS_time_t timeval = {0}; + OSAPI_TEST_FUNCTION_RC(OS_GetLocalTime_Impl, (&timeval), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_clock_gettime), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_clock_gettime), -1); OSAPI_TEST_FUNCTION_RC(OS_GetLocalTime_Impl, (&timeval), OS_ERROR); } @@ -50,12 +49,11 @@ void Test_OS_SetLocalTime_Impl(void) * Test Case For: * int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct) */ - OS_time_t timeval; - timeval.seconds = 1; - timeval.microsecs = 1; + OS_time_t timeval = {0}; + OSAPI_TEST_FUNCTION_RC(OS_SetLocalTime_Impl, (&timeval), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_clock_settime), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_clock_settime), -1); OSAPI_TEST_FUNCTION_RC(OS_SetLocalTime_Impl, (&timeval), OS_ERROR); } diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-io.c b/src/unit-test-coverage/portable/src/coveragetest-posix-io.c index 26fdf3059..f3c7ea87b 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-posix-io.c +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-io.c @@ -43,14 +43,18 @@ void Test_OS_GenericClose_Impl(void) * Test Case For: * int32 OS_GenericClose_Impl(uint32 local_id) */ - OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl, (0), OS_SUCCESS); + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl, (&token), OS_SUCCESS); /* * Test path where underlying close() fails. * Should still return success. */ - UT_SetForceFail(UT_KEY(OCS_close), -1); - OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl, (0), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OCS_close), -1); + OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl, (&token), OS_SUCCESS); } void Test_OS_GenericSeek_Impl(void) @@ -59,25 +63,28 @@ void Test_OS_GenericSeek_Impl(void) * Test Case For: * int32 OS_GenericSeek_Impl (uint32 local_id, int32 offset, uint32 whence) */ + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); /* note on success this wrapper returns the result of lseek(), not OS_SUCCESS */ - UT_SetForceFail(UT_KEY(OCS_lseek), 111); - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, OS_SEEK_CUR), 111); - UT_SetForceFail(UT_KEY(OCS_lseek), 222); - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, OS_SEEK_SET), 222); - UT_SetForceFail(UT_KEY(OCS_lseek), 333); - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, OS_SEEK_END), 333); + UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), 111); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_CUR), 111); + UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), 222); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_SET), 222); + UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), 333); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_END), 333); /* bad whence */ - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, -1234), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, 1234), OS_ERROR); /* generic failure of lseek() */ - UT_SetForceFail(UT_KEY(OCS_lseek), -1); - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, OS_SEEK_END), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), -1); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_END), OS_ERROR); /* The seek implementation also checks for this specific pipe errno */ OCS_errno = OCS_ESPIPE; - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, OS_SEEK_END), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_END), OS_ERR_NOT_IMPLEMENTED); } void Test_OS_GenericRead_Impl(void) @@ -86,24 +93,27 @@ void Test_OS_GenericRead_Impl(void) * Test Case For: * int32 OS_GenericRead_Impl (uint32 local_id, void *buffer, uint32 nbytes, int32 timeout) */ - char SrcData[] = "ABCDEFGHIJK"; - char DestData[sizeof(SrcData)] = {0}; + char SrcData[] = "ABCDEFGHIJK"; + char DestData[sizeof(SrcData)] = {0}; + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); UT_SetDataBuffer(UT_KEY(OCS_read), SrcData, sizeof(SrcData), false); - UT_PortablePosixIOTest_Set_Selectable(0, false); - OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (0, DestData, sizeof(DestData), 0), sizeof(DestData)); + UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, false); + OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (&token, DestData, sizeof(DestData), 0), sizeof(DestData)); UtAssert_MemCmp(SrcData, DestData, sizeof(SrcData), "read() data Valid"); /* test invocation of select() in nonblocking mode */ UT_ResetState(UT_KEY(OCS_read)); UT_SetDataBuffer(UT_KEY(OCS_read), SrcData, sizeof(SrcData), false); - UT_PortablePosixIOTest_Set_Selectable(0, true); - OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (0, DestData, sizeof(DestData), 0), sizeof(DestData)); + UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true); + OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (&token, DestData, sizeof(DestData), 0), sizeof(DestData)); UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called"); /* read() failure */ - UT_SetForceFail(UT_KEY(OCS_read), -1); - OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (0, DestData, sizeof(DestData), 0), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_read), -1); + OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (&token, DestData, sizeof(DestData), 0), OS_ERROR); } void Test_OS_GenericWrite_Impl(void) @@ -112,24 +122,27 @@ void Test_OS_GenericWrite_Impl(void) * Test Case For: * int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, int32 timeout) */ - char SrcData[] = "ABCDEFGHIJKL"; - char DestData[sizeof(SrcData)] = {0}; + char SrcData[] = "ABCDEFGHIJKL"; + char DestData[sizeof(SrcData)] = {0}; + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); UT_SetDataBuffer(UT_KEY(OCS_write), DestData, sizeof(DestData), false); - UT_PortablePosixIOTest_Set_Selectable(0, false); - OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (0, SrcData, sizeof(SrcData), 0), sizeof(SrcData)); + UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, false); + OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (&token, SrcData, sizeof(SrcData), 0), sizeof(SrcData)); UtAssert_MemCmp(SrcData, DestData, sizeof(SrcData), "write() data valid"); /* test invocation of select() in nonblocking mode */ UT_ResetState(UT_KEY(OCS_write)); UT_SetDataBuffer(UT_KEY(OCS_write), DestData, sizeof(DestData), false); - UT_PortablePosixIOTest_Set_Selectable(0, true); - OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (0, SrcData, sizeof(SrcData), 0), sizeof(SrcData)); + UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true); + OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (&token, SrcData, sizeof(SrcData), 0), sizeof(SrcData)); UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called"); /* write() failure */ - UT_SetForceFail(UT_KEY(OCS_write), -1); - OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (0, DestData, sizeof(DestData), 0), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_write), -1); + OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (&token, DestData, sizeof(DestData), 0), OS_ERROR); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/portable/src/os-portable-coveragetest.h b/src/unit-test-coverage/portable/src/os-portable-coveragetest.h index 287d4c005..ce017dd0a 100644 --- a/src/unit-test-coverage/portable/src/os-portable-coveragetest.h +++ b/src/unit-test-coverage/portable/src/os-portable-coveragetest.h @@ -25,18 +25,8 @@ * */ -#ifndef INCLUDE_OS_PORTABLE_COVERAGETEST_H_ -#define INCLUDE_OS_PORTABLE_COVERAGETEST_H_ - -/** - * \file os-vxworks-coveragetest.h - * \ingroup vxworks - * \author joseph.p.hickey@nasa.gov - * - */ - -#ifndef _OS_PORTABLE_COVERAGETEST_H_ -#define _OS_PORTABLE_COVERAGETEST_H_ +#ifndef OS_PORTABLE_COVERAGETEST_H +#define OS_PORTABLE_COVERAGETEST_H /* * Includes @@ -57,6 +47,17 @@ #define ADD_TEST(test) UtTest_Add((Test_##test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) +/* + * The default/primary table index used by most coverage tests. + */ +#define UT_INDEX_0 OSAL_INDEX_C(0) + +/* + * A secondary table index for coverage tests which require + * more than one entry + */ +#define UT_INDEX_1 OSAL_INDEX_C(1) + /* Osapi_Test_Setup * * Purpose: @@ -65,6 +66,4 @@ void Osapi_Test_Setup(void); void Osapi_Test_Teardown(void); -#endif /* _OS_PORTABLE_COVERAGETEST_H_ */ - -#endif /* INCLUDE_OS_PORTABLE_COVERAGETEST_H_ */ +#endif /* OS_PORTABLE_COVERAGETEST_H */ diff --git a/src/unit-test-coverage/shared/CMakeLists.txt b/src/unit-test-coverage/shared/CMakeLists.txt index 582ddcf2e..9f9211880 100644 --- a/src/unit-test-coverage/shared/CMakeLists.txt +++ b/src/unit-test-coverage/shared/CMakeLists.txt @@ -26,6 +26,7 @@ set(MODULE_LIST ) set(SHARED_COVERAGE_LINK_LIST + os-shared-coverage-support ut-adaptor-shared ut_osapi_impl_stubs ut_osapi_shared_stubs @@ -33,6 +34,10 @@ set(SHARED_COVERAGE_LINK_LIST ut_libc_stubs ) +add_library(os-shared-coverage-support STATIC + src/os-shared-coverage-support.c +) + add_subdirectory(adaptors) diff --git a/src/unit-test-coverage/shared/adaptors/inc/ut-adaptor-module.h b/src/unit-test-coverage/shared/adaptors/inc/ut-adaptor-module.h index 354027f89..da0ce088b 100644 --- a/src/unit-test-coverage/shared/adaptors/inc/ut-adaptor-module.h +++ b/src/unit-test-coverage/shared/adaptors/inc/ut-adaptor-module.h @@ -25,11 +25,11 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_MODULE_H_ -#define INCLUDE_UT_ADAPTOR_MODULE_H_ +#ifndef UT_ADAPTOR_MODULE_H +#define UT_ADAPTOR_MODULE_H -#include -#include +#include "common_types.h" +#include "osapi-module.h" /***************************************************** * @@ -49,7 +49,7 @@ void Osapi_Internal_ResetState(void); /* A dummy function for the static symbol lookup test. Not called */ void Test_DummyFunc(void); -int32 Osapi_Call_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName); +int32 Osapi_Call_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName, const char *ModuleName); int32 Osapi_Call_ModuleLoad_Static(const char *ModuleName); -#endif /* INCLUDE_UT_ADAPTOR_MODULE_H_ */ +#endif /* UT_ADAPTOR_MODULE_H */ diff --git a/src/unit-test-coverage/shared/adaptors/src/ut-adaptor-module.c b/src/unit-test-coverage/shared/adaptors/src/ut-adaptor-module.c index 8963abdc7..1be553798 100644 --- a/src/unit-test-coverage/shared/adaptors/src/ut-adaptor-module.c +++ b/src/unit-test-coverage/shared/adaptors/src/ut-adaptor-module.c @@ -28,9 +28,9 @@ #include "ut-adaptor-module.h" #include "os-shared-module.h" -int32 Osapi_Call_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName) +int32 Osapi_Call_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName, const char *ModuleName) { - return OS_SymbolLookup_Static(SymbolAddress, SymbolName); + return OS_SymbolLookup_Static(SymbolAddress, SymbolName, ModuleName); } int32 Osapi_Call_ModuleLoad_Static(const char *ModuleName) diff --git a/src/unit-test-coverage/shared/src/coveragetest-binsem.c b/src/unit-test-coverage/shared/src/coveragetest-binsem.c index 07c605722..37bfcd920 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -62,7 +62,7 @@ void Test_OS_BinSemCreate(void) OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(NULL, NULL, 0, 0), OS_INVALID_POINTER); - UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG); } @@ -146,11 +146,11 @@ void Test_OS_BinSemGetIdByName(void) int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_BinSemGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_BinSemGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_BinSemGetIdByName(&objid, "NF"); @@ -165,18 +165,12 @@ void Test_OS_BinSemGetInfo(void) * Test Case For: * int32 OS_BinSemGetInfo (uint32 sem_id, OS_bin_sem_prop_t *bin_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_bin_sem_prop_t prop; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_bin_sem_prop_t prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_BINSEM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_BinSemGetInfo(UT_OBJID_1, &prop); UtAssert_True(actual == expected, "OS_BinSemGetInfo() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-clock.c b/src/unit-test-coverage/shared/src/coveragetest-clock.c index 1e7b9b538..244f8b2e1 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-clock.c +++ b/src/unit-test-coverage/shared/src/coveragetest-clock.c @@ -61,6 +61,105 @@ void Test_OS_SetLocalTime(void) UtAssert_True(actual == expected, "OS_SetLocalTime() (%ld) == OS_INVALID_POINTER", (long)actual); } +void Test_OS_TimeAccessConversions(void) +{ + /* + * Test cases for the various time access and conversion functions: + * + * int64 OS_TimeGetTotalSeconds(OS_time_t tm) + * int64 OS_TimeGetTotalMilliseconds(OS_time_t tm) + * int64 OS_TimeGetTotalMicroseconds(OS_time_t tm) + * int64 OS_TimeGetTotalNanoseconds(OS_time_t tm) + * + * uint32 OS_TimeGetSubsecondsPart(OS_time_t tm) + * uint32 OS_TimeGetMillisecondsPart(OS_time_t tm) + * uint32 OS_TimeGetMicrosecondsPart(OS_time_t tm) + * uint32 OS_TimeGetNanosecondsPart(OS_time_t tm) + * + * OS_time_t OS_TimeAssembleFromMilliseconds(int64 seconds, uint32 milliseconds) + * OS_time_t OS_TimeAssembleFromMicroseconds(int64 seconds, uint32 microseconds) + * OS_time_t OS_TimeAssembleFromNanoseconds(int64 seconds, uint32 nanoseconds) + * OS_time_t OS_TimeAssembleFromSubseconds(int64 seconds, uint32 subseconds) + * + * OS_time_t OS_TimeAdd(OS_time_t time1, OS_time_t time2) + * OS_time_t OS_TimeSubtract(OS_time_t time1, OS_time_t time2) + */ + OS_time_t t1; + OS_time_t t2; + OS_time_t t3; + OS_time_t t4; + + /* To base-2 32-bit fixed point: 0.234567890 s * 0x100000000 ~= 0x3c0ca428 */ + t1 = OS_TimeAssembleFromNanoseconds(1, 234567890); + + /* From base-2 32-bit fixed point: 0x87654321 / 0x100000000 ~= 0.528888888 s */ + t2 = OS_TimeAssembleFromSubseconds(2, 0x87654321); + + /* To base-2 32-bit fixed point: 0.045678 s * 0x100000000 ~= 0x0bb18dad */ + t3 = OS_TimeAssembleFromMicroseconds(0, 45678); + + /* To base-2 32-bit fixed point: 0.901 s * 0x100000000 ~= 0xe6a7ef9e */ + t4 = OS_TimeAssembleFromMilliseconds(1, 901); + + /* These functions only return the total (whole + fraction) in the requested units */ + UtAssert_UINT32_EQ(OS_TimeGetTotalSeconds(t1), 1); + UtAssert_UINT32_EQ(OS_TimeGetTotalSeconds(t2), 2); + UtAssert_UINT32_EQ(OS_TimeGetTotalSeconds(t3), 0); + UtAssert_UINT32_EQ(OS_TimeGetTotalSeconds(t4), 1); + + UtAssert_UINT32_EQ(OS_TimeGetTotalMilliseconds(t1), 1234); + UtAssert_UINT32_EQ(OS_TimeGetTotalMilliseconds(t2), 2528); + UtAssert_UINT32_EQ(OS_TimeGetTotalMilliseconds(t3), 45); + UtAssert_UINT32_EQ(OS_TimeGetTotalMilliseconds(t4), 1901); + + UtAssert_UINT32_EQ(OS_TimeGetTotalMicroseconds(t1), 1234567); + UtAssert_UINT32_EQ(OS_TimeGetTotalMicroseconds(t2), 2528888); + UtAssert_UINT32_EQ(OS_TimeGetTotalMicroseconds(t3), 45678); + UtAssert_UINT32_EQ(OS_TimeGetTotalMicroseconds(t4), 1901000); + + /* Note: Nanoseconds/Subseconds may not be exact due to limitations of OS_time_t resolution */ + UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t1), 1234567800); + UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t2), 2528888800); + UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t3), 45678000); + UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t4), 1901000000); + + /* These functions only return the fractional part, not the whole part */ + UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t1), 0x3c0ca2a6); + UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t2), 0x876541a4); + UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t3), 0x0bb18dad); + UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t4), 0xe6a7ef9e); + + UtAssert_UINT32_EQ(OS_TimeGetMillisecondsPart(t1), 234); + UtAssert_UINT32_EQ(OS_TimeGetMillisecondsPart(t2), 528); + UtAssert_UINT32_EQ(OS_TimeGetMillisecondsPart(t3), 45); + UtAssert_UINT32_EQ(OS_TimeGetMillisecondsPart(t4), 901); + + UtAssert_UINT32_EQ(OS_TimeGetMicrosecondsPart(t1), 234567); + UtAssert_UINT32_EQ(OS_TimeGetMicrosecondsPart(t2), 528888); + UtAssert_UINT32_EQ(OS_TimeGetMicrosecondsPart(t3), 45678); + UtAssert_UINT32_EQ(OS_TimeGetMicrosecondsPart(t4), 901000); + + UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t1), 234567800); + UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t2), 528888800); + UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t3), 45678000); + UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t4), 901000000); + + /* Simple Add/Subtract */ + t3 = OS_TimeAdd(t1, t2); + UtAssert_UINT32_EQ(OS_TimeGetTotalMilliseconds(t3), 3763); + t4 = OS_TimeSubtract(t3, t2); + UtAssert_UINT32_EQ(OS_TimeGetTotalMilliseconds(t4), 1234); + + /* Add/Subtract that will require carry */ + t1 = OS_TimeAssembleFromNanoseconds(3, 777777777); + t2 = OS_TimeAssembleFromNanoseconds(4, 888888888); + + t3 = OS_TimeAdd(t1, t2); + UtAssert_UINT32_EQ(OS_TimeGetTotalMilliseconds(t3), 8666); + t4 = OS_TimeSubtract(t3, t2); + UtAssert_UINT32_EQ(OS_TimeGetTotalMilliseconds(t4), 3777); +} + /* Osapi_Test_Setup * * Purpose: @@ -86,4 +185,5 @@ void UtTest_Setup(void) { ADD_TEST(OS_GetLocalTime); ADD_TEST(OS_SetLocalTime); + ADD_TEST(OS_TimeAccessConversions); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-common.c b/src/unit-test-coverage/shared/src/coveragetest-common.c index c200e96be..f760641bd 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-common.c +++ b/src/unit-test-coverage/shared/src/coveragetest-common.c @@ -57,9 +57,9 @@ static int32 TimeBaseInitGlobal(void *UserObj, int32 StubRetcode, uint32 CallCou static int32 ObjectDeleteCountHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) { - uint32 *counter = (uint32 *)Context->ArgPtr[1]; + uint32 *counter = UT_Hook_GetArgValueByName(Context, "callback_arg", uint32 *); - if (CallCount == 0) + if (CallCount < 2) { *counter = 1; } @@ -77,6 +77,11 @@ static int32 SetShutdownFlagHook(void *UserObj, int32 StubRetcode, uint32 CallCo return StubRetcode; } +static int32 TestEventHandlerHook(OS_Event_t event, osal_id_t object_id, void *data) +{ + return UT_DEFAULT_IMPL(TestEventHandlerHook); +} + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -108,17 +113,17 @@ void Test_OS_API_Init(void) /* other error paths */ OS_SharedGlobalVars.Initialized = false; - UT_SetForceFail(UT_KEY(OS_ObjectIdInit), -222); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdInit), -222); OSAPI_TEST_FUNCTION_RC(OS_API_Init(), -222); UT_ResetState(UT_KEY(OS_ObjectIdInit)); OS_SharedGlobalVars.Initialized = false; - UT_SetForceFail(UT_KEY(OS_API_Impl_Init), -333); + UT_SetDefaultReturnValue(UT_KEY(OS_API_Impl_Init), -333); OSAPI_TEST_FUNCTION_RC(OS_API_Init(), -333); UT_ResetState(UT_KEY(OS_API_Impl_Init)); OS_SharedGlobalVars.Initialized = false; - UT_SetForceFail(UT_KEY(OS_TaskAPI_Init), -444); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskAPI_Init), -444); OSAPI_TEST_FUNCTION_RC(OS_API_Init(), -444); UT_ResetState(UT_KEY(OS_TaskAPI_Init)); } @@ -151,7 +156,7 @@ void Test_OS_CleanUpObject(void) while (objtype < OS_OBJECT_TYPE_USER) { UT_ResetState(0); - UT_SetForceFail(UT_KEY(OS_IdentifyObject), objtype); + UT_SetDefaultReturnValue(UT_KEY(OS_IdentifyObject), objtype); switch (objtype) { @@ -195,7 +200,7 @@ void Test_OS_CleanUpObject(void) /* note the return code here is ignored - * the goal is simply to defeat the default * check that the objid was valid (it isn't) */ - UT_SetForceFail(delhandler, OS_ERROR); + UT_SetDefaultReturnValue(delhandler, OS_ERROR); OS_CleanUpObject(OS_OBJECT_ID_UNDEFINED, &ActualObjs); CallCount = UT_GetStubCount(delhandler); @@ -258,6 +263,37 @@ void Test_OS_IdleLoopAndShutdown(void) UtAssert_True(CallCount == 1, "OS_ApplicationShutdown_Impl() call count (%lu) == 1", (unsigned long)CallCount); } +void Test_OS_NotifyEvent(void) +{ + /* + * Test cases for: + * int32 OS_NotifyEvent(OS_Event_t event, osal_id_t object_id, void *data) + * int32 OS_RegisterEventHandler(OS_EventHandler_t handler) + */ + + OS_SharedGlobalVars.EventHandler = NULL; + + /* With no hook function registered OS_NotifyEvent() should return success */ + OSAPI_TEST_FUNCTION_RC(OS_NotifyEvent(OS_EVENT_RESERVED, OS_OBJECT_ID_UNDEFINED, NULL), OS_SUCCESS); + + /* Registering a NULL hook function should fail */ + OSAPI_TEST_FUNCTION_RC(OS_RegisterEventHandler(NULL), OS_INVALID_POINTER); + + /* Now Register the locally-defined hook function */ + OSAPI_TEST_FUNCTION_RC(OS_RegisterEventHandler(TestEventHandlerHook), OS_SUCCESS); + + /* Now this should invoke the test hook */ + OSAPI_TEST_FUNCTION_RC(OS_NotifyEvent(OS_EVENT_RESERVED, OS_OBJECT_ID_UNDEFINED, NULL), OS_SUCCESS); + UtAssert_STUB_COUNT(TestEventHandlerHook, 1); + + /* Should also return whatever the hook returned */ + UT_SetDefaultReturnValue(UT_KEY(TestEventHandlerHook), -12345); + OSAPI_TEST_FUNCTION_RC(OS_NotifyEvent(OS_EVENT_RESERVED, OS_OBJECT_ID_UNDEFINED, NULL), -12345); + UtAssert_STUB_COUNT(TestEventHandlerHook, 2); + + OS_SharedGlobalVars.EventHandler = NULL; +} + /* ------------------- End of test cases --------------------------------------*/ /* Osapi_Test_Setup @@ -288,4 +324,5 @@ void UtTest_Setup(void) ADD_TEST(OS_CleanUpObject); ADD_TEST(OS_IdleLoopAndShutdown); ADD_TEST(OS_ApplicationExit); + ADD_TEST(OS_NotifyEvent); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-countsem.c b/src/unit-test-coverage/shared/src/coveragetest-countsem.c index 5afc26277..f4d9fae62 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -59,12 +59,10 @@ void Test_OS_CountSemCreate(void) int32 actual = OS_CountSemCreate(&objid, "UT", 0, 0); UtAssert_True(actual == expected, "OS_CountSemCreate() (%ld) == OS_SUCCESS", (long)actual); -#ifdef jphfix OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); -#endif OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(NULL, NULL, 0, 0), OS_INVALID_POINTER); - UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG); } @@ -134,11 +132,11 @@ void Test_OS_CountSemGetIdByName(void) int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_CountSemGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_CountSemGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_CountSemGetIdByName(&objid, "NF"); @@ -156,21 +154,13 @@ void Test_OS_CountSemGetInfo(void) int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; OS_count_sem_prop_t prop; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_COUNTSEM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_CountSemGetInfo(UT_OBJID_1, &prop); UtAssert_True(actual == expected, "OS_CountSemGetInfo() (%ld) == OS_SUCCESS", (long)actual); -#ifdef jphfix - UtAssert_True(prop.creator == 111, "prop.creator (%lu) == 111", (unsigned long)prop.creator); -#endif + OSAPI_TEST_OBJID(prop.creator, ==, UT_OBJID_OTHER); UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); diff --git a/src/unit-test-coverage/shared/src/coveragetest-file.c b/src/unit-test-coverage/shared/src/coveragetest-file.c index 74893e81a..3729b54b1 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -78,11 +78,11 @@ void Test_OS_OpenCreate(void) UtAssert_True(actual == expected, "OS_OpenCreate() (%ld) == OS_ERROR (bad flags)", (long)actual); /* Test failure to convert path */ - UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR); expected = OS_ERROR; actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE); UtAssert_True(actual == OS_ERROR, "OS_OpenCreate() (%ld) == OS_ERROR (bad path)", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TranslatePath)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TranslatePath)); } void Test_OS_close(void) @@ -237,7 +237,7 @@ void Test_OS_rename(void) int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; - OS_global_stream_table[1].active_id = UT_OBJID_1; + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 1); strncpy(OS_stream_table[1].stream_name, "/cf/file1", sizeof(OS_stream_table[1].stream_name)); actual = OS_rename("/cf/file1", "/cf/file2"); @@ -267,23 +267,23 @@ void Test_OS_cp(void) UtAssert_True(actual == expected, "OS_cp() (%ld) == OS_SUCCESS", (long)actual); - UT_SetForceFail(UT_KEY(OS_GenericRead_Impl), -444); + UT_SetDefaultReturnValue(UT_KEY(OS_GenericRead_Impl), -444); expected = -444; actual = OS_cp("/cf/file1", "/cf/file2"); UtAssert_True(actual == expected, "OS_cp() (%ld) == -444", (long)actual); - UT_ClearForceFail(UT_KEY(OS_GenericRead_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_GenericRead_Impl)); UT_SetDataBuffer(UT_KEY(OS_GenericRead_Impl), ReadBuf, sizeof(ReadBuf), false); - UT_SetForceFail(UT_KEY(OS_GenericWrite_Impl), -555); + UT_SetDefaultReturnValue(UT_KEY(OS_GenericWrite_Impl), -555); expected = -555; actual = OS_cp("/cf/file1", "/cf/file2"); UtAssert_True(actual == expected, "OS_cp() (%ld) == -555", (long)actual); - UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_INVALID_POINTER); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_INVALID_POINTER); expected = OS_INVALID_POINTER; actual = OS_cp("/cf/file1", "/cf/file2"); UtAssert_True(actual == expected, "OS_cp() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TranslatePath)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TranslatePath)); } void Test_OS_mv(void) @@ -299,7 +299,7 @@ void Test_OS_mv(void) /* In the default case, the implementation tries to rename first. * Force rename to fail so it does a full copy and remove */ - UT_SetForceFail(UT_KEY(OS_FileRename_Impl), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_FileRename_Impl), OS_ERROR); actual = OS_mv("/cf/file1", "/cf/file2"); UtAssert_True(actual == expected, "OS_mv() (%ld) == OS_SUCCESS", (long)actual); } @@ -310,18 +310,12 @@ void Test_OS_FDGetInfo(void) * Test Case For: * int32 OS_FDGetInfo (uint32 filedes, OS_file_prop_t *fd_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_file_prop_t file_prop; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_file_prop_t file_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_FDGetInfo(UT_OBJID_1, &file_prop); UtAssert_True(actual == expected, "OS_FDGetInfo() (%ld) == OS_SUCCESS", (long)actual); @@ -343,8 +337,8 @@ void Test_OS_FileOpenCheck(void) UtAssert_True(actual == expected, "OS_FileOpenCheck() (%ld) == OS_ERROR", (long)actual); - OS_global_stream_table[0].active_id = UT_OBJID_1; - UT_SetForceFail(UT_KEY(OCS_strcmp), 0); + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 1); + UT_SetDefaultReturnValue(UT_KEY(OCS_strcmp), 0); expected = OS_SUCCESS; actual = OS_FileOpenCheck("/cf/file"); @@ -367,9 +361,9 @@ void Test_OS_CloseFileByName(void) UtAssert_True(actual == expected, "OS_CloseFileByName() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); /* setup for success */ - expected = OS_SUCCESS; - OS_global_stream_table[0].active_id = UT_OBJID_1; - UT_SetForceFail(UT_KEY(OCS_strcmp), 0); + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 1); + expected = OS_SUCCESS; + UT_SetDefaultReturnValue(UT_KEY(OCS_strcmp), 0); actual = OS_CloseFileByName("/cf/file"); UtAssert_True(actual == expected, "OS_CloseFileByName() (%ld) == OS_SUCCESS", (long)actual); @@ -387,12 +381,18 @@ void Test_OS_CloseAllFiles(void) int32 expected = -222; int32 actual; - OS_global_stream_table[0].active_id = UT_OBJID_1; - OS_global_stream_table[1].active_id = UT_OBJID_2; - UT_SetDeferredRetcode(UT_KEY(OS_GenericClose_Impl), 1, expected); + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 2); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdIteratorProcessEntry), 1, expected); actual = OS_CloseAllFiles(); UtAssert_True(actual == expected, "OS_CloseAllFiles() (%ld) == -222", (long)actual); + + /* This uses a helper function OS_FileIteratorClose() with the iterator, + * which needs to be called for coverage - it just invokes OS_close() */ + expected = OS_SUCCESS; + actual = OS_FileIteratorClose(UT_OBJID_1, NULL); + + UtAssert_True(actual == expected, "OS_FileIteratorClose() (%ld) == OS_SUCCESS", (long)actual); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 528d33886..ce24aabc7 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -58,16 +58,15 @@ void Test_OS_FileSysAddFixedMap(void) OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, NULL, NULL), OS_INVALID_POINTER); - UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 1, 2 + OS_MAX_LOCAL_PATH_LEN); - OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_ERR_NAME_TOO_LONG); - UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 2, 2 + OS_MAX_PATH_LEN); - OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_ERR_NAME_TOO_LONG); - UT_ResetState(UT_KEY(OCS_strlen)); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_FS_ERR_PATH_TOO_LONG); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 2, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_FS_ERR_PATH_TOO_LONG); - UT_SetForceFail(UT_KEY(OCS_strrchr), -1); - UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 3, 2 + OS_FS_DEV_NAME_LEN); + UT_SetDefaultReturnValue(UT_KEY(OCS_strrchr), -1); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 3, OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_ERR_NAME_TOO_LONG); - UT_ResetState(UT_KEY(OCS_strlen)); + UT_ResetState(UT_KEY(OCS_memchr)); UT_ResetState(UT_KEY(OCS_strrchr)); OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS); @@ -86,40 +85,40 @@ void Test_OS_mkfs(void) char TestBuffer[128]; - actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", 0, 0); + actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_SUCCESS", (long)actual); /* * Test an entry NOT found in the OS_VolumeTable */ - actual = OS_mkfs(TestBuffer, "/rd1", "vol1", 0, 0); + actual = OS_mkfs(TestBuffer, "/rd1", "vol1", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_SUCCESS", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_mkfs(NULL, NULL, NULL, 0, 0); + actual = OS_mkfs(NULL, NULL, NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_FS_DEV_NAME_LEN); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", 0, 0); + actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); /* set up for failure due to empty strings */ expected = OS_FS_ERR_PATH_INVALID; - actual = OS_mkfs(TestBuffer, "", "", 0, 0); + actual = OS_mkfs(TestBuffer, "", "", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); /* set up for failure due to formatting */ - UT_SetForceFail(UT_KEY(OS_FileSysFormatVolume_Impl), OS_FS_ERR_DRIVE_NOT_CREATED); + UT_SetDefaultReturnValue(UT_KEY(OS_FileSysFormatVolume_Impl), OS_FS_ERR_DRIVE_NOT_CREATED); expected = OS_FS_ERR_DRIVE_NOT_CREATED; - actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", 0, 0); + actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_DRIVE_NOT_CREATED (format failure)", (long)actual); /* set up for failure due to no free slots */ - UT_SetForceFail(UT_KEY(OS_ObjectIdAllocateNew), OS_ERR_NO_FREE_IDS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERR_NO_FREE_IDS); expected = OS_FS_ERR_DEVICE_NOT_FREE; - actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", 0, 0); + actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_DEVICE_NOT_FREE", (long)actual); } @@ -136,17 +135,17 @@ void Test_OS_rmfs(void) UtAssert_True(actual == expected, "OS_rmfs() (%ld) == OS_SUCCESS", (long)actual); /* check error paths */ - UT_SetForceFail(UT_KEY(OS_ObjectIdGetByName), OS_ERR_NAME_NOT_FOUND); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetByName), OS_ERR_NAME_NOT_FOUND); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_rmfs("/ramdev4"); UtAssert_True(actual == expected, "OS_rmfs() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdGetByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetByName)); expected = OS_INVALID_POINTER; actual = OS_rmfs(NULL); UtAssert_True(actual == expected, "OS_rmfs() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_FS_DEV_NAME_LEN); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_rmfs("/ramdev4"); UtAssert_True(actual == expected, "OS_rmfs() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); @@ -164,26 +163,26 @@ void Test_OS_initfs(void) char TestBuffer[128]; - actual = OS_initfs(TestBuffer, "/ramdev0", "vol", 0, 0); + actual = OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_SUCCESS", (long)actual); - actual = OS_initfs(NULL, "/hda2", "vol2", 0, 0); + actual = OS_initfs(NULL, "/hda2", "vol2", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_SUCCESS", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_initfs(NULL, NULL, NULL, 0, 0); + actual = OS_initfs(NULL, NULL, NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_FS_DEV_NAME_LEN); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_initfs(TestBuffer, "/ramdev0", "vol", 0, 0); + actual = OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); /* set up for failure */ - UT_SetForceFail(UT_KEY(OS_ObjectIdAllocateNew), OS_ERR_NO_FREE_IDS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERR_NO_FREE_IDS); expected = OS_FS_ERR_DEVICE_NOT_FREE; - actual = OS_initfs(TestBuffer, "/ramdev0", "vol", 0, 0); + actual = OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_FS_ERR_DEVICE_NOT_FREE", (long)actual); } @@ -217,7 +216,7 @@ void Test_OS_mount(void) actual = OS_mount(NULL, NULL); UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_FS_DEV_NAME_LEN); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_mount("/ramdev0", "/ram0"); UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); @@ -247,85 +246,61 @@ void Test_OS_unmount(void) actual = OS_unmount(NULL); UtAssert_True(actual == expected, "OS_unmount() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_PATH_LEN); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_unmount("/ram0"); UtAssert_True(actual == expected, "OS_unmount() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); } -void Test_OS_fsBlocksFree(void) +void Test_OS_FileSysStatVolume(void) { /* * Test Case For: - * int32 OS_fsBlocksFree (const char *name) + * int32 OS_FileSysStatVolume(const char *name, OS_statvfs_t *statbuf) */ - int32 expected = 1111; - int32 actual = ~OS_SUCCESS; - OS_statvfs_t statval; - - statval.block_size = 1024; - statval.blocks_free = 1111; - statval.total_blocks = 2222; - UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false); - OS_filesys_table[1].flags = - OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - actual = OS_fsBlocksFree("/cf"); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == 1111", (long)actual); + OS_statvfs_t statbuf; + OS_statvfs_t statref; + int32 expected; + int32 actual; - expected = OS_INVALID_POINTER; - actual = OS_fsBlocksFree(NULL); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_PATH_LEN); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_fsBlocksFree("/cf"); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); - - UT_SetForceFail(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); - expected = OS_FS_ERR_PATH_INVALID; - actual = OS_fsBlocksFree("invalid"); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); -} - -void Test_OS_fsBytesFree(void) -{ - /* - * Test Case For: - * int32 OS_fsBytesFree (const char *name, uint64 *bytes_free) - */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_statvfs_t statval; - uint64 bytes_free = 0; - - statval.block_size = 1024; - statval.blocks_free = 1111; - statval.total_blocks = 2222; - UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false); + statref.block_size = OSAL_SIZE_C(1024); + statref.blocks_free = OSAL_BLOCKCOUNT_C(1111); + statref.total_blocks = OSAL_BLOCKCOUNT_C(2222); + UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statref, sizeof(statref), false); OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - actual = OS_fsBytesFree("/cf", &bytes_free); + expected = OS_SUCCESS; + actual = OS_FileSysStatVolume("/cf", &statbuf); + UtAssert_True(actual == expected, "OS_FileSysStatVolume() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(bytes_free == (1024 * 1111), "bytes_free (%lu) == (1024*1111)", (unsigned long)bytes_free); + UtAssert_True(statbuf.block_size == statref.block_size, "blocks_size (%lu) == %lu", + (unsigned long)statbuf.block_size, (unsigned long)statref.block_size); + UtAssert_True(statbuf.total_blocks == statref.total_blocks, "total_blocks (%lu) == %lu", + (unsigned long)statbuf.total_blocks, (unsigned long)statref.total_blocks); + UtAssert_True(statbuf.blocks_free == statref.blocks_free, "blocks_free (%lu) == %lu", + (unsigned long)statbuf.blocks_free, (unsigned long)statref.blocks_free); + /* validate error checking */ expected = OS_INVALID_POINTER; - actual = OS_fsBytesFree(NULL, NULL); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_PATH_LEN); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_fsBytesFree("/cf", &bytes_free); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + actual = OS_FileSysStatVolume(NULL, &statbuf); + UtAssert_True(actual == expected, "OS_FileSysStatVolume() (%ld) == OS_INVALID_POINTER", (long)actual); + actual = OS_FileSysStatVolume("/cf", NULL); + UtAssert_True(actual == expected, "OS_FileSysStatVolume() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); - expected = OS_FS_ERR_PATH_INVALID; - actual = OS_fsBytesFree("invalid", &bytes_free); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); + /* Test Fail due to no matching VolTab entry */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); + expected = OS_ERR_NAME_NOT_FOUND; + actual = OS_FileSysStatVolume("/cf", &statbuf); + UtAssert_True(actual == expected, "OS_FileSysStatVolume() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); + UT_ResetState(UT_KEY(OS_ObjectIdGetBySearch)); + + /* Verify pass through of impl error */ + UT_SetDefaultReturnValue(UT_KEY(OS_FileSysStatVolume_Impl), OS_ERR_OPERATION_NOT_SUPPORTED); + expected = OS_ERR_OPERATION_NOT_SUPPORTED; + actual = OS_FileSysStatVolume("/cf", &statbuf); + UtAssert_True(actual == expected, "OS_FileSysStatVolume() (%ld) == OS_ERR_OPERATION_NOT_SUPPORTED", (long)actual); } void Test_OS_chkfs(void) @@ -346,14 +321,14 @@ void Test_OS_chkfs(void) actual = OS_chkfs(NULL, false); UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_PATH_LEN); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_chkfs("/cf", false); UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); /* Test Fail due to no matching VolTab entry */ - UT_SetForceFail(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_chkfs("none", true); UtAssert_True(actual == expected, "OS_chkfs() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); @@ -371,11 +346,11 @@ void Test_OS_FS_GetPhysDriveName(void) UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), OS_MAX_PATH_LEN + 10); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_FS_GetPhysDriveName(NameBuf, "none"); UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_FS_GetPhysDriveName(NameBuf, "none"); @@ -388,7 +363,7 @@ void Test_OS_FS_GetPhysDriveName(void) UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_SUCCESS", (long)actual); /* Test Fail due to no matching VolTab entry */ - UT_SetForceFail(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_FS_GetPhysDriveName(NameBuf, "none"); UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); @@ -400,9 +375,14 @@ void Test_OS_GetFsInfo(void) * Test Case For: * int32 OS_GetFsInfo(OS_FsInfo_t *filesys_info) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - os_fsinfo_t filesys_info; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + os_fsinfo_t filesys_info; + OS_common_record_t rec; + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdIteratorGetNext), 1); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdIteratorGetNext), 3, 0); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdIteratorGetNext), 4, 0); actual = OS_GetFsInfo(&filesys_info); @@ -414,15 +394,21 @@ void Test_OS_GetFsInfo(void) "filesys_info.MaxVolumes (%lu) == OS_MAX_FILE_SYSTEMS", (unsigned long)filesys_info.MaxVolumes); /* since there are no open files, the free fd count should match the max */ - UtAssert_True(filesys_info.FreeFds == OS_MAX_NUM_OPEN_FILES, "filesys_info.FreeFds (%lu) == OS_MAX_NUM_OPEN_FILES", - (unsigned long)filesys_info.FreeFds); + UtAssert_True(filesys_info.FreeFds == 2, "filesys_info.FreeFds (%lu) == 2", (unsigned long)filesys_info.FreeFds); - UtAssert_True(filesys_info.FreeVolumes == OS_MAX_FILE_SYSTEMS, - "filesys_info.FreeVolumes (%lu) == OS_MAX_FILE_SYSTEMS", (unsigned long)filesys_info.FreeVolumes); + UtAssert_True(filesys_info.FreeVolumes == 3, "filesys_info.FreeVolumes (%lu) == 3", + (unsigned long)filesys_info.FreeVolumes); expected = OS_INVALID_POINTER; actual = OS_GetFsInfo(NULL); UtAssert_True(actual == expected, "OS_GetFsInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* This function uses a helper OS_FileSysFilterFree() that needs to be called for coverage. */ + /* It is just a wrapper around OS_ObjectIdDefined() for the record ID */ + memset(&rec, 0, sizeof(rec)); + UtAssert_True(OS_FileSysFilterFree(NULL, NULL, &rec), "OS_FileSysFilterFree() (unused record)"); + rec.active_id = UT_OBJID_1; + UtAssert_True(!OS_FileSysFilterFree(NULL, NULL, &rec), "!OS_FileSysFilterFree() (used record)"); } void Test_OS_TranslatePath(void) @@ -451,18 +437,18 @@ void Test_OS_TranslatePath(void) actual = OS_TranslatePath(NULL, NULL); UtAssert_True(actual == expected, "OS_TranslatePath(NULL,NULL) (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), OS_MAX_PATH_LEN + 10); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_TranslatePath("/cf/test", LocalBuffer); UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); /* Invalid no '/' */ expected = OS_FS_ERR_PATH_INVALID; actual = OS_TranslatePath("invalid", LocalBuffer); UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); - UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 2, OS_MAX_FILE_NAME + 1); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 2, OS_ERROR); expected = OS_FS_ERR_NAME_TOO_LONG; actual = OS_TranslatePath("/cf/test", LocalBuffer); UtAssert_True(actual == expected, "OS_TranslatePath(/cf/test) (%ld) == OS_FS_ERR_NAME_TOO_LONG", (long)actual); @@ -472,19 +458,19 @@ void Test_OS_TranslatePath(void) actual = OS_TranslatePath("invalid/", LocalBuffer); UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); - UT_SetForceFail(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); actual = OS_TranslatePath("/cf/test", LocalBuffer); UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdGetBySearch)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch)); /* VirtPathLen < VirtPathBegin */ - UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 4, OS_MAX_PATH_LEN); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 4, OS_ERROR); expected = OS_FS_ERR_PATH_INVALID; actual = OS_TranslatePath("/cf/test", LocalBuffer); UtAssert_True(actual == expected, "OS_TranslatePath(/cf/test) (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); /* (SysMountPointLen + VirtPathLen) > OS_MAX_LOCAL_PATH_LEN */ - UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 3, OS_MAX_LOCAL_PATH_LEN); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 3, OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_TranslatePath("/cf/test", LocalBuffer); UtAssert_True(actual == expected, "OS_TranslatePath(/cf/test) (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); @@ -507,12 +493,17 @@ void Test_OS_FileSys_FindVirtMountPoint(void) bool result; OS_common_record_t refobj; const char refstr[] = "/ut"; + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + token.obj_idx = UT_INDEX_1; + token.obj_type = OS_OBJECT_TYPE_OS_FILESYS; memset(&refobj, 0, sizeof(refobj)); OS_filesys_table[1].flags = 0; OS_filesys_table[1].virtual_mountpt[0] = 0; - result = OS_FileSys_FindVirtMountPoint((void *)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (unmounted) == false", refstr); OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; @@ -520,17 +511,17 @@ void Test_OS_FileSys_FindVirtMountPoint(void) /* Verify cases where one is a substring of the other - * these should also return false */ strncpy(OS_filesys_table[1].virtual_mountpt, "/ut11", sizeof(OS_filesys_table[1].virtual_mountpt)); - result = OS_FileSys_FindVirtMountPoint((void *)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (mountpt=%s) == false", refstr, OS_filesys_table[1].virtual_mountpt); strncpy(OS_filesys_table[1].virtual_mountpt, "/u", sizeof(OS_filesys_table[1].virtual_mountpt)); - result = OS_FileSys_FindVirtMountPoint((void *)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (mountpt=%s) == false", refstr, OS_filesys_table[1].virtual_mountpt); strncpy(OS_filesys_table[1].virtual_mountpt, "/ut", sizeof(OS_filesys_table[1].virtual_mountpt)); - result = OS_FileSys_FindVirtMountPoint((void *)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); UtAssert_True(result, "OS_FileSys_FindVirtMountPoint(%s) (nominal) == true", refstr); } @@ -565,11 +556,10 @@ void UtTest_Setup(void) ADD_TEST(OS_initfs); ADD_TEST(OS_mount); ADD_TEST(OS_unmount); - ADD_TEST(OS_fsBlocksFree); - ADD_TEST(OS_fsBytesFree); ADD_TEST(OS_chkfs); ADD_TEST(OS_FS_GetPhysDriveName); ADD_TEST(OS_GetFsInfo); ADD_TEST(OS_TranslatePath); ADD_TEST(OS_FileSys_FindVirtMountPoint); + ADD_TEST(OS_FileSysStatVolume); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index 07fc471de..00834d784 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -27,6 +27,7 @@ #include "os-shared-coveragetest.h" #include "os-shared-idmap.h" #include "os-shared-common.h" +#include "os-shared-task.h" #include @@ -39,7 +40,7 @@ typedef struct } Test_OS_ObjTypeCount_t; /* a match function that always matches */ -static bool TestAlwaysMatch(void *ref, uint32 local_id, const OS_common_record_t *obj) +static bool TestAlwaysMatch(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { return true; } @@ -65,6 +66,13 @@ static void ObjTypeCounter(osal_id_t object_id, void *arg) } } +static int32 TestIterator(osal_id_t object_id, void *arg) +{ + uint32 *c = arg; + ++(*c); + return UT_DEFAULT_IMPL(TestIterator); +} + void Test_OS_ObjectIdInit(void) { /* @@ -84,77 +92,203 @@ void Test_OS_LockUnlockGlobal(void) * void OS_Lock_Global(uint32 idtype) * void OS_Unlock_Global(uint32 idtype) */ + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + token.obj_type = OS_OBJECT_TYPE_OS_COUNTSEM; + token.lock_mode = OS_LOCK_MODE_GLOBAL; /* * As these have no return codes, these tests * exist to get coverage of the paths. */ - OS_Lock_Global(OS_OBJECT_TYPE_OS_COUNTSEM); - OS_Unlock_Global(OS_OBJECT_TYPE_OS_COUNTSEM); - OS_Lock_Global(0); - OS_Unlock_Global(0); - OS_Lock_Global(55555); - OS_Unlock_Global(55555); + OS_Lock_Global(&token); + OS_Unlock_Global(&token); + + token.obj_type = OS_OBJECT_TYPE_UNDEFINED; + + OS_Lock_Global(&token); + OS_Unlock_Global(&token); + + token.obj_type = 55555; + + OS_Lock_Global(&token); + OS_Unlock_Global(&token); + + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId), 0); + token.obj_type = OS_OBJECT_TYPE_OS_BINSEM; + + OS_Lock_Global(&token); + OS_Unlock_Global(&token); + + UT_ResetState(UT_KEY(OS_TaskGetId)); + + /* + * Execute paths where the incorrect patten is followed, + * such as unlocking from a different task than the lock. + * These trigger OS_DEBUG messages, if compiled in. + * + * Start by locking twice in a row + */ + OS_Lock_Global(&token); + OS_Lock_Global(&token); - UT_SetForceFail(UT_KEY(OS_TaskGetId), 0); - OS_Lock_Global(OS_OBJECT_TYPE_OS_BINSEM); - OS_Unlock_Global(OS_OBJECT_TYPE_OS_BINSEM); + /* + * Next unlock with wrong/corrupt/bad key + */ + token.lock_key.key_value ^= 0x11111111; + OS_Unlock_Global(&token); } -void Test_OS_ObjectIdConvertLock(void) +void Test_OS_ObjectIdConvertToken(void) { /* * Test Case For: - * static int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, - * uint32 idtype, uint32 reference_id, OS_common_record_t *obj) + * int32 OS_ObjectIdConvertToken(OS_object_token_t *token) * * NOTE: These test cases just focus on code paths that are not exercised * by the other test cases in this file. */ int32 expected; int32 actual; - uint32 array_index; + OS_object_token_t token; OS_common_record_t *record; osal_id_t objid; - UT_idbuf_t corrupt_objid; /* get a valid (fake) OSAL ID to start with */ - OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "ut", &array_index, &record); - objid = record->active_id; + OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "ut", &token); + objid = token.obj_id; + + /* The prep function should have unlocked once */ + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + + record = OS_OBJECT_TABLE_GET(OS_global_task_table, token); + record->refcount = 5; + record->active_id = objid; /* * Attempt to obtain a lock for the same record with a non-matching ID * This should return an error. */ - corrupt_objid.id = objid; - corrupt_objid.val ^= 0x10; /* flip a bit */ - actual = OS_ObjectIdConvertLock(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, corrupt_objid.id, record); - expected = OS_ERR_INVALID_ID; + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_id = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(token.obj_id) ^ 0x10); /* flip a bit */ + actual = OS_ObjectIdConvertToken(&token); + expected = OS_ERR_INVALID_ID; UtAssert_True(actual == expected, "OS_ObjectIdConvertLock() (%ld) == OS_ERR_INVALID_ID (%ld)", (long)actual, (long)expected); + /* Global should not be released */ + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + /* * Use mode OS_LOCK_MODE_NONE with matching ID * This should return success. */ - actual = OS_ObjectIdConvertLock(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, objid, record); - expected = OS_SUCCESS; + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_SUCCESS; - UtAssert_True(actual == expected, "OS_ObjectIdConvertLock() (%ld) == OS_ERR_INVALID_ID (%ld)", (long)actual, + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(NONE) (%ld) == OS_SUCCESS (%ld)", (long)actual, + (long)expected); + + /* Global should not be released */ + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + + /* + * Use mode OS_LOCK_MODE_GLOBAL with matching ID + * This should return success and update refcount + */ + token.lock_mode = OS_LOCK_MODE_GLOBAL; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_SUCCESS; + + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(GLOBAL) (%ld) == OS_SUCCESS (%ld)", (long)actual, + (long)expected); + UtAssert_UINT32_EQ(record->refcount, 6); + + /* Global should not be released */ + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + + /* + * Use mode OS_LOCK_MODE_REFCOUNT with matching ID + * This should return success, increment refcount + */ + token.lock_mode = OS_LOCK_MODE_REFCOUNT; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_SUCCESS; + + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(REFCOUNT) (%ld) == OS_SUCCESS (%ld)", (long)actual, (long)expected); + UtAssert_UINT32_EQ(record->refcount, 7); + + /* Global should be released */ + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2); + + /* + * Use mode OS_LOCK_MODE_RESERVED with non-reserved ID. + */ + token.lock_mode = OS_LOCK_MODE_RESERVED; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_ERR_INVALID_ID; + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(RESERVED) (%ld) == OS_ERR_INVALID_ID (%ld)", (long)actual, + (long)expected); + + /* Global should not be released */ + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2); + /* + * Use mode OS_LOCK_MODE_EXCLUSIVE with matching ID and other refs. + * This should return OS_ERR_OBJECT_IN_USE. + */ + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_ERR_OBJECT_IN_USE; + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(EXCLUSIVE) (%ld) == OS_ERR_OBJECT_IN_USE (%ld)", + (long)actual, (long)expected); + + /* should have delayed 4 times, on the 5th try it returns error */ + UtAssert_STUB_COUNT(OS_WaitForStateChange_Impl, 4); + + /* Global should not be released */ + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2); + + /* It should also have preserved the original ID */ + UtAssert_True(OS_ObjectIdEqual(record->active_id, objid), "OS_ObjectIdConvertLock(EXCLUSIVE) objid restored"); /* * Use mode OS_LOCK_MODE_EXCLUSIVE with matching ID and no other refs. - * This should return success. + * This should return success and set the active_id to OS_OBJECT_ID_RESERVED. */ - record->flags = 0; record->refcount = 0; - actual = OS_ObjectIdConvertLock(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TASK, objid, record); + actual = OS_ObjectIdConvertToken(&token); expected = OS_SUCCESS; + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(EXCLUSIVE) (%ld) == OS_SUCCESS (%ld)", (long)actual, + (long)expected); + UtAssert_True(OS_ObjectIdEqual(record->active_id, OS_OBJECT_ID_RESERVED), + "OS_ObjectIdConvertLock(EXCLUSIVE) objid reserved"); - UtAssert_True(actual == expected, "OS_ObjectIdConvertLock() (%ld) == OS_SUCCESS (%ld)", (long)actual, + /* Global should be released */ + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 3); + + /* + * Use mode OS_LOCK_MODE_RESERVED with reserved ID. + * This should return OS_SUCCESS. + */ + token.lock_mode = OS_LOCK_MODE_RESERVED; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_SUCCESS; + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(RESERVED) (%ld) == OS_SUCCESS (%ld)", (long)actual, (long)expected); + + /* Global should not be released */ + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 3); } void Test_OS_ObjectIdGetBySearch(void) @@ -167,17 +301,21 @@ void Test_OS_ObjectIdGetBySearch(void) * NOTE: These test cases just focus on code paths that are not exercised * by the other test cases in this file. */ - int32 expected; - int32 actual; - OS_common_record_t *record; + int32 expected; + int32 actual; + OS_object_token_t token; OS_global_task_table[0].active_id = UT_OBJID_OTHER; - actual = OS_ObjectIdGetBySearch(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, TestAlwaysMatch, NULL, &record); + actual = OS_ObjectIdGetBySearch(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, TestAlwaysMatch, NULL, &token); expected = OS_SUCCESS; - OS_global_task_table[0].active_id = OS_OBJECT_ID_UNDEFINED; UtAssert_True(actual == expected, "OS_ObjectIdGetBySearch() (%ld) == OS_SUCCESS (%ld)", (long)actual, (long)expected); + + UtAssert_Bool(OS_ObjectIdEqual(token.obj_id, UT_OBJID_OTHER), "Token Object ID"); + UtAssert_UINT32_EQ(token.obj_idx, 0); + + OS_global_task_table[0].active_id = OS_OBJECT_ID_UNDEFINED; } void Test_OS_GetMaxForObjectType(void) @@ -186,9 +324,9 @@ void Test_OS_GetMaxForObjectType(void) * Test Case For: * uint32 OS_GetMaxForObjectType(uint32 idtype); */ - uint32 idtype = 0; - uint32 expected = 0xFFFFFFFF; - uint32 max = 0; + osal_objtype_t idtype; + uint32 expected = 0xFFFFFFFF; + uint32 max = 0; for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype) { @@ -219,9 +357,9 @@ void Test_OS_GetBaseForObjectType(void) * Test Case For: * uint32 OS_GetBaseForObjectType(uint32 idtype); */ - uint32 idtype = 0; - uint32 expected = 0xFFFFFFFF; - uint32 max = 0; + osal_objtype_t idtype; + uint32 expected = 0xFFFFFFFF; + uint32 max = 0; for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype) { @@ -256,10 +394,10 @@ void Test_OS_ObjectIdToArrayIndex(void) * different test case. The only additional test here is to provide a value * which is out of range. */ - osal_id_t objid; - uint32 local_idx = 0xFFFFFFFF; - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + osal_id_t objid; + osal_index_t local_idx; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; /* need to get a "valid" objid for the nominal case */ OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1, &objid); @@ -271,8 +409,12 @@ void Test_OS_ObjectIdToArrayIndex(void) /* coverage for off-nominal case */ expected = OS_ERR_INVALID_ID; - actual = OS_ObjectIdToArrayIndex(0xFFFFFFFF, UT_OBJID_OTHER, &local_idx); + actual = OS_ObjectIdToArrayIndex(0xFFFF, UT_OBJID_OTHER, &local_idx); UtAssert_True(actual == expected, "OS_ObjectIdToArrayIndex() (%ld) == OS_ERR_INVALID_ID", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TASK, objid, NULL); + UtAssert_True(actual == expected, "OS_ObjectIdToArrayIndex() (%ld) == OS_INVALID_POINTER", (long)actual); } void Test_OS_ObjectIdFindByName(void) @@ -287,19 +429,18 @@ void Test_OS_ObjectIdFindByName(void) char TaskName[] = "UT_find"; osal_id_t objid; int32 expected = OS_ERR_NAME_NOT_FOUND; - int32 actual = OS_ObjectIdFindByName(OS_OBJECT_TYPE_UNDEFINED, NULL, NULL); - + int32 actual = OS_ObjectIdFindByName(OS_OBJECT_TYPE_UNDEFINED, NULL, &objid); UtAssert_True(actual == expected, "OS_ObjectFindIdByName(%s) (%ld) == OS_ERR_NAME_NOT_FOUND", "NULL", (long)actual); /* * Pass in a name that is beyond OS_MAX_API_NAME */ - UT_SetForceFail(UT_KEY(OCS_strlen), OS_MAX_API_NAME + 10); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_ERR_NAME_TOO_LONG; actual = OS_ObjectIdFindByName(OS_OBJECT_TYPE_OS_TASK, TaskName, &objid); UtAssert_True(actual == expected, "OS_ObjectFindIdByName(%s) (%ld) == OS_ERR_NAME_TOO_LONG", TaskName, (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); /* * Pass in a name that is actually not found @@ -328,79 +469,75 @@ void Test_OS_ObjectIdGetById(void) { /* * Test Case For: - * int32 OS_ObjectIdGetById(OS_lock_mode_t check_mode, uint32 idtype, uint32 id, uint32 *array_index, - * OS_common_record_t **record); + * int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, OS_object_token_t + * *token); * */ int32 actual = ~OS_SUCCESS; int32 expected = OS_SUCCESS; osal_id_t refobjid; - uint32 local_idx = 0xFFFFFFFF; - OS_common_record_t *rptr = NULL; + osal_index_t local_idx; + OS_common_record_t *rptr = NULL; + OS_object_token_t token1; + OS_object_token_t token2; /* verify that the call returns ERROR when not initialized */ OS_SharedGlobalVars.Initialized = false; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0, OS_OBJECT_ID_UNDEFINED, &local_idx, &rptr); - expected = OS_ERROR; + actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0, OS_OBJECT_ID_UNDEFINED, &token1); + expected = OS_ERROR; UtAssert_True(actual == expected, "OS_ObjectIdGetById(uninitialized) (%ld) == OS_ERROR", (long)actual); /* set "true" for the remainder of tests */ OS_SharedGlobalVars.Initialized = true; - OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1, &refobjid); + OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1000, &refobjid); OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx); - OS_global_task_table[local_idx].active_id = refobjid; - expected = OS_SUCCESS; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx, &rptr); + rptr = &OS_global_task_table[local_idx]; + rptr->active_id = refobjid; + expected = OS_SUCCESS; + actual = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_TASK, refobjid, &token1); /* Verify Outputs */ UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(local_idx == 1, "local_idx (%lu) == 1", (unsigned long)local_idx); - UtAssert_True(rptr != NULL, "rptr (%p) != NULL", (void *)rptr); + UtAssert_UINT32_EQ(token1.obj_idx, local_idx); UtAssert_True(rptr->refcount == 1, "refcount (%u) == 1", (unsigned int)rptr->refcount); /* attempting to get an exclusive lock should return IN_USE error */ expected = OS_ERR_OBJECT_IN_USE; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx, &rptr); + actual = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TASK, refobjid, &token2); UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_OBJECT_IN_USE", (long)actual); + /* refcount decrement should work */ + OS_ObjectIdRelease(&token1); + UtAssert_True(rptr->refcount == 0, "refcount (%u) == 0", (unsigned int)rptr->refcount); + + /* noop if done a second time */ + OS_ObjectIdRelease(&token1); + UtAssert_True(rptr->refcount == 0, "refcount (%u) == 0", (unsigned int)rptr->refcount); + /* attempt to get non-exclusive lock during shutdown should fail */ OS_SharedGlobalVars.ShutdownFlag = OS_SHUTDOWN_MAGIC_NUMBER; expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx, &rptr); + actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, refobjid, &token1); UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); OS_SharedGlobalVars.ShutdownFlag = 0; /* attempt to get lock for invalid type object should fail */ - expected = OS_ERR_INVALID_ID; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0xFFFFFFFF, refobjid, &local_idx, &rptr); - UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_INVALID_ID", (long)actual); + expected = OS_ERR_INCORRECT_OBJ_TYPE; + actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0xFFFF, refobjid, &token1); + UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); OS_SharedGlobalVars.ShutdownFlag = 0; - /* refcount decrement should work */ - expected = OS_SUCCESS; - actual = OS_ObjectIdRefcountDecr(rptr); - UtAssert_True(actual == expected, "OS_ObjectIdRefcountDecr() (%ld) == OS_SUCCESS", (long)actual); - - /* decrement should fail if done a second time */ - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_ObjectIdRefcountDecr(rptr); - UtAssert_True(actual == expected, "OS_ObjectIdRefcountDecr() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - /* clear out state entry */ memset(&OS_global_task_table[local_idx], 0, sizeof(OS_global_task_table[local_idx])); - - expected = OS_ERR_INVALID_ID; - actual = OS_ObjectIdRefcountDecr(rptr); - UtAssert_True(actual == expected, "OS_ObjectIdRefcountDecr() (%ld) == OS_ERR_INVALID_ID", (long)actual); } -void Test_OS_ObjectIdFindNext(void) +void Test_OS_ObjectIdFindNextFree(void) { /* * Test Case For: - * int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record); - * int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, uint32 *outid); + * int32 OS_ObjectIdFindNextFree(OS_object_token_t *token); + * int32 OS_ObjectIdFinalizeNew(int32 operation_status, &token, uint32 *outid); * * Note This test case covers both functions because they are somewhat interlinked and * they share state between them - The output of FindNext() should be passed to Finalize() @@ -409,75 +546,81 @@ void Test_OS_ObjectIdFindNext(void) int32 expected; int32 actual; + OS_object_token_t token1; + OS_object_token_t token2; OS_common_record_t *rec1; OS_common_record_t *rec2; osal_id_t id1; osal_id_t id2; - UT_idbuf_t check_id; - UT_idbuf_t saved_id; + osal_id_t saved_id; uint32 i; + memset(&token1, 0, sizeof(token1)); + token1.lock_mode = OS_LOCK_MODE_GLOBAL; + token1.obj_type = OS_OBJECT_TYPE_OS_TASK; + /* Need to first obtain a valid ID to finalize */ expected = OS_SUCCESS; - actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec1); - UtAssert_True(actual == expected, "OS_ObjectIdFindNext() (%ld) == OS_SUCCESS", (long)actual); + actual = OS_ObjectIdFindNextFree(&token1); + UtAssert_True(actual == expected, "OS_ObjectIdFindNextFree() (%ld) == OS_SUCCESS", (long)actual); /* nominal case (success) */ id1 = OS_OBJECT_ID_UNDEFINED; - actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, rec1, &id1); + actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, &token1, &id1); + OSAPI_TEST_OBJID(id1, ==, token1.obj_id); /* Verify Outputs */ + rec1 = OS_OBJECT_TABLE_GET(OS_global_task_table, token1); UtAssert_True(actual == expected, "OS_ObjectIdFinalizeNew() (%ld) == OS_SUCCESS", (long)actual); - OSAPI_TEST_OBJID(id1, ==, rec1->active_id); + OSAPI_TEST_OBJID(token1.obj_id, ==, rec1->active_id); /* Allocate another ID (should be different!) */ - actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); - UtAssert_True(actual == expected, "OS_ObjectIdFindNext() (%ld) == OS_SUCCESS", (long)actual); - OSAPI_TEST_OBJID(rec2->active_id, !=, rec1->active_id); + memset(&token2, 0, sizeof(token2)); + token2.lock_mode = OS_LOCK_MODE_GLOBAL; + token2.obj_type = OS_OBJECT_TYPE_OS_TASK; + actual = OS_ObjectIdFindNextFree(&token2); + UtAssert_True(actual == expected, "OS_ObjectIdFindNextFree() (%ld) == OS_SUCCESS", (long)actual); + rec2 = OS_OBJECT_TABLE_GET(OS_global_task_table, token2); + OSAPI_TEST_OBJID(token2.obj_id, !=, token1.obj_id); /* Failure to initialize the second one. * Verify the error code passes thru */ - expected = -1234; - saved_id.id = rec2->active_id; - id2 = OS_OBJECT_ID_UNDEFINED; - actual = OS_ObjectIdFinalizeNew(expected, rec2, &id2); + expected = -1234; + saved_id = token2.obj_id; + id2 = OS_OBJECT_ID_UNDEFINED; + actual = OS_ObjectIdFinalizeNew(expected, &token2, &id2); /* Verify Outputs */ UtAssert_True(actual == expected, "OS_ObjectIdFinalizeNew() (%ld) == %ld", (long)actual, (long)expected); OSAPI_TEST_OBJID(id2, ==, OS_OBJECT_ID_UNDEFINED); OSAPI_TEST_OBJID(rec2->active_id, ==, OS_OBJECT_ID_UNDEFINED); + OSAPI_TEST_OBJID(token2.obj_id, ==, saved_id); - /* next call should re-issue the same id because init failed */ - expected = OS_SUCCESS; - actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); - UtAssert_True(actual == expected, "OS_ObjectIdFindNext() (%ld) == OS_SUCCESS", (long)actual); - OSAPI_TEST_OBJID(rec2->active_id, ==, saved_id.id); - - /* test invalid case*/ - rec2->active_id = OS_OBJECT_ID_UNDEFINED; - expected = OS_ERR_INVALID_ID; - actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, rec2, &id2); - UtAssert_True(actual == expected, "OS_ObjectIdFinalizeNew() (%ld) == %ld", (long)actual, (long)expected); - OSAPI_TEST_OBJID(id2, ==, OS_OBJECT_ID_UNDEFINED); - OSAPI_TEST_OBJID(rec2->active_id, ==, OS_OBJECT_ID_UNDEFINED); + /* next call should not re-issue the same id */ + memset(&token2, 0, sizeof(token2)); + token2.obj_type = OS_OBJECT_TYPE_OS_TASK; + expected = OS_SUCCESS; + actual = OS_ObjectIdFindNextFree(&token2); + UtAssert_True(actual == expected, "OS_ObjectIdFindNextFree() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_OBJID(token2.obj_id, !=, saved_id); /* * Finally - test the wrap-around function to verify that object IDs * will continue to allocate correctly after OS_OBJECT_INDEX_MASK */ - expected = OS_SUCCESS; - saved_id.id = OS_OBJECT_ID_UNDEFINED; + expected = OS_SUCCESS; + saved_id = OS_OBJECT_ID_UNDEFINED; for (i = 0; i < (OS_OBJECT_INDEX_MASK + 2); ++i) { - actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); - /* not usuing UtAssert_True here as it will create thousands of duplicates. */ + actual = OS_ObjectIdFindNextFree(&token2); + /* not using UtAssert_True here as it will create thousands of duplicates. */ if (expected != actual) { - UtAssert_Failed("OS_ObjectIdFindNext() failure (%ld)", (long)actual); + UtAssert_Failed("OS_ObjectIdFindNextFree() failure (%ld)", (long)actual); break; } - actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, rec2, NULL); + actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, &token2, NULL); if (expected != actual) { UtAssert_Failed("OS_ObjectIdFinalizeNew() failure (%ld)", (long)actual); @@ -485,80 +628,100 @@ void Test_OS_ObjectIdFindNext(void) } /* should always be different than the previous ID */ - if (OS_ObjectIdEqual(saved_id.id, rec2->active_id)) + if (OS_ObjectIdEqual(saved_id, token2.obj_id)) { - UtAssert_Failed("OS_ObjectIdFindNext() re-issued ID (%lx)", (unsigned long)saved_id.val); + UtAssert_Failed("OS_ObjectIdFindNextFree() re-issued ID (%lx)", OS_ObjectIdToInteger(token2.obj_id)); break; } /* it also should never be id1, which was previously allocated */ - check_id.id = id1; - if (OS_ObjectIdEqual(check_id.id, rec2->active_id)) + if (OS_ObjectIdEqual(token1.obj_id, token2.obj_id)) { - UtAssert_Failed("OS_ObjectIdFindNext() duplicate ID (%lx)", (unsigned long)check_id.val); + UtAssert_Failed("OS_ObjectIdFindNextFree() duplicate ID (%lx)", OS_ObjectIdToInteger(token1.obj_id)); break; } if (rec1 == rec2) { - UtAssert_Failed("OS_ObjectIdFindNext() duplicate slot (%p)", (void *)rec1); + UtAssert_Failed("OS_ObjectIdFindNextFree() duplicate slot (%p)", (void *)rec1); break; } /* Find the wrap. Once this occurs the test is successful. */ - check_id.id = rec2->active_id; - if (saved_id.val > check_id.val) + if (OS_ObjectIdToInteger(saved_id) > OS_ObjectIdToInteger(token2.obj_id)) { /* Success */ break; } /* clear the entry for re-use */ - saved_id.id = rec2->active_id; - rec2->active_id = OS_OBJECT_ID_UNDEFINED; + saved_id = token2.obj_id; + rec2 = OS_OBJECT_TABLE_GET(OS_global_task_table, token2); + memset(rec2, 0, sizeof(*rec2)); } /* verify that the wrap occurred */ - UtAssert_True(i < (OS_OBJECT_INDEX_MASK + 2), "OS_ObjectIdFindNext() wrap around occurred"); + UtAssert_True(i < (OS_OBJECT_INDEX_MASK + 2), "OS_ObjectIdFindNextFree() wrap around occurred"); } void Test_OS_ObjectIdAllocateNew(void) { /* * Test Case For: - * int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_index, OS_common_record_t **record); + * int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token) * - * Most of the business logic is done by OS_ObjectIdFindNext() which is tested separately + * Most of the business logic is done by OS_ObjectIdFindNextFree() which is tested separately * This test case mainly focuses on additional error checking */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - uint32 indx; - OS_common_record_t *rptr = NULL; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_object_token_t token; - actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &indx, &rptr); + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &token); /* Verify Outputs */ UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(rptr != NULL, "rptr (%p) != NULL", (void *)rptr); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_EXCLUSIVE); + UtAssert_UINT32_EQ(token.obj_type, OS_OBJECT_TYPE_OS_TASK); + UtAssert_Bool(OS_ObjectIdDefined(token.obj_id), "ObjectIdDefined(token.obj_id)"); /* Passing a NULL name also should work here (used for internal objects) */ - actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, NULL, &indx, &rptr); + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, NULL, &token); UtAssert_True(actual == expected, "OS_ObjectIdAllocate(NULL) (%ld) == OS_SUCCESS", (long)actual); - rptr->name_entry = "UT_alloc"; - expected = OS_ERR_NAME_TAKEN; - actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &indx, &rptr); + OS_global_task_table[0].name_entry = "UT_alloc"; + expected = OS_ERR_NAME_TAKEN; + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &token); UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_NAME_TAKEN", (long)actual); + /* + * Although an object with that name exists, it isn't fully created yet. + * OS_ObjectIdAllocateNew() should leave the object record in a state where + * attempts to get object ID by name should fail. + */ + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_ObjectIdGetByName(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &token); + UtAssert_True(actual == expected, "OS_ObjectIdGetByName() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + OS_SharedGlobalVars.ShutdownFlag = OS_SHUTDOWN_MAGIC_NUMBER; - expected = OS_ERROR; - actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &indx, &rptr); + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &token); OS_SharedGlobalVars.ShutdownFlag = 0; - UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_NAME_TAKEN", (long)actual); + UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); expected = OS_ERR_INCORRECT_OBJ_TYPE; - actual = OS_ObjectIdAllocateNew(0xFFFFFFFF, "UT_alloc", &indx, &rptr); + actual = OS_ObjectIdAllocateNew(0xFFFF, "UT_alloc", &token); UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); + + /* + * Test late-stage failure path - + * If object was allocated successfully to the point that a table index was assigned, + * but then failed later, it should call FinalizeNew with the error code so the table + * entry can be cleaned up (effect is the same as if the underlying impl failed). + */ + UT_SetDefaultReturnValue(UT_KEY(OS_NotifyEvent), OS_ERR_INVALID_SIZE); + expected = OS_ERR_INVALID_SIZE; + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc2", &token); + UtAssert_True(actual == expected, "OS_ObjectIdAllocateNew() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); } void Test_OS_ConvertToArrayIndex(void) @@ -569,44 +732,241 @@ void Test_OS_ConvertToArrayIndex(void) * * */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; // OS_ConvertToArrayIndex(); - uint32 local_idx1 = 0xFFFFFFF0; - uint32 local_idx2 = 0xFFFFFFF1; - OS_common_record_t *rptr = NULL; + int32 expected = OS_SUCCESS; + int32 actual; + osal_id_t refobjid; + osal_index_t local_idx; /* Need a valid ID to work with */ - OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, &local_idx1, &rptr); - actual = OS_ConvertToArrayIndex(rptr->active_id, &local_idx2); + OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1234, &refobjid); + actual = OS_ConvertToArrayIndex(refobjid, &local_idx); UtAssert_True(actual == expected, "OS_ConvertToArrayIndex() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(local_idx1 == local_idx2, "local_idx1 (%lu) == local_idx2 (%lu)", (unsigned long)local_idx1, - (unsigned long)local_idx2); + UtAssert_True(local_idx < OS_MAX_TASKS, "local_idx (%lu) < OS_MAX_TASKS (%lu)", (unsigned long)local_idx, + (unsigned long)OS_MAX_TASKS); expected = OS_ERR_INVALID_ID; - actual = OS_ConvertToArrayIndex(OS_OBJECT_ID_UNDEFINED, &local_idx2); + actual = OS_ConvertToArrayIndex(OS_OBJECT_ID_UNDEFINED, &local_idx); UtAssert_True(actual == expected, "OS_ConvertToArrayIndex() (%ld) == OS_ERR_INVALID_ID", (long)actual); } +void Test_OS_ObjectIdTransaction(void) +{ + /* + * Test Case For: + * int32 OS_ObjectIdTransactionInit(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_object_token_t *token); + * void OS_ObjectIdTransactionCancel(OS_object_token_t *token); + * void OS_ObjectIdTransactionFinish(OS_object_token_t *token, osal_id_t *final_id); + * void OS_ObjectIdTransferToken(OS_object_token_t *token_from, OS_object_token_t *token_to); + */ + + OS_object_token_t token; + OS_object_token_t token2; + osal_id_t objid; + OS_common_record_t *record; + + memset(&token, 0xAA, sizeof(token)); + memset(&OS_SharedGlobalVars, 0, sizeof(OS_SharedGlobalVars)); + + /* With OS_SharedGlobalVars uninitialized (0) it should prevent transactions */ + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdTransactionInit(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_BINSEM, &token), OS_ERROR); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_NONE); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 0); + + /* shutdown will prevent transactions */ + OS_SharedGlobalVars.Initialized = true; + OS_SharedGlobalVars.ShutdownFlag = OS_SHUTDOWN_MAGIC_NUMBER; + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdTransactionInit(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_BINSEM, &token), + OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_NONE); + UtAssert_UINT32_EQ(token.obj_type, OS_OBJECT_TYPE_UNDEFINED); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 0); + + /* except for exclusive (delete) transactions, which should succeed */ + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdTransactionInit(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_BINSEM, &token), + OS_SUCCESS); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_EXCLUSIVE); + UtAssert_UINT32_EQ(token.obj_idx, -1); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 1); + + /* cancel should unlock */ + OS_ObjectIdTransactionCancel(&token); + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + + /* other cases for normal operating mode */ + OS_SharedGlobalVars.ShutdownFlag = 0; + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdTransactionInit(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_COUNTSEM, &token), + OS_SUCCESS); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_GLOBAL); + UtAssert_UINT32_EQ(token.obj_type, OS_OBJECT_TYPE_OS_COUNTSEM); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 2); + + /* bad object type */ + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdTransactionInit(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_UNDEFINED, &token), + OS_ERR_INCORRECT_OBJ_TYPE); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_NONE); + UtAssert_UINT32_EQ(token.obj_type, OS_OBJECT_TYPE_UNDEFINED); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 2); + + /* normal finish (sets ID from passed in value) */ + objid = UT_OBJID_1; + token.obj_id = UT_OBJID_2; + token.obj_idx = UT_INDEX_2; + token.obj_type = OS_OBJECT_TYPE_OS_TASK; + token.lock_mode = OS_LOCK_MODE_GLOBAL; + record = OS_ObjectIdGlobalFromToken(&token); + record->refcount = 1; + + OS_ObjectIdTransactionFinish(&token, &objid); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 2); + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2); + OSAPI_TEST_OBJID(record->active_id, ==, objid); + UtAssert_UINT32_EQ(record->refcount, 0); + + /* exclusive lock finish (restores ID from token) */ + record->refcount = 1; + record->active_id = OS_OBJECT_ID_RESERVED; + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + OS_ObjectIdTransactionFinish(&token, NULL); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 3); + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 3); + OSAPI_TEST_OBJID(record->active_id, ==, token.obj_id); + UtAssert_UINT32_EQ(record->refcount, 0); + + /* refcount finish (no change to ID) */ + token.lock_mode = OS_LOCK_MODE_REFCOUNT; + record->refcount = 1; + record->active_id = UT_OBJID_1; + OS_ObjectIdTransactionFinish(&token, NULL); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 4); + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 4); + OSAPI_TEST_OBJID(record->active_id, ==, UT_OBJID_1); + UtAssert_UINT32_EQ(record->refcount, 0); + + /* other finish with refcount already 0 */ + token.lock_mode = OS_LOCK_MODE_GLOBAL; + OS_ObjectIdTransactionFinish(&token, NULL); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 4); + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 5); + OSAPI_TEST_OBJID(record->active_id, ==, UT_OBJID_1); + UtAssert_UINT32_EQ(record->refcount, 0); + + /* test transferring a refcount token */ + memset(&token2, 0xBB, sizeof(token2)); + token.obj_id = UT_OBJID_2; + token.obj_idx = UT_INDEX_2; + token.obj_type = OS_OBJECT_TYPE_OS_TASK; + token.lock_mode = OS_LOCK_MODE_GLOBAL; + + OS_ObjectIdTransferToken(&token, &token2); + + /* actual lock_mode should only be on token2 now */ + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_NONE); + UtAssert_UINT32_EQ(token2.lock_mode, OS_LOCK_MODE_GLOBAL); + + /* other fields should stay the same */ + UtAssert_UINT32_EQ(token.obj_idx, token2.obj_idx); + UtAssert_UINT32_EQ(token.obj_type, token2.obj_type); + OSAPI_TEST_OBJID(token.obj_id, ==, token2.obj_id); +} + +void Test_OS_ObjectIdFinalize(void) +{ + /* + * Test Case For: + * int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_object_token_t *token, osal_id_t *outid); + * int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_object_token_t *token); + */ + int32 expected; + int32 actual; + OS_object_token_t token; + osal_id_t objid; + OS_common_record_t *record; + + memset(&token, 0, sizeof(token)); + + objid = UT_OBJID_1; + token.obj_id = UT_OBJID_2; + token.obj_idx = UT_INDEX_2; + token.obj_type = OS_OBJECT_TYPE_OS_TASK; + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + + record = OS_ObjectIdGlobalFromToken(&token); + + /* if creation fails, RC should be passed through and ID set to UNDEFINED */ + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + record->active_id = OS_OBJECT_ID_RESERVED; + expected = OS_ERR_INVALID_ID; + actual = OS_ObjectIdFinalizeNew(OS_ERR_INVALID_ID, &token, &objid); + UtAssert_True(actual == expected, "OS_ObjectIdFinalizeNew() rc passthru (%ld) == OS_ERR_INVALID_ID (%ld)", + (long)actual, (long)expected); + OSAPI_TEST_OBJID(objid, ==, OS_OBJECT_ID_UNDEFINED); + OSAPI_TEST_OBJID(record->active_id, ==, OS_OBJECT_ID_UNDEFINED); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_NONE); + + /* if creation succeeds, RC should be passed through and ID set to token value */ + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + record->active_id = OS_OBJECT_ID_RESERVED; + expected = OS_SUCCESS; + actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, &token, &objid); + UtAssert_True(actual == expected, "OS_ObjectIdFinalizeNew() rc passthru (%ld) == OS_SUCCESS (%ld)", (long)actual, + (long)expected); + OSAPI_TEST_OBJID(objid, ==, token.obj_id); + OSAPI_TEST_OBJID(record->active_id, ==, token.obj_id); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_NONE); + + /* verify passing NULL for out ID for path coverage */ + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + record->active_id = OS_OBJECT_ID_RESERVED; + expected = OS_SUCCESS; + actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, &token, NULL); + UtAssert_True(actual == expected, "OS_ObjectIdFinalizeNew() rc passthru (%ld) == OS_SUCCESS (%ld)", (long)actual, + (long)expected); + OSAPI_TEST_OBJID(record->active_id, ==, token.obj_id); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_NONE); + + /* if delete succeeds, RC should be passed through and ID set to UNDEFINED */ + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + record->active_id = OS_OBJECT_ID_RESERVED; + expected = OS_SUCCESS; + actual = OS_ObjectIdFinalizeDelete(OS_SUCCESS, &token); + UtAssert_True(actual == expected, "OS_ObjectIdFinalizeDelete() rc passthru (%ld) == OS_SUCCESS (%ld)", (long)actual, + (long)expected); + OSAPI_TEST_OBJID(record->active_id, ==, OS_OBJECT_ID_UNDEFINED); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_NONE); + + /* if delete fails, RC should be passed through and ID set to the token value */ + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + record->active_id = OS_OBJECT_ID_RESERVED; + expected = OS_ERR_INVALID_ID; + actual = OS_ObjectIdFinalizeDelete(OS_ERR_INVALID_ID, &token); + UtAssert_True(actual == expected, "OS_ObjectIdFinalizeDelete() rc passthru (%ld) == OS_ERR_INVALID_ID (%ld)", + (long)actual, (long)expected); + OSAPI_TEST_OBJID(record->active_id, ==, token.obj_id); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_NONE); +} + void Test_OS_ForEachObject(void) { /* * Test Case For: * void OS_ForEachObject (uint32 creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg); */ - uint32 objtype = OS_OBJECT_TYPE_UNDEFINED; - OS_common_record_t * rptr = NULL; - uint32 local_idx = 0xFFFFFFFF; + OS_object_token_t token; UT_idbuf_t self_id; Test_OS_ObjTypeCount_t Count; self_id.id = OS_TaskGetId(); memset(&Count, 0, sizeof(Count)); + memset(&token, 0, sizeof(token)); - while (objtype < OS_OBJECT_TYPE_USER) + while (token.obj_type < OS_OBJECT_TYPE_USER) { - OS_ObjectIdFindNext(objtype, &local_idx, &rptr); - ++objtype; + if (OS_ObjectIdFindNextFree(&token) == OS_SUCCESS) + { + OS_ObjectIdGlobalFromToken(&token)->active_id = token.obj_id; + } + ++token.obj_type; } OS_ForEachObject(OS_OBJECT_ID_UNDEFINED, &ObjTypeCounter, &Count); @@ -641,8 +1001,8 @@ void Test_OS_GetResourceName(void) * Test Case For: * int32 OS_GetResourceName(uint32 id, char *buffer, uint32 buffer_size) */ - uint32 local_idx = 0xFFFFFFFF; - OS_common_record_t *rptr = NULL; + OS_object_token_t token; + OS_common_record_t *rptr; char NameBuffer[OS_MAX_API_NAME]; int32 expected; int32 actual; @@ -651,22 +1011,62 @@ void Test_OS_GetResourceName(void) * Set up for the OS_GetResourceName function to return success */ /* Need a valid ID to work with */ - OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, &local_idx, &rptr); + memset(&token, 0, sizeof(token)); + token.obj_type = OS_OBJECT_TYPE_OS_TASK; + OS_ObjectIdFindNextFree(&token); + rptr = OS_OBJECT_TABLE_GET(OS_global_task_table, token); rptr->name_entry = "UTTask"; - expected = OS_SUCCESS; - actual = OS_GetResourceName(rptr->active_id, NameBuffer, sizeof(NameBuffer)); + rptr->active_id = token.obj_id; + + expected = OS_SUCCESS; + actual = OS_GetResourceName(token.obj_id, NameBuffer, sizeof(NameBuffer)); UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(strcmp(NameBuffer, "UTTask") == 0, "NameBuffer (%s) == UTTask", NameBuffer); expected = OS_ERR_NAME_TOO_LONG; - actual = OS_GetResourceName(rptr->active_id, NameBuffer, 2); + actual = OS_GetResourceName(token.obj_id, NameBuffer, OSAL_SIZE_C(2)); UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_GetResourceName(rptr->active_id, NULL, 0); + actual = OS_GetResourceName(token.obj_id, NULL, OSAL_SIZE_C(0)); UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_INVALID_POINTER", (long)actual); } +void Test_OS_ObjectIdIterator(void) +{ + /* + * Test Case For: + * OS_ObjectIdIteratorInit, OS_ObjectFilterActive, OS_ObjectIdIterateActive + * OS_ObjectIdIteratorGetNext, OS_ObjectIdIteratorDestroy, OS_ObjectIdIteratorProcessEntry + */ + OS_object_iter_t iter; + OS_common_record_t rec; + uint32 testarg; + + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdIteratorInit(NULL, NULL, OS_OBJECT_TYPE_UNDEFINED, &iter), + OS_ERR_INCORRECT_OBJ_TYPE); + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdIterateActive(OS_OBJECT_TYPE_OS_TASK, &iter), OS_SUCCESS); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 1); + + memset(&rec, 0, sizeof(rec)); + UtAssert_True(!OS_ObjectFilterActive(NULL, NULL, &rec), "OS_ObjectFilterActive() empty record"); + + rec.active_id = UT_OBJID_1; + UtAssert_True(OS_ObjectFilterActive(NULL, NULL, &rec), "OS_ObjectFilterActive() non-empty record"); + + /* OS_ObjectIdIteratorProcessEntry unlocks and re-locks */ + testarg = 4; + iter.arg = &testarg; + OS_ObjectIdIteratorProcessEntry(&iter, TestIterator); + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 2); + + /* OS_ObjectIdIteratorDestroy is just a passthrough to OS_ObjectIdTransactionCancel, + * but need to call for coverage */ + OS_ObjectIdIteratorDestroy(&iter); + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2); +} + /* Osapi_Test_Setup * * Purpose: @@ -702,16 +1102,19 @@ void UtTest_Setup(void) { ADD_TEST(OS_ObjectIdInit); ADD_TEST(OS_LockUnlockGlobal); - ADD_TEST(OS_ObjectIdFindNext); + ADD_TEST(OS_ObjectIdFindNextFree); ADD_TEST(OS_ObjectIdToArrayIndex); ADD_TEST(OS_ObjectIdFindByName); ADD_TEST(OS_ObjectIdGetById); + ADD_TEST(OS_ObjectIdTransaction); ADD_TEST(OS_ObjectIdAllocateNew); - ADD_TEST(OS_ObjectIdConvertLock); + ADD_TEST(OS_ObjectIdFinalize); + ADD_TEST(OS_ObjectIdConvertToken); ADD_TEST(OS_ObjectIdGetBySearch); ADD_TEST(OS_ConvertToArrayIndex); ADD_TEST(OS_ForEachObject); ADD_TEST(OS_GetMaxForObjectType); ADD_TEST(OS_GetBaseForObjectType); ADD_TEST(OS_GetResourceName); + ADD_TEST(OS_ObjectIdIterator); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-module.c b/src/unit-test-coverage/shared/src/coveragetest-module.c index 7cd0146b3..2552626bb 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -68,7 +68,7 @@ void Test_OS_ModuleLoad(void) */ int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_ModuleLoad(&objid, "UT", "File"); + int32 actual = OS_ModuleLoad(&objid, "UT", "File", OS_MODULE_FLAG_GLOBAL_SYMBOLS); UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual); actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl)); @@ -76,25 +76,32 @@ void Test_OS_ModuleLoad(void) OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); /* for a static module, it should also return a valid objid, but should NOT invoke OS_ModuleLoad_Impl */ - actual = OS_ModuleLoad(&objid, "UTS", "File2"); + actual = OS_ModuleLoad(&objid, "UTS", "File2", OS_MODULE_FLAG_GLOBAL_SYMBOLS); UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual); actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl)); UtAssert_True(actual == 1, "OS_ModuleLoad_Impl() called (%ld) == 1", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); + /* a dynamic module with local symbols */ + actual = OS_ModuleLoad(&objid, "UT", "File3", OS_MODULE_FLAG_LOCAL_SYMBOLS); + UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual); + actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl)); + UtAssert_True(actual == 2, "OS_ModuleLoad_Impl() called (%ld) == 2", (long)actual); + OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); + /* error cases */ - actual = OS_ModuleLoad(NULL, NULL, NULL); + actual = OS_ModuleLoad(NULL, NULL, NULL, OS_MODULE_FLAG_GLOBAL_SYMBOLS); expected = OS_INVALID_POINTER; UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_API_NAME); - actual = OS_ModuleLoad(&objid, "UTS", "File2"); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); + actual = OS_ModuleLoad(&objid, "UTS", "File2", OS_MODULE_FLAG_GLOBAL_SYMBOLS); expected = OS_ERR_NAME_TOO_LONG; UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ResetState(UT_KEY(OCS_strlen)); + UT_ResetState(UT_KEY(OCS_memchr)); - UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_ERROR); - actual = OS_ModuleLoad(&objid, "UT", "FileBad"); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR); + actual = OS_ModuleLoad(&objid, "UT", "FileBad", OS_MODULE_FLAG_GLOBAL_SYMBOLS); expected = OS_ERROR; UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_ERROR", (long)actual); } @@ -127,8 +134,8 @@ void Test_OS_SymbolLookup(void) actual = OS_SymbolLookup(&symaddr, "uttestsym0"); UtAssert_True(actual == expected, "OS_SymbolLookup(name=%s) (%ld) == OS_SUCCESS", "uttestsym0", (long)actual); - UT_ResetState(UT_KEY(OS_SymbolLookup_Impl)); - UT_SetForceFail(UT_KEY(OS_SymbolLookup_Impl), OS_ERROR); + UT_ResetState(UT_KEY(OS_GlobalSymbolLookup_Impl)); + UT_SetDefaultReturnValue(UT_KEY(OS_GlobalSymbolLookup_Impl), OS_ERROR); /* this lookup should always fail */ symaddr = 0; @@ -151,6 +158,44 @@ void Test_OS_SymbolLookup(void) UtAssert_True(actual == expected, "OS_SymbolLookup(UT_staticsym) (%ld) == OS_SUCCESS", (long)actual); } +void Test_OS_ModuleSymbolLookup(void) +{ + /* + * Test Case For: + * int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const char *symbol_name) + */ + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + cpuaddr testaddr = 0; + cpuaddr symaddr = 0; + + actual = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "uttestsym0"); + UtAssert_True(actual == expected, "OS_ModuleSymbolLookup(name=%s) (%ld) == OS_SUCCESS", "uttestsym0", (long)actual); + + UT_ResetState(UT_KEY(OS_ModuleSymbolLookup_Impl)); + UT_SetDefaultReturnValue(UT_KEY(OS_ModuleSymbolLookup_Impl), OS_ERROR); + + /* this lookup should always fail */ + symaddr = 0; + testaddr = 0; + actual = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "uttestsym1"); + expected = OS_ERROR; + UtAssert_True(actual == expected, "OS_ModuleSymbolLookup(name=%s) (%ld) == OS_ERROR", "uttestsym1", (long)actual); + UtAssert_True(symaddr == testaddr, "OS_ModuleSymbolLookup(address=%lx) == %lx", (unsigned long)symaddr, + (unsigned long)testaddr); + + actual = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, NULL, NULL); + expected = OS_INVALID_POINTER; + UtAssert_True(actual == expected, "OS_ModuleSymbolLookup(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + + /* + * Look up a symbol that is present in the static symbol table + */ + actual = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "UT_staticsym"); + expected = OS_SUCCESS; + UtAssert_True(actual == expected, "OS_ModuleSymbolLookup(UT_staticsym) (%ld) == OS_SUCCESS", (long)actual); +} + void Test_OS_StaticSymbolLookup(void) { /* @@ -167,8 +212,14 @@ void Test_OS_StaticSymbolLookup(void) cpuaddr addr; /* nominal */ - actual = OS_SymbolLookup_Static(&addr, "UT_staticsym"); - UtAssert_True(actual == expected, "OS_SymbolLookup_Static(name=%s) (%ld) == OS_SUCCESS", "Test_Func1", + actual = OS_SymbolLookup_Static(&addr, "UT_staticsym", NULL); + UtAssert_True(actual == expected, "OS_SymbolLookup_Static(name=%s, NULL) (%ld) == OS_SUCCESS", "Test_Func1", + (long)actual); + UtAssert_True(addr == (cpuaddr)&Test_DummyFunc, "OS_SymbolLookup_Static(address=%lx) == %lx", (unsigned long)addr, + (unsigned long)&Test_DummyFunc); + + actual = OS_SymbolLookup_Static(&addr, "UT_staticsym", "UTS"); + UtAssert_True(actual == expected, "OS_SymbolLookup_Static(name=%s, UTS) (%ld) == OS_SUCCESS", "Test_Func1", (long)actual); UtAssert_True(addr == (cpuaddr)&Test_DummyFunc, "OS_SymbolLookup_Static(address=%lx) == %lx", (unsigned long)addr, (unsigned long)&Test_DummyFunc); @@ -177,7 +228,14 @@ void Test_OS_StaticSymbolLookup(void) UtAssert_True(actual == expected, "OS_ModuleLoad_Static(name=%s) (%ld) == OS_SUCCESS", "UT", (long)actual); expected = OS_ERROR; - actual = OS_SymbolLookup_Static(&addr, "Invalid"); + actual = OS_SymbolLookup_Static(&addr, "UT_staticsym", "NoModuleMatch"); + UtAssert_True(actual == expected, "OS_SymbolLookup_Static(name=%s, NoModuleMatch) (%ld) == OS_ERROR", "Test_Func1", + (long)actual); + UtAssert_True(addr == (cpuaddr)&Test_DummyFunc, "OS_SymbolLookup_Static(address=%lx) == %lx", (unsigned long)addr, + (unsigned long)&Test_DummyFunc); + + expected = OS_ERROR; + actual = OS_SymbolLookup_Static(&addr, "Invalid", NULL); UtAssert_True(actual == expected, "OS_SymbolLookup_Static(name=%s) (%ld) == OS_ERROR", "Invalid", (long)actual); expected = OS_ERR_NAME_NOT_FOUND; @@ -190,16 +248,22 @@ void Test_OS_SymbolTableDump(void) int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; - actual = OS_SymbolTableDump("test", 555); + actual = OS_SymbolTableDump("test", OSAL_SIZE_C(555)); UtAssert_True(actual == expected, "OS_SymbolTableDump() (%ld) == OS_SUCCESS", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_SymbolTableDump(NULL, 555); + actual = OS_SymbolTableDump(NULL, OSAL_SIZE_C(555)); UtAssert_True(actual == expected, "OS_SymbolTableDump() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR); expected = OS_ERROR; - actual = OS_SymbolTableDump("test", 555); + actual = OS_SymbolTableDump("test", OSAL_SIZE_C(555)); + UtAssert_True(actual == expected, "OS_SymbolTableDump() (%ld) == OS_ERROR", (long)actual); + + UT_ResetState(UT_KEY(OS_TranslatePath)); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdTransactionInit), OS_ERROR); + expected = OS_ERROR; + actual = OS_SymbolTableDump("test", OSAL_SIZE_C(555)); UtAssert_True(actual == expected, "OS_SymbolTableDump() (%ld) == OS_ERROR", (long)actual); } @@ -209,19 +273,13 @@ void Test_OS_ModuleGetInfo(void) * Test Case For: * int32 OS_ModuleInfo ( uint32 module_id, OS_module_prop_t *module_prop ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_module_prop_t module_prop; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_module_prop_t module_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_MODULE, UT_INDEX_1, "ABC", UT_OBJID_OTHER); strncpy(OS_module_table[1].file_name, "DEF", sizeof(OS_module_table[1].file_name)); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + actual = OS_ModuleInfo(UT_OBJID_1, &module_prop); UtAssert_True(actual == expected, "OS_ModuleGetInfo() (%ld) == OS_SUCCESS", (long)actual); @@ -260,6 +318,7 @@ void UtTest_Setup(void) ADD_TEST(OS_ModuleLoad); ADD_TEST(OS_ModuleUnload); ADD_TEST(OS_SymbolLookup); + ADD_TEST(OS_ModuleSymbolLookup); ADD_TEST(OS_ModuleGetInfo); ADD_TEST(OS_SymbolTableDump); ADD_TEST(OS_StaticSymbolLookup); diff --git a/src/unit-test-coverage/shared/src/coveragetest-mutex.c b/src/unit-test-coverage/shared/src/coveragetest-mutex.c index ad13a1539..d5a5158d1 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -61,7 +61,7 @@ void Test_OS_MutSemCreate(void) OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(NULL, NULL, 0), OS_INVALID_POINTER); - UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(&objid, "UT", 0), OS_ERR_NAME_TOO_LONG); } @@ -85,12 +85,26 @@ void Test_OS_MutSemGive(void) * Test Case For: * int32 OS_MutSemGive ( uint32 sem_id ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + OS_mutex_internal_record_t *mutex; + int32 expected; + int32 actual; - actual = OS_MutSemGive(UT_OBJID_1); + expected = OS_SUCCESS; + + /* Set up for "last owner" matching the calling task (nominal) */ + mutex = &OS_mutex_table[1]; + mutex->last_owner = OS_TaskGetId(); + actual = OS_MutSemGive(UT_OBJID_1); UtAssert_True(actual == expected, "OS_MutSemGive() (%ld) == OS_SUCCESS", (long)actual); + + /* owner should be unset */ + UtAssert_True(!OS_ObjectIdDefined(mutex->last_owner), "Mutex owner unset"); + + /* Call again when not "owned". This still works (or at least it calls the OS impl) + * but should generate a debug message */ + actual = OS_MutSemGive(UT_OBJID_1); + UtAssert_True(actual == expected, "OS_MutSemGive(), not owned (%ld) == OS_SUCCESS", (long)actual); } void Test_OS_MutSemTake(void) @@ -99,11 +113,24 @@ void Test_OS_MutSemTake(void) * Test Case For: * int32 OS_MutSemTake ( uint32 sem_id ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + OS_mutex_internal_record_t *mutex; + int32 expected; + int32 actual; - actual = OS_MutSemTake(UT_OBJID_1); + expected = OS_SUCCESS; + + /* Set up for "last owner" being undefined (nominal) */ + mutex = &OS_mutex_table[1]; + mutex->last_owner = OS_OBJECT_ID_UNDEFINED; + actual = OS_MutSemTake(UT_OBJID_1); + UtAssert_True(actual == expected, "OS_MutSemTake() (%ld) == OS_SUCCESS", (long)actual); + /* owner should be set */ + UtAssert_True(OS_ObjectIdDefined(mutex->last_owner), "Mutex owner set"); + + /* Call again when not already "owned". This still works (or at least it calls the OS impl) + * but should generate a debug message */ + actual = OS_MutSemTake(UT_OBJID_1); UtAssert_True(actual == expected, "OS_MutSemTake() (%ld) == OS_SUCCESS", (long)actual); } @@ -117,11 +144,11 @@ void Test_OS_MutSemGetIdByName(void) int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_MutSemGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_MutSemGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_MutSemGetIdByName(&objid, "NF"); @@ -136,18 +163,12 @@ void Test_OS_MutSemGetInfo(void) * Test Case For: * int32 OS_MutSemGetInfo (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_mut_sem_prop_t prop; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_mut_sem_prop_t prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_MUTEX, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_MutSemGetInfo(UT_OBJID_1, &prop); UtAssert_True(actual == expected, "OS_MutSemGetInfo() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-network.c b/src/unit-test-coverage/shared/src/coveragetest-network.c index 871992d1f..8a076a551 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-network.c +++ b/src/unit-test-coverage/shared/src/coveragetest-network.c @@ -52,7 +52,7 @@ void Test_OS_NetworkGetHostName(void) actual = OS_NetworkGetHostName(Buffer, sizeof(Buffer)); UtAssert_True(actual == expected, "OS_NetworkGetHostName() (%ld) == OS_SUCCESS", (long)actual); - UT_SetForceFail(UT_KEY(OS_NetworkGetHostName_Impl), -4444); + UT_SetDefaultReturnValue(UT_KEY(OS_NetworkGetHostName_Impl), -4444); expected = -4444; actual = OS_NetworkGetHostName(Buffer, sizeof(Buffer)); UtAssert_True(actual == expected, "OS_NetworkGetHostName(impl error) (%ld) == -4444", (long)actual); @@ -61,7 +61,7 @@ void Test_OS_NetworkGetHostName(void) actual = OS_NetworkGetHostName(NULL, sizeof(Buffer)); UtAssert_True(actual == expected, "OS_NetworkGetHostName(Ptr=NULL) (%ld) == OS_INVALID_POINTER", (long)actual); - expected = OS_ERROR; + expected = OS_ERR_INVALID_SIZE; actual = OS_NetworkGetHostName(Buffer, 0); UtAssert_True(actual == expected, "OS_NetworkGetHostName(Size=0) (%ld) == OS_ERROR", (long)actual); } @@ -79,7 +79,7 @@ void Test_OS_NetworkGetID(void) actual = OS_NetworkGetID(); UtAssert_True(actual == expected, "OS_NetworkGetID(nominal) (%ld) == 42", (long)actual); - UT_SetForceFail(UT_KEY(OS_NetworkGetID_Impl), -5555); + UT_SetDefaultReturnValue(UT_KEY(OS_NetworkGetID_Impl), -5555); expected = -1; actual = OS_NetworkGetID(); UtAssert_True(actual == expected, "OS_NetworkGetID(error) (%ld) == -1", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-printf.c b/src/unit-test-coverage/shared/src/coveragetest-printf.c index 8d6a888d6..44f7f7586 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-printf.c +++ b/src/unit-test-coverage/shared/src/coveragetest-printf.c @@ -38,10 +38,16 @@ void Test_OS_ConsoleAPI_Init(void) * Test Case For: * int32 OS_ConsoleAPI_Init(void) */ - uint32 CallCount = 0; - uint32 local_id = 0; + uint32 CallCount = 0; + OS_object_token_t token; + + /* make a custom token to force use of array index 0 */ + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_type = OS_OBJECT_TYPE_OS_CONSOLE; + token.obj_idx = UT_INDEX_0; + token.obj_id = UT_OBJID_1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdAllocateNew), &local_id, sizeof(local_id), false); + UT_SetDataBuffer(UT_KEY(OS_ObjectIdAllocateNew), &token, sizeof(token), false); /* call for coverage */ OS_ConsoleAPI_Init(); @@ -93,10 +99,10 @@ void Test_OS_printf(void) /* * For coverage, exercise different paths depending on the return value */ - UT_SetForceFail(UT_KEY(OCS_vsnprintf), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_vsnprintf), -1); OS_printf("UnitTest6"); - UT_SetForceFail(UT_KEY(OCS_vsnprintf), OS_BUFFER_SIZE + 10); + UT_SetDefaultReturnValue(UT_KEY(OCS_vsnprintf), OS_BUFFER_SIZE + 10); OS_printf("UnitTest7"); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-queue.c b/src/unit-test-coverage/shared/src/coveragetest-queue.c index 4c8bfa89a..44dab954f 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-queue.c +++ b/src/unit-test-coverage/shared/src/coveragetest-queue.c @@ -56,23 +56,27 @@ void Test_OS_QueueCreate(void) */ int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_QueueCreate(&objid, "UT", 0, 0, 0); + int32 actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(4), 0); UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_SUCCESS", (long)actual); /* test error cases */ expected = OS_INVALID_POINTER; - actual = OS_QueueCreate(NULL, "UT", 0, 0, 0); + actual = OS_QueueCreate(NULL, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(4), 0); UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_API_NAME); + expected = OS_ERR_INVALID_SIZE; + actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(0), 0); + UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); + + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_ERR_NAME_TOO_LONG; - actual = OS_QueueCreate(&objid, "UT", 0, 0, 0); + actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(0), OSAL_SIZE_C(4), 0); UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); expected = OS_QUEUE_INVALID_SIZE; - actual = OS_QueueCreate(&objid, "UT", 1 + OS_QUEUE_MAX_DEPTH, 0, 0); + actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(1 + OS_QUEUE_MAX_DEPTH), OSAL_SIZE_C(4), 0); UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_QUEUE_INVALID_SIZE", (long)actual); } @@ -98,7 +102,7 @@ void Test_OS_QueueGet(void) */ int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; - uint32 actual_size; + size_t actual_size; char Buf[4]; actual = OS_QueueGet(UT_OBJID_1, Buf, sizeof(Buf), &actual_size, 0); @@ -126,14 +130,20 @@ void Test_OS_QueuePut(void) int32 actual = ~OS_SUCCESS; const char Data[4] = "xyz"; - actual = OS_QueuePut(UT_OBJID_1, Data, sizeof(Data), 0); + OS_queue_table[1].max_depth = 10; + OS_queue_table[1].max_size = sizeof(Data); + actual = OS_QueuePut(UT_OBJID_1, Data, sizeof(Data), 0); UtAssert_True(actual == expected, "OS_QueuePut() (%ld) == OS_SUCCESS", (long)actual); /* test error cases */ expected = OS_INVALID_POINTER; actual = OS_QueuePut(UT_OBJID_1, NULL, sizeof(Data), 0); UtAssert_True(actual == expected, "OS_QueuePut() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_QUEUE_INVALID_SIZE; + actual = OS_QueuePut(UT_OBJID_1, Data, 1 + sizeof(Data), 0); + UtAssert_True(actual == expected, "OS_QueuePut() (%ld) == OS_QUEUE_INVALID_SIZE", (long)actual); } void Test_OS_QueueGetIdByName(void) @@ -146,10 +156,10 @@ void Test_OS_QueueGetIdByName(void) int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_QueueGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_QueueGetIdByName() (%ld) == OS_SUCCESS", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_QueueGetIdByName(&objid, "NF"); @@ -166,20 +176,15 @@ void Test_OS_QueueGetInfo(void) * Test Case For: * int32 OS_QueueGetInfo (uint32 queue_id, OS_queue_prop_t *queue_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_queue_prop_t queue_prop; - osal_id_t id; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - id = UT_OBJID_OTHER; - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_queue_prop_t queue_prop; + osal_id_t id; + + id = UT_OBJID_OTHER; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_QUEUE, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_QueueGetInfo(UT_OBJID_1, &queue_prop); UtAssert_True(actual == expected, "OS_QueueGetInfo() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-select.c b/src/unit-test-coverage/shared/src/coveragetest-select.c index 79c43f004..34d81579e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-select.c +++ b/src/unit-test-coverage/shared/src/coveragetest-select.c @@ -107,7 +107,7 @@ void Test_OS_SelectFdAddClearOps(void) UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == false"); expected = -42; - UT_SetForceFail(UT_KEY(OS_ObjectIdToArrayIndex), expected); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdToArrayIndex), expected); actual = OS_SelectFdAdd(&UtSet, UT_OBJID_2); UtAssert_True(actual == expected, "OS_SelectFdAdd() (%ld) == %ld", (long)actual, (long)expected); actual = OS_SelectFdClear(&UtSet, UT_OBJID_1); @@ -115,7 +115,7 @@ void Test_OS_SelectFdAddClearOps(void) UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_1), "OS_SelectFdIsSet(1) == false"); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == false"); - UT_ClearForceFail(UT_KEY(OS_ObjectIdToArrayIndex)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdToArrayIndex)); UtAssert_True(OS_SelectFdIsSet(&UtSet, UT_OBJID_1), "OS_SelectFdIsSet(1) == true"); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == false"); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-sockets.c b/src/unit-test-coverage/shared/src/coveragetest-sockets.c index 13c7314a6..6981bfca0 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -58,10 +58,18 @@ void Test_OS_CreateSocketName(void) * * This focuses on coverage paths, as this function does not return a value */ - OS_SockAddr_t testaddr; + OS_SockAddr_t testaddr; + OS_object_token_t token; - UT_SetForceFail(UT_KEY(OS_SocketAddrToString_Impl), OS_ERROR); - OS_CreateSocketName(0, &testaddr, "ut"); + OS_stream_table[0].stream_name[0] = 'x'; + + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_idx = UT_INDEX_0; + token.obj_id = UT_OBJID_1; + token.obj_type = OS_OBJECT_TYPE_OS_STREAM; + + UT_SetDefaultReturnValue(UT_KEY(OS_SocketAddrToString_Impl), OS_ERROR); + OS_CreateSocketName(&token, &testaddr, "ut"); /* * The function should have called snprintf() to create the name @@ -150,15 +158,16 @@ void Test_OS_SocketAccept(void) */ int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; - uint32 local_id = 0; + osal_index_t local_id; osal_id_t connsock_id; OS_SockAddr_t Addr; + local_id = UT_INDEX_0; connsock_id = OS_OBJECT_ID_UNDEFINED; OS_stream_table[local_id].socket_type = OS_SocketType_STREAM; OS_stream_table[local_id].stream_state = OS_STREAM_STATE_BOUND; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_id, sizeof(local_id), false); + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, local_id); memset(&Addr, 0, sizeof(Addr)); actual = OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0); @@ -191,7 +200,7 @@ void Test_OS_SocketAccept(void) */ OS_stream_table[1].stream_state = OS_STREAM_STATE_BOUND; expected = -1234; - UT_SetForceFail(UT_KEY(OS_SocketAccept_Impl), -1234); + UT_SetDefaultReturnValue(UT_KEY(OS_SocketAccept_Impl), -1234); actual = OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0); UtAssert_True(actual == expected, "OS_SocketAccept() underlying failure (%ld) == -1234", (long)actual); } @@ -210,11 +219,11 @@ void Test_OS_SocketConnect(void) int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; OS_SockAddr_t Addr; - uint32 idbuf; + osal_index_t idbuf; memset(&Addr, 0, sizeof(Addr)); - idbuf = 1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &idbuf, sizeof(idbuf), false); + idbuf = UT_INDEX_1; + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, idbuf); OS_stream_table[idbuf].socket_domain = OS_SocketDomain_INET; OS_stream_table[idbuf].socket_type = OS_SocketType_STREAM; OS_stream_table[idbuf].stream_state = 0; @@ -263,19 +272,20 @@ void Test_OS_SocketRecvFrom(void) int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; OS_SockAddr_t Addr; - uint32 idbuf; + osal_index_t idbuf; memset(&Addr, 0, sizeof(Addr)); - idbuf = 1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &idbuf, sizeof(idbuf), false); + idbuf = UT_INDEX_1; + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, idbuf); OS_stream_table[idbuf].socket_type = OS_SocketType_DATAGRAM; OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_BOUND; actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, 1, &Addr, 0); + actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0); UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_SUCCESS", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_SocketRecvFrom(UT_OBJID_1, NULL, 0, NULL, 0); + actual = OS_SocketRecvFrom(UT_OBJID_1, NULL, OSAL_SIZE_C(0), NULL, 0); UtAssert_True(actual == expected, "OS_SocketRecvFrom(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); /* @@ -283,7 +293,7 @@ void Test_OS_SocketRecvFrom(void) */ OS_stream_table[1].socket_type = OS_SocketType_INVALID; expected = OS_ERR_INCORRECT_OBJ_TYPE; - actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, 1, &Addr, 0); + actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0); UtAssert_True(actual == expected, "OS_SocketRecvFrom() non-datagram (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); @@ -293,7 +303,7 @@ void Test_OS_SocketRecvFrom(void) OS_stream_table[1].socket_type = OS_SocketType_DATAGRAM; OS_stream_table[1].stream_state = 0; expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, 1, &Addr, 0); + actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0); UtAssert_True(actual == expected, "OS_SocketRecvFrom() non-bound (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); } @@ -313,27 +323,35 @@ void Test_OS_SocketSendTo(void) int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; OS_SockAddr_t Addr; - uint32 idbuf; + osal_index_t idbuf; memset(&Addr, 0, sizeof(Addr)); - idbuf = 1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &idbuf, sizeof(idbuf), false); + idbuf = UT_INDEX_1; + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, idbuf); OS_stream_table[idbuf].socket_type = OS_SocketType_DATAGRAM; OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_BOUND; - actual = OS_SocketSendTo(UT_OBJID_1, &Buf, 1, &Addr); + actual = OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), &Addr); UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_SUCCESS", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_SocketSendTo(UT_OBJID_1, NULL, 0, NULL); + actual = OS_SocketSendTo(UT_OBJID_1, NULL, sizeof(Buf), &Addr); UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + expected = OS_INVALID_POINTER; + actual = OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), NULL); + UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INVALID_SIZE; + actual = OS_SocketSendTo(UT_OBJID_1, &Buf, OSAL_SIZE_C(0), &Addr); + UtAssert_True(actual == expected, "OS_SocketSendTo(0) (%ld) == OS_ERR_INVALID_SIZE", (long)actual); + /* * Should fail if not a datagram socket */ OS_stream_table[1].socket_type = OS_SocketType_INVALID; expected = OS_ERR_INCORRECT_OBJ_TYPE; - actual = OS_SocketSendTo(UT_OBJID_1, &Buf, 1, &Addr); + actual = OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), &Addr); UtAssert_True(actual == expected, "OS_SocketSendTo() non-datagram (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); } @@ -353,11 +371,11 @@ void Test_OS_SocketGetIdByName(void) int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_SocketGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_SocketGetIdByName(&objid, "NF"); @@ -379,18 +397,11 @@ void Test_OS_SocketGetInfo(void) * Test Case For: * int32 OS_SocketGetInfo (uint32 sock_id, OS_socket_prop_t *sock_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_socket_prop_t prop; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_socket_prop_t prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); actual = OS_SocketGetInfo(UT_OBJID_1, &prop); UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_SUCCESS", (long)actual); @@ -439,7 +450,7 @@ void Test_OS_SocketAddr(void) actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INVALID); UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); - actual = OS_SocketAddrToString(NULL, 0, NULL); + actual = OS_SocketAddrToString(NULL, OSAL_SIZE_C(0), NULL); UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); actual = OS_SocketAddrFromString(NULL, NULL); diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index f1e640c6d..a97af4301 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -56,6 +56,7 @@ void Test_OS_TaskEntryPoint(void) uint32 CallCount = 0; UT_TestHook_Count = 0; + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERROR); OS_TaskEntryPoint(UT_OBJID_1); UtAssert_True(UT_TestHook_Count == 0, "UT_TestHook_Count (%lu) == 0", (unsigned long)UT_TestHook_Count); CallCount = UT_GetStubCount(UT_KEY(OS_TaskMatch_Impl)); @@ -106,17 +107,24 @@ void Test_OS_TaskCreate(void) */ int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 128, 0, 0); + int32 actual; + + actual = + OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(128), OSAL_PRIORITY_C(0), 0); UtAssert_True(actual == expected, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(NULL, NULL, NULL, NULL, 0, 0, 0), OS_INVALID_POINTER); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 0, 0), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 128, 10 + OS_MAX_TASK_PRIORITY, 0), - OS_ERR_INVALID_PRIORITY); - UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 128, 0, 0), OS_ERR_NAME_TOO_LONG); + OSAPI_TEST_FUNCTION_RC( + OS_TaskCreate(NULL, NULL, NULL, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), + OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC( + OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), + OS_ERR_INVALID_SIZE); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); + OSAPI_TEST_FUNCTION_RC( + OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(128), OSAL_PRIORITY_C(0), 0), + OS_ERR_NAME_TOO_LONG); } void Test_OS_TaskDelete(void) @@ -135,7 +143,7 @@ void Test_OS_TaskDelete(void) UtAssert_True(actual == expected, "OS_TaskDelete() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(UT_TestHook_Count == 1, "UT_TestHook_Count (%lu) == 1", (unsigned long)UT_TestHook_Count); - UT_SetForceFail(UT_KEY(OS_TaskDelete_Impl), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskDelete_Impl), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_TaskDelete(UT_OBJID_1), OS_ERROR); UtAssert_True(UT_TestHook_Count == 1, "UT_TestHook_Count (%lu) == 1", (unsigned long)UT_TestHook_Count); @@ -148,14 +156,6 @@ void Test_OS_TaskExit(void) * Test Case For: * void OS_TaskExit() */ - uint32 local_index = 0; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.active_id = UT_OBJID_1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); OS_TaskExit(); @@ -180,11 +180,9 @@ void Test_OS_TaskSetPriority(void) * int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority) */ int32 expected = OS_SUCCESS; - int32 actual = OS_TaskSetPriority(UT_OBJID_1, 1); + int32 actual = OS_TaskSetPriority(UT_OBJID_1, OSAL_PRIORITY_C(1)); UtAssert_True(actual == expected, "OS_TaskSetPriority() (%ld) == OS_SUCCESS", (long)actual); - - OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority(UT_OBJID_1, 10 + OS_MAX_TASK_PRIORITY), OS_ERR_INVALID_PRIORITY); } void Test_OS_TaskRegister(void) { @@ -207,11 +205,11 @@ void Test_OS_TaskGetId(void) osal_id_t objid; idbuf.val = 5555; - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), idbuf.val); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), idbuf.val); objid = OS_TaskGetId(); OSAPI_TEST_OBJID(objid, ==, idbuf.id); - UT_SetForceFail(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); objid = OS_TaskGetId(); OSAPI_TEST_OBJID(objid, ==, OS_OBJECT_ID_UNDEFINED); } @@ -226,11 +224,11 @@ void Test_OS_TaskGetIdByName(void) int32 actual = ~OS_SUCCESS; osal_id_t objid = OS_OBJECT_ID_UNDEFINED; - UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_TaskGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_TaskGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_TaskGetIdByName(&objid, "NF"); @@ -245,20 +243,14 @@ void Test_OS_TaskGetInfo(void) * Test Case For: * int32 OS_TaskGetInfo (uint32 task_id, OS_task_prop_t *task_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_task_prop_t task_prop; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - OS_task_table[1].stack_size = 222; - OS_task_table[1].priority = 333; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_task_prop_t task_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_TASK, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + OS_task_table[1].stack_size = OSAL_SIZE_C(222); + OS_task_table[1].priority = OSAL_PRIORITY_C(133); + actual = OS_TaskGetInfo(UT_OBJID_1, &task_prop); UtAssert_True(actual == expected, "OS_TaskGetInfo() (%ld) == OS_SUCCESS", (long)actual); @@ -266,10 +258,10 @@ void Test_OS_TaskGetInfo(void) UtAssert_True(strcmp(task_prop.name, "ABC") == 0, "task_prop.name (%s) == ABC", task_prop.name); UtAssert_True(task_prop.stack_size == 222, "task_prop.stack_size (%lu) == 222", (unsigned long)task_prop.stack_size); - UtAssert_True(task_prop.priority == 333, "task_prop.priority (%lu) == 333", (unsigned long)task_prop.priority); + UtAssert_True(task_prop.priority == 133, "task_prop.priority (%lu) == 133", (unsigned long)task_prop.priority); - OS_task_table[1].stack_size = 0; - OS_task_table[1].priority = 0; + OS_task_table[1].stack_size = OSAL_SIZE_C(0); + OS_task_table[1].priority = OSAL_PRIORITY_C(0); OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo(OS_OBJECT_ID_UNDEFINED, NULL), OS_INVALID_POINTER); } @@ -283,7 +275,7 @@ void Test_OS_TaskInstallDeleteHandler(void) int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1); actual = OS_TaskInstallDeleteHandler(UT_TestHook); UtAssert_True(actual == expected, "OS_TaskInstallDeleteHandler() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(OS_task_table[1].delete_hook_pointer == UT_TestHook, @@ -325,17 +317,17 @@ void Test_OS_TaskFindIdBySystemData(void) actual = OS_TaskFindIdBySystemData(NULL, &test_sysdata, sizeof(test_sysdata)); UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OS_TaskValidateSystemData_Impl), expected); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskValidateSystemData_Impl), expected); actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskValidateSystemData_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskValidateSystemData_Impl)); /* Test search failure */ expected = OS_ERR_NAME_NOT_FOUND; - UT_SetForceFail(UT_KEY(OS_ObjectIdGetBySearch), expected); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), expected); actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdGetBySearch)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch)); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-time.c b/src/unit-test-coverage/shared/src/coveragetest-time.c index d62a28fb1..9e90abcc5 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -81,33 +81,33 @@ void Test_OS_TimerAdd(void) actual = OS_TimerAdd(NULL, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_API_NAME); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_ERR_NAME_TOO_LONG; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); - expected = OS_TIMER_ERR_INVALID_ARGS; + expected = OS_INVALID_POINTER; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, NULL, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); - UT_SetForceFail(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); expected = OS_ERROR; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERROR", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdGetById)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetById)); - UT_SetForceFail(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); expected = OS_ERROR; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERROR", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdAllocateNew)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew)); } void Test_OS_TimerCreate(void) @@ -116,11 +116,11 @@ void Test_OS_TimerCreate(void) * Test Case For: * int32 OS_TimerCreate(uint32 *timer_id, const char *timer_name, uint32 *accuracy, OS_TimerCallback_t callback_ptr) */ - int32 expected = OS_SUCCESS; - osal_id_t objid = OS_OBJECT_ID_UNDEFINED; - uint32 local_id = 0xFFFFFFFF; - uint32 accuracy = 0xFFFFFFFF; - int32 actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); + int32 expected = OS_SUCCESS; + osal_id_t objid = OS_OBJECT_ID_UNDEFINED; + osal_index_t local_id; + uint32 accuracy = 0xFFFFFFFF; + int32 actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_SUCCESS", (long)actual); @@ -139,21 +139,29 @@ void Test_OS_TimerCreate(void) actual = OS_TimerCreate(&objid, NULL, NULL, NULL); UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_INVALID_POINTER", (long)actual); - expected = OS_TIMER_ERR_INVALID_ARGS; + expected = OS_INVALID_POINTER; actual = OS_TimerCreate(&objid, "UT", &accuracy, NULL); UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); - UT_SetForceFail(UT_KEY(OS_TimeBaseCreate), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_TimeBaseCreate), OS_ERROR); expected = OS_ERROR; actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_ERROR", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TimeBaseCreate)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TimeBaseCreate)); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_API_NAME); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_ERR_NAME_TOO_LONG; actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); + + /* This function creates its own timebase. If OS_DoTimerAdd() fails this timebase needs to be deleted */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + expected = OS_ERROR; + actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); + UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_ERROR", (long)actual); + UT_ResetState(UT_KEY(OS_ObjectIdGetById)); + UtAssert_STUB_COUNT(OS_TimeBaseDelete, 1); } void Test_OS_TimerSet(void) @@ -170,10 +178,11 @@ void Test_OS_TimerSet(void) actual = OS_TimerSet(UT_OBJID_1, 0, 1); UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_SUCCESS", (long)actual); - OS_timecb_table[2].timebase_ref = 0; - OS_timecb_table[2].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; - OS_global_timebase_table[0].active_id = UT_OBJID_2; - actual = OS_TimerSet(UT_OBJID_2, 0, 1); + OS_timecb_table[2].timebase_token.obj_type = OS_OBJECT_TYPE_OS_TIMEBASE; + OS_timecb_table[2].timebase_token.obj_id = UT_OBJID_2; + OS_timecb_table[2].timebase_token.obj_idx = UT_INDEX_0; + OS_timecb_table[2].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; + actual = OS_TimerSet(UT_OBJID_2, 0, 1); UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_SUCCESS", (long)actual); memset(OS_timecb_table, 0, sizeof(OS_timecb_table)); @@ -181,11 +190,11 @@ void Test_OS_TimerSet(void) actual = OS_TimerSet(UT_OBJID_2, UINT32_MAX, UINT32_MAX); UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerSet(UT_OBJID_2, 0, 1); UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); } void Test_OS_TimerDelete(void) @@ -194,40 +203,67 @@ void Test_OS_TimerDelete(void) * Test Case For: * int32 OS_TimerDelete(uint32 timer_id) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TimerDelete(UT_OBJID_1); + int32 expected; + int32 actual; + osal_id_t timebase_id; + osal_id_t timer_objid_1, timer_objid_2; + OS_timebase_internal_record_t *timebase; + OS_object_token_t timebase_token; + uint32 accuracy; + expected = OS_SUCCESS; + + /* The ObjIds in the ring need to match what will be in the token */ + /* Get a "timebase" from the stub so the objid will validate */ + OS_TimeBaseCreate(&timebase_id, "ut", NULL); + OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &timebase_token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, timebase_token); + OS_TimerAdd(&timer_objid_1, "UT1", timebase_id, UT_TimerArgCallback, NULL); + OS_TimerAdd(&timer_objid_2, "UT2", timebase_id, UT_TimerArgCallback, NULL); + + /* Sanity check: After adding the two timers the "first_cb" should be pointing at timer 2 */ + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_2), "First CB at timer 2"); + + actual = OS_TimerDelete(timer_objid_2); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); - OS_timecb_table[1].timebase_ref = 0; - OS_timecb_table[2].timebase_ref = 0; - OS_timecb_table[2].next_ref = 1; - OS_timecb_table[1].next_ref = 1; - OS_timebase_table[0].first_cb = UT_OBJID_2; - actual = OS_TimerDelete(UT_OBJID_2); + /* After deleting timer 2 the "first_cb" should be pointing at timer 1 */ + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_1), "First CB at timer 1"); + + /* Re-add timer 2 again */ + OS_TimerAdd(&timer_objid_2, "UT2", timebase_id, UT_TimerArgCallback, NULL); + + /* Sanity check: the "first_cb" should be pointing at timer 2 again */ + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_2), "First CB at timer 2"); + + /* delete timer 1 */ + actual = OS_TimerDelete(timer_objid_1); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); - OS_timebase_table[0].first_cb = UT_OBJID_1; - actual = OS_TimerDelete(UT_OBJID_1); + /* The "first_cb" should be still pointing at timer 2 */ + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_2), "First CB at timer 2"); + + actual = OS_TimerDelete(timer_objid_2); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); + /* The "first_cb" should be undefined */ + UtAssert_True(!OS_ObjectIdDefined(timebase->first_cb), "First CB at OS_OBJECT_ID_UNDEFINED"); + /* verify deletion of the dedicated timebase objects * these are implicitly created as part of timer creation for API compatibility */ - OS_TimeBaseCreate(&OS_global_timebase_table[0].active_id, "ut", NULL); - OS_timecb_table[1].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; - OS_timecb_table[1].timebase_ref = 0; - actual = OS_TimerDelete(UT_OBJID_1); + OS_TimerCreate(&timer_objid_1, "UT1", &accuracy, UT_TimerCallback); + actual = OS_TimerDelete(timer_objid_1); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(UT_GetStubCount(UT_KEY(OS_TimeBaseDelete)) == 1, "OS_TimerDelete() invoked OS_TimeBaseDelete()"); memset(OS_timecb_table, 0, sizeof(OS_timecb_table)); memset(OS_timebase_table, 0, sizeof(OS_timebase_table)); - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerDelete(UT_OBJID_2); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); } void Test_OS_TimerGetIdByName(void) @@ -240,10 +276,10 @@ void Test_OS_TimerGetIdByName(void) int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_TimerGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_TimerGetIdByName() (%ld) == OS_SUCCESS", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_TimerGetIdByName(&objid, "NF"); @@ -253,11 +289,11 @@ void Test_OS_TimerGetIdByName(void) actual = OS_TimerGetIdByName(NULL, "NF"); UtAssert_True(actual == expected, "OS_TimerGetIdByName() (%ld) == %ld", (long)actual, (long)expected); - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerGetIdByName(&objid, "NF"); UtAssert_True(actual == expected, "OS_TimerGetIdByName() (%ld) == %ld", (long)actual, (long)expected); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); } void Test_OS_TimerGetInfo(void) @@ -266,21 +302,18 @@ void Test_OS_TimerGetInfo(void) * Test Case For: * int32 OS_TimerGetInfo (uint32 timer_id, OS_timer_prop_t *timer_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_timer_prop_t timer_prop; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - OS_timecb_table[1].interval_time = 2222; - OS_timecb_table[1].timebase_ref = 0; - OS_timebase_table[0].accuracy_usec = 3333; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_timer_prop_t timer_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_TIMECB, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + + OS_timecb_table[1].interval_time = 2222; + OS_timecb_table[1].timebase_token.obj_type = OS_OBJECT_TYPE_OS_TIMEBASE; + OS_timecb_table[1].timebase_token.obj_id = UT_OBJID_1; + OS_timecb_table[1].timebase_token.obj_idx = UT_INDEX_0; + OS_timebase_table[0].accuracy_usec = 3333; + actual = OS_TimerGetInfo(UT_OBJID_1, &timer_prop); UtAssert_True(actual == expected, "OS_TimerGetInfo() (%ld) == OS_SUCCESS", (long)actual); @@ -293,11 +326,11 @@ void Test_OS_TimerGetInfo(void) actual = OS_TimerGetInfo(UT_OBJID_1, NULL); UtAssert_True(actual == expected, "OS_TimerGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerGetInfo(UT_OBJID_1, &timer_prop); UtAssert_True(actual == expected, "OS_TimerGetInfo() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index 9484cb9c0..52489b730 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -38,7 +38,7 @@ static uint32 TimerSyncCount = 0; static uint32 TimerSyncRetVal = 0; static uint32 TimeCB = 0; -static uint32 UT_TimerSync(uint32 timer_id) +static uint32 UT_TimerSync(osal_id_t timer_id) { ++TimerSyncCount; return TimerSyncRetVal; @@ -99,13 +99,13 @@ void Test_OS_TimeBaseCreate(void) actual = OS_TimeBaseCreate(NULL, NULL, NULL); UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_API_NAME); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_ERR_NAME_TOO_LONG; actual = OS_TimeBaseCreate(&objid, "UT", UT_TimerSync); UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimeBaseCreate(&objid, "UT", UT_TimerSync); UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); @@ -128,7 +128,7 @@ void Test_OS_TimeBaseSet(void) UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); /* test error paths */ - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimeBaseSet(UT_OBJID_1, 1000, 1000); UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); @@ -146,7 +146,7 @@ void Test_OS_TimeBaseDelete(void) UtAssert_True(actual == expected, "OS_TimeBaseDelete() (%ld) == OS_SUCCESS", (long)actual); /* test error paths */ - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimeBaseDelete(UT_OBJID_1); UtAssert_True(actual == expected, "OS_TimeBaseDelete() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); @@ -162,11 +162,11 @@ void Test_OS_TimeBaseGetIdByName(void) int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_TimeBaseGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_TimeBaseGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_TimeBaseGetIdByName(&objid, "NF"); @@ -177,7 +177,7 @@ void Test_OS_TimeBaseGetIdByName(void) actual = OS_TimeBaseGetIdByName(NULL, NULL); UtAssert_True(actual == expected, "OS_TimeBaseGetIdByName() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimeBaseGetIdByName(&objid, "NF"); UtAssert_True(actual == expected, "OS_TimeBaseGetIdByName() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); @@ -189,21 +189,16 @@ void Test_OS_TimeBaseGetInfo(void) * Test Case For: * int32 OS_TimeBaseGetInfo (uint32 timebase_id, OS_timebase_prop_t *timebase_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_timebase_prop_t timebase_prop; - uint32 local_index = 1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_timebase_prop_t timebase_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_TIMEBASE, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + OS_timebase_table[1].nominal_interval_time = 2222; OS_timebase_table[1].freerun_time = 3333; OS_timebase_table[1].accuracy_usec = 4444; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + actual = OS_TimeBaseGetInfo(UT_OBJID_1, &timebase_prop); UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_SUCCESS", (long)actual); @@ -222,7 +217,7 @@ void Test_OS_TimeBaseGetInfo(void) actual = OS_TimeBaseGetInfo(UT_OBJID_1, NULL); UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimeBaseGetInfo(UT_OBJID_1, &timebase_prop); UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); @@ -239,6 +234,10 @@ void Test_OS_TimeBaseGetFreeRun(void) int32 actual = OS_TimeBaseGetFreeRun(UT_OBJID_1, &freerun); UtAssert_True(actual == expected, "OS_TimeBaseGetFreeRun() (%ld) == OS_SUCCESS", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_TimeBaseGetFreeRun(UT_OBJID_1, NULL); + UtAssert_True(actual == expected, "OS_TimeBaseGetFreeRun() (%ld) == OS_INVALID_POINTER", (long)actual); } void Test_OS_TimeBase_CallbackThread(void) @@ -247,41 +246,41 @@ void Test_OS_TimeBase_CallbackThread(void) * Test Case For: * void OS_TimeBase_CallbackThread(uint32 timebase_id) */ - OS_common_record_t fake_record; - OS_common_record_t *recptr = &fake_record; - osal_id_t idbuf; + OS_common_record_t *recptr; + OS_object_token_t timecb_token; - memset(&fake_record, 0, sizeof(fake_record)); - fake_record.active_id = UT_OBJID_2; + recptr = &OS_global_timebase_table[2]; + memset(recptr, 0, sizeof(*recptr)); + recptr->active_id = UT_OBJID_2; + OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, UT_OBJID_1, &timecb_token); OS_timebase_table[2].external_sync = UT_TimerSync; - OS_timecb_table[0].wait_time = 2000; - OS_timecb_table[0].callback_ptr = UT_TimeCB; + OS_timebase_table[2].first_cb = timecb_token.obj_id; + OS_timecb_table[1].prev_cb = timecb_token.obj_id; + OS_timecb_table[1].next_cb = timecb_token.obj_id; + OS_timecb_table[1].wait_time = 2000; + OS_timecb_table[1].callback_ptr = UT_TimeCB; TimerSyncCount = 0; TimerSyncRetVal = 0; TimeCB = 0; - idbuf = UT_OBJID_2; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &idbuf, sizeof(idbuf), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &recptr, sizeof(recptr), false); + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_TIMEBASE, UT_INDEX_2); UT_SetHookFunction(UT_KEY(OS_TimeBaseLock_Impl), ClearObjectsHook, recptr); OS_TimeBase_CallbackThread(UT_OBJID_2); UtAssert_True(TimerSyncCount == 11, "TimerSyncCount (%lu) == 11", (unsigned long)TimerSyncCount); UT_ResetState(UT_KEY(OS_TimeBaseLock_Impl)); - TimerSyncCount = 0; - TimerSyncRetVal = 1000; - fake_record.active_id = UT_OBJID_2; - idbuf = UT_OBJID_2; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &idbuf, sizeof(idbuf), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &recptr, sizeof(recptr), false); + TimerSyncCount = 0; + TimerSyncRetVal = 1000; + recptr->active_id = UT_OBJID_2; + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_TIMEBASE, UT_INDEX_2); UT_SetHookFunction(UT_KEY(OS_TimeBaseLock_Impl), ClearObjectsHook, recptr); OS_TimeBase_CallbackThread(UT_OBJID_2); /* Check that the TimeCB function was called */ UtAssert_True(TimeCB > 0, "TimeCB (%lu) > 0", (unsigned long)TimeCB); - UT_SetForceFail(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); OS_TimeBase_CallbackThread(UT_OBJID_2); } diff --git a/src/unit-test-coverage/shared/src/os-shared-coverage-support.c b/src/unit-test-coverage/shared/src/os-shared-coverage-support.c new file mode 100644 index 000000000..a857abb8a --- /dev/null +++ b/src/unit-test-coverage/shared/src/os-shared-coverage-support.c @@ -0,0 +1,114 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file os-shared-coverage-support.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ +#include "os-shared-coveragetest.h" +#include "os-shared-idmap.h" +#include "os-shared-common.h" + +void OS_UT_SetupIterator(osal_objtype_t obj_type, osal_index_t first_idx, osal_index_t num_entries) +{ + OS_object_token_t tokenlist[num_entries]; + osal_index_t idx = OSAL_INDEX_C(0); + + while (idx < num_entries) + { + tokenlist[idx].lock_mode = OS_LOCK_MODE_NONE; + tokenlist[idx].obj_type = obj_type; + tokenlist[idx].obj_idx = first_idx + idx; + tokenlist[idx].obj_id = OS_ObjectIdFromInteger((obj_type << OS_OBJECT_TYPE_SHIFT) | tokenlist[idx].obj_idx); + ++idx; + } + + UT_SetDataBuffer(UT_KEY(OS_ObjectIdIteratorGetNext), tokenlist, sizeof(OS_object_token_t) * num_entries, true); +} + +void OS_UT_SetupTestTargetIndex(osal_objtype_t obj_type, osal_index_t test_idx) +{ + OS_object_token_t token; + + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_type = obj_type; + token.obj_idx = test_idx; + token.obj_id = OS_ObjectIdFromInteger((obj_type << OS_OBJECT_TYPE_SHIFT) | test_idx); + + UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &token, sizeof(OS_object_token_t), true); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_SUCCESS); +} + +void OS_UT_SetupBasicInfoTest(osal_objtype_t obj_type, osal_index_t test_idx, const char *name, osal_id_t creator) +{ + OS_common_record_t *rptr; + + switch (obj_type) + { + case OS_OBJECT_TYPE_OS_TASK: + rptr = OS_global_task_table; + break; + case OS_OBJECT_TYPE_OS_QUEUE: + rptr = OS_global_queue_table; + break; + case OS_OBJECT_TYPE_OS_BINSEM: + rptr = OS_global_bin_sem_table; + break; + case OS_OBJECT_TYPE_OS_COUNTSEM: + rptr = OS_global_count_sem_table; + break; + case OS_OBJECT_TYPE_OS_MUTEX: + rptr = OS_global_mutex_table; + break; + case OS_OBJECT_TYPE_OS_CONSOLE: + rptr = OS_global_console_table; + break; + case OS_OBJECT_TYPE_OS_MODULE: + rptr = OS_global_module_table; + break; + case OS_OBJECT_TYPE_OS_FILESYS: + rptr = OS_global_filesys_table; + break; + case OS_OBJECT_TYPE_OS_TIMEBASE: + rptr = OS_global_timebase_table; + break; + case OS_OBJECT_TYPE_OS_TIMECB: + rptr = OS_global_timecb_table; + break; + case OS_OBJECT_TYPE_OS_STREAM: + rptr = OS_global_stream_table; + break; + case OS_OBJECT_TYPE_OS_DIR: + rptr = OS_global_dir_table; + break; + default: + rptr = NULL; + break; + } + + rptr += test_idx; + memset(rptr, 0, sizeof(*rptr)); + rptr->creator = UT_OBJID_OTHER; + rptr->name_entry = "ABC"; + + OS_UT_SetupTestTargetIndex(obj_type, test_idx); +} diff --git a/src/unit-test-coverage/shared/src/os-shared-coveragetest.h b/src/unit-test-coverage/shared/src/os-shared-coveragetest.h index 86c23d952..bfefc17d0 100644 --- a/src/unit-test-coverage/shared/src/os-shared-coveragetest.h +++ b/src/unit-test-coverage/shared/src/os-shared-coveragetest.h @@ -25,13 +25,13 @@ * */ -#ifndef INCLUDE_OS_SHARED_COVERAGETEST_H_ -#define INCLUDE_OS_SHARED_COVERAGETEST_H_ +#ifndef OS_SHARED_COVERAGETEST_H +#define OS_SHARED_COVERAGETEST_H #include #include #include -#include +#include "osapi.h" #include "os-shared-idmap.h" @@ -74,6 +74,35 @@ typedef union #define UT_OBJID_OTHER ((osal_id_t) {0x12345}) #define UT_OBJID_MAX ((osal_id_t) {0xFFFFFFFF}) +#define UT_INDEX_0 OSAL_INDEX_C(0) +#define UT_INDEX_1 OSAL_INDEX_C(1) +#define UT_INDEX_2 OSAL_INDEX_C(2) + +/* + * Set up an coverage test iterator of the given type. + * + * The OS_ObjectIdIteratorGetNext() stub routine will be configured + * to return the given range of IDs. + */ +void OS_UT_SetupIterator(osal_objtype_t obj_type, osal_index_t first_idx, osal_index_t num_entries); + +/* + * Set up the UT stubs for the target entry of the next test case. + * + * This configures the OS_ObjectIdGetById() stub to return a token + * that refers to the given entry index. + */ +void OS_UT_SetupTestTargetIndex(osal_objtype_t obj_type, osal_index_t test_idx); + +/* + * Set up the UT stubs for a "get info" test. + * + * This sets up a single entry in the global table with the given name and + * ID value. It also configures the OS_ObjectIdGetById() stub to return a + * token that refers to the same table entry. + */ +void OS_UT_SetupBasicInfoTest(osal_objtype_t obj_type, osal_index_t test_idx, const char *name, osal_id_t creator); + /* * Setup function prior to every test */ @@ -84,4 +113,4 @@ void Osapi_Test_Setup(void); */ void Osapi_Test_Teardown(void); -#endif /* INCLUDE_OS_SHARED_COVERAGETEST_H_ */ +#endif /* OS_SHARED_COVERAGETEST_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_arpa_inet.h b/src/unit-test-coverage/ut-stubs/inc/OCS_arpa_inet.h index 09ea6539e..77128e614 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_arpa_inet.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_arpa_inet.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for arpa/inet.h */ -#ifndef _OSAL_STUB_ARPA_INET_H_ -#define _OSAL_STUB_ARPA_INET_H_ +#ifndef OCS_ARPA_INET_H +#define OCS_ARPA_INET_H #include @@ -39,4 +39,4 @@ extern const char *OCS_inet_ntop(int af, const void *cp, char *buf, size_t len); extern int OCS_inet_pton(int af, const char *cp, void *buf); -#endif /* _OSAL_STUB_ARPA_INET_H_ */ +#endif /* OCS_ARPA_INET_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_assert.h b/src/unit-test-coverage/ut-stubs/inc/OCS_assert.h index da4f69005..fc23e44d3 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_assert.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_assert.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for assert.h */ -#ifndef _OSAL_STUB_ASSERT_H_ -#define _OSAL_STUB_ASSERT_H_ +#ifndef OCS_ASSERT_H +#define OCS_ASSERT_H #include @@ -38,4 +38,4 @@ void OCS_assert(bool expression); -#endif /* _OSAL_STUB_ASSERT_H_ */ +#endif /* OCS_ASSERT_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_basetypes.h b/src/unit-test-coverage/ut-stubs/inc/OCS_basetypes.h index 368286bfd..0d1098e6f 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_basetypes.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_basetypes.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub basic data types */ -#ifndef _OSAL_STUB_BASETYPES_H_ -#define _OSAL_STUB_BASETYPES_H_ +#ifndef OCS_BASETYPES_H +#define OCS_BASETYPES_H /* * NOTE: These header files are intentionally _not_ overridden @@ -36,4 +36,4 @@ #include /* for correct INT_MAX, etc. */ #include /* for correct boolean semantics */ -#endif /* _OSAL_STUB_BASETYPES_H_ */ +#endif /* OCS_BASETYPES_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_blkIo.h b/src/unit-test-coverage/ut-stubs/inc/OCS_blkIo.h index 9883751e7..8816c7f42 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_blkIo.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_blkIo.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub basic data types */ -#ifndef _OSAL_STUB_BLKIO_H_ -#define _OSAL_STUB_BLKIO_H_ +#ifndef OCS_BLKIO_H +#define OCS_BLKIO_H #include #include @@ -32,4 +32,4 @@ typedef struct OCS_BLK_DEV } OCS_BLK_DEV; typedef OCS_BLK_DEV *OCS_BLK_DEV_ID; -#endif /* _OSAL_STUB_BLKIO_H_ */ +#endif /* OCS_BLKIO_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_bsp-impl.h b/src/unit-test-coverage/ut-stubs/inc/OCS_bsp-impl.h index 5cefc0938..f0a285402 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_bsp-impl.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_bsp-impl.h @@ -42,8 +42,8 @@ * BSP-provided console or debug terminal device. */ -#ifndef INCLUDE_OCS_BSP_IMPL_H_ -#define INCLUDE_OCS_BSP_IMPL_H_ +#ifndef OCS_BSP_IMPL_H +#define OCS_BSP_IMPL_H #include @@ -70,7 +70,7 @@ Note: This should write the string as-is without buffering. ------------------------------------------------------------------*/ -extern void OCS_OS_BSP_ConsoleOutput_Impl(const char *Str, uint32_t DataLen); +extern void OCS_OS_BSP_ConsoleOutput_Impl(const char *Str, size_t DataLen); /*---------------------------------------------------------------- Function: OS_BSP_ConsoleSetMode_Impl @@ -90,4 +90,4 @@ extern void OCS_OS_BSP_ConsoleOutput_Impl(const char *Str, uint32_t DataLen); ------------------------------------------------------------------*/ extern void OCS_OS_BSP_ConsoleSetMode_Impl(uint32_t ModeBits); -#endif /* INCLUDE_OCS_BSP_IMPL_H_ */ +#endif /* OCS_BSP_IMPL_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_cbioLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_cbioLib.h index 0a7700f19..cfabf811b 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_cbioLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_cbioLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for cbioLib.h */ -#ifndef _OSAL_STUB_CBIOLIB_H_ -#define _OSAL_STUB_CBIOLIB_H_ +#ifndef OCS_CBIOLIB_H +#define OCS_CBIOLIB_H #include #include @@ -37,4 +37,4 @@ /* prototypes normally declared in cbioLib.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_CBIOLIB_H_ */ +#endif /* OCS_CBIOLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_complex.h b/src/unit-test-coverage/ut-stubs/inc/OCS_complex.h index ec467a2df..2e68e379d 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_complex.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_complex.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for complex.h */ -#ifndef _OSAL_STUB_COMPLEX_H_ -#define _OSAL_STUB_COMPLEX_H_ +#ifndef OCS_COMPLEX_H +#define OCS_COMPLEX_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in complex.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_COMPLEX_H_ */ +#endif /* OCS_COMPLEX_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_ctype.h b/src/unit-test-coverage/ut-stubs/inc/OCS_ctype.h index b74c2d2e2..f68aa8b0b 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_ctype.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_ctype.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ctype.h */ -#ifndef _OSAL_STUB_CTYPE_H_ -#define _OSAL_STUB_CTYPE_H_ +#ifndef OCS_CTYPE_H +#define OCS_CTYPE_H #include @@ -38,4 +38,4 @@ extern int OCS_isgraph(int c); -#endif /* _OSAL_STUB_CTYPE_H_ */ +#endif /* OCS_CTYPE_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_dirent.h b/src/unit-test-coverage/ut-stubs/inc/OCS_dirent.h index 3e0768ec6..af9ce8418 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_dirent.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_dirent.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for dirent.h */ -#ifndef _OSAL_STUB_DIRENT_H_ -#define _OSAL_STUB_DIRENT_H_ +#ifndef OCS_DIRENT_H +#define OCS_DIRENT_H #include @@ -48,4 +48,4 @@ extern OCS_DIR * OCS_opendir(const char *name); extern struct OCS_dirent *OCS_readdir(OCS_DIR *dirp); extern void OCS_rewinddir(OCS_DIR *dirp); -#endif /* _OSAL_STUB_DIRENT_H_ */ +#endif /* OCS_DIRENT_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_dlfcn.h b/src/unit-test-coverage/ut-stubs/inc/OCS_dlfcn.h index 3e1016218..fe8934a17 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_dlfcn.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_dlfcn.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for dlfcn.h */ -#ifndef _OSAL_STUB_DLFCN_H_ -#define _OSAL_STUB_DLFCN_H_ +#ifndef OCS_DLFCN_H +#define OCS_DLFCN_H #include @@ -41,4 +41,4 @@ extern char *OCS_dlerror(void); extern void *OCS_dlopen(const char *file, int flags); extern void *OCS_dlsym(void *handle, const char *name); -#endif /* _OSAL_STUB_DLFCN_H_ */ +#endif /* OCS_DLFCN_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_dosFsLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_dosFsLib.h index 00951db11..1f783ecf2 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_dosFsLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_dosFsLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for dosFsLib.h */ -#ifndef _OSAL_STUB_DOSFSLIB_H_ -#define _OSAL_STUB_DOSFSLIB_H_ +#ifndef OCS_DOSFSLIB_H +#define OCS_DOSFSLIB_H #include #include @@ -43,4 +43,4 @@ /* ----------------------------------------- */ extern OCS_STATUS OCS_dosFsVolFormat(char *path, int opt, OCS_FUNCPTR pPromptFunc); -#endif /* _OSAL_STUB_DOSFSLIB_H_ */ +#endif /* OCS_DOSFSLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_drv_hdisk_ataDrv.h b/src/unit-test-coverage/ut-stubs/inc/OCS_drv_hdisk_ataDrv.h index c9970c19a..65c63d700 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_drv_hdisk_ataDrv.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_drv_hdisk_ataDrv.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for drv/hdisk/ataDrv.h */ -#ifndef _OSAL_STUB_DRV_HDISK_ATADRV_H_ -#define _OSAL_STUB_DRV_HDISK_ATADRV_H_ +#ifndef OCS_DRV_HDISK_ATADRV_H +#define OCS_DRV_HDISK_ATADRV_H #include #include @@ -39,4 +39,4 @@ /* ----------------------------------------- */ extern OCS_BLK_DEV *OCS_ataDevCreate(int ctrl, int drive, unsigned int nBlocks, unsigned int blkOffset); -#endif /* _OSAL_STUB_DRV_HDISK_ATADRV_H_ */ +#endif /* OCS_DRV_HDISK_ATADRV_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_errno.h b/src/unit-test-coverage/ut-stubs/inc/OCS_errno.h index 98bfc8847..79c123e0d 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_errno.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_errno.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for errno.h */ -#ifndef _OSAL_STUB_ERRNO_H_ -#define _OSAL_STUB_ERRNO_H_ +#ifndef OCS_ERRNO_H +#define OCS_ERRNO_H #include @@ -30,10 +30,14 @@ /* POSIX-specific errnos */ #define OCS_EINTR 0x1801 #define OCS_EAGAIN 0x1802 +#define OCS_EEXIST 0x180a #define OCS_EINVAL 0x1803 #define OCS_EMSGSIZE 0x1804 #define OCS_ETIMEDOUT 0x1805 #define OCS_ESPIPE 0x1806 +#define OCS_ENOTSUP 0x1807 +#define OCS_ENOSYS 0x1808 +#define OCS_EROFS 0x1809 /* ----------------------------------------- */ /* types normally defined in errno.h */ @@ -45,4 +49,4 @@ extern int OCS_errno; -#endif /* _OSAL_STUB_ERRNO_H_ */ +#endif /* OCS_ERRNO_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_errnoLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_errnoLib.h index 27bdde88f..73b0c2039 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_errnoLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_errnoLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for errnoLib.h */ -#ifndef _OSAL_STUB_ERRNOLIB_H_ -#define _OSAL_STUB_ERRNOLIB_H_ +#ifndef OCS_ERRNOLIB_H +#define OCS_ERRNOLIB_H #include #include @@ -39,4 +39,4 @@ extern int OCS_errnoGet(void); -#endif /* _OSAL_STUB_ERRNOLIB_H_ */ +#endif /* OCS_ERRNOLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_fcntl.h b/src/unit-test-coverage/ut-stubs/inc/OCS_fcntl.h index 1aec16909..b1ab963f9 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_fcntl.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_fcntl.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for fcntl.h */ -#ifndef _OSAL_STUB_FCNTL_H_ -#define _OSAL_STUB_FCNTL_H_ +#ifndef OCS_FCNTL_H +#define OCS_FCNTL_H #include @@ -38,6 +38,10 @@ * * These are exposed to apps through fcntl.h and sys/stat.h */ +#define OCS_S_IRWXO 0x1110 +#define OCS_S_IRWXG 0x2220 +#define OCS_S_IRWXU 0x4440 + #define OCS_S_IXOTH 0x1000 #define OCS_S_IXGRP 0x2000 #define OCS_S_IXUSR 0x4000 @@ -77,4 +81,4 @@ extern int OCS_fcntl(int fd, int cmd, ...); extern int OCS_open(const char *file, int oflag, ...); -#endif /* _OSAL_STUB_FCNTL_H_ */ +#endif /* OCS_FCNTL_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_fenv.h b/src/unit-test-coverage/ut-stubs/inc/OCS_fenv.h index fd6d80ceb..aba58fad0 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_fenv.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_fenv.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for fenv.h */ -#ifndef _OSAL_STUB_FENV_H_ -#define _OSAL_STUB_FENV_H_ +#ifndef OCS_FENV_H +#define OCS_FENV_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in fenv.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_FENV_H_ */ +#endif /* OCS_FENV_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_float.h b/src/unit-test-coverage/ut-stubs/inc/OCS_float.h index afe94b3e1..97cab7bbc 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_float.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_float.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for float.h */ -#ifndef _OSAL_STUB_FLOAT_H_ -#define _OSAL_STUB_FLOAT_H_ +#ifndef OCS_FLOAT_H +#define OCS_FLOAT_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in float.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_FLOAT_H_ */ +#endif /* OCS_FLOAT_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_hostLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_hostLib.h index 6198581e8..ed9e020a3 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_hostLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_hostLib.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OCS_HOSTLIB_H_ -#define INCLUDE_OCS_HOSTLIB_H_ +#ifndef OCS_HOSTLIB_H +#define OCS_HOSTLIB_H #include #include @@ -44,4 +44,4 @@ /* ----------------------------------------- */ extern int OCS_hostGetByName(char *name); -#endif /* INCLUDE_OCS_HOSTLIB_H_ */ +#endif /* OCS_HOSTLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_intLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_intLib.h index 1a0b2c0bb..724f8396b 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_intLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_intLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for intLib.h */ -#ifndef _OSAL_STUB_INTLIB_H_ -#define _OSAL_STUB_INTLIB_H_ +#ifndef OCS_INTLIB_H +#define OCS_INTLIB_H #include #include @@ -44,4 +44,4 @@ extern int OCS_intLock(void); extern int OCS_intUnlock(int lockKey); extern OCS_VOIDFUNCPTR *OCS_INUM_TO_IVEC(unsigned int ui); -#endif /* _OSAL_STUB_INTLIB_H_ */ +#endif /* OCS_INTLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_inttypes.h b/src/unit-test-coverage/ut-stubs/inc/OCS_inttypes.h index 205ca36d0..0b326e904 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_inttypes.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_inttypes.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for inttypes.h */ -#ifndef _OSAL_STUB_INTTYPES_H_ -#define _OSAL_STUB_INTTYPES_H_ +#ifndef OCS_INTTYPES_H +#define OCS_INTTYPES_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in inttypes.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_INTTYPES_H_ */ +#endif /* OCS_INTTYPES_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_ioLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_ioLib.h index 88138eaff..6e8dd63d7 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_ioLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_ioLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ioLib.h */ -#ifndef _OSAL_STUB_IOLIB_H_ -#define _OSAL_STUB_IOLIB_H_ +#ifndef OCS_IOLIB_H +#define OCS_IOLIB_H #include #include @@ -42,4 +42,4 @@ extern int OCS_ioctl(int fd, unsigned long request, ...); -#endif /* _OSAL_STUB_IOLIB_H_ */ +#endif /* OCS_IOLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_iv.h b/src/unit-test-coverage/ut-stubs/inc/OCS_iv.h index c43c74831..5ddb8182e 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_iv.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_iv.h @@ -19,9 +19,9 @@ */ /* OSAL coverage stub replacement for iv.h */ -#ifndef _OSAL_STUB_IV_H_ -#define _OSAL_STUB_IV_H_ +#ifndef OCS_IV_H +#define OCS_IV_H #include -#endif /* _OSAL_STUB_IV_H_ */ +#endif /* OCS_IV_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_loadLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_loadLib.h index 06e83f4b8..b9eb5abc6 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_loadLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_loadLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for loadLib.h */ -#ifndef _OSAL_STUB_LOADLIB_H_ -#define _OSAL_STUB_LOADLIB_H_ +#ifndef OCS_LOADLIB_H +#define OCS_LOADLIB_H #include #include @@ -40,4 +40,4 @@ extern OCS_MODULE_ID OCS_loadModule(int fd, unsigned int symFlag); -#endif /* _OSAL_STUB_LOADLIB_H_ */ +#endif /* OCS_LOADLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_locale.h b/src/unit-test-coverage/ut-stubs/inc/OCS_locale.h index 5fe7584bc..40d070f8e 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_locale.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_locale.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for locale.h */ -#ifndef _OSAL_STUB_LOCALE_H_ -#define _OSAL_STUB_LOCALE_H_ +#ifndef OCS_LOCALE_H +#define OCS_LOCALE_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in locale.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_LOCALE_H_ */ +#endif /* OCS_LOCALE_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_logLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_logLib.h index 122326fce..0eb53f915 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_logLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_logLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for logLib.h */ -#ifndef _OSAL_STUB_LOGLIB_H_ -#define _OSAL_STUB_LOGLIB_H_ +#ifndef OCS_LOGLIB_H +#define OCS_LOGLIB_H #include #include @@ -37,4 +37,4 @@ /* prototypes normally declared in logLib.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_LOGLIB_H_ */ +#endif /* OCS_LOGLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_math.h b/src/unit-test-coverage/ut-stubs/inc/OCS_math.h index 2de714646..3b07bce2d 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_math.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_math.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for math.h */ -#ifndef _OSAL_STUB_MATH_H_ -#define _OSAL_STUB_MATH_H_ +#ifndef OCS_MATH_H +#define OCS_MATH_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in math.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_MATH_H_ */ +#endif /* OCS_MATH_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_memPartLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_memPartLib.h index c7c6a2b5c..d1201761a 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_memPartLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_memPartLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for memPartLib.h */ -#ifndef _OSAL_STUB_MEMPARTLIB_H_ -#define _OSAL_STUB_MEMPARTLIB_H_ +#ifndef OCS_MEMPARTLIB_H +#define OCS_MEMPARTLIB_H #include #include @@ -54,4 +54,4 @@ extern OCS_STATUS OCS_memPartInfoGet(OCS_PART_ID partId, /* partition ID extern OCS_PART_ID OCS_memSysPartId; -#endif /* _OSAL_STUB_MEMPARTLIB_H_ */ +#endif /* OCS_MEMPARTLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_moduleLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_moduleLib.h index 98637b23a..a7b3ca224 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_moduleLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_moduleLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for moduleLib.h */ -#ifndef _OSAL_STUB_MODULELIB_H_ -#define _OSAL_STUB_MODULELIB_H_ +#ifndef OCS_MODULELIB_H +#define OCS_MODULELIB_H #include #include @@ -58,4 +58,4 @@ typedef struct OCS_MODULE_INFO extern OCS_STATUS OCS_moduleInfoGet(OCS_MODULE_ID moduleId, OCS_MODULE_INFO *pModuleInfo); -#endif /* _OSAL_STUB_MODULELIB_H_ */ +#endif /* OCS_MODULELIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_mqueue.h b/src/unit-test-coverage/ut-stubs/inc/OCS_mqueue.h index b3c051bcb..da7ae4eb9 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_mqueue.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_mqueue.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for mqueue.h */ -#ifndef _OSAL_STUB_MQUEUE_H_ -#define _OSAL_STUB_MQUEUE_H_ +#ifndef OCS_MQUEUE_H +#define OCS_MQUEUE_H #include #include @@ -55,4 +55,4 @@ extern int OCS_mq_timedsend(OCS_mqd_t mqdes, const char *msg_ptr, size_t const struct OCS_timespec *abs_timeout); extern int OCS_mq_unlink(const char *name); -#endif /* _OSAL_STUB_MQUEUE_H_ */ +#endif /* OCS_MQUEUE_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_msgQLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_msgQLib.h index f313b71e4..46e540cc7 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_msgQLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_msgQLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for msgQLib.h */ -#ifndef _OSAL_STUB_MSGQLIB_H_ -#define _OSAL_STUB_MSGQLIB_H_ +#ifndef OCS_MSGQLIB_H +#define OCS_MSGQLIB_H #include #include @@ -54,4 +54,4 @@ extern OCS_STATUS OCS_msgQDelete(OCS_MSG_Q_ID msgQId); extern int OCS_msgQReceive(OCS_MSG_Q_ID msgQId, char *buffer, OCS_UINT maxNBytes, int timeout); extern OCS_STATUS OCS_msgQSend(OCS_MSG_Q_ID msgQId, char *buffer, OCS_UINT nBytes, int timeout, int priority); -#endif /* _OSAL_STUB_MSGQLIB_H_ */ +#endif /* OCS_MSGQLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_net_if.h b/src/unit-test-coverage/ut-stubs/inc/OCS_net_if.h index 3bcb94134..b04003749 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_net_if.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_net_if.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for net/if.h */ -#ifndef _OSAL_STUB_NET_IF_H_ -#define _OSAL_STUB_NET_IF_H_ +#ifndef OCS_NET_IF_H +#define OCS_NET_IF_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in net/if.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_NET_IF_H_ */ +#endif /* OCS_NET_IF_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_netdb.h b/src/unit-test-coverage/ut-stubs/inc/OCS_netdb.h index 5803f098e..69aedbfad 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_netdb.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_netdb.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for netdb.h */ -#ifndef _OSAL_STUB_NETDB_H_ -#define _OSAL_STUB_NETDB_H_ +#ifndef OCS_NETDB_H +#define OCS_NETDB_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in netdb.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_NETDB_H_ */ +#endif /* OCS_NETDB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_netinet_in.h b/src/unit-test-coverage/ut-stubs/inc/OCS_netinet_in.h index 1ea9295fe..db4194a17 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_netinet_in.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_netinet_in.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for netinet/in.h */ -#ifndef _OSAL_STUB_NETINET_IN_H_ -#define _OSAL_STUB_NETINET_IN_H_ +#ifndef OCS_NETINET_IN_H +#define OCS_NETINET_IN_H #include @@ -41,4 +41,4 @@ extern uint16_t OCS_ntohs(uint16_t netshort); extern uint32_t OCS_htonl(uint32_t hostlong); extern uint32_t OCS_ntohl(uint32_t netlong); -#endif /* _OSAL_STUB_NETINET_IN_H_ */ +#endif /* OCS_NETINET_IN_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_netinet_tcp.h b/src/unit-test-coverage/ut-stubs/inc/OCS_netinet_tcp.h index 0a755caf0..e9a89fa26 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_netinet_tcp.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_netinet_tcp.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for netinet/tcp.h */ -#ifndef _OSAL_STUB_NETINET_TCP_H_ -#define _OSAL_STUB_NETINET_TCP_H_ +#ifndef OCS_NETINET_TCP_H +#define OCS_NETINET_TCP_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in netinet/tcp.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_NETINET_TCP_H_ */ +#endif /* OCS_NETINET_TCP_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_objLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_objLib.h index ac057bd71..12716d859 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_objLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_objLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for objLib.h */ -#ifndef _OSAL_STUB_OBJLIB_H_ -#define _OSAL_STUB_OBJLIB_H_ +#ifndef OCS_OBJLIB_H +#define OCS_OBJLIB_H #include #include @@ -44,4 +44,4 @@ /* prototypes normally declared in objLib.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_OBJLIB_H_ */ +#endif /* OCS_OBJLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_poll.h b/src/unit-test-coverage/ut-stubs/inc/OCS_poll.h index 92d0ae860..471ebf757 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_poll.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_poll.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for poll.h */ -#ifndef _OSAL_STUB_POLL_H_ -#define _OSAL_STUB_POLL_H_ +#ifndef OCS_POLL_H +#define OCS_POLL_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in poll.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_POLL_H_ */ +#endif /* OCS_POLL_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_pthread.h b/src/unit-test-coverage/ut-stubs/inc/OCS_pthread.h index 03003f848..975513806 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_pthread.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_pthread.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for pthread.h */ -#ifndef _OSAL_STUB_PTHREAD_H_ -#define _OSAL_STUB_PTHREAD_H_ +#ifndef OCS_PTHREAD_H +#define OCS_PTHREAD_H #include #include @@ -122,4 +122,4 @@ extern int OCS_pthread_setschedprio(OCS_pthread_t target_thread, int prio); extern int OCS_pthread_setspecific(OCS_pthread_key_t key, const void *pointer); extern int OCS_pthread_sigmask(int how, const OCS_sigset_t *set, OCS_sigset_t *oldset); -#endif /* _OSAL_STUB_PTHREAD_H_ */ +#endif /* OCS_PTHREAD_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_ramDiskCbio.h b/src/unit-test-coverage/ut-stubs/inc/OCS_ramDiskCbio.h index 9aad6bb0e..1eb14362d 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_ramDiskCbio.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_ramDiskCbio.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ramDiskCbio.h */ -#ifndef _OSAL_STUB_RAMDISKCBIO_H_ -#define _OSAL_STUB_RAMDISKCBIO_H_ +#ifndef OCS_RAMDISKCBIO_H +#define OCS_RAMDISKCBIO_H #include #include @@ -37,4 +37,4 @@ /* prototypes normally declared in ramDiskCbio.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_RAMDISKCBIO_H_ */ +#endif /* OCS_RAMDISKCBIO_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_ramDrv.h b/src/unit-test-coverage/ut-stubs/inc/OCS_ramDrv.h index 3195323a1..6b6ce2e44 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_ramDrv.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_ramDrv.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ramDrv.h */ -#ifndef _OSAL_STUB_RAMDRV_H_ -#define _OSAL_STUB_RAMDRV_H_ +#ifndef OCS_RAMDRV_H +#define OCS_RAMDRV_H #include #include @@ -39,4 +39,4 @@ /* ----------------------------------------- */ extern OCS_BLK_DEV *OCS_ramDevCreate(char *ramAddr, int bytesPerSec, int secPerTrack, int nSectors, int secOffset); -#endif /* _OSAL_STUB_RAMDRV_H_ */ +#endif /* OCS_RAMDRV_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sched.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sched.h index 8a7cdf4d9..ceae63638 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sched.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sched.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sched.h */ -#ifndef _OSAL_STUB_SCHED_H_ -#define _OSAL_STUB_SCHED_H_ +#ifndef OCS_SCHED_H +#define OCS_SCHED_H #include @@ -45,4 +45,4 @@ struct OCS_sched_param extern int OCS_sched_get_priority_max(int policy); extern int OCS_sched_get_priority_min(int policy); -#endif /* _OSAL_STUB_SCHED_H_ */ +#endif /* OCS_SCHED_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_semLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_semLib.h index 5fe016edb..aedc0d2b2 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_semLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_semLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for semLib.h */ -#ifndef _OSAL_STUB_SEMLIB_H_ -#define _OSAL_STUB_SEMLIB_H_ +#ifndef OCS_SEMLIB_H +#define OCS_SEMLIB_H #include #include @@ -70,4 +70,4 @@ extern OCS_STATUS OCS_semFlush(OCS_SEM_ID semId); extern OCS_STATUS OCS_semTake(OCS_SEM_ID semId, int timeout); extern OCS_STATUS OCS_semGive(OCS_SEM_ID semId); -#endif /* _OSAL_STUB_SEMLIB_H_ */ +#endif /* OCS_SEMLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_semaphore.h b/src/unit-test-coverage/ut-stubs/inc/OCS_semaphore.h index 034ad6f0f..b05c25df5 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_semaphore.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_semaphore.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for semaphore.h */ -#ifndef _OSAL_STUB_SEMAPHORE_H_ -#define _OSAL_STUB_SEMAPHORE_H_ +#ifndef OCS_SEMAPHORE_H +#define OCS_SEMAPHORE_H #include #include @@ -49,4 +49,4 @@ extern int OCS_sem_post(OCS_sem_t *sem); extern int OCS_sem_timedwait(OCS_sem_t *sem, const struct OCS_timespec *abstime); extern int OCS_sem_wait(OCS_sem_t *sem); -#endif /* _OSAL_STUB_SEMAPHORE_H_ */ +#endif /* OCS_SEMAPHORE_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_setjmp.h b/src/unit-test-coverage/ut-stubs/inc/OCS_setjmp.h index 89ed14b05..febc81156 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_setjmp.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_setjmp.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for setjmp.h */ -#ifndef _OSAL_STUB_SETJMP_H_ -#define _OSAL_STUB_SETJMP_H_ +#ifndef OCS_SETJMP_H +#define OCS_SETJMP_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in setjmp.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_SETJMP_H_ */ +#endif /* OCS_SETJMP_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_shellLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_shellLib.h index 8f2dc631c..4f316da0b 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_shellLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_shellLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for shellLib.h */ -#ifndef _OSAL_STUB_SHELLLIB_H_ -#define _OSAL_STUB_SHELLLIB_H_ +#ifndef OCS_SHELLLIB_H +#define OCS_SHELLLIB_H #include #include @@ -40,4 +40,4 @@ extern OCS_STATUS OCS_shellGenericInit(const char *config, int stackSize, const char *shellName, char **pShellName, OCS_BOOL interactive, OCS_BOOL loginAccess, int fdin, int fdout, int fderr); -#endif /* _OSAL_STUB_SHELLLIB_H_ */ +#endif /* OCS_SHELLLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_signal.h b/src/unit-test-coverage/ut-stubs/inc/OCS_signal.h index c0d3006bb..13990a46f 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_signal.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_signal.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for signal.h */ -#ifndef _OSAL_STUB_SIGNAL_H_ -#define _OSAL_STUB_SIGNAL_H_ +#ifndef OCS_SIGNAL_H +#define OCS_SIGNAL_H #include #include @@ -74,4 +74,4 @@ extern int OCS_sigprocmask(int how, const OCS_sigset_t *set, OCS_si extern int OCS_sigsuspend(const OCS_sigset_t *set); extern int OCS_sigwait(const OCS_sigset_t *set, int *sig); -#endif /* _OSAL_STUB_SIGNAL_H_ */ +#endif /* OCS_SIGNAL_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_stat.h b/src/unit-test-coverage/ut-stubs/inc/OCS_stat.h index c05d4f53a..bc2702ae5 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_stat.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_stat.h @@ -19,11 +19,12 @@ */ /* OSAL coverage stub replacement for stat.h */ -#ifndef _OSAL_STUB_STAT_H_ -#define _OSAL_STUB_STAT_H_ +#ifndef OCS_STAT_H +#define OCS_STAT_H #include #include +#include /* ----------------------------------------- */ /* constants normally defined in sys/stat.h */ @@ -39,11 +40,12 @@ struct OCS_stat { - OCS_mode_t st_mode; - OCS_off_t st_size; - OCS_time_t st_mtime; - OCS_uid_t st_uid; - OCS_gid_t st_gid; + OCS_mode_t st_mode; + OCS_off_t st_size; + OCS_time_t st_mtime; + struct OCS_timespec st_mtim; + OCS_uid_t st_uid; + OCS_gid_t st_gid; }; /* ----------------------------------------- */ @@ -72,4 +74,4 @@ extern int OCS_fstat(int fd, struct OCS_stat *buf); extern int OCS_statvfs(const char *file, struct OCS_statvfs *buf); -#endif /* _OSAL_STUB_STAT_H_ */ +#endif /* OCS_STAT_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_stdarg.h b/src/unit-test-coverage/ut-stubs/inc/OCS_stdarg.h index 474e68c3e..b788b203f 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_stdarg.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_stdarg.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for stdarg.h */ -#ifndef _OSAL_STUB_STDARG_H_ -#define _OSAL_STUB_STDARG_H_ +#ifndef OCS_STDARG_H +#define OCS_STDARG_H #include @@ -43,4 +43,4 @@ typedef struct #define OCS_va_start(ap, last) ap.p = &last #define OCS_va_end(ap) -#endif /* _OSAL_STUB_STDARG_H_ */ +#endif /* OCS_STDARG_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_stdio.h b/src/unit-test-coverage/ut-stubs/inc/OCS_stdio.h index b6a03a08c..31ce73425 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_stdio.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_stdio.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for stdio.h */ -#ifndef _OSAL_STUB_STDIO_H_ -#define _OSAL_STUB_STDIO_H_ +#ifndef OCS_STDIO_H +#define OCS_STDIO_H #include #include @@ -47,10 +47,11 @@ extern int OCS_rename(const char *old, const char *nw); extern int OCS_snprintf(char *s, size_t maxlen, const char *format, ...); extern int OCS_vsnprintf(char *s, size_t maxlen, const char *format, OCS_va_list arg); extern int OCS_printf(const char *format, ...); +extern int OCS_fprintf(OCS_FILE *fp, const char *format, ...); extern int OCS_putchar(int c); extern OCS_FILE *OCS_stdin; extern OCS_FILE *OCS_stdout; extern OCS_FILE *OCS_stderr; -#endif /* _OSAL_STUB_STDIO_H_ */ +#endif /* OCS_STDIO_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_stdlib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_stdlib.h index 7332b9d32..b0fe69988 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_stdlib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_stdlib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for stdlib.h */ -#ifndef _OSAL_STUB_STDLIB_H_ -#define _OSAL_STUB_STDLIB_H_ +#ifndef OCS_STDLIB_H +#define OCS_STDLIB_H #include @@ -39,10 +39,11 @@ /* prototypes normally declared in stdlib.h */ /* ----------------------------------------- */ +extern void OCS_abort(void); extern void OCS_exit(int status); extern unsigned long int OCS_strtoul(const char *nptr, char **endptr, int base); extern int OCS_system(const char *command); extern void * OCS_malloc(size_t sz); extern void OCS_free(void *ptr); -#endif /* _OSAL_STUB_STDLIB_H_ */ +#endif /* OCS_STDLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_string.h b/src/unit-test-coverage/ut-stubs/inc/OCS_string.h index a4a931284..470ba2e82 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_string.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_string.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for string.h */ -#ifndef _OSAL_STUB_STRING_H_ -#define _OSAL_STUB_STRING_H_ +#ifndef OCS_STRING_H +#define OCS_STRING_H #include @@ -36,6 +36,7 @@ /* prototypes normally declared in string.h */ /* ----------------------------------------- */ +extern void * OCS_memchr(const void *s, int c, size_t n); extern void * OCS_memcpy(void *dest, const void *src, size_t n); extern void * OCS_memset(void *s, int c, size_t n); extern int OCS_strcmp(const char *s1, const char *s2); @@ -49,4 +50,4 @@ extern char * OCS_strcat(char *dest, const char *src); extern char * OCS_strncat(char *dest, const char *src, size_t n); extern char * OCS_strerror(int errnum); -#endif /* _OSAL_STUB_STRING_H_ */ +#endif /* OCS_STRING_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_strings.h b/src/unit-test-coverage/ut-stubs/inc/OCS_strings.h index 480522ec2..74e2c5cab 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_strings.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_strings.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for strings.h */ -#ifndef _OSAL_STUB_STRINGS_H_ -#define _OSAL_STUB_STRINGS_H_ +#ifndef OCS_STRINGS_H +#define OCS_STRINGS_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in strings.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_STRINGS_H_ */ +#endif /* OCS_STRINGS_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_symLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_symLib.h index 61a437942..16037a4f8 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_symLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_symLib.h @@ -26,8 +26,8 @@ * OSAL coverage stub replacement for symLib.h */ -#ifndef INCLUDE_OCS_SYMLIB_H_ -#define INCLUDE_OCS_SYMLIB_H_ +#ifndef OCS_SYMLIB_H +#define OCS_SYMLIB_H #include #include @@ -70,4 +70,4 @@ extern OCS_STATUS OCS_symFindByName(OCS_SYMTAB_ID symTblId, char *name, char ** extern OCS_SYMBOL *OCS_symEach(OCS_SYMTAB_ID symTblId, OCS_symEach_Routine_t routine, int routineArg); extern OCS_STATUS OCS_symFind(OCS_SYMTAB_ID symTblId, OCS_SYMBOL_DESC *pSymbol); -#endif /* INCLUDE_OCS_SYMLIB_H_ */ +#endif /* OCS_SYMLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sysLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sysLib.h index 36b43f7e8..0f6093256 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sysLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sysLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sysLib.h */ -#ifndef _OSAL_STUB_SYSLIB_H_ -#define _OSAL_STUB_SYSLIB_H_ +#ifndef OCS_SYSLIB_H +#define OCS_SYSLIB_H #include #include @@ -38,4 +38,4 @@ /* ----------------------------------------- */ extern int OCS_sysClkRateGet(void); -#endif /* _OSAL_STUB_SYSLIB_H_ */ +#endif /* OCS_SYSLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_ioctl.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_ioctl.h index 230ecb053..60ef5e79e 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_ioctl.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_ioctl.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/ioctl.h */ -#ifndef _OSAL_STUB_SYS_IOCTL_H_ -#define _OSAL_STUB_SYS_IOCTL_H_ +#ifndef OCS_SYS_IOCTL_H +#define OCS_SYS_IOCTL_H #include @@ -38,4 +38,4 @@ extern int OCS_ioctl(int fd, unsigned long request, ...); -#endif /* _OSAL_STUB_SYS_IOCTL_H_ */ +#endif /* OCS_SYS_IOCTL_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_ipc.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_ipc.h index 9384f38a0..f566826f2 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_ipc.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_ipc.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/ipc.h */ -#ifndef _OSAL_STUB_SYS_IPC_H_ -#define _OSAL_STUB_SYS_IPC_H_ +#ifndef OCS_SYS_IPC_H +#define OCS_SYS_IPC_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in sys/ipc.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_SYS_IPC_H_ */ +#endif /* OCS_SYS_IPC_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_mman.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_mman.h index 944ac9d43..7bdff049f 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_mman.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_mman.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/mman.h */ -#ifndef _OSAL_STUB_SYS_MMAN_H_ -#define _OSAL_STUB_SYS_MMAN_H_ +#ifndef OCS_SYS_MMAN_H +#define OCS_SYS_MMAN_H #include @@ -45,4 +45,4 @@ void *OCS_mmap(void *addr, size_t length, int prot, int flags, int fd, OCS_off_t offset); int OCS_munmap(void *addr, size_t length); -#endif /* _OSAL_STUB_SYS_MMAN_H_ */ +#endif /* OCS_SYS_MMAN_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_select.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_select.h index 10c1c1e7b..531cad372 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_select.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_select.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OCS_SYS_SELECT_H_ -#define INCLUDE_OCS_SYS_SELECT_H_ +#ifndef OCS_SYS_SELECT_H +#define OCS_SYS_SELECT_H #include #include @@ -55,4 +55,4 @@ extern int OCS_FD_ISSET(int fd, OCS_fd_set *set); extern void OCS_FD_CLR(int fd, OCS_fd_set *set); extern void OCS_FD_ZERO(OCS_fd_set *set); -#endif /* INCLUDE_OCS_SYS_SELECT_H_ */ +#endif /* OCS_SYS_SELECT_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_socket.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_socket.h index c5c13391d..35e079f03 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_socket.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_socket.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/socket.h */ -#ifndef _OSAL_STUB_SYS_SOCKET_H_ -#define _OSAL_STUB_SYS_SOCKET_H_ +#ifndef OCS_SYS_SOCKET_H +#define OCS_SYS_SOCKET_H #include #include @@ -55,4 +55,4 @@ extern OCS_ssize_t OCS_sendto(int fd, const void *buf, size_t n, int flags, cons extern int OCS_setsockopt(int fd, int level, int optname, const void *optval, OCS_socklen_t optlen); extern int OCS_socket(int domain, int type, int protocol); -#endif /* _OSAL_STUB_SYS_SOCKET_H_ */ +#endif /* OCS_SYS_SOCKET_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_time.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_time.h index d510083df..54b7044b3 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_time.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_time.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/time.h */ -#ifndef _OSAL_STUB_SYS_TIME_H_ -#define _OSAL_STUB_SYS_TIME_H_ +#ifndef OCS_SYS_TIME_H +#define OCS_SYS_TIME_H #include #include @@ -37,4 +37,4 @@ /* prototypes normally declared in sys/time.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_SYS_TIME_H_ */ +#endif /* OCS_SYS_TIME_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_times.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_times.h index eb177637f..3f92ec9ca 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_times.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_times.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/times.h */ -#ifndef _OSAL_STUB_SYS_TIMES_H_ -#define _OSAL_STUB_SYS_TIMES_H_ +#ifndef OCS_SYS_TIMES_H +#define OCS_SYS_TIMES_H #include #include @@ -37,4 +37,4 @@ /* prototypes normally declared in sys/times.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_SYS_TIMES_H_ */ +#endif /* OCS_SYS_TIMES_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_types.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_types.h index c9f8a5a3b..c3db9b65f 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_types.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_types.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/types.h */ -#ifndef _OSAL_STUB_SYS_TYPES_H_ -#define _OSAL_STUB_SYS_TYPES_H_ +#ifndef OCS_SYS_TYPES_H +#define OCS_SYS_TYPES_H #include @@ -43,4 +43,4 @@ typedef int OCS_uid_t; /* prototypes normally declared in sys/types.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_SYS_TYPES_H_ */ +#endif /* OCS_SYS_TYPES_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_un.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_un.h index 1a1cdafb0..197ea1840 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_un.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_un.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/un.h */ -#ifndef _OSAL_STUB_SYS_UN_H_ -#define _OSAL_STUB_SYS_UN_H_ +#ifndef OCS_SYS_UN_H +#define OCS_SYS_UN_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in sys/un.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_SYS_UN_H_ */ +#endif /* OCS_SYS_UN_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_wait.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_wait.h index ceef2726d..6ec53b345 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_wait.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_wait.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/wait.h */ -#ifndef _OSAL_STUB_SYS_WAIT_H_ -#define _OSAL_STUB_SYS_WAIT_H_ +#ifndef OCS_SYS_WAIT_H +#define OCS_SYS_WAIT_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in sys/wait.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_SYS_WAIT_H_ */ +#endif /* OCS_SYS_WAIT_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_taskLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_taskLib.h index 6760a41f0..bc2bccc39 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_taskLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_taskLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for taskLib.h */ -#ifndef _OSAL_STUB_TASKLIB_H_ -#define _OSAL_STUB_TASKLIB_H_ +#ifndef OCS_TASKLIB_H +#define OCS_TASKLIB_H #include #include @@ -79,4 +79,4 @@ OCS_STATUS OCS_taskInit(OCS_WIND_TCB *pTcb, char *name, int priority, int option OCS_WIND_TCB *OCS_taskTcb(OCS_TASK_ID tid); -#endif /* _OSAL_STUB_TASKLIB_H_ */ +#endif /* OCS_TASKLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_taskVarLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_taskVarLib.h index 611e61d78..9ac4f3937 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_taskVarLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_taskVarLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for taskVarLib.h */ -#ifndef _OSAL_STUB_TASKVARLIB_H_ -#define _OSAL_STUB_TASKVARLIB_H_ +#ifndef OCS_TASKVARLIB_H +#define OCS_TASKVARLIB_H #include #include @@ -39,4 +39,4 @@ extern OCS_STATUS OCS_taskVarAdd(int tid, int *pVar); -#endif /* _OSAL_STUB_TASKVARLIB_H_ */ +#endif /* OCS_TASKVARLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_termios.h b/src/unit-test-coverage/ut-stubs/inc/OCS_termios.h index 69f91ddcd..6420fa2d0 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_termios.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_termios.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for termios.h */ -#ifndef _OSAL_STUB_TERMIOS_H_ -#define _OSAL_STUB_TERMIOS_H_ +#ifndef OCS_TERMIOS_H +#define OCS_TERMIOS_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in termios.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_TERMIOS_H_ */ +#endif /* OCS_TERMIOS_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_tgmath.h b/src/unit-test-coverage/ut-stubs/inc/OCS_tgmath.h index d095228a5..b547b841a 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_tgmath.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_tgmath.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for tgmath.h */ -#ifndef _OSAL_STUB_TGMATH_H_ -#define _OSAL_STUB_TGMATH_H_ +#ifndef OCS_TGMATH_H +#define OCS_TGMATH_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in tgmath.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_TGMATH_H_ */ +#endif /* OCS_TGMATH_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_time.h b/src/unit-test-coverage/ut-stubs/inc/OCS_time.h index 88decb45c..20894c1b6 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_time.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_time.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for time.h */ -#ifndef _OSAL_STUB_TIME_H_ -#define _OSAL_STUB_TIME_H_ +#ifndef OCS_TIME_H +#define OCS_TIME_H #include #include @@ -79,4 +79,4 @@ extern int OCS_timer_settime(OCS_timer_t timerid, int flags, const struct OCS_it extern int OCS_timer_connect(OCS_timer_t timerid, OCS_TIMER_CONNECT_FUNC func, int arg); -#endif /* _OSAL_STUB_TIME_H_ */ +#endif /* OCS_TIME_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_timers.h b/src/unit-test-coverage/ut-stubs/inc/OCS_timers.h index 6f1707626..be5085b59 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_timers.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_timers.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for timers.h */ -#ifndef _OSAL_STUB_TIMERS_H_ -#define _OSAL_STUB_TIMERS_H_ +#ifndef OCS_TIMERS_H +#define OCS_TIMERS_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in timers.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_TIMERS_H_ */ +#endif /* OCS_TIMERS_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_ulimit.h b/src/unit-test-coverage/ut-stubs/inc/OCS_ulimit.h index d2789d3ec..153150bec 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_ulimit.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_ulimit.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ulimit.h */ -#ifndef _OSAL_STUB_ULIMIT_H_ -#define _OSAL_STUB_ULIMIT_H_ +#ifndef OCS_ULIMIT_H +#define OCS_ULIMIT_H #include @@ -37,4 +37,4 @@ /* ----------------------------------------- */ long OCS_ulimit(int cmd, long newlimit); -#endif /* _OSAL_STUB_ULIMIT_H_ */ +#endif /* OCS_ULIMIT_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_unistd.h b/src/unit-test-coverage/ut-stubs/inc/OCS_unistd.h index 43eb9b74c..34a5d4c1c 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_unistd.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_unistd.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for unistd.h */ -#ifndef _OSAL_STUB_UNISTD_H_ -#define _OSAL_STUB_UNISTD_H_ +#ifndef OCS_UNISTD_H +#define OCS_UNISTD_H #include #include @@ -56,4 +56,4 @@ extern int OCS_rmdir(const char *path); extern long int OCS_sysconf(int name); extern OCS_ssize_t OCS_write(int fd, const void *buf, size_t n); -#endif /* _OSAL_STUB_UNISTD_H_ */ +#endif /* OCS_UNISTD_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_unldLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_unldLib.h index ed4847847..c3de289e7 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_unldLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_unldLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for unldLib.h */ -#ifndef _OSAL_STUB_UNLDLIB_H_ -#define _OSAL_STUB_UNLDLIB_H_ +#ifndef OCS_UNLDLIB_H +#define OCS_UNLDLIB_H #include #include @@ -39,4 +39,4 @@ /* ----------------------------------------- */ extern OCS_STATUS OCS_unldByModuleId(OCS_MODULE_ID moduleId, int options); -#endif /* _OSAL_STUB_UNLDLIB_H_ */ +#endif /* OCS_UNLDLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_usrLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_usrLib.h index 0929b6049..bc8c9127a 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_usrLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_usrLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for usrLib.h */ -#ifndef _OSAL_STUB_USRLIB_H_ -#define _OSAL_STUB_USRLIB_H_ +#ifndef OCS_USRLIB_H +#define OCS_USRLIB_H #include #include @@ -37,4 +37,4 @@ /* prototypes normally declared in usrLib.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_USRLIB_H_ */ +#endif /* OCS_USRLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_version.h b/src/unit-test-coverage/ut-stubs/inc/OCS_version.h index 1839ce637..89766255f 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_version.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_version.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for version.h */ -#ifndef _OSAL_STUB_VERSION_H_ -#define _OSAL_STUB_VERSION_H_ +#ifndef OCS_VERSION_H +#define OCS_VERSION_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in version.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_VERSION_H_ */ +#endif /* OCS_VERSION_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_vxWorks.h b/src/unit-test-coverage/ut-stubs/inc/OCS_vxWorks.h index cbb7f6c64..6db9b9300 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_vxWorks.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_vxWorks.h @@ -25,8 +25,8 @@ * OSAL coverage stub replacement for vxWorks.h */ -#ifndef INCLUDE_OCS_VXWORKS_H_ -#define INCLUDE_OCS_VXWORKS_H_ +#ifndef OCS_VXWORKS_H +#define OCS_VXWORKS_H #include @@ -76,4 +76,4 @@ typedef void (*OCS_VOIDFUNCPTR)(void); /* prototypes normally declared in vxWorks.h */ /* ----------------------------------------- */ -#endif /* INCLUDE_OCS_VXWORKS_H_ */ +#endif /* OCS_VXWORKS_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_wchar.h b/src/unit-test-coverage/ut-stubs/inc/OCS_wchar.h index f2e667c26..050413681 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_wchar.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_wchar.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for wchar.h */ -#ifndef _OSAL_STUB_WCHAR_H_ -#define _OSAL_STUB_WCHAR_H_ +#ifndef OCS_WCHAR_H +#define OCS_WCHAR_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in wchar.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_WCHAR_H_ */ +#endif /* OCS_WCHAR_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_wctype.h b/src/unit-test-coverage/ut-stubs/inc/OCS_wctype.h index 5fa115d55..0aa046df6 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_wctype.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_wctype.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for wctype.h */ -#ifndef _OSAL_STUB_WCTYPE_H_ -#define _OSAL_STUB_WCTYPE_H_ +#ifndef OCS_WCTYPE_H +#define OCS_WCTYPE_H #include @@ -36,4 +36,4 @@ /* prototypes normally declared in wctype.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_WCTYPE_H_ */ +#endif /* OCS_WCTYPE_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_xbdBlkDev.h b/src/unit-test-coverage/ut-stubs/inc/OCS_xbdBlkDev.h index 314ca080e..346083205 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_xbdBlkDev.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_xbdBlkDev.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for xbdBlkDev.h */ -#ifndef _OSAL_STUB_XBDBLKDEV_H_ -#define _OSAL_STUB_XBDBLKDEV_H_ +#ifndef OCS_XBDBLKDEV_H +#define OCS_XBDBLKDEV_H #include #include @@ -42,4 +42,4 @@ typedef int OCS_device_t; extern OCS_device_t OCS_xbdBlkDevCreateSync(OCS_BLK_DEV *bd, const char *name); extern OCS_STATUS OCS_xbdBlkDevDelete(OCS_device_t dev, OCS_BLK_DEV **ppbd); -#endif /* _OSAL_STUB_XBDBLKDEV_H_ */ +#endif /* OCS_XBDBLKDEV_H */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_xbdRamDisk.h b/src/unit-test-coverage/ut-stubs/inc/OCS_xbdRamDisk.h index 92bf6ba87..ac2fec4df 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_xbdRamDisk.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_xbdRamDisk.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for xbdRamDisk.h */ -#ifndef _OSAL_STUB_XBDRAMDISK_H_ -#define _OSAL_STUB_XBDRAMDISK_H_ +#ifndef OCS_XBDRAMDISK_H +#define OCS_XBDRAMDISK_H #include #include @@ -37,4 +37,4 @@ /* prototypes normally declared in xbdRamDisk.h */ /* ----------------------------------------- */ -#endif /* _OSAL_STUB_XBDRAMDISK_H_ */ +#endif /* OCS_XBDRAMDISK_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/arpa/inet.h b/src/unit-test-coverage/ut-stubs/override_inc/arpa/inet.h index 5c5a9f90d..b2a1af6b7 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/arpa/inet.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/arpa/inet.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for arpa/inet.h */ -#ifndef _OSAL_OVERRIDE_ARPA_INET_H_ -#define _OSAL_OVERRIDE_ARPA_INET_H_ +#ifndef OSAL_OVERRIDE_ARPA_INET_H +#define OSAL_OVERRIDE_ARPA_INET_H #include @@ -30,4 +30,4 @@ #define inet_ntop OCS_inet_ntop #define inet_pton OCS_inet_pton -#endif /* _OSAL_OVERRIDE_ARPA_INET_H_ */ +#endif /* OSAL_OVERRIDE_ARPA_INET_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/assert.h b/src/unit-test-coverage/ut-stubs/override_inc/assert.h index 6e889619e..7e606c698 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/assert.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/assert.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for assert.h */ -#ifndef _OSAL_OVERRIDE_ASSERT_H_ -#define _OSAL_OVERRIDE_ASSERT_H_ +#ifndef OSAL_OVERRIDE_ASSERT_H +#define OSAL_OVERRIDE_ASSERT_H #include @@ -30,4 +30,4 @@ #define assert OCS_assert -#endif /* _OSAL_OVERRIDE_ASSERT_H_ */ +#endif /* OSAL_OVERRIDE_ASSERT_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/blkIo.h b/src/unit-test-coverage/ut-stubs/override_inc/blkIo.h index 645c242a6..c367eb5e6 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/blkIo.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/blkIo.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for blkIo.h */ -#ifndef _OSAL_OVERRIDE_BLKIO_H_ -#define _OSAL_OVERRIDE_BLKIO_H_ +#ifndef OSAL_OVERRIDE_BLKIO_H +#define OSAL_OVERRIDE_BLKIO_H #include #include @@ -32,4 +32,4 @@ #define BLK_DEV OCS_BLK_DEV #define BLK_DEV_ID OCS_BLK_DEV_ID -#endif /* _OSAL_OVERRIDE_BLKIO_H_ */ +#endif /* OSAL_OVERRIDE_BLKIO_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/bsp-impl.h b/src/unit-test-coverage/ut-stubs/override_inc/bsp-impl.h index eadea5868..1bde70096 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/bsp-impl.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/bsp-impl.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_BSP_IMPL_H_ -#define INCLUDE_BSP_IMPL_H_ +#ifndef BSP_IMPL_H +#define BSP_IMPL_H #include "OCS_bsp-impl.h" @@ -43,4 +43,4 @@ END bsp-impl.h *********************/ -#endif /* INCLUDE_BSP_IMPL_H_ */ +#endif /* BSP_IMPL_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/cbioLib.h b/src/unit-test-coverage/ut-stubs/override_inc/cbioLib.h index 0310e8f77..1d2456dd3 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/cbioLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/cbioLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for cbioLib.h */ -#ifndef _OSAL_OVERRIDE_CBIOLIB_H_ -#define _OSAL_OVERRIDE_CBIOLIB_H_ +#ifndef OSAL_OVERRIDE_CBIOLIB_H +#define OSAL_OVERRIDE_CBIOLIB_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in cbioLib.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_CBIOLIB_H_ */ +#endif /* OSAL_OVERRIDE_CBIOLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/complex.h b/src/unit-test-coverage/ut-stubs/override_inc/complex.h index 941797e33..18fe48ec8 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/complex.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/complex.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for complex.h */ -#ifndef _OSAL_OVERRIDE_COMPLEX_H_ -#define _OSAL_OVERRIDE_COMPLEX_H_ +#ifndef OSAL_OVERRIDE_COMPLEX_H +#define OSAL_OVERRIDE_COMPLEX_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in complex.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_COMPLEX_H_ */ +#endif /* OSAL_OVERRIDE_COMPLEX_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/ctype.h b/src/unit-test-coverage/ut-stubs/override_inc/ctype.h index 1a7903a0e..bc20c62fc 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/ctype.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/ctype.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ctype.h */ -#ifndef _OSAL_OVERRIDE_CTYPE_H_ -#define _OSAL_OVERRIDE_CTYPE_H_ +#ifndef OSAL_OVERRIDE_CTYPE_H +#define OSAL_OVERRIDE_CTYPE_H #include @@ -30,4 +30,4 @@ #define isgraph OCS_isgraph -#endif /* _OSAL_OVERRIDE_CTYPE_H_ */ +#endif /* OSAL_OVERRIDE_CTYPE_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/dirent.h b/src/unit-test-coverage/ut-stubs/override_inc/dirent.h index bbf7648a4..4b1de1b47 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/dirent.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/dirent.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for dirent.h */ -#ifndef _OSAL_OVERRIDE_DIRENT_H_ -#define _OSAL_OVERRIDE_DIRENT_H_ +#ifndef OSAL_OVERRIDE_DIRENT_H +#define OSAL_OVERRIDE_DIRENT_H #include @@ -35,4 +35,4 @@ #define readdir OCS_readdir #define rewinddir OCS_rewinddir -#endif /* _OSAL_OVERRIDE_DIRENT_H_ */ +#endif /* OSAL_OVERRIDE_DIRENT_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/dlfcn.h b/src/unit-test-coverage/ut-stubs/override_inc/dlfcn.h index 02f9d57a0..20cccc404 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/dlfcn.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/dlfcn.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for dlfcn.h */ -#ifndef _OSAL_OVERRIDE_DLFCN_H_ -#define _OSAL_OVERRIDE_DLFCN_H_ +#ifndef OSAL_OVERRIDE_DLFCN_H +#define OSAL_OVERRIDE_DLFCN_H #include @@ -33,4 +33,4 @@ #define dlopen OCS_dlopen #define dlsym OCS_dlsym -#endif /* _OSAL_OVERRIDE_DLFCN_H_ */ +#endif /* OSAL_OVERRIDE_DLFCN_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/dosFsLib.h b/src/unit-test-coverage/ut-stubs/override_inc/dosFsLib.h index bc3935e57..503da1d14 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/dosFsLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/dosFsLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for dosFsLib.h */ -#ifndef _OSAL_OVERRIDE_DOSFSLIB_H_ -#define _OSAL_OVERRIDE_DOSFSLIB_H_ +#ifndef OSAL_OVERRIDE_DOSFSLIB_H +#define OSAL_OVERRIDE_DOSFSLIB_H #include #include @@ -36,4 +36,4 @@ #define dosFsVolFormat OCS_dosFsVolFormat -#endif /* _OSAL_OVERRIDE_DOSFSLIB_H_ */ +#endif /* OSAL_OVERRIDE_DOSFSLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/drv/hdisk/ataDrv.h b/src/unit-test-coverage/ut-stubs/override_inc/drv/hdisk/ataDrv.h index 7aca05fd5..325551d07 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/drv/hdisk/ataDrv.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/drv/hdisk/ataDrv.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for drv/hdisk/ataDrv.h */ -#ifndef _OSAL_OVERRIDE_DRV_HDISK_ATADRV_H_ -#define _OSAL_OVERRIDE_DRV_HDISK_ATADRV_H_ +#ifndef OSAL_OVERRIDE_DRV_HDISK_ATADRV_H +#define OSAL_OVERRIDE_DRV_HDISK_ATADRV_H #include #include @@ -31,4 +31,4 @@ /* ----------------------------------------- */ #define ataDevCreate OCS_ataDevCreate -#endif /* _OSAL_OVERRIDE_DRV_HDISK_ATADRV_H_ */ +#endif /* OSAL_OVERRIDE_DRV_HDISK_ATADRV_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/errno.h b/src/unit-test-coverage/ut-stubs/override_inc/errno.h index ada97f87e..80ccf685e 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/errno.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/errno.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for errno.h */ -#ifndef _OSAL_OVERRIDE_ERRNO_H_ -#define _OSAL_OVERRIDE_ERRNO_H_ +#ifndef OSAL_OVERRIDE_ERRNO_H +#define OSAL_OVERRIDE_ERRNO_H #include @@ -30,10 +30,14 @@ #define EINTR OCS_EINTR #define EAGAIN OCS_EAGAIN #define EINVAL OCS_EINVAL +#define EEXIST OCS_EEXIST #define EMSGSIZE OCS_EMSGSIZE #define ETIMEDOUT OCS_ETIMEDOUT #define ESPIPE OCS_ESPIPE +#define ENOTSUP OCS_ENOTSUP +#define ENOSYS OCS_ENOSYS +#define EROFS OCS_EROFS #define errno OCS_errno -#endif /* _OSAL_OVERRIDE_ERRNO_H_ */ +#endif /* OSAL_OVERRIDE_ERRNO_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/errnoLib.h b/src/unit-test-coverage/ut-stubs/override_inc/errnoLib.h index c28e22fbb..a8589b83c 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/errnoLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/errnoLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for errnoLib.h */ -#ifndef _OSAL_OVERRIDE_ERRNOLIB_H_ -#define _OSAL_OVERRIDE_ERRNOLIB_H_ +#ifndef OSAL_OVERRIDE_ERRNOLIB_H +#define OSAL_OVERRIDE_ERRNOLIB_H #include #include @@ -30,4 +30,4 @@ /* ----------------------------------------- */ #define errnoGet OCS_errnoGet -#endif /* _OSAL_OVERRIDE_ERRNOLIB_H_ */ +#endif /* OSAL_OVERRIDE_ERRNOLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/fcntl.h b/src/unit-test-coverage/ut-stubs/override_inc/fcntl.h index e78b8b3a4..35cc45daa 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/fcntl.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/fcntl.h @@ -19,14 +19,17 @@ */ /* OSAL coverage stub replacement for fcntl.h */ -#ifndef _OSAL_OVERRIDE_FCNTL_H_ -#define _OSAL_OVERRIDE_FCNTL_H_ +#ifndef OSAL_OVERRIDE_FCNTL_H +#define OSAL_OVERRIDE_FCNTL_H #include /* ----------------------------------------- */ /* mappings for declarations in fcntl.h */ /* ----------------------------------------- */ +#define S_IRWXU OCS_S_IRWXU +#define S_IRWXG OCS_S_IRWXG +#define S_IRWXO OCS_S_IRWXO #define S_IXOTH OCS_S_IXOTH #define S_IXGRP OCS_S_IXGRP #define S_IXUSR OCS_S_IXUSR @@ -53,4 +56,4 @@ #define fcntl OCS_fcntl #define open OCS_open -#endif /* _OSAL_OVERRIDE_FCNTL_H_ */ +#endif /* OSAL_OVERRIDE_FCNTL_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/fenv.h b/src/unit-test-coverage/ut-stubs/override_inc/fenv.h index f260c305b..8573a3de7 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/fenv.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/fenv.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for fenv.h */ -#ifndef _OSAL_OVERRIDE_FENV_H_ -#define _OSAL_OVERRIDE_FENV_H_ +#ifndef OSAL_OVERRIDE_FENV_H +#define OSAL_OVERRIDE_FENV_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in fenv.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_FENV_H_ */ +#endif /* OSAL_OVERRIDE_FENV_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/float.h b/src/unit-test-coverage/ut-stubs/override_inc/float.h index 22c3d745a..cc993a971 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/float.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/float.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for float.h */ -#ifndef _OSAL_OVERRIDE_FLOAT_H_ -#define _OSAL_OVERRIDE_FLOAT_H_ +#ifndef OSAL_OVERRIDE_FLOAT_H +#define OSAL_OVERRIDE_FLOAT_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in float.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_FLOAT_H_ */ +#endif /* OSAL_OVERRIDE_FLOAT_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/hostLib.h b/src/unit-test-coverage/ut-stubs/override_inc/hostLib.h index 5ac654f15..2719ea193 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/hostLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/hostLib.h @@ -26,8 +26,8 @@ * OSAL coverage stub replacement for hostLib.h */ -#ifndef INCLUDE_HOSTLIB_H_ -#define INCLUDE_HOSTLIB_H_ +#ifndef HOSTLIB_H +#define HOSTLIB_H #include #include @@ -37,4 +37,4 @@ /* ----------------------------------------- */ #define hostGetByName OCS_hostGetByName -#endif /* INCLUDE_HOSTLIB_H_ */ +#endif /* HOSTLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/intLib.h b/src/unit-test-coverage/ut-stubs/override_inc/intLib.h index 98b666ec6..ed9669c40 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/intLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/intLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for intLib.h */ -#ifndef _OSAL_OVERRIDE_INTLIB_H_ -#define _OSAL_OVERRIDE_INTLIB_H_ +#ifndef OSAL_OVERRIDE_INTLIB_H +#define OSAL_OVERRIDE_INTLIB_H #include #include @@ -36,4 +36,4 @@ #define intUnlock OCS_intUnlock #define INUM_TO_IVEC OCS_INUM_TO_IVEC -#endif /* _OSAL_OVERRIDE_INTLIB_H_ */ +#endif /* OSAL_OVERRIDE_INTLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/inttypes.h b/src/unit-test-coverage/ut-stubs/override_inc/inttypes.h index 95d44dd03..a973d6244 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/inttypes.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/inttypes.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for inttypes.h */ -#ifndef _OSAL_OVERRIDE_INTTYPES_H_ -#define _OSAL_OVERRIDE_INTTYPES_H_ +#ifndef OSAL_OVERRIDE_INTTYPES_H +#define OSAL_OVERRIDE_INTTYPES_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in inttypes.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_INTTYPES_H_ */ +#endif /* OSAL_OVERRIDE_INTTYPES_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/ioLib.h b/src/unit-test-coverage/ut-stubs/override_inc/ioLib.h index aa8d04501..f8006ed59 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/ioLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/ioLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ioLib.h */ -#ifndef _OSAL_OVERRIDE_IOLIB_H_ -#define _OSAL_OVERRIDE_IOLIB_H_ +#ifndef OSAL_OVERRIDE_IOLIB_H +#define OSAL_OVERRIDE_IOLIB_H #include #include @@ -33,4 +33,4 @@ #define FIOUNMOUNT OCS_FIOUNMOUNT #define ioctl OCS_ioctl -#endif /* _OSAL_OVERRIDE_IOLIB_H_ */ +#endif /* OSAL_OVERRIDE_IOLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/iv.h b/src/unit-test-coverage/ut-stubs/override_inc/iv.h index af02ea147..760755c9c 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/iv.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/iv.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for iv.h */ -#ifndef _OSAL_OVERRIDE_IV_H_ -#define _OSAL_OVERRIDE_IV_H_ +#ifndef OSAL_OVERRIDE_IV_H +#define OSAL_OVERRIDE_IV_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in iv.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_IV_H_ */ +#endif /* OSAL_OVERRIDE_IV_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/loadLib.h b/src/unit-test-coverage/ut-stubs/override_inc/loadLib.h index cd8324ec6..d45867fa5 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/loadLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/loadLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for loadLib.h */ -#ifndef _OSAL_OVERRIDE_LOADLIB_H_ -#define _OSAL_OVERRIDE_LOADLIB_H_ +#ifndef OSAL_OVERRIDE_LOADLIB_H +#define OSAL_OVERRIDE_LOADLIB_H #include #include @@ -32,4 +32,4 @@ #define loadModule OCS_loadModule -#endif /* _OSAL_OVERRIDE_LOADLIB_H_ */ +#endif /* OSAL_OVERRIDE_LOADLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/locale.h b/src/unit-test-coverage/ut-stubs/override_inc/locale.h index 124963b3f..07b96a1fc 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/locale.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/locale.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for locale.h */ -#ifndef _OSAL_OVERRIDE_LOCALE_H_ -#define _OSAL_OVERRIDE_LOCALE_H_ +#ifndef OSAL_OVERRIDE_LOCALE_H +#define OSAL_OVERRIDE_LOCALE_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in locale.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_LOCALE_H_ */ +#endif /* OSAL_OVERRIDE_LOCALE_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/logLib.h b/src/unit-test-coverage/ut-stubs/override_inc/logLib.h index 005a1eb4f..a58c2b2a0 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/logLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/logLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for logLib.h */ -#ifndef _OSAL_OVERRIDE_LOGLIB_H_ -#define _OSAL_OVERRIDE_LOGLIB_H_ +#ifndef OSAL_OVERRIDE_LOGLIB_H +#define OSAL_OVERRIDE_LOGLIB_H #include #include @@ -29,4 +29,4 @@ /* mappings for declarations in logLib.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_LOGLIB_H_ */ +#endif /* OSAL_OVERRIDE_LOGLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/math.h b/src/unit-test-coverage/ut-stubs/override_inc/math.h index 07d08024e..ff67798ea 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/math.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/math.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for math.h */ -#ifndef _OSAL_OVERRIDE_MATH_H_ -#define _OSAL_OVERRIDE_MATH_H_ +#ifndef OSAL_OVERRIDE_MATH_H +#define OSAL_OVERRIDE_MATH_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in math.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_MATH_H_ */ +#endif /* OSAL_OVERRIDE_MATH_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/memPartLib.h b/src/unit-test-coverage/ut-stubs/override_inc/memPartLib.h index 6c40c603e..d66695b40 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/memPartLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/memPartLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for memPartLib.h */ -#ifndef _OSAL_OVERRIDE_MEMPARTLIB_H_ -#define _OSAL_OVERRIDE_MEMPARTLIB_H_ +#ifndef OSAL_OVERRIDE_MEMPARTLIB_H +#define OSAL_OVERRIDE_MEMPARTLIB_H #include #include @@ -35,4 +35,4 @@ #define memPartInfoGet OCS_memPartInfoGet #define memSysPartId OCS_memSysPartId -#endif /* _OSAL_OVERRIDE_MEMPARTLIB_H_ */ +#endif /* OSAL_OVERRIDE_MEMPARTLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/moduleLib.h b/src/unit-test-coverage/ut-stubs/override_inc/moduleLib.h index c92fd2e0c..e15586153 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/moduleLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/moduleLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for moduleLib.h */ -#ifndef _OSAL_OVERRIDE_MODULELIB_H_ -#define _OSAL_OVERRIDE_MODULELIB_H_ +#ifndef OSAL_OVERRIDE_MODULELIB_H +#define OSAL_OVERRIDE_MODULELIB_H #include #include @@ -34,4 +34,4 @@ #define moduleInfoGet OCS_moduleInfoGet -#endif /* _OSAL_OVERRIDE_MODULELIB_H_ */ +#endif /* OSAL_OVERRIDE_MODULELIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/mqueue.h b/src/unit-test-coverage/ut-stubs/override_inc/mqueue.h index 44b6464b3..5bd35d613 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/mqueue.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/mqueue.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for mqueue.h */ -#ifndef _OSAL_OVERRIDE_MQUEUE_H_ -#define _OSAL_OVERRIDE_MQUEUE_H_ +#ifndef OSAL_OVERRIDE_MQUEUE_H +#define OSAL_OVERRIDE_MQUEUE_H #include #include @@ -39,4 +39,4 @@ #define mq_timedsend OCS_mq_timedsend #define mq_unlink OCS_mq_unlink -#endif /* _OSAL_OVERRIDE_MQUEUE_H_ */ +#endif /* OSAL_OVERRIDE_MQUEUE_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/msgQLib.h b/src/unit-test-coverage/ut-stubs/override_inc/msgQLib.h index 88a269e17..8a5ba72d5 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/msgQLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/msgQLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for msgQLib.h */ -#ifndef _OSAL_OVERRIDE_MSGQLIB_H_ -#define _OSAL_OVERRIDE_MSGQLIB_H_ +#ifndef OSAL_OVERRIDE_MSGQLIB_H +#define OSAL_OVERRIDE_MSGQLIB_H #include #include @@ -42,4 +42,4 @@ #define msgQReceive OCS_msgQReceive #define msgQSend OCS_msgQSend -#endif /* _OSAL_OVERRIDE_MSGQLIB_H_ */ +#endif /* OSAL_OVERRIDE_MSGQLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/net/if.h b/src/unit-test-coverage/ut-stubs/override_inc/net/if.h index e92f24a1c..e3a1c48a2 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/net/if.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/net/if.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for net/if.h */ -#ifndef _OSAL_OVERRIDE_NET_IF_H_ -#define _OSAL_OVERRIDE_NET_IF_H_ +#ifndef OSAL_OVERRIDE_NET_IF_H +#define OSAL_OVERRIDE_NET_IF_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in net/if.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_NET_IF_H_ */ +#endif /* OSAL_OVERRIDE_NET_IF_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/netdb.h b/src/unit-test-coverage/ut-stubs/override_inc/netdb.h index cbc87575a..fe5425609 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/netdb.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/netdb.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for netdb.h */ -#ifndef _OSAL_OVERRIDE_NETDB_H_ -#define _OSAL_OVERRIDE_NETDB_H_ +#ifndef OSAL_OVERRIDE_NETDB_H +#define OSAL_OVERRIDE_NETDB_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in netdb.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_NETDB_H_ */ +#endif /* OSAL_OVERRIDE_NETDB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/netinet/in.h b/src/unit-test-coverage/ut-stubs/override_inc/netinet/in.h index ddedb8e16..eb885172c 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/netinet/in.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/netinet/in.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for netinet/in.h */ -#ifndef _OSAL_OVERRIDE_NETINET_IN_H_ -#define _OSAL_OVERRIDE_NETINET_IN_H_ +#ifndef OSAL_OVERRIDE_NETINET_IN_H +#define OSAL_OVERRIDE_NETINET_IN_H #include @@ -33,4 +33,4 @@ #define htonl OCS_htonl #define ntohl OCS_ntohl -#endif /* _OSAL_OVERRIDE_NETINET_IN_H_ */ +#endif /* OSAL_OVERRIDE_NETINET_IN_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/netinet/tcp.h b/src/unit-test-coverage/ut-stubs/override_inc/netinet/tcp.h index 0aecd0f69..a0269e6de 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/netinet/tcp.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/netinet/tcp.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for netinet/tcp.h */ -#ifndef _OSAL_OVERRIDE_NETINET_TCP_H_ -#define _OSAL_OVERRIDE_NETINET_TCP_H_ +#ifndef OSAL_OVERRIDE_NETINET_TCP_H +#define OSAL_OVERRIDE_NETINET_TCP_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in netinet/tcp.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_NETINET_TCP_H_ */ +#endif /* OSAL_OVERRIDE_NETINET_TCP_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/objLib.h b/src/unit-test-coverage/ut-stubs/override_inc/objLib.h index e90e69c8d..54496069a 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/objLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/objLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for objLib.h */ -#ifndef _OSAL_OVERRIDE_OBJLIB_H_ -#define _OSAL_OVERRIDE_OBJLIB_H_ +#ifndef OSAL_OVERRIDE_OBJLIB_H +#define OSAL_OVERRIDE_OBJLIB_H #include #include @@ -36,4 +36,4 @@ #define S_objLib_OBJ_TIMEOUT OCS_S_objLib_OBJ_TIMEOUT #define S_objLib_OBJ_NO_METHOD OCS_S_objLib_OBJ_NO_METHOD -#endif /* _OSAL_OVERRIDE_OBJLIB_H_ */ +#endif /* OSAL_OVERRIDE_OBJLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/poll.h b/src/unit-test-coverage/ut-stubs/override_inc/poll.h index cbd8efe16..adaae476c 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/poll.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/poll.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for poll.h */ -#ifndef _OSAL_OVERRIDE_POLL_H_ -#define _OSAL_OVERRIDE_POLL_H_ +#ifndef OSAL_OVERRIDE_POLL_H +#define OSAL_OVERRIDE_POLL_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in poll.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_POLL_H_ */ +#endif /* OSAL_OVERRIDE_POLL_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/pthread.h b/src/unit-test-coverage/ut-stubs/override_inc/pthread.h index 127afa071..3a061f2d4 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/pthread.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/pthread.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for pthread.h */ -#ifndef _OSAL_OVERRIDE_PTHREAD_H_ -#define _OSAL_OVERRIDE_PTHREAD_H_ +#ifndef OSAL_OVERRIDE_PTHREAD_H +#define OSAL_OVERRIDE_PTHREAD_H #include #include @@ -76,4 +76,4 @@ #define pthread_setspecific OCS_pthread_setspecific #define pthread_sigmask OCS_pthread_sigmask -#endif /* _OSAL_OVERRIDE_PTHREAD_H_ */ +#endif /* OSAL_OVERRIDE_PTHREAD_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/ramDiskCbio.h b/src/unit-test-coverage/ut-stubs/override_inc/ramDiskCbio.h index bb55400b7..1c925fc43 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/ramDiskCbio.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/ramDiskCbio.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ramDiskCbio.h */ -#ifndef _OSAL_OVERRIDE_RAMDISKCBIO_H_ -#define _OSAL_OVERRIDE_RAMDISKCBIO_H_ +#ifndef OSAL_OVERRIDE_RAMDISKCBIO_H +#define OSAL_OVERRIDE_RAMDISKCBIO_H #include #include @@ -29,4 +29,4 @@ /* mappings for declarations in ramDiskCbio.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_RAMDISKCBIO_H_ */ +#endif /* OSAL_OVERRIDE_RAMDISKCBIO_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/ramDrv.h b/src/unit-test-coverage/ut-stubs/override_inc/ramDrv.h index 7e37959c7..97896710c 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/ramDrv.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/ramDrv.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ramDrv.h */ -#ifndef _OSAL_OVERRIDE_RAMDRV_H_ -#define _OSAL_OVERRIDE_RAMDRV_H_ +#ifndef OSAL_OVERRIDE_RAMDRV_H +#define OSAL_OVERRIDE_RAMDRV_H #include #include @@ -32,4 +32,4 @@ #define ramDevCreate OCS_ramDevCreate -#endif /* _OSAL_OVERRIDE_RAMDRV_H_ */ +#endif /* OSAL_OVERRIDE_RAMDRV_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sched.h b/src/unit-test-coverage/ut-stubs/override_inc/sched.h index 1d2811ea9..53f6484a3 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sched.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sched.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sched.h */ -#ifndef _OSAL_OVERRIDE_SCHED_H_ -#define _OSAL_OVERRIDE_SCHED_H_ +#ifndef OSAL_OVERRIDE_SCHED_H +#define OSAL_OVERRIDE_SCHED_H #include @@ -36,4 +36,4 @@ #define sched_get_priority_max OCS_sched_get_priority_max #define sched_get_priority_min OCS_sched_get_priority_min -#endif /* _OSAL_OVERRIDE_SCHED_H_ */ +#endif /* OSAL_OVERRIDE_SCHED_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/selectLib.h b/src/unit-test-coverage/ut-stubs/override_inc/selectLib.h index 153bbf321..d43a2a58b 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/selectLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/selectLib.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_SELECTLIB_H_ -#define INCLUDE_SELECTLIB_H_ +#ifndef SELECTLIB_H +#define SELECTLIB_H #include #include @@ -35,4 +35,4 @@ /* mappings for declarations in selectLib.h */ /* ----------------------------------------- */ -#endif /* INCLUDE_SELECTLIB_H_ */ +#endif /* SELECTLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/semLib.h b/src/unit-test-coverage/ut-stubs/override_inc/semLib.h index f7704907b..d73febc05 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/semLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/semLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for semLib.h */ -#ifndef _OSAL_OVERRIDE_SEMLIB_H_ -#define _OSAL_OVERRIDE_SEMLIB_H_ +#ifndef OSAL_OVERRIDE_SEMLIB_H +#define OSAL_OVERRIDE_SEMLIB_H #include #include @@ -54,4 +54,4 @@ #define semTake OCS_semTake #define semGive OCS_semGive -#endif /* _OSAL_OVERRIDE_SEMLIB_H_ */ +#endif /* OSAL_OVERRIDE_SEMLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/semaphore.h b/src/unit-test-coverage/ut-stubs/override_inc/semaphore.h index cf04b8636..845434983 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/semaphore.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/semaphore.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for semaphore.h */ -#ifndef _OSAL_OVERRIDE_SEMAPHORE_H_ -#define _OSAL_OVERRIDE_SEMAPHORE_H_ +#ifndef OSAL_OVERRIDE_SEMAPHORE_H +#define OSAL_OVERRIDE_SEMAPHORE_H #include #include @@ -36,4 +36,4 @@ #define sem_timedwait OCS_sem_timedwait #define sem_wait OCS_sem_wait -#endif /* _OSAL_OVERRIDE_SEMAPHORE_H_ */ +#endif /* OSAL_OVERRIDE_SEMAPHORE_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/setjmp.h b/src/unit-test-coverage/ut-stubs/override_inc/setjmp.h index bf56ccd51..61d82bc1f 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/setjmp.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/setjmp.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for setjmp.h */ -#ifndef _OSAL_OVERRIDE_SETJMP_H_ -#define _OSAL_OVERRIDE_SETJMP_H_ +#ifndef OSAL_OVERRIDE_SETJMP_H +#define OSAL_OVERRIDE_SETJMP_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in setjmp.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_SETJMP_H_ */ +#endif /* OSAL_OVERRIDE_SETJMP_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/shellLib.h b/src/unit-test-coverage/ut-stubs/override_inc/shellLib.h index d072d0fb3..ce6e4d61c 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/shellLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/shellLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for shellLib.h */ -#ifndef _OSAL_OVERRIDE_SHELLLIB_H_ -#define _OSAL_OVERRIDE_SHELLLIB_H_ +#ifndef OSAL_OVERRIDE_SHELLLIB_H +#define OSAL_OVERRIDE_SHELLLIB_H #include #include @@ -30,4 +30,4 @@ /* ----------------------------------------- */ #define shellGenericInit OCS_shellGenericInit -#endif /* _OSAL_OVERRIDE_SHELLLIB_H_ */ +#endif /* OSAL_OVERRIDE_SHELLLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/signal.h b/src/unit-test-coverage/ut-stubs/override_inc/signal.h index 82ac74ae9..ec1b31caf 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/signal.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/signal.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for signal.h */ -#ifndef _OSAL_OVERRIDE_SIGNAL_H_ -#define _OSAL_OVERRIDE_SIGNAL_H_ +#ifndef OSAL_OVERRIDE_SIGNAL_H +#define OSAL_OVERRIDE_SIGNAL_H #include @@ -56,4 +56,4 @@ #define sigsuspend OCS_sigsuspend #define sigwait OCS_sigwait -#endif /* _OSAL_OVERRIDE_SIGNAL_H_ */ +#endif /* OSAL_OVERRIDE_SIGNAL_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/stat.h b/src/unit-test-coverage/ut-stubs/override_inc/stat.h index a53ada220..e0cabeafd 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/stat.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/stat.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for stat.h */ -#ifndef _OSAL_OVERRIDE_STAT_H_ -#define _OSAL_OVERRIDE_STAT_H_ +#ifndef OSAL_OVERRIDE_STAT_H +#define OSAL_OVERRIDE_STAT_H #include @@ -40,4 +40,4 @@ #define statvfs OCS_statvfs #define statfs OCS_statvfs -#endif /* _OSAL_OVERRIDE_STAT_H_ */ +#endif /* OSAL_OVERRIDE_STAT_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/stdarg.h b/src/unit-test-coverage/ut-stubs/override_inc/stdarg.h index 50f84b773..187c73683 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/stdarg.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/stdarg.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for stdarg.h */ -#ifndef _OSAL_OVERRIDE_STDARG_H_ -#define _OSAL_OVERRIDE_STDARG_H_ +#ifndef OSAL_OVERRIDE_STDARG_H +#define OSAL_OVERRIDE_STDARG_H #include @@ -32,4 +32,4 @@ #define va_start(ap, last) OCS_va_start(ap, last) #define va_end(ap) OCS_va_end(ap) -#endif /* _OSAL_OVERRIDE_STDARG_H_ */ +#endif /* OSAL_OVERRIDE_STDARG_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/stdio.h b/src/unit-test-coverage/ut-stubs/override_inc/stdio.h index ef1afa2c1..e09a93696 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/stdio.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/stdio.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for stdio.h */ -#ifndef _OSAL_OVERRIDE_STDIO_H_ -#define _OSAL_OVERRIDE_STDIO_H_ +#ifndef OSAL_OVERRIDE_STDIO_H +#define OSAL_OVERRIDE_STDIO_H #include @@ -28,20 +28,21 @@ /* mappings for declarations in stdio.h */ /* ----------------------------------------- */ -#define FILE OCS_FILE -#define fclose OCS_fclose -#define fgets OCS_fgets -#define fopen OCS_fopen -#define fputs OCS_fputs -#define remove OCS_remove -#define rename OCS_rename -#define snprintf OCS_snprintf -#define vsnprintf OCS_vsnprintf -#define printf(...) OCS_printf(__VA_ARGS__) -#define putchar OCS_putchar +#define FILE OCS_FILE +#define fclose OCS_fclose +#define fgets OCS_fgets +#define fopen OCS_fopen +#define fputs OCS_fputs +#define remove OCS_remove +#define rename OCS_rename +#define snprintf OCS_snprintf +#define vsnprintf OCS_vsnprintf +#define printf(...) OCS_printf(__VA_ARGS__) +#define fprintf(...) OCS_fprintf(__VA_ARGS__) +#define putchar OCS_putchar #define stdin OCS_stdin #define stdout OCS_stdout #define stderr OCS_stderr -#endif /* _OSAL_OVERRIDE_STDIO_H_ */ +#endif /* OSAL_OVERRIDE_STDIO_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/stdlib.h b/src/unit-test-coverage/ut-stubs/override_inc/stdlib.h index 2d16d6cf2..9ea6f219b 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/stdlib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/stdlib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for stdlib.h */ -#ifndef _OSAL_OVERRIDE_STDLIB_H_ -#define _OSAL_OVERRIDE_STDLIB_H_ +#ifndef OSAL_OVERRIDE_STDLIB_H +#define OSAL_OVERRIDE_STDLIB_H #include @@ -30,10 +30,11 @@ #define EXIT_SUCCESS OCS_EXIT_SUCCESS #define EXIT_FAILURE OCS_EXIT_FAILURE +#define abort OCS_abort #define exit OCS_exit #define strtoul OCS_strtoul #define system OCS_system #define malloc OCS_malloc #define free OCS_free -#endif /* _OSAL_OVERRIDE_STDLIB_H_ */ +#endif /* OSAL_OVERRIDE_STDLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/string.h b/src/unit-test-coverage/ut-stubs/override_inc/string.h index 86b4d6046..e4b83f152 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/string.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/string.h @@ -19,14 +19,15 @@ */ /* OSAL coverage stub replacement for string.h */ -#ifndef _OSAL_OVERRIDE_STRING_H_ -#define _OSAL_OVERRIDE_STRING_H_ +#ifndef OSAL_OVERRIDE_STRING_H +#define OSAL_OVERRIDE_STRING_H #include /* ----------------------------------------- */ /* mappings for declarations in string.h */ /* ----------------------------------------- */ +#define memchr OCS_memchr #define memcpy OCS_memcpy #define memset OCS_memset #define strcmp OCS_strcmp @@ -40,4 +41,4 @@ #define strncat OCS_strncat #define strerror OCS_strerror -#endif /* _OSAL_OVERRIDE_STRING_H_ */ +#endif /* OSAL_OVERRIDE_STRING_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/strings.h b/src/unit-test-coverage/ut-stubs/override_inc/strings.h index 8e799498b..1d7142f31 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/strings.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/strings.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for strings.h */ -#ifndef _OSAL_OVERRIDE_STRINGS_H_ -#define _OSAL_OVERRIDE_STRINGS_H_ +#ifndef OSAL_OVERRIDE_STRINGS_H +#define OSAL_OVERRIDE_STRINGS_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in strings.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_STRINGS_H_ */ +#endif /* OSAL_OVERRIDE_STRINGS_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/symLib.h b/src/unit-test-coverage/ut-stubs/override_inc/symLib.h index 8513fa755..1adcd6adf 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/symLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/symLib.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_SYMLIB_H_ -#define INCLUDE_SYMLIB_H_ +#ifndef SYMLIB_H +#define SYMLIB_H #include #include @@ -51,4 +51,4 @@ #define symEach OCS_symEach #define symFind OCS_symFind -#endif /* INCLUDE_SYMLIB_H_ */ +#endif /* SYMLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/ioctl.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/ioctl.h index d0748e8a5..8038d86b4 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/ioctl.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/ioctl.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/ioctl.h */ -#ifndef _OSAL_OVERRIDE_SYS_IOCTL_H_ -#define _OSAL_OVERRIDE_SYS_IOCTL_H_ +#ifndef OSAL_OVERRIDE_SYS_IOCTL_H +#define OSAL_OVERRIDE_SYS_IOCTL_H #include @@ -30,4 +30,4 @@ #define ioctl OCS_ioctl -#endif /* _OSAL_OVERRIDE_SYS_IOCTL_H_ */ +#endif /* OSAL_OVERRIDE_SYS_IOCTL_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/ipc.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/ipc.h index db1c81f5b..7d99f3b4c 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/ipc.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/ipc.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/ipc.h */ -#ifndef _OSAL_OVERRIDE_SYS_IPC_H_ -#define _OSAL_OVERRIDE_SYS_IPC_H_ +#ifndef OSAL_OVERRIDE_SYS_IPC_H +#define OSAL_OVERRIDE_SYS_IPC_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in sys/ipc.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_SYS_IPC_H_ */ +#endif /* OSAL_OVERRIDE_SYS_IPC_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/mman.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/mman.h index 675abaf7f..ef3c670f8 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/mman.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/mman.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/mman.h */ -#ifndef _OSAL_OVERRIDE_SYS_MMAN_H_ -#define _OSAL_OVERRIDE_SYS_MMAN_H_ +#ifndef OSAL_OVERRIDE_SYS_MMAN_H +#define OSAL_OVERRIDE_SYS_MMAN_H #include @@ -38,4 +38,4 @@ #define mmap OCS_mmap #define munmap OCS_munmap -#endif /* _OSAL_OVERRIDE_SYS_MMAN_H_ */ +#endif /* OSAL_OVERRIDE_SYS_MMAN_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/select.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/select.h index 649137bdf..4a2ddb46f 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/select.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/select.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_SELECT_H_ -#define INCLUDE_SELECT_H_ +#ifndef SELECT_H +#define SELECT_H #include @@ -50,4 +50,4 @@ #define FD_CLR OCS_FD_CLR #define FD_ZERO OCS_FD_ZERO -#endif /* INCLUDE_SELECT_H_ */ +#endif /* SELECT_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/signal.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/signal.h index e3d401b9f..0304c264e 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/signal.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/signal.h @@ -19,10 +19,10 @@ */ /* OSAL coverage stub replacement for sys/signal.h */ -#ifndef _OSAL_OVERRIDE_SYS_SIGNAL_H_ -#define _OSAL_OVERRIDE_SYS_SIGNAL_H_ +#ifndef OSAL_OVERRIDE_SYS_SIGNAL_H +#define OSAL_OVERRIDE_SYS_SIGNAL_H /* alias to signal.h */ #include -#endif /* _OSAL_OVERRIDE_SYS_SIGNAL_H_ */ +#endif /* OSAL_OVERRIDE_SYS_SIGNAL_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/socket.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/socket.h index bb1ef7309..11128a920 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/socket.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/socket.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/socket.h */ -#ifndef _OSAL_OVERRIDE_SYS_SOCKET_H_ -#define _OSAL_OVERRIDE_SYS_SOCKET_H_ +#ifndef OSAL_OVERRIDE_SYS_SOCKET_H +#define OSAL_OVERRIDE_SYS_SOCKET_H #include @@ -39,4 +39,4 @@ #define setsockopt OCS_setsockopt #define socket OCS_socket -#endif /* _OSAL_OVERRIDE_SYS_SOCKET_H_ */ +#endif /* OSAL_OVERRIDE_SYS_SOCKET_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/stat.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/stat.h index a63bfc525..b6f5d80ce 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/stat.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/stat.h @@ -19,10 +19,10 @@ */ /* OSAL coverage stub replacement for sys/stat.h */ -#ifndef _OSAL_OVERRIDE_SYS_STAT_H_ -#define _OSAL_OVERRIDE_SYS_STAT_H_ +#ifndef OSAL_OVERRIDE_SYS_STAT_H +#define OSAL_OVERRIDE_SYS_STAT_H /* alias to stat.h */ #include -#endif /* _OSAL_OVERRIDE_SYS_STAT_H_ */ +#endif /* OSAL_OVERRIDE_SYS_STAT_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/statvfs.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/statvfs.h index feb6fa97d..7d53a30e2 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/statvfs.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/statvfs.h @@ -19,10 +19,10 @@ */ /* OSAL coverage stub replacement for sys/statvfs.h */ -#ifndef _OSAL_OVERRIDE_SYS_STATVFS_H_ -#define _OSAL_OVERRIDE_SYS_STATVFS_H_ +#ifndef OSAL_OVERRIDE_SYS_STATVFS_H +#define OSAL_OVERRIDE_SYS_STATVFS_H /* alias to stat.h */ #include -#endif /* _OSAL_OVERRIDE_SYS_STATVFS_H_ */ +#endif /* OSAL_OVERRIDE_SYS_STATVFS_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/time.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/time.h index d327024cb..111336de4 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/time.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/time.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/time.h */ -#ifndef _OSAL_OVERRIDE_SYS_TIME_H_ -#define _OSAL_OVERRIDE_SYS_TIME_H_ +#ifndef OSAL_OVERRIDE_SYS_TIME_H +#define OSAL_OVERRIDE_SYS_TIME_H #include #include @@ -29,4 +29,4 @@ /* mappings for declarations in sys/time.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_SYS_TIME_H_ */ +#endif /* OSAL_OVERRIDE_SYS_TIME_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/times.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/times.h index e4c6626c7..052399273 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/times.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/times.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/times.h */ -#ifndef _OSAL_OVERRIDE_SYS_TIMES_H_ -#define _OSAL_OVERRIDE_SYS_TIMES_H_ +#ifndef OSAL_OVERRIDE_SYS_TIMES_H +#define OSAL_OVERRIDE_SYS_TIMES_H #include #include @@ -29,4 +29,4 @@ /* mappings for declarations in sys/times.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_SYS_TIMES_H_ */ +#endif /* OSAL_OVERRIDE_SYS_TIMES_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/types.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/types.h index 50ef43ffa..c1cd599f8 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/types.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/types.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/types.h */ -#ifndef _OSAL_OVERRIDE_SYS_TYPES_H_ -#define _OSAL_OVERRIDE_SYS_TYPES_H_ +#ifndef OSAL_OVERRIDE_SYS_TYPES_H +#define OSAL_OVERRIDE_SYS_TYPES_H #include @@ -34,4 +34,4 @@ #define gid_t OCS_gid_t #define uid_t OCS_uid_t -#endif /* _OSAL_OVERRIDE_SYS_TYPES_H_ */ +#endif /* OSAL_OVERRIDE_SYS_TYPES_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/un.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/un.h index 7f093ac5c..9addd5013 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/un.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/un.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/un.h */ -#ifndef _OSAL_OVERRIDE_SYS_UN_H_ -#define _OSAL_OVERRIDE_SYS_UN_H_ +#ifndef OSAL_OVERRIDE_SYS_UN_H +#define OSAL_OVERRIDE_SYS_UN_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in sys/un.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_SYS_UN_H_ */ +#endif /* OSAL_OVERRIDE_SYS_UN_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/wait.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/wait.h index 358781c80..1d410f5e3 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/wait.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/wait.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sys/wait.h */ -#ifndef _OSAL_OVERRIDE_SYS_WAIT_H_ -#define _OSAL_OVERRIDE_SYS_WAIT_H_ +#ifndef OSAL_OVERRIDE_SYS_WAIT_H +#define OSAL_OVERRIDE_SYS_WAIT_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in sys/wait.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_SYS_WAIT_H_ */ +#endif /* OSAL_OVERRIDE_SYS_WAIT_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sysLib.h b/src/unit-test-coverage/ut-stubs/override_inc/sysLib.h index 06363364e..145041eb7 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sysLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sysLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for sysLib.h */ -#ifndef _OSAL_OVERRIDE_SYSLIB_H_ -#define _OSAL_OVERRIDE_SYSLIB_H_ +#ifndef OSAL_OVERRIDE_SYSLIB_H +#define OSAL_OVERRIDE_SYSLIB_H #include #include @@ -30,4 +30,4 @@ /* ----------------------------------------- */ #define sysClkRateGet OCS_sysClkRateGet -#endif /* _OSAL_OVERRIDE_SYSLIB_H_ */ +#endif /* OSAL_OVERRIDE_SYSLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/taskLib.h b/src/unit-test-coverage/ut-stubs/override_inc/taskLib.h index 625923443..0b939ea80 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/taskLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/taskLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for taskLib.h */ -#ifndef _OSAL_OVERRIDE_TASKLIB_H_ -#define _OSAL_OVERRIDE_TASKLIB_H_ +#ifndef OSAL_OVERRIDE_TASKLIB_H +#define OSAL_OVERRIDE_TASKLIB_H #include #include @@ -53,4 +53,4 @@ #define taskInit OCS_taskInit #define taskTcb OCS_taskTcb -#endif /* _OSAL_OVERRIDE_TASKLIB_H_ */ +#endif /* OSAL_OVERRIDE_TASKLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/taskVarLib.h b/src/unit-test-coverage/ut-stubs/override_inc/taskVarLib.h index 470bafd88..46f3f7a4a 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/taskVarLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/taskVarLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for taskVarLib.h */ -#ifndef _OSAL_OVERRIDE_TASKVARLIB_H_ -#define _OSAL_OVERRIDE_TASKVARLIB_H_ +#ifndef OSAL_OVERRIDE_TASKVARLIB_H +#define OSAL_OVERRIDE_TASKVARLIB_H #include #include @@ -31,4 +31,4 @@ #define taskVarAdd OCS_taskVarAdd -#endif /* _OSAL_OVERRIDE_TASKVARLIB_H_ */ +#endif /* OSAL_OVERRIDE_TASKVARLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/termios.h b/src/unit-test-coverage/ut-stubs/override_inc/termios.h index fbab2171d..ab4887d2c 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/termios.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/termios.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for termios.h */ -#ifndef _OSAL_OVERRIDE_TERMIOS_H_ -#define _OSAL_OVERRIDE_TERMIOS_H_ +#ifndef OSAL_OVERRIDE_TERMIOS_H +#define OSAL_OVERRIDE_TERMIOS_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in termios.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_TERMIOS_H_ */ +#endif /* OSAL_OVERRIDE_TERMIOS_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/tgmath.h b/src/unit-test-coverage/ut-stubs/override_inc/tgmath.h index 0643ca2bd..87bd41129 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/tgmath.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/tgmath.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for tgmath.h */ -#ifndef _OSAL_OVERRIDE_TGMATH_H_ -#define _OSAL_OVERRIDE_TGMATH_H_ +#ifndef OSAL_OVERRIDE_TGMATH_H +#define OSAL_OVERRIDE_TGMATH_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in tgmath.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_TGMATH_H_ */ +#endif /* OSAL_OVERRIDE_TGMATH_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/time.h b/src/unit-test-coverage/ut-stubs/override_inc/time.h index 67e0cf09e..9cfcbe605 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/time.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/time.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for time.h */ -#ifndef _OSAL_OVERRIDE_TIME_H_ -#define _OSAL_OVERRIDE_TIME_H_ +#ifndef OSAL_OVERRIDE_TIME_H +#define OSAL_OVERRIDE_TIME_H #include @@ -51,4 +51,4 @@ #define timer_settime OCS_timer_settime #define timer_connect OCS_timer_connect -#endif /* _OSAL_OVERRIDE_TIME_H_ */ +#endif /* OSAL_OVERRIDE_TIME_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/timers.h b/src/unit-test-coverage/ut-stubs/override_inc/timers.h index eae5889c6..b6c6012ae 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/timers.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/timers.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for timers.h */ -#ifndef _OSAL_OVERRIDE_TIMERS_H_ -#define _OSAL_OVERRIDE_TIMERS_H_ +#ifndef OSAL_OVERRIDE_TIMERS_H +#define OSAL_OVERRIDE_TIMERS_H #include #include @@ -29,4 +29,4 @@ * Note: this is just an alias for time.h */ -#endif /* _OSAL_OVERRIDE_TIMERS_H_ */ +#endif /* OSAL_OVERRIDE_TIMERS_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/ulimit.h b/src/unit-test-coverage/ut-stubs/override_inc/ulimit.h index 7a26b4009..c1d9c6768 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/ulimit.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/ulimit.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for ulimit.h */ -#ifndef _OSAL_OVERRIDE_ULIMIT_H_ -#define _OSAL_OVERRIDE_ULIMIT_H_ +#ifndef OSAL_OVERRIDE_ULIMIT_H +#define OSAL_OVERRIDE_ULIMIT_H #include @@ -29,4 +29,4 @@ /* ----------------------------------------- */ #define ulimit OCS_ulimit -#endif /* _OSAL_OVERRIDE_ULIMIT_H_ */ +#endif /* OSAL_OVERRIDE_ULIMIT_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/unistd.h b/src/unit-test-coverage/ut-stubs/override_inc/unistd.h index 2f77e11a6..31d3afeb6 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/unistd.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/unistd.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for unistd.h */ -#ifndef _OSAL_OVERRIDE_UNISTD_H_ -#define _OSAL_OVERRIDE_UNISTD_H_ +#ifndef OSAL_OVERRIDE_UNISTD_H +#define OSAL_OVERRIDE_UNISTD_H #include @@ -47,4 +47,4 @@ #define sysconf OCS_sysconf #define write OCS_write -#endif /* _OSAL_OVERRIDE_UNISTD_H_ */ +#endif /* OSAL_OVERRIDE_UNISTD_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/unldLib.h b/src/unit-test-coverage/ut-stubs/override_inc/unldLib.h index ed7fb77f7..5076192cf 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/unldLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/unldLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for unldLib.h */ -#ifndef _OSAL_OVERRIDE_UNLDLIB_H_ -#define _OSAL_OVERRIDE_UNLDLIB_H_ +#ifndef OSAL_OVERRIDE_UNLDLIB_H +#define OSAL_OVERRIDE_UNLDLIB_H #include #include @@ -31,4 +31,4 @@ /* ----------------------------------------- */ #define unldByModuleId OCS_unldByModuleId -#endif /* _OSAL_OVERRIDE_UNLDLIB_H_ */ +#endif /* OSAL_OVERRIDE_UNLDLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/usrLib.h b/src/unit-test-coverage/ut-stubs/override_inc/usrLib.h index 7d1eda6b1..21f4b9104 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/usrLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/usrLib.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for usrLib.h */ -#ifndef _OSAL_OVERRIDE_USRLIB_H_ -#define _OSAL_OVERRIDE_USRLIB_H_ +#ifndef OSAL_OVERRIDE_USRLIB_H +#define OSAL_OVERRIDE_USRLIB_H #include #include @@ -29,4 +29,4 @@ /* mappings for declarations in usrLib.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_USRLIB_H_ */ +#endif /* OSAL_OVERRIDE_USRLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/version.h b/src/unit-test-coverage/ut-stubs/override_inc/version.h index fac7aaaef..4ccf55a6c 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/version.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/version.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for version.h */ -#ifndef _OSAL_OVERRIDE_VERSION_H_ -#define _OSAL_OVERRIDE_VERSION_H_ +#ifndef OSAL_OVERRIDE_VERSION_H +#define OSAL_OVERRIDE_VERSION_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in version.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_VERSION_H_ */ +#endif /* OSAL_OVERRIDE_VERSION_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/vxWorks.h b/src/unit-test-coverage/ut-stubs/override_inc/vxWorks.h index 1c9572df7..0f36e6510 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/vxWorks.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/vxWorks.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_VXWORKS_H_ -#define INCLUDE_VXWORKS_H_ +#ifndef VXWORKS_H +#define VXWORKS_H #include @@ -53,4 +53,4 @@ #define _Vx_usr_arg_t OCS_Vx_usr_arg_t -#endif /* INCLUDE_VXWORKS_H_ */ +#endif /* VXWORKS_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/wchar.h b/src/unit-test-coverage/ut-stubs/override_inc/wchar.h index 00f72b272..9f0d251eb 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/wchar.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/wchar.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for wchar.h */ -#ifndef _OSAL_OVERRIDE_WCHAR_H_ -#define _OSAL_OVERRIDE_WCHAR_H_ +#ifndef OSAL_OVERRIDE_WCHAR_H +#define OSAL_OVERRIDE_WCHAR_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in wchar.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_WCHAR_H_ */ +#endif /* OSAL_OVERRIDE_WCHAR_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/wctype.h b/src/unit-test-coverage/ut-stubs/override_inc/wctype.h index cc2d3fbc3..abcec3509 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/wctype.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/wctype.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for wctype.h */ -#ifndef _OSAL_OVERRIDE_WCTYPE_H_ -#define _OSAL_OVERRIDE_WCTYPE_H_ +#ifndef OSAL_OVERRIDE_WCTYPE_H +#define OSAL_OVERRIDE_WCTYPE_H #include @@ -28,4 +28,4 @@ /* mappings for declarations in wctype.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_WCTYPE_H_ */ +#endif /* OSAL_OVERRIDE_WCTYPE_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/xbdBlkDev.h b/src/unit-test-coverage/ut-stubs/override_inc/xbdBlkDev.h index 03bf58d16..39bba2a37 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/xbdBlkDev.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/xbdBlkDev.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for xbdBlkDev.h */ -#ifndef _OSAL_OVERRIDE_XBDBLKDEV_H_ -#define _OSAL_OVERRIDE_XBDBLKDEV_H_ +#ifndef OSAL_OVERRIDE_XBDBLKDEV_H +#define OSAL_OVERRIDE_XBDBLKDEV_H #include #include @@ -35,4 +35,4 @@ #define xbdBlkDevCreateSync OCS_xbdBlkDevCreateSync #define xbdBlkDevDelete OCS_xbdBlkDevDelete -#endif /* _OSAL_OVERRIDE_XBDBLKDEV_H_ */ +#endif /* OSAL_OVERRIDE_XBDBLKDEV_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/xbdRamDisk.h b/src/unit-test-coverage/ut-stubs/override_inc/xbdRamDisk.h index 4b01cf054..9344b0294 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/xbdRamDisk.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/xbdRamDisk.h @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for xbdRamDisk.h */ -#ifndef _OSAL_OVERRIDE_XBDRAMDISK_H_ -#define _OSAL_OVERRIDE_XBDRAMDISK_H_ +#ifndef OSAL_OVERRIDE_XBDRAMDISK_H +#define OSAL_OVERRIDE_XBDRAMDISK_H #include #include @@ -29,4 +29,4 @@ /* mappings for declarations in xbdRamDisk.h */ /* ----------------------------------------- */ -#endif /* _OSAL_OVERRIDE_XBDRAMDISK_H_ */ +#endif /* OSAL_OVERRIDE_XBDRAMDISK_H */ diff --git a/src/unit-test-coverage/ut-stubs/src/bsp-console-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/bsp-console-impl-stubs.c index 23aeb900c..d3ed86ea3 100644 --- a/src/unit-test-coverage/ut-stubs/src/bsp-console-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/bsp-console-impl-stubs.c @@ -43,7 +43,7 @@ Note: This should write the string as-is without buffering. ------------------------------------------------------------------*/ -void OCS_OS_BSP_ConsoleOutput_Impl(const char *Str, uint32_t DataLen) +void OCS_OS_BSP_ConsoleOutput_Impl(const char *Str, size_t DataLen) { int32_t retcode = UT_DEFAULT_IMPL(OCS_OS_BSP_ConsoleOutput_Impl); diff --git a/src/unit-test-coverage/ut-stubs/src/libc-stdio-stubs.c b/src/unit-test-coverage/ut-stubs/src/libc-stdio-stubs.c index aa67f8aa2..c1bfd05ea 100644 --- a/src/unit-test-coverage/ut-stubs/src/libc-stdio-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/libc-stdio-stubs.c @@ -45,7 +45,7 @@ int OCS_fclose(OCS_FILE *stream) char *OCS_fgets(char *s, int n, OCS_FILE *stream) { int32 Status; - uint32 CopySize; + size_t CopySize; Status = UT_DEFAULT_IMPL_RC(OCS_fgets, OCS_STDIO_MAX_SIZE); @@ -196,6 +196,11 @@ int OCS_printf(const char *format, ...) return UT_DEFAULT_IMPL(OCS_printf); } +int OCS_fprintf(OCS_FILE *fp, const char *format, ...) +{ + return UT_DEFAULT_IMPL(OCS_fprintf); +} + static OCS_FILE LOCAL_FP[3] = {{10}, {11}, {12}}; OCS_FILE *OCS_stdin = &LOCAL_FP[0]; diff --git a/src/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c b/src/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c index 88eabb995..97a8e3492 100644 --- a/src/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c @@ -59,6 +59,13 @@ void OCS_exit(int c) */ } +void OCS_abort(void) +{ + UT_DEFAULT_IMPL(OCS_abort); + + /* Note - same issue as with OCS_exit() - this isn't supposed to return */ +} + unsigned long int OCS_strtoul(const char *nptr, char **endptr, int base) { int32 Status; @@ -92,7 +99,7 @@ void *OCS_malloc(size_t sz) cpuaddr PoolEnd; cpuaddr NextBlock; size_t NextSize; - uint32 PoolSize; + size_t PoolSize; uint32 CallCnt; struct MPOOL_REC *Rec; @@ -163,7 +170,7 @@ void OCS_free(void *ptr) int32 Status; cpuaddr BlockAddr; void * PoolPtr; - uint32 PoolSize; + size_t PoolSize; struct MPOOL_REC *Rec; /* diff --git a/src/unit-test-coverage/ut-stubs/src/libc-string-stubs.c b/src/unit-test-coverage/ut-stubs/src/libc-string-stubs.c index d8cac53a7..3cc275c2d 100644 --- a/src/unit-test-coverage/ut-stubs/src/libc-string-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/libc-string-stubs.c @@ -45,6 +45,24 @@ void *OCS_memset(void *s, int c, size_t n) return Result; } +void *OCS_memchr(const void *s, int c, size_t n) +{ + int32 Status; + void *Result; + + Status = UT_DEFAULT_IMPL(OCS_memchr); + if (Status == 0) + { + Result = memchr(s, c, n); + } + else + { + Result = NULL; + } + + return Result; +} + void *OCS_memcpy(void *dest, const void *src, size_t n) { int32 Status; diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c index c54b742e1..cee315962 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c @@ -38,10 +38,10 @@ ** Semaphore API */ -UT_DEFAULT_STUB(OS_BinSemCreate_Impl, (uint32 sem_id, uint32 sem_initial_value, uint32 options)) -UT_DEFAULT_STUB(OS_BinSemFlush_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_BinSemGive_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_BinSemTake_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_BinSemTimedWait_Impl, (uint32 sem_id, uint32 msecs)) -UT_DEFAULT_STUB(OS_BinSemDelete_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_BinSemGetInfo_Impl, (uint32 sem_id, OS_bin_sem_prop_t *bin_prop)) +UT_DEFAULT_STUB(OS_BinSemCreate_Impl, (const OS_object_token_t *token, uint32 sem_initial_value, uint32 options)) +UT_DEFAULT_STUB(OS_BinSemFlush_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_BinSemGive_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_BinSemTake_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_BinSemTimedWait_Impl, (const OS_object_token_t *token, uint32 msecs)) +UT_DEFAULT_STUB(OS_BinSemDelete_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_BinSemGetInfo_Impl, (const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c index 07393f74f..07edfa887 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c @@ -34,7 +34,7 @@ #include "os-shared-common.h" -UT_DEFAULT_STUB(OS_API_Impl_Init, (uint32 idtype)) +UT_DEFAULT_STUB(OS_API_Impl_Init, (osal_objtype_t idtype)) void OS_IdleLoop_Impl(void) { @@ -45,3 +45,8 @@ void OS_ApplicationShutdown_Impl(void) { UT_DEFAULT_IMPL(OS_ApplicationShutdown_Impl); } + +void OS_WaitForStateChange_Impl(osal_objtype_t objtype, uint32 attempts) +{ + UT_DEFAULT_IMPL(OS_WaitForStateChange_Impl); +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c index 6a0d202fb..99dc96511 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c @@ -37,11 +37,11 @@ /* ** Console output API (printf) */ -void OS_ConsoleWakeup_Impl(uint32 local_id) +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_ConsoleWakeup_Impl); } -int32 OS_ConsoleCreate_Impl(uint32 local_id) +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { return UT_DEFAULT_IMPL(OS_ConsoleCreate_Impl); } diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c index caa024050..d6dcf2a54 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c @@ -38,9 +38,9 @@ ** Semaphore API */ -UT_DEFAULT_STUB(OS_CountSemCreate_Impl, (uint32 sem_id, uint32 sem_initial_value, uint32 options)) -UT_DEFAULT_STUB(OS_CountSemGive_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_CountSemTake_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_CountSemTimedWait_Impl, (uint32 sem_id, uint32 msecs)) -UT_DEFAULT_STUB(OS_CountSemDelete_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_CountSemGetInfo_Impl, (uint32 sem_id, OS_count_sem_prop_t *count_prop)) +UT_DEFAULT_STUB(OS_CountSemCreate_Impl, (const OS_object_token_t *token, uint32 sem_initial_value, uint32 options)) +UT_DEFAULT_STUB(OS_CountSemGive_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_CountSemTake_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_CountSemTimedWait_Impl, (const OS_object_token_t *token, uint32 msecs)) +UT_DEFAULT_STUB(OS_CountSemDelete_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_CountSemGetInfo_Impl, (const OS_object_token_t *token, OS_count_sem_prop_t *count_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c index 26fec0ba1..e5f0d52f5 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c @@ -39,27 +39,27 @@ * File API abstraction layer */ -UT_DEFAULT_STUB(OS_FileOpen_Impl, (uint32 file_id, const char *local_path, int32 flags, int32 access)) +UT_DEFAULT_STUB(OS_FileOpen_Impl, (const OS_object_token_t *token, const char *local_path, int32 flags, int32 access)) UT_DEFAULT_STUB(OS_FileStat_Impl, (const char *local_path, os_fstat_t *filestat)) UT_DEFAULT_STUB(OS_FileRemove_Impl, (const char *local_path)) UT_DEFAULT_STUB(OS_FileRename_Impl, (const char *old_path, const char *new_path)) UT_DEFAULT_STUB(OS_FileChmod_Impl, (const char *local_path, uint32 access)) -UT_DEFAULT_STUB(OS_ShellOutputToFile_Impl, (uint32 file_id, const char *Cmd)) +UT_DEFAULT_STUB(OS_ShellOutputToFile_Impl, (const OS_object_token_t *token, const char *Cmd)) /* * Directory API abstraction layer */ UT_DEFAULT_STUB(OS_DirCreate_Impl, (const char *local_path, uint32 access)) -UT_DEFAULT_STUB(OS_DirOpen_Impl, (uint32 dir_id, const char *local_path)) -UT_DEFAULT_STUB(OS_DirClose_Impl, (uint32 dir_id)) -UT_DEFAULT_STUB(OS_DirRead_Impl, (uint32 dir_id, os_dirent_t *dirent)) -UT_DEFAULT_STUB(OS_DirRewind_Impl, (uint32 dir_id)) +UT_DEFAULT_STUB(OS_DirOpen_Impl, (const OS_object_token_t *token, const char *local_path)) +UT_DEFAULT_STUB(OS_DirClose_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_DirRead_Impl, (const OS_object_token_t *token, os_dirent_t *dirent)) +UT_DEFAULT_STUB(OS_DirRewind_Impl, (const OS_object_token_t *token)) UT_DEFAULT_STUB(OS_DirRemove_Impl, (const char *local_path)) /* * Stream abstraction layer (applies to sockets and files) */ -int32 OS_GenericRead_Impl(uint32 stream_id, void *buffer, uint32 nbytes, int32 timeout) +int32 OS_GenericRead_Impl(const OS_object_token_t *token, void *buffer, size_t nbytes, int32 timeout) { int32 Status = UT_DEFAULT_IMPL(OS_GenericRead_Impl); @@ -71,7 +71,7 @@ int32 OS_GenericRead_Impl(uint32 stream_id, void *buffer, uint32 nbytes, int32 t return Status; } -int32 OS_GenericWrite_Impl(uint32 stream_id, const void *buffer, uint32 nbytes, int32 timeout) +int32 OS_GenericWrite_Impl(const OS_object_token_t *token, const void *buffer, size_t nbytes, int32 timeout) { int32 Status = UT_DEFAULT_IMPL(OS_GenericWrite_Impl); @@ -83,5 +83,5 @@ int32 OS_GenericWrite_Impl(uint32 stream_id, const void *buffer, uint32 nbytes, return Status; } -UT_DEFAULT_STUB(OS_GenericSeek_Impl, (uint32 file_id, int32 offset, uint32 whence)) -UT_DEFAULT_STUB(OS_GenericClose_Impl, (uint32 file_id)) +UT_DEFAULT_STUB(OS_GenericSeek_Impl, (const OS_object_token_t *token, int32 offset, uint32 whence)) +UT_DEFAULT_STUB(OS_GenericClose_Impl, (const OS_object_token_t *token)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c index 8c0ac6f24..0dd5577e0 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c @@ -36,14 +36,14 @@ /* * File system abstraction layer */ -UT_DEFAULT_STUB(OS_FileSysStartVolume_Impl, (uint32 filesys_id)) -UT_DEFAULT_STUB(OS_FileSysStopVolume_Impl, (uint32 filesys_id)) -UT_DEFAULT_STUB(OS_FileSysFormatVolume_Impl, (uint32 filesys_id)) -UT_DEFAULT_STUB(OS_FileSysCheckVolume_Impl, (uint32 filesys_id, bool repair)) -UT_DEFAULT_STUB(OS_FileSysMountVolume_Impl, (uint32 filesys_id)) -UT_DEFAULT_STUB(OS_FileSysUnmountVolume_Impl, (uint32 filesys_id)) +UT_DEFAULT_STUB(OS_FileSysStartVolume_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_FileSysStopVolume_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_FileSysFormatVolume_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_FileSysCheckVolume_Impl, (const OS_object_token_t *token, bool repair)) +UT_DEFAULT_STUB(OS_FileSysMountVolume_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_FileSysUnmountVolume_Impl, (const OS_object_token_t *token)) -int32 OS_FileSysStatVolume_Impl(uint32 filesys_id, OS_statvfs_t *result) +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) { int32 Status = UT_DEFAULT_IMPL(OS_FileSysStatVolume_Impl); diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c index f3546e9f9..7bff71d1e 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c @@ -38,5 +38,11 @@ * Table locking and unlocking for global objects can be done at the shared code * layer but the actual implementation is OS-specific */ -UT_DEFAULT_STUB(OS_Lock_Global_Impl, (uint32 idtype)) -UT_DEFAULT_STUB(OS_Unlock_Global_Impl, (uint32 idtype)) +void OS_Lock_Global_Impl(osal_objtype_t idtype) +{ + UT_DEFAULT_IMPL(OS_Lock_Global_Impl); +} +void OS_Unlock_Global_Impl(osal_objtype_t idtype) +{ + UT_DEFAULT_IMPL(OS_Unlock_Global_Impl); +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c index 8c5d7aa77..fedb8593b 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c @@ -36,8 +36,10 @@ /* * Module Loader API */ -UT_DEFAULT_STUB(OS_ModuleLoad_Impl, (uint32 module_id, const char *translated_path)) -UT_DEFAULT_STUB(OS_ModuleUnload_Impl, (uint32 module_id)) -UT_DEFAULT_STUB(OS_ModuleGetInfo_Impl, (uint32 module_id, OS_module_prop_t *module_prop)) -UT_DEFAULT_STUB(OS_SymbolLookup_Impl, (cpuaddr * SymbolAddress, const char *SymbolName)) -UT_DEFAULT_STUB(OS_SymbolTableDump_Impl, (const char *filename, uint32 size_limit)) +UT_DEFAULT_STUB(OS_ModuleLoad_Impl, (const OS_object_token_t *token, const char *translated_path)) +UT_DEFAULT_STUB(OS_ModuleUnload_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_ModuleGetInfo_Impl, (const OS_object_token_t *token, OS_module_prop_t *module_prop)) +UT_DEFAULT_STUB(OS_GlobalSymbolLookup_Impl, (cpuaddr * SymbolAddress, const char *SymbolName)) +UT_DEFAULT_STUB(OS_ModuleSymbolLookup_Impl, + (const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName)) +UT_DEFAULT_STUB(OS_SymbolTableDump_Impl, (const char *filename, size_t size_limit)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c index 7bc4230bc..f106785f4 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c @@ -38,8 +38,8 @@ ** Mutex API */ -UT_DEFAULT_STUB(OS_MutSemCreate_Impl, (uint32 sem_id, uint32 options)) -UT_DEFAULT_STUB(OS_MutSemGive_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_MutSemTake_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_MutSemDelete_Impl, (uint32 sem_id)) -UT_DEFAULT_STUB(OS_MutSemGetInfo_Impl, (uint32 sem_id, OS_mut_sem_prop_t *mut_prop)) +UT_DEFAULT_STUB(OS_MutSemCreate_Impl, (const OS_object_token_t *token, uint32 options)) +UT_DEFAULT_STUB(OS_MutSemGive_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_MutSemTake_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_MutSemDelete_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_MutSemGetInfo_Impl, (const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c index e576d35ca..f797457e7 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c @@ -37,23 +37,24 @@ /* * Sockets API abstraction layer */ -UT_DEFAULT_STUB(OS_SocketOpen_Impl, (uint32 sock_id)) -UT_DEFAULT_STUB(OS_SocketClose_Impl, (uint32 sock_id)) -UT_DEFAULT_STUB(OS_SocketBind_Impl, (uint32 sock_id, const OS_SockAddr_t *Addr)) -UT_DEFAULT_STUB(OS_SocketAccept_Impl, (uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Addr, int32 timeout)) -UT_DEFAULT_STUB(OS_SocketConnect_Impl, (uint32 sock_id, const OS_SockAddr_t *Addr, int32 timeout)) +UT_DEFAULT_STUB(OS_SocketOpen_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_SocketClose_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_SocketBind_Impl, (const OS_object_token_t *token, const OS_SockAddr_t *Addr)) +UT_DEFAULT_STUB(OS_SocketAccept_Impl, (const OS_object_token_t *sock_token, const OS_object_token_t *conn_token, + OS_SockAddr_t *Addr, int32 timeout)) +UT_DEFAULT_STUB(OS_SocketConnect_Impl, (const OS_object_token_t *token, const OS_SockAddr_t *Addr, int32 timeout)) UT_DEFAULT_STUB(OS_SocketRecvFrom_Impl, - (uint32 sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout)) + (const OS_object_token_t *token, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout)) UT_DEFAULT_STUB(OS_SocketSendTo_Impl, - (uint32 sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr)) -UT_DEFAULT_STUB(OS_SocketGetInfo_Impl, (uint32 sock_id, OS_socket_prop_t *sock_prop)) + (const OS_object_token_t *token, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr)) +UT_DEFAULT_STUB(OS_SocketGetInfo_Impl, (const OS_object_token_t *token, OS_socket_prop_t *sock_prop)) UT_DEFAULT_STUB(OS_SocketAddrInit_Impl, (OS_SockAddr_t * Addr, OS_SocketDomain_t Domain)) -UT_DEFAULT_STUB(OS_SocketAddrToString_Impl, (char *buffer, uint32 buflen, const OS_SockAddr_t *Addr)) +UT_DEFAULT_STUB(OS_SocketAddrToString_Impl, (char *buffer, size_t buflen, const OS_SockAddr_t *Addr)) UT_DEFAULT_STUB(OS_SocketAddrGetPort_Impl, (uint16 * PortNum, const OS_SockAddr_t *Addr)) UT_DEFAULT_STUB(OS_SocketAddrFromString_Impl, (OS_SockAddr_t * Addr, const char *string)) UT_DEFAULT_STUB(OS_SocketAddrSetPort_Impl, (OS_SockAddr_t * Addr, uint16 PortNum)) -UT_DEFAULT_STUB(OS_NetworkGetHostName_Impl, (char *host_name, uint32 name_len)) +UT_DEFAULT_STUB(OS_NetworkGetHostName_Impl, (char *host_name, size_t name_len)) int32 OS_NetworkGetID_Impl(int32 *IdBuf) { diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c index 306733f5b..238a8831f 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c @@ -38,8 +38,9 @@ ** Message Queue API */ -UT_DEFAULT_STUB(OS_QueueCreate_Impl, (uint32 queue_id, uint32 flags)) -UT_DEFAULT_STUB(OS_QueueDelete_Impl, (uint32 queue_id)) -UT_DEFAULT_STUB(OS_QueueGet_Impl, (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout)) -UT_DEFAULT_STUB(OS_QueuePut_Impl, (uint32 queue_id, const void *data, uint32 size, uint32 flags)) -UT_DEFAULT_STUB(OS_QueueGetInfo_Impl, (uint32 queue_id, OS_queue_prop_t *queue_prop)) +UT_DEFAULT_STUB(OS_QueueCreate_Impl, (const OS_object_token_t *token, uint32 flags)) +UT_DEFAULT_STUB(OS_QueueDelete_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_QueueGet_Impl, + (const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout)) +UT_DEFAULT_STUB(OS_QueuePut_Impl, (const OS_object_token_t *token, const void *data, size_t size, uint32 flags)) +UT_DEFAULT_STUB(OS_QueueGetInfo_Impl, (const OS_object_token_t *token, OS_queue_prop_t *queue_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c index f30e43840..4f4b720d6 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c @@ -33,5 +33,5 @@ #include "utstubs.h" #include "os-shared-select.h" -UT_DEFAULT_STUB(OS_SelectSingle_Impl, (uint32 stream_id, uint32 *SelectFlags, int32 msecs)) +UT_DEFAULT_STUB(OS_SelectSingle_Impl, (const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs)) UT_DEFAULT_STUB(OS_SelectMultiple_Impl, (OS_FdSet * ReadSet, OS_FdSet *WriteSet, int32 msecs)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c index 76acb04f9..fd3dd43d2 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c @@ -33,26 +33,28 @@ #include "utstubs.h" #include "os-shared-task.h" +#include "osapi-idmap.h" /* ** Task API */ -UT_DEFAULT_STUB(OS_TaskMatch_Impl, (uint32 task_id)) -UT_DEFAULT_STUB(OS_TaskCreate_Impl, (uint32 task_id, uint32 flags)) -UT_DEFAULT_STUB(OS_TaskDelete_Impl, (uint32 task_id)) +UT_DEFAULT_STUB(OS_TaskMatch_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_TaskDetach_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_TaskCreate_Impl, (const OS_object_token_t *token, uint32 flags)) +UT_DEFAULT_STUB(OS_TaskDelete_Impl, (const OS_object_token_t *token)) void OS_TaskExit_Impl(void) { UT_DEFAULT_IMPL(OS_TaskExit_Impl); } UT_DEFAULT_STUB(OS_TaskDelay_Impl, (uint32 millisecond)) -UT_DEFAULT_STUB(OS_TaskSetPriority_Impl, (uint32 task_id, uint32 new_priority)) +UT_DEFAULT_STUB(OS_TaskSetPriority_Impl, (const OS_object_token_t *token, osal_priority_t new_priority)) osal_id_t OS_TaskGetId_Impl(void) { int32 status; osal_id_t id; - status = UT_DEFAULT_IMPL(OS_TaskGetId_Impl); + status = UT_DEFAULT_IMPL_RC(OS_TaskGetId_Impl, 1); /* convert the int32 status value to an osal_id_t - * (this assumes the types are compatible) */ @@ -60,12 +62,12 @@ osal_id_t OS_TaskGetId_Impl(void) return id; } -UT_DEFAULT_STUB(OS_TaskGetInfo_Impl, (uint32 task_id, OS_task_prop_t *task_prop)) +UT_DEFAULT_STUB(OS_TaskGetInfo_Impl, (const OS_object_token_t *token, OS_task_prop_t *task_prop)) UT_DEFAULT_STUB(OS_TaskRegister_Impl, (osal_id_t global_task_id)) -bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj) +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { return UT_DEFAULT_IMPL(OS_TaskIdMatchSystemData_Impl); } -UT_DEFAULT_STUB(OS_TaskValidateSystemData_Impl, (const void *sysdata, uint32 sysdata_size)) +UT_DEFAULT_STUB(OS_TaskValidateSystemData_Impl, (const void *sysdata, size_t sysdata_size)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c index 5d7e89fe6..f04c150ca 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c @@ -37,22 +37,21 @@ /* ** OS Time/Tick related API */ -UT_DEFAULT_STUB(OS_TimeBaseCreate_Impl, (uint32 timer_id)) -UT_DEFAULT_STUB(OS_TimeBaseSet_Impl, (uint32 timer_id, int32 start_time, int32 interval_time)) -UT_DEFAULT_STUB(OS_TimeBaseDelete_Impl, (uint32 timer_id)) -void OS_TimeBaseLock_Impl(uint32 timebase_id) +UT_DEFAULT_STUB(OS_TimeBaseCreate_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_TimeBaseSet_Impl, (const OS_object_token_t *token, uint32 start_time, uint32 interval_time)) +UT_DEFAULT_STUB(OS_TimeBaseDelete_Impl, (const OS_object_token_t *token)) +void OS_TimeBaseLock_Impl(const OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_TimeBaseLock_Impl); } -void OS_TimeBaseUnlock_Impl(uint32 timebase_id) +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_TimeBaseUnlock_Impl); } -UT_DEFAULT_STUB(OS_TimeBaseGetInfo_Impl, (uint32 timer_id, OS_timebase_prop_t *timer_prop)) +UT_DEFAULT_STUB(OS_TimeBaseGetInfo_Impl, (const OS_object_token_t *token, OS_timebase_prop_t *timer_prop)) -UT_DEFAULT_STUB(OS_TimeBaseRegister_Impl, (uint32 timebase_id)) /* * Clock API low-level handlers */ diff --git a/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c index 58778d7f0..60fab614f 100644 --- a/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c @@ -37,7 +37,7 @@ /* ** Console output API (printf) */ -void OS_ConsoleOutput_Impl(uint32 local_id) +void OS_ConsoleOutput_Impl(const OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_ConsoleOutput_Impl); } diff --git a/src/unit-test-coverage/ut-stubs/src/posix-dlfcn-stubs.c b/src/unit-test-coverage/ut-stubs/src/posix-dlfcn-stubs.c index 0ce005221..a97a164c9 100644 --- a/src/unit-test-coverage/ut-stubs/src/posix-dlfcn-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/posix-dlfcn-stubs.c @@ -19,8 +19,8 @@ */ /* OSAL coverage stub replacement for dlfcn.h */ -#ifndef _OSAL_STUB_DLFCN_H_ -#define _OSAL_STUB_DLFCN_H_ +#ifndef OCS_DLFCN_H +#define OCS_DLFCN_H /* ----------------------------------------- */ /* constants normally defined in dlfcn.h */ @@ -39,4 +39,4 @@ extern char *OCS_dlerror(void); extern void *OCS_dlopen(const char *file, int mode); extern void *OCS_dlsym(void *handle, const char *name); -#endif /* _OSAL_STUB_DLFCN_H_ */ +#endif /* OCS_DLFCN_H */ diff --git a/src/unit-test-coverage/ut-stubs/src/posix-unistd-stubs.c b/src/unit-test-coverage/ut-stubs/src/posix-unistd-stubs.c index 20cff601a..b23a44845 100644 --- a/src/unit-test-coverage/ut-stubs/src/posix-unistd-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/posix-unistd-stubs.c @@ -99,7 +99,7 @@ OCS_off_t OCS_lseek(int fd, OCS_off_t offset, int whence) OCS_ssize_t OCS_read(int fd, void *buf, size_t n) { int32 Status; - uint32 CopySize; + size_t CopySize; Status = UT_DEFAULT_IMPL_RC(OCS_read, OCS_MAX_RDWR_SIZE); @@ -159,7 +159,7 @@ long int OCS_sysconf(int name) OCS_ssize_t OCS_write(int fd, const void *buf, size_t n) { int32 Status; - uint32 CopySize; + size_t CopySize; Status = UT_DEFAULT_IMPL_RC(OCS_write, OCS_MAX_RDWR_SIZE); diff --git a/src/unit-test-coverage/ut-stubs/src/vxworks-intLib-stubs.c b/src/unit-test-coverage/ut-stubs/src/vxworks-intLib-stubs.c index d72d25a91..ff3d15fde 100644 --- a/src/unit-test-coverage/ut-stubs/src/vxworks-intLib-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/vxworks-intLib-stubs.c @@ -50,10 +50,10 @@ static void OCS_intLib_dummyfunc(void) {} OCS_VOIDFUNCPTR *OCS_INUM_TO_IVEC(unsigned int ui) { - int32 Status = UT_DEFAULT_IMPL(OCS_INUM_TO_IVEC); - OCS_VOIDFUNCPTR *VecTbl; - OCS_VOIDFUNCPTR DummyVec; - uint32 VecTblSize; + int32 Status = UT_DEFAULT_IMPL(OCS_INUM_TO_IVEC); + OCS_VOIDFUNCPTR * VecTbl; + static OCS_VOIDFUNCPTR DummyVec; + size_t VecTblSize; if (Status == 0) { diff --git a/src/unit-test-coverage/vxworks/CMakeLists.txt b/src/unit-test-coverage/vxworks/CMakeLists.txt index fee10fc5e..5bc877276 100644 --- a/src/unit-test-coverage/vxworks/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/CMakeLists.txt @@ -5,7 +5,7 @@ set(VXWORKS_MODULE_LIST common console countsem - dirs + dirs-globals files filesys idmap @@ -24,6 +24,7 @@ set(VXWORKS_PORTABLE_BLOCK_LIST posix-gettime posix-io posix-files + posix-dirs console-bsp bsd-select diff --git a/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt b/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt index f5e1d59f5..459d59373 100644 --- a/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(ut-adaptor-${SETNAME} STATIC src/ut-adaptor-console.c src/ut-adaptor-countsem.c src/ut-adaptor-dirs.c + src/ut-adaptor-dirtable-stub.c src/ut-adaptor-files.c src/ut-adaptor-filesys.c src/ut-adaptor-idmap.c diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-binsem.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-binsem.h index 01033e846..3e33db446 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-binsem.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-binsem.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_BINSEM_H_ -#define INCLUDE_UT_ADAPTOR_BINSEM_H_ +#ifndef UT_ADAPTOR_BINSEM_H +#define UT_ADAPTOR_BINSEM_H -#include +#include "common_types.h" #include #include #include @@ -48,4 +48,4 @@ extern const UT_EntryKey_t UT_StubKey_GenericSemGive; extern int32 UT_Call_OS_VxWorks_BinSemAPI_Impl_Init(void); -#endif /* INCLUDE_UT_ADAPTOR_BINSEM_H_ */ +#endif /* UT_ADAPTOR_BINSEM_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-common.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-common.h index 30d9dfd18..75dd24a0a 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-common.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-common.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_COMMON_H_ -#define INCLUDE_UT_ADAPTOR_COMMON_H_ +#ifndef UT_ADAPTOR_COMMON_H +#define UT_ADAPTOR_COMMON_H -#include +#include "common_types.h" #include #include @@ -55,4 +55,4 @@ extern int32 OS_VxWorks_GenericSemGive(OCS_SEM_ID vxid); */ extern const UT_EntryKey_t UT_StubKey_OS_VxWorks_TableMutex_Init; -#endif /* INCLUDE_UT_ADAPTOR_COMMON_H_ */ +#endif /* UT_ADAPTOR_COMMON_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h index 72dec2e7a..2d45fbafb 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_CONSOLE_H_ -#define INCLUDE_UT_ADAPTOR_CONSOLE_H_ +#ifndef UT_ADAPTOR_CONSOLE_H +#define UT_ADAPTOR_CONSOLE_H -#include +#include "common_types.h" #include "ut-adaptor-common.h" extern void *const UT_Ref_OS_impl_console_table; @@ -42,6 +42,6 @@ extern void UT_ConsoleTest_TaskEntry(int arg); /** * Force the "is_async" field to a given state for coverage testing */ -extern void UT_ConsoleTest_SetConsoleAsync(uint32 local_id, bool is_async); +extern void UT_ConsoleTest_SetConsoleAsync(osal_index_t local_id, bool is_async); -#endif /* INCLUDE_UT_ADAPTOR_CONSOLE_H_ */ +#endif /* UT_ADAPTOR_CONSOLE_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-countsem.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-countsem.h index eed755c48..9e628a9ec 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-countsem.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-countsem.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_COUNTSEM_H_ -#define INCLUDE_UT_ADAPTOR_COUNTSEM_H_ +#ifndef UT_ADAPTOR_COUNTSEM_H +#define UT_ADAPTOR_COUNTSEM_H -#include +#include "common_types.h" #include #include @@ -46,4 +46,4 @@ extern size_t const UT_Ref_OS_impl_count_sem_table_SIZE; int32 UT_Call_OS_VxWorks_CountSemAPI_Impl_Init(void); -#endif /* INCLUDE_UT_ADAPTOR_COUNTSEM_H_ */ +#endif /* UT_ADAPTOR_COUNTSEM_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-dirs.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-dirs.h index b93409c41..d528b209e 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-dirs.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-dirs.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_DIRS_H_ -#define INCLUDE_UT_ADAPTOR_DIRS_H_ +#ifndef UT_ADAPTOR_DIRS_H +#define UT_ADAPTOR_DIRS_H -#include +#include "common_types.h" /***************************************************** * @@ -44,4 +44,4 @@ */ extern int32 UT_Call_OS_VxWorks_DirAPI_Impl_Init(void); -#endif /* INCLUDE_UT_ADAPTOR_DIRS_H_ */ +#endif /* UT_ADAPTOR_DIRS_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-files.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-files.h index 23ddfad9d..a77d79ce8 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-files.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-files.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_FILES_H_ -#define INCLUDE_UT_ADAPTOR_FILES_H_ +#ifndef UT_ADAPTOR_FILES_H +#define UT_ADAPTOR_FILES_H -#include +#include "common_types.h" /***************************************************** * @@ -53,6 +53,6 @@ extern int32 UT_Call_OS_VxWorks_StreamAPI_Impl_Init(void); unsigned int UT_FileTest_GetSelfEUID(void); unsigned int UT_FileTest_GetSelfEGID(void); -void UT_FileTest_Set_Selectable(uint32 local_id, bool is_selectable); +void UT_FileTest_Set_Selectable(osal_index_t local_id, bool is_selectable); -#endif /* INCLUDE_UT_ADAPTOR_FILES_H_ */ +#endif /* UT_ADAPTOR_FILES_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filesys.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filesys.h index 8049ee0d9..b82f90ca0 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filesys.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filesys.h @@ -25,15 +25,15 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_FILESYS_H_ -#define INCLUDE_UT_ADAPTOR_FILESYS_H_ +#ifndef UT_ADAPTOR_FILESYS_H +#define UT_ADAPTOR_FILESYS_H -#include +#include "common_types.h" #include extern void *const UT_Ref_OS_impl_filesys_table; extern size_t const UT_Ref_OS_impl_filesys_table_SIZE; -void UT_FileSysTest_SetupFileSysEntry(uint32 id, OCS_BLK_DEV *blkdev, OCS_device_t xbddev, uint32 MaxParts); +void UT_FileSysTest_SetupFileSysEntry(osal_index_t id, OCS_BLK_DEV *blkdev, OCS_device_t xbddev, uint32 MaxParts); -#endif /* INCLUDE_UT_ADAPTOR_FILESYS_H_ */ +#endif /* UT_ADAPTOR_FILESYS_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filetable-stub.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filetable-stub.h index 873c17237..3881fde0e 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filetable-stub.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filetable-stub.h @@ -25,13 +25,13 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_FILETABLE_STUB_H_ -#define INCLUDE_UT_ADAPTOR_FILETABLE_STUB_H_ +#ifndef UT_ADAPTOR_FILETABLE_STUB_H +#define UT_ADAPTOR_FILETABLE_STUB_H -#include +#include "common_types.h" #include extern void *const UT_FileTableTest_OS_impl_filehandle_table; extern size_t const UT_FileTableTest_OS_impl_filehandle_table_SIZE; -#endif /* INCLUDE_UT_ADAPTOR_FILETABLE_STUB_H_ */ +#endif /* UT_ADAPTOR_FILETABLE_STUB_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-idmap.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-idmap.h index cd8b50127..69117f85e 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-idmap.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-idmap.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_IDMAP_H_ -#define INCLUDE_UT_ADAPTOR_IDMAP_H_ +#ifndef UT_ADAPTOR_IDMAP_H +#define UT_ADAPTOR_IDMAP_H -#include +#include "common_types.h" #include /***************************************************** @@ -39,7 +39,7 @@ * but are not part of the implementation API. * *****************************************************/ -int32 UT_Call_OS_VxWorks_TableMutex_Init(uint32 idtype); -void UT_IdMapTest_SetImplTableMutex(uint32 idtype, OCS_SEM_ID vxid); +int32 UT_Call_OS_VxWorks_TableMutex_Init(osal_objtype_t idtype); +void UT_IdMapTest_SetImplTableMutex(osal_objtype_t idtype, OCS_SEM_ID vxid); -#endif /* INCLUDE_UT_ADAPTOR_IDMAP_H_ */ +#endif /* UT_ADAPTOR_IDMAP_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-loader.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-loader.h index e3447fe52..2d5a11827 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-loader.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-loader.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_LOADER_H_ -#define INCLUDE_UT_ADAPTOR_LOADER_H_ +#ifndef UT_ADAPTOR_LOADER_H +#define UT_ADAPTOR_LOADER_H -#include +#include "common_types.h" #include #include #include @@ -38,4 +38,4 @@ extern size_t const UT_Ref_OS_impl_module_table_SIZE; extern int32 UT_Call_OS_VxWorks_ModuleAPI_Impl_Init(void); -#endif /* INCLUDE_UT_ADAPTOR_LOADER_H_ */ +#endif /* UT_ADAPTOR_LOADER_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-mutex.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-mutex.h index f30c94c27..a4ed0f0ac 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-mutex.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-mutex.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_MUTEX_H_ -#define INCLUDE_UT_ADAPTOR_MUTEX_H_ +#ifndef UT_ADAPTOR_MUTEX_H +#define UT_ADAPTOR_MUTEX_H -#include +#include "common_types.h" #include #include @@ -46,4 +46,4 @@ extern size_t const UT_Ref_OS_impl_mutex_table_SIZE; int32 UT_Call_OS_VxWorks_MutexAPI_Impl_Init(void); -#endif /* INCLUDE_UT_ADAPTOR_MUTEX_H_ */ +#endif /* UT_ADAPTOR_MUTEX_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-queues.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-queues.h index e630e85ba..e29935dc5 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-queues.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-queues.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_QUEUES_H_ -#define INCLUDE_UT_ADAPTOR_QUEUES_H_ +#ifndef UT_ADAPTOR_QUEUES_H +#define UT_ADAPTOR_QUEUES_H -#include +#include "common_types.h" #include extern void *const UT_Ref_OS_impl_queue_table; @@ -45,4 +45,4 @@ extern size_t const UT_Ref_OS_impl_queue_table_SIZE; int32 UT_Call_OS_VxWorks_QueueAPI_Impl_Init(void); -#endif /* INCLUDE_UT_ADAPTOR_QUEUES_H_ */ +#endif /* UT_ADAPTOR_QUEUES_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h index b29ec05c4..9e8f1a32f 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h @@ -25,11 +25,11 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_SYMTAB_H_ -#define INCLUDE_UT_ADAPTOR_SYMTAB_H_ +#ifndef UT_ADAPTOR_SYMTAB_H +#define UT_ADAPTOR_SYMTAB_H -#include +#include "common_types.h" -int32 UT_SymTabTest_CallIteratorFunc(const char *name, void *val, uint32 TestSize, uint32 SizeLimit); +int32 UT_SymTabTest_CallIteratorFunc(const char *name, void *val, size_t TestSize, size_t SizeLimit); -#endif /* INCLUDE_UT_ADAPTOR_SYMTAB_H_ */ +#endif /* UT_ADAPTOR_SYMTAB_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h index d2b3a44bc..68a4894f5 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_TASKS_H_ -#define INCLUDE_UT_ADAPTOR_TASKS_H_ +#ifndef UT_ADAPTOR_TASKS_H +#define UT_ADAPTOR_TASKS_H -#include +#include "common_types.h" #include extern void *const UT_Ref_OS_impl_task_table; @@ -44,8 +44,8 @@ extern size_t const UT_Ref_OS_impl_task_table_SIZE; *****************************************************/ int32 UT_Call_OS_VxWorks_TaskAPI_Impl_Init(void); -void UT_TaskTest_SetImplTaskId(uint32 local_id, OCS_TASK_ID TaskId); -int UT_TaskTest_CallEntryPoint(int arg); -OCS_WIND_TCB *UT_TaskTest_GetTaskTcb(uint32 local_id); +void UT_TaskTest_SetImplTaskId(osal_index_t local_id, OCS_TASK_ID TaskId); +int UT_TaskTest_CallEntryPoint(osal_id_t arg); +OCS_WIND_TCB *UT_TaskTest_GetTaskTcb(osal_index_t local_id); -#endif /* INCLUDE_UT_ADAPTOR_TASKS_H_ */ +#endif /* UT_ADAPTOR_TASKS_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h index 19cac7f67..a377dd541 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h @@ -25,10 +25,10 @@ * */ -#ifndef INCLUDE_UT_ADAPTOR_TIMEBASE_H_ -#define INCLUDE_UT_ADAPTOR_TIMEBASE_H_ +#ifndef UT_ADAPTOR_TIMEBASE_H +#define UT_ADAPTOR_TIMEBASE_H -#include +#include "common_types.h" #include #include @@ -37,29 +37,29 @@ extern size_t const UT_Ref_OS_impl_timebase_table_SIZE; int32 UT_Call_OS_VxWorks_TimeBaseAPI_Impl_Init(void); -void UT_TimeBaseTest_Setup(uint32 local_id, int signo, bool reset_flag); +void UT_TimeBaseTest_Setup(osal_index_t local_id, int signo, bool reset_flag); /** * Invokes OS_VxWorks_SigWait() with the given arguments. * This is normally a static function but exposed via a non-static wrapper for UT purposes. */ -int32 UT_TimeBaseTest_CallSigWaitFunc(uint32 local_id); +int32 UT_TimeBaseTest_CallSigWaitFunc(osal_id_t timebase_id); /* Invokes the static OS_VxWorks_TimeBaseTask() function with given argument */ int UT_TimeBaseTest_CallHelperTaskFunc(int arg); /* Invokes the static OS_VxWorks_RegisterTimer() function with given argument */ -void UT_TimeBaseTest_CallRegisterTimer(uint32 local_id); +void UT_TimeBaseTest_CallRegisterTimer(osal_id_t obj_id); /* Hook functions which set the timer registration state */ -void UT_TimeBaseTest_SetTimeBaseRegState(uint32 local_id, bool is_success); -void UT_TimeBaseTest_ClearTimeBaseRegState(uint32 local_id); +void UT_TimeBaseTest_SetTimeBaseRegState(osal_index_t local_id, bool is_success); +void UT_TimeBaseTest_ClearTimeBaseRegState(osal_index_t local_id); /* Hook functions which test the timer registration state */ -bool UT_TimeBaseTest_CheckTimeBaseRegisteredState(uint32 local_id); -bool UT_TimeBaseTest_CheckTimeBaseErrorState(uint32 local_id); +bool UT_TimeBaseTest_CheckTimeBaseRegisteredState(osal_index_t local_id); +bool UT_TimeBaseTest_CheckTimeBaseErrorState(osal_index_t local_id); /* Invoke the internal UsecToTimespec API */ void UT_TimeBaseTest_UsecToTimespec(uint32 usecs, struct OCS_timespec *time_spec); -#endif /* INCLUDE_UT_ADAPTOR_TIMEBASE_H_ */ +#endif /* UT_ADAPTOR_TIMEBASE_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-common.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-common.c index 9c68e5cdb..065795735 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-common.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-common.c @@ -26,7 +26,7 @@ */ /* pull in the OSAL configuration */ -#include +#include "osconfig.h" #include #include diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c index b0f280feb..8d474d81c 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c @@ -40,7 +40,7 @@ void UT_ConsoleTest_TaskEntry(int arg) OS_VxWorks_ConsoleTask_Entry(arg); } -void UT_ConsoleTest_SetConsoleAsync(uint32 local_id, bool is_async) +void UT_ConsoleTest_SetConsoleAsync(osal_index_t local_id, bool is_async) { OS_impl_console_table[local_id].is_async = is_async; } diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-dirtable-stub.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-dirtable-stub.c new file mode 100644 index 000000000..392b5cee0 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-dirtable-stub.c @@ -0,0 +1,35 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file ut-adaptor-filetable-stub.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-filetable-stub.h" + +#include +#include +#include + +OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-files.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-files.c index 2cdd8d7c2..017750b9e 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-files.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-files.c @@ -53,7 +53,7 @@ unsigned int UT_FileTest_GetSelfEGID(void) return OS_IMPL_SELF_EGID; } -void UT_FileTest_Set_Selectable(uint32 local_id, bool is_selectable) +void UT_FileTest_Set_Selectable(osal_index_t local_id, bool is_selectable) { OS_impl_filehandle_table[local_id].selectable = is_selectable; } diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filesys.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filesys.c index 9094de350..0e5331f22 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filesys.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filesys.c @@ -34,7 +34,7 @@ void *const UT_Ref_OS_impl_filesys_table = OS_impl_filesys_table; size_t const UT_Ref_OS_impl_filesys_table_SIZE = sizeof(OS_impl_filesys_table); -void UT_FileSysTest_SetupFileSysEntry(uint32 id, OCS_BLK_DEV *blkdev, OCS_device_t xbddev, uint32 MaxParts) +void UT_FileSysTest_SetupFileSysEntry(osal_index_t id, OCS_BLK_DEV *blkdev, OCS_device_t xbddev, uint32 MaxParts) { OS_impl_filesys_table[id].blkDev = blkdev; OS_impl_filesys_table[id].xbd = xbddev; diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filetable-stub.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filetable-stub.c index 9af7e1383..20af8c951 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filetable-stub.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filetable-stub.c @@ -31,7 +31,7 @@ #include #include -OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; +OS_impl_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; void *const UT_FileTableTest_OS_impl_filehandle_table = OS_impl_filehandle_table; size_t const UT_FileTableTest_OS_impl_filehandle_table_SIZE = sizeof(OS_impl_filehandle_table); diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-idmap.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-idmap.c index f4053559b..f436f8146 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-idmap.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-idmap.c @@ -25,19 +25,20 @@ * */ /* pull in the OSAL configuration */ -#include +#include "osconfig.h" #include #include #include +#include "os-impl-idmap.h" #include "ut-adaptor-idmap.h" -int32 UT_Call_OS_VxWorks_TableMutex_Init(uint32 idtype) +int32 UT_Call_OS_VxWorks_TableMutex_Init(osal_objtype_t idtype) { return OS_VxWorks_TableMutex_Init(idtype); } -void UT_IdMapTest_SetImplTableMutex(uint32 idtype, OCS_SEM_ID vxid) +void UT_IdMapTest_SetImplTableMutex(osal_objtype_t idtype, OCS_SEM_ID vxid) { - VX_MUTEX_TABLE[idtype].vxid = vxid; + OS_impl_objtype_lock_table[idtype]->vxid = vxid; } diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c index 61e5a37a7..5cdbb8d10 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c @@ -36,7 +36,7 @@ * A UT-specific wrapper function to invoke the Symbol Table Iterator. * This is normally static so it needs this wrapper to call it. */ -int32 UT_SymTabTest_CallIteratorFunc(const char *name, void *val, uint32 TestSize, uint32 SizeLimit) +int32 UT_SymTabTest_CallIteratorFunc(const char *name, void *val, size_t TestSize, size_t SizeLimit) { OS_VxWorks_SymbolDumpState.Sizelimit = SizeLimit; OS_VxWorks_SymbolDumpState.CurrSize = TestSize; diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c index 10f06f39e..4fdeabb57 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c @@ -31,6 +31,7 @@ #include #include +#include "osapi-idmap.h" void *const UT_Ref_OS_impl_task_table = OS_impl_task_table; size_t const UT_Ref_OS_impl_task_table_SIZE = sizeof(OS_impl_task_table); @@ -40,7 +41,7 @@ int32 UT_Call_OS_VxWorks_TaskAPI_Impl_Init(void) return OS_VxWorks_TaskAPI_Impl_Init(); } -void UT_TaskTest_SetImplTaskId(uint32 local_id, OCS_TASK_ID TaskId) +void UT_TaskTest_SetImplTaskId(osal_index_t local_id, OCS_TASK_ID TaskId) { OS_impl_task_table[local_id].vxid = TaskId; } @@ -50,12 +51,12 @@ void UT_TaskTest_SetImplTaskId(uint32 local_id, OCS_TASK_ID TaskId) * in order for the UT to invoke it there must be a non-static * way to get access to it. */ -int UT_TaskTest_CallEntryPoint(int arg) +int UT_TaskTest_CallEntryPoint(osal_id_t arg) { - return OS_VxWorks_TaskEntry(arg); + return OS_VxWorks_TaskEntry(OS_ObjectIdToInteger(arg)); } -OCS_WIND_TCB *UT_TaskTest_GetTaskTcb(uint32 local_id) +OCS_WIND_TCB *UT_TaskTest_GetTaskTcb(osal_index_t local_id) { return &OS_impl_task_table[local_id].tcb; } diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c index 0806059b8..e1eb97c8f 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c @@ -40,9 +40,9 @@ int32 UT_Call_OS_VxWorks_TimeBaseAPI_Impl_Init(void) return OS_VxWorks_TimeBaseAPI_Impl_Init(); } -int32 UT_TimeBaseTest_CallSigWaitFunc(uint32 local_id) +int32 UT_TimeBaseTest_CallSigWaitFunc(osal_id_t timebase_id) { - return OS_VxWorks_SigWait(local_id); + return OS_VxWorks_SigWait(timebase_id); } int UT_TimeBaseTest_CallHelperTaskFunc(int arg) @@ -50,27 +50,27 @@ int UT_TimeBaseTest_CallHelperTaskFunc(int arg) return OS_VxWorks_TimeBaseTask(arg); } -void UT_TimeBaseTest_CallRegisterTimer(uint32 local_id) +void UT_TimeBaseTest_CallRegisterTimer(osal_id_t obj_id) { - OS_VxWorks_RegisterTimer(local_id); + OS_VxWorks_RegisterTimer(obj_id); } -bool UT_TimeBaseTest_CheckTimeBaseRegisteredState(uint32 local_id) +bool UT_TimeBaseTest_CheckTimeBaseRegisteredState(osal_index_t local_id) { return (OS_impl_timebase_table[local_id].timer_state == OS_TimerRegState_SUCCESS); } -bool UT_TimeBaseTest_CheckTimeBaseErrorState(uint32 local_id) +bool UT_TimeBaseTest_CheckTimeBaseErrorState(osal_index_t local_id) { return (OS_impl_timebase_table[local_id].timer_state == OS_TimerRegState_ERROR); } -void UT_TimeBaseTest_ClearTimeBaseRegState(uint32 local_id) +void UT_TimeBaseTest_ClearTimeBaseRegState(osal_index_t local_id) { OS_impl_timebase_table[local_id].timer_state = OS_TimerRegState_INIT; } -void UT_TimeBaseTest_SetTimeBaseRegState(uint32 local_id, bool is_success) +void UT_TimeBaseTest_SetTimeBaseRegState(osal_index_t local_id, bool is_success) { /* Mimic the setting of the Reg state global, which * is typically done by the task after spawning @@ -90,7 +90,7 @@ void UT_TimeBaseTest_UsecToTimespec(uint32 usecs, struct OCS_timespec *time_spec OS_VxWorks_UsecToTimespec(usecs, time_spec); } -void UT_TimeBaseTest_Setup(uint32 local_id, int signo, bool reset_flag) +void UT_TimeBaseTest_Setup(osal_index_t local_id, int signo, bool reset_flag) { static OCS_WIND_TCB FAKE_TASK; static OCS_SEM FAKE_SEM; diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c b/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c index 931f7f37d..41e19cf25 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c @@ -50,10 +50,12 @@ void Test_OS_BinSemCreate_Impl(void) * Test Case For: * int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(0, 0, 0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; - UT_SetForceFail(UT_KEY(OCS_semBInitialize), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(0, 0, 0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(&token, 0, 0), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OCS_semBInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(&token, 0, 0), OS_SEM_FAILURE); } void Test_OS_BinSemDelete_Impl(void) @@ -62,7 +64,9 @@ void Test_OS_BinSemDelete_Impl(void) * Test Case For: * int32 OS_BinSemDelete_Impl (uint32 sem_id) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemDelete_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemDelete_Impl(&token), OS_SUCCESS); } void Test_OS_BinSemGive_Impl(void) @@ -71,10 +75,12 @@ void Test_OS_BinSemGive_Impl(void) * Test Case For: * int32 OS_BinSemGive_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; - UT_SetForceFail(UT_StubKey_GenericSemGive, OS_SEM_FAILURE); - OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(&token), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_StubKey_GenericSemGive, OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(&token), OS_SEM_FAILURE); } void Test_OS_BinSemFlush_Impl(void) @@ -83,10 +89,12 @@ void Test_OS_BinSemFlush_Impl(void) * Test Case For: * int32 OS_BinSemFlush_Impl (uint32 sem_id) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(&token), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_semFlush), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(0), OS_SEM_FAILURE); + UT_SetDefaultReturnValue(UT_KEY(OCS_semFlush), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(&token), OS_SEM_FAILURE); } void Test_OS_BinSemTake_Impl(void) @@ -95,7 +103,9 @@ void Test_OS_BinSemTake_Impl(void) * Test Case For: * int32 OS_BinSemTake_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemTake_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemTake_Impl(&token), OS_SUCCESS); } void Test_OS_BinSemTimedWait_Impl(void) @@ -104,13 +114,15 @@ void Test_OS_BinSemTimedWait_Impl(void) * Test Case For: * int32 OS_BinSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0, 100), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(&token, 100), OS_SUCCESS); - UT_SetForceFail(UT_StubKey_GenericSemTake, OS_SEM_FAILURE); - OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0, 100), OS_SEM_FAILURE); + UT_SetDefaultReturnValue(UT_StubKey_GenericSemTake, OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(&token, 100), OS_SEM_FAILURE); - UT_SetForceFail(UT_KEY(OS_Milli2Ticks), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0, 100), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_Milli2Ticks), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(&token, 100), OS_ERROR); } void Test_OS_BinSemGetInfo_Impl(void) @@ -120,8 +132,10 @@ void Test_OS_BinSemGetInfo_Impl(void) * int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *sem_prop) */ OS_bin_sem_prop_t sem_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&sem_prop, 0xEE, sizeof(sem_prop)); - OSAPI_TEST_FUNCTION_RC(OS_BinSemGetInfo_Impl(0, &sem_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGetInfo_Impl(&token, &sem_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-common.c b/src/unit-test-coverage/vxworks/src/coveragetest-common.c index 874ac2ae7..85ce295c1 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-common.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-common.c @@ -42,9 +42,9 @@ void Test_OS_API_Impl_Init(void) * int32 OS_API_Impl_Init(uint32 idtype) */ OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(0), OS_SUCCESS); - UT_SetForceFail(UT_StubKey_OS_VxWorks_TableMutex_Init, OS_ERROR); + UT_SetDefaultReturnValue(UT_StubKey_OS_VxWorks_TableMutex_Init, OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); - UT_ClearForceFail(UT_StubKey_OS_VxWorks_TableMutex_Init); + UT_ClearDefaultReturnValue(UT_StubKey_OS_VxWorks_TableMutex_Init); OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_QUEUE), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_BINSEM), OS_SUCCESS); @@ -85,7 +85,7 @@ void Test_OS_VxWorks_GenericSemGive(void) OCS_SEM_ID SemID = NULL; OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemGive(SemID), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_semGive), OCS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_semGive), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemGive(SemID), OS_SEM_FAILURE); } /* end OS_VxWorks_GenericSemGive */ @@ -98,7 +98,7 @@ void Test_OS_VxWorks_GenericSemTake(void) OCS_SEM_ID SemID = NULL; OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemTake(SemID, 10), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_semTake), OCS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_semTake), OCS_ERROR); OCS_errno = OCS_S_objLib_OBJ_TIMEOUT; OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemTake(SemID, 0), OS_SEM_TIMEOUT); OCS_errno = OCS_S_objLib_OBJ_ID_ERROR; diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-console.c b/src/unit-test-coverage/vxworks/src/coveragetest-console.c index c39910841..39dc83670 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-console.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-console.c @@ -41,35 +41,41 @@ void Test_OS_ConsoleWakeup_Impl(void) * Test Case For: * void OS_ConsoleWakeup_Impl(const char *string) */ + OS_object_token_t token = UT_TOKEN_0; /* no return code - check for coverage */ UT_ConsoleTest_SetConsoleAsync(0, true); - OS_ConsoleWakeup_Impl(0); + OS_ConsoleWakeup_Impl(&token); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semGive)) == 1, "semGive() called in async mode"); - UT_SetForceFail(UT_KEY(OCS_semGive), -1); - OS_ConsoleWakeup_Impl(0); + UT_SetDefaultReturnValue(UT_KEY(OCS_semGive), -1); + OS_ConsoleWakeup_Impl(&token); UT_ConsoleTest_SetConsoleAsync(0, false); OS_console_table[0].WritePos = 1; - OS_ConsoleWakeup_Impl(0); + OS_ConsoleWakeup_Impl(&token); UtAssert_True(UT_GetStubCount(UT_KEY(OS_ConsoleOutput_Impl)) == 1, "OS_ConsoleOutput_Impl() called in sync mode"); } void Test_OS_ConsoleCreate_Impl(void) { - OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(0), OS_SUCCESS); + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskSpawn)) == 1, "taskSpawn() called"); - UT_SetForceFail(UT_KEY(OCS_semCInitialize), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(0), OS_SEM_FAILURE); - UT_ClearForceFail(UT_KEY(OCS_semCInitialize)); + UT_SetDefaultReturnValue(UT_KEY(OCS_semCInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_SEM_FAILURE); + UT_ClearDefaultReturnValue(UT_KEY(OCS_semCInitialize)); - UT_SetForceFail(UT_KEY(OCS_taskSpawn), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(0), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_taskSpawn)); + UT_SetDefaultReturnValue(UT_KEY(OCS_taskSpawn), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_ERROR); + UT_ClearDefaultReturnValue(UT_KEY(OCS_taskSpawn)); - OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(OS_MAX_CONSOLES + 1), OS_ERR_NOT_IMPLEMENTED); + token.obj_idx = OS_MAX_CONSOLES + 1; + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_ERR_NOT_IMPLEMENTED); /* Also call the actual console task, to get coverage on it. * This task has an infinite loop, which only exits if semTake fails */ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c b/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c index f29a015c4..e09a9ee78 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c @@ -46,10 +46,12 @@ void Test_OS_CountSemCreate_Impl(void) * Test Case For: * int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(0, 0, 0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; - UT_SetForceFail(UT_KEY(OCS_semCInitialize), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(0, 0, 0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(&token, 0, 0), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OCS_semCInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(&token, 0, 0), OS_SEM_FAILURE); } void Test_OS_CountSemDelete_Impl(void) @@ -58,7 +60,9 @@ void Test_OS_CountSemDelete_Impl(void) * Test Case For: * int32 OS_CountSemDelete_Impl (uint32 sem_id) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemDelete_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_CountSemDelete_Impl(&token), OS_SUCCESS); } void Test_OS_CountSemGive_Impl(void) @@ -67,7 +71,9 @@ void Test_OS_CountSemGive_Impl(void) * Test Case For: * int32 OS_CountSemGive_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemGive_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_CountSemGive_Impl(&token), OS_SUCCESS); } void Test_OS_CountSemTake_Impl(void) @@ -76,7 +82,9 @@ void Test_OS_CountSemTake_Impl(void) * Test Case For: * int32 OS_CountSemTake_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemTake_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_CountSemTake_Impl(&token), OS_SUCCESS); } void Test_OS_CountSemTimedWait_Impl(void) @@ -85,10 +93,12 @@ void Test_OS_CountSemTimedWait_Impl(void) * Test Case For: * int32 OS_CountSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(0, 100), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(&token, 100), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OS_Milli2Ticks), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(0, 100), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_Milli2Ticks), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(&token, 100), OS_ERROR); } void Test_OS_CountSemGetInfo_Impl(void) @@ -98,8 +108,10 @@ void Test_OS_CountSemGetInfo_Impl(void) * int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) */ OS_count_sem_prop_t count_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&count_prop, 0xEE, sizeof(count_prop)); - OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo_Impl(0, &count_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo_Impl(&token, &count_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-dirs-globals.c b/src/unit-test-coverage/vxworks/src/coveragetest-dirs-globals.c new file mode 100644 index 000000000..c7c402383 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-dirs-globals.c @@ -0,0 +1,76 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file coveragetest-dirs-globals.c + * \ingroup vxworks + * \author steven.seeger@nasa.gov + * + */ + +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-dirs.h" + +#include "os-shared-dir.h" + +#include +#include +#include +#include +#include + +void Test_OS_VxWorks_DirAPI_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_DirAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_DirAPI_Impl_Init(), OS_SUCCESS); +} + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) {} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_DirAPI_Impl_Init); +} diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c index 6cdf934ec..8e08eae57 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c @@ -45,19 +45,23 @@ void Test_OS_FileSysStartVolume_Impl(void) * Test Case For: * int32 OS_FileSysStartVolume_Impl (uint32 filesys_id) */ - int32 expected; + int32 expected; + OS_object_token_t token; + + token = UT_TOKEN_0; /* Emulate an UNKNOWN entry */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_UNKNOWN; - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(0), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_ERR_NOT_IMPLEMENTED); /* Emulate an FS_BASED entry */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_FS_BASED; - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_SUCCESS); /* Emulate a VOLATILE_DISK entry (ramdisk) */ OS_filesys_table[1].fstype = OS_FILESYS_TYPE_VOLATILE_DISK; - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(1), OS_SUCCESS); + token.obj_idx = UT_INDEX_1; + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_SUCCESS); /* Emulate a NORMAL_DISK entry (ATA) */ OS_filesys_table[2].fstype = OS_FILESYS_TYPE_NORMAL_DISK; @@ -67,15 +71,17 @@ void Test_OS_FileSysStartVolume_Impl(void) #else expected = OS_ERR_NOT_IMPLEMENTED; #endif - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(2), expected); + token = UT_TOKEN_2; + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), expected); /* Failure to create XBD layer */ - UT_SetForceFail(UT_KEY(OCS_xbdBlkDevCreateSync), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(1), OS_FS_ERR_DRIVE_NOT_CREATED); + UT_SetDefaultReturnValue(UT_KEY(OCS_xbdBlkDevCreateSync), -1); + token = UT_TOKEN_1; + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_FS_ERR_DRIVE_NOT_CREATED); /* Failure to create low level block dev */ - UT_SetForceFail(UT_KEY(OCS_ramDevCreate), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(1), OS_FS_ERR_DRIVE_NOT_CREATED); + UT_SetDefaultReturnValue(UT_KEY(OCS_ramDevCreate), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_FS_ERR_DRIVE_NOT_CREATED); } void Test_OS_FileSysStopVolume_Impl(void) @@ -83,12 +89,15 @@ void Test_OS_FileSysStopVolume_Impl(void) /* Test Case For: * int32 OS_FileSysStopVolume_Impl (uint32 filesys_id) */ - OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS); /* Failure to delete XBD layer */ OS_filesys_table[1].fstype = OS_FILESYS_TYPE_VOLATILE_DISK; UT_FileSysTest_SetupFileSysEntry(1, NULL, 1, 4); - OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(1), OS_SUCCESS); + token = UT_TOKEN_1; + OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_xbdBlkDevDelete)) == 1, "xbdBlkDevDelete() called"); } @@ -97,21 +106,22 @@ void Test_OS_FileSysFormatVolume_Impl(void) /* Test Case For: * int32 OS_FileSysFormatVolume_Impl (uint32 filesys_id) */ + OS_object_token_t token = UT_TOKEN_0; /* test unimplemented fs type */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_UNKNOWN; - OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(0), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(&token), OS_ERR_NOT_IMPLEMENTED); /* fs-based should be noop */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_FS_BASED; - OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(&token), OS_SUCCESS); OS_filesys_table[0].fstype = OS_FILESYS_TYPE_VOLATILE_DISK; - OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(&token), OS_SUCCESS); /* Failure of the dosFsVolFormat() call */ - UT_SetForceFail(UT_KEY(OCS_dosFsVolFormat), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(0), OS_FS_ERR_DRIVE_NOT_CREATED); + UT_SetDefaultReturnValue(UT_KEY(OCS_dosFsVolFormat), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(&token), OS_FS_ERR_DRIVE_NOT_CREATED); } void Test_OS_FileSysMountVolume_Impl(void) @@ -119,12 +129,39 @@ void Test_OS_FileSysMountVolume_Impl(void) /* Test Case For: * int32 OS_FileSysMountVolume_Impl (uint32 filesys_id) */ + OS_object_token_t token = UT_TOKEN_0; + struct OCS_stat statbuf; + + memset(&OS_filesys_table[0], 0, sizeof(OS_filesys_table[0])); + OS_filesys_table[0].fstype = OS_FILESYS_TYPE_NORMAL_DISK; + strcpy(OS_filesys_table[0].system_mountpt, "/ut"); + + OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_ERROR); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); + + /* Additional cases for the FS_BASED handling */ + OS_filesys_table[0].fstype = OS_FILESYS_TYPE_FS_BASED; - OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(0), OS_SUCCESS); + /* Mount dir does not exist but can be created */ + UT_SetDefaultReturnValue(UT_KEY(OCS_stat), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(0), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + /* Mount dir does not exist and cannot be created */ + UT_SetDeferredRetcode(UT_KEY(OCS_mkdir), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_FS_ERR_DRIVE_NOT_CREATED); + + /* Mount dir does exist but not a directory */ + UT_ClearDefaultReturnValue(UT_KEY(OCS_stat)); + OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_FS_ERR_PATH_INVALID); + + /* Mount dir does exist and is a directory */ + memset(&statbuf, 0, sizeof(statbuf)); + statbuf.st_mode = OCS_S_IFDIR; + UT_SetDataBuffer(UT_KEY(OCS_stat), &statbuf, sizeof(statbuf), false); + OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_SUCCESS); } void Test_OS_FileSysUnmountVolume_Impl(void) @@ -132,16 +169,25 @@ void Test_OS_FileSysUnmountVolume_Impl(void) /* Test Case For: * int32 OS_FileSysUnmountVolume_Impl (uint32 filesys_id) */ + OS_object_token_t token = UT_TOKEN_0; + + memset(&OS_filesys_table[0], 0, sizeof(OS_filesys_table[0])); + OS_filesys_table[0].fstype = OS_FILESYS_TYPE_NORMAL_DISK; + strcpy(OS_filesys_table[0].system_mountpt, "/ut"); + + OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(&token), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(0), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(&token), OS_ERROR); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); - UT_SetForceFail(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(0), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_SetDefaultReturnValue(UT_KEY(OCS_ioctl), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(&token), OS_ERROR); + UT_ClearDefaultReturnValue(UT_KEY(OCS_ioctl)); - UT_SetForceFail(UT_KEY(OCS_ioctl), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(0), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_ioctl)); + /* Additional cases for the FS_BASED handling (no op on unmount) */ + OS_filesys_table[0].fstype = OS_FILESYS_TYPE_FS_BASED; + OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(&token), OS_SUCCESS); } void Test_OS_FileSysStatVolume_Impl(void) @@ -150,11 +196,13 @@ void Test_OS_FileSysStatVolume_Impl(void) * Test Case For: * int32 OS_FileSysStatVolume_Impl (uint32 filesys_id, OS_statvfs_t *result) */ - OS_statvfs_t stat; - OSAPI_TEST_FUNCTION_RC(OS_FileSysStatVolume_Impl(0, &stat), OS_SUCCESS); + OS_statvfs_t stat; + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_FileSysStatVolume_Impl(&token, &stat), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_statvfs), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysStatVolume_Impl(0, &stat), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_statvfs), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStatVolume_Impl(&token, &stat), OS_ERROR); } void Test_OS_FileSysCheckVolume_Impl(void) @@ -163,14 +211,16 @@ void Test_OS_FileSysCheckVolume_Impl(void) * Test Case For: * int32 OS_FileSysCheckVolume_Impl (uint32 filesys_id, bool repair) */ - OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(0, true), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(&token, true), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(0, false), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(&token, false), OS_ERROR); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); - UT_SetForceFail(UT_KEY(OCS_ioctl), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(0, false), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_ioctl), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(&token, false), OS_ERROR); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-heap.c b/src/unit-test-coverage/vxworks/src/coveragetest-heap.c index 10d68a79a..06b04b7a5 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-heap.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-heap.c @@ -40,7 +40,7 @@ void Test_OS_HeapGetInfo_Impl(void) memset(&heap_prop, 0xEE, sizeof(heap_prop)); OSAPI_TEST_FUNCTION_RC(OS_HeapGetInfo_Impl(&heap_prop), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_memPartInfoGet), OCS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_memPartInfoGet), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_HeapGetInfo_Impl(&heap_prop), OS_ERROR); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c b/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c index 124f7d322..f593d6148 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c @@ -41,22 +41,13 @@ void Test_OS_Lock_Global_Impl(void) * Test Case For: * int32 OS_Lock_Global_Impl(uint32 idtype) */ - OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(10000), OS_ERROR); - - /* - * Confirm that if vxid is 0/NULL that the function returns error - * and does not call semTake. - */ - UT_IdMapTest_SetImplTableMutex(OS_OBJECT_TYPE_OS_TASK, (OCS_SEM_ID)0); - OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); - UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semTake)) == 0, "semTake() NOT called"); UT_IdMapTest_SetImplTableMutex(OS_OBJECT_TYPE_OS_TASK, &TestGlobalSem); - OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); + OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semTake)) == 1, "semTake() called"); - UT_SetForceFail(UT_KEY(OCS_semTake), -1); - OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_semTake), -1); + OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK); /* for coverage of error path */ } void Test_OS_Unlock_Global_Impl(void) @@ -65,11 +56,13 @@ void Test_OS_Unlock_Global_Impl(void) * Test Case For: * int32 OS_Unlock_Global_Impl(uint32 idtype) */ - OSAPI_TEST_FUNCTION_RC(OS_Unlock_Global_Impl(10000), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_Unlock_Global_Impl(0), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_Unlock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_semGive), -1); - OSAPI_TEST_FUNCTION_RC(OS_Unlock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); + + UT_IdMapTest_SetImplTableMutex(OS_OBJECT_TYPE_OS_TASK, &TestGlobalSem); + OS_Unlock_Global_Impl(OS_OBJECT_TYPE_OS_TASK); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semGive)) == 1, "semTake() called"); + + UT_SetDefaultReturnValue(UT_KEY(OCS_semGive), -1); + OS_Unlock_Global_Impl(OS_OBJECT_TYPE_OS_TASK); /* for coverage of error path */ } void Test_OS_API_Impl_Init(void) @@ -79,12 +72,28 @@ void Test_OS_API_Impl_Init(void) * int32 OS_API_Impl_Init(uint32 idtype) */ OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(0), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_semMInitialize), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_semMInitialize), -1); OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_semMInitialize)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_semMInitialize)); OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); } +void Test_OS_WaitForStateChange_Impl(void) +{ + /* + * Test Case For: + * void OS_WaitForStateChange_Impl(osal_objtype_t idtype, uint32 attempts) + */ + + /* + * This has no return value/error results - just needs to be called for coverage. + * Call it once with a low number and once with a high number of attempts - + * which should cause it to hit its limit for wait time. + */ + OS_WaitForStateChange_Impl(OS_OBJECT_TYPE_OS_TASK, 1); + OS_WaitForStateChange_Impl(OS_OBJECT_TYPE_OS_TASK, 1000); +} + /* ------------------- End of test cases --------------------------------------*/ /* Osapi_Test_Setup @@ -115,4 +124,5 @@ void UtTest_Setup(void) ADD_TEST(OS_Lock_Global_Impl); ADD_TEST(OS_Unlock_Global_Impl); ADD_TEST(OS_API_Impl_Init); + ADD_TEST(OS_WaitForStateChange_Impl); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-loader.c b/src/unit-test-coverage/vxworks/src/coveragetest-loader.c index 4fede680c..505f69892 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-loader.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-loader.c @@ -50,13 +50,15 @@ void Test_OS_ModuleLoad_Impl(void) /* Test Case For: * int32 OS_ModuleLoad_Impl ( uint32 module_id, char *translated_path ) */ - OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0, "local"), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0, "local"), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); - UT_SetForceFail(UT_KEY(OCS_loadModule), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0, "local"), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_loadModule)); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(&token, "local"), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(&token, "local"), OS_ERROR); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); + UT_SetDefaultReturnValue(UT_KEY(OCS_loadModule), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(&token, "local"), OS_ERROR); + UT_ClearDefaultReturnValue(UT_KEY(OCS_loadModule)); } void Test_OS_ModuleUnload_Impl(void) @@ -64,10 +66,12 @@ void Test_OS_ModuleUnload_Impl(void) /* Test Case For: * int32 OS_ModuleUnload_Impl ( uint32 module_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_unldByModuleId), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_unldByModuleId)); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(&token), OS_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(OCS_unldByModuleId), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(&token), OS_ERROR); + UT_ClearDefaultReturnValue(UT_KEY(OCS_unldByModuleId)); } void Test_OS_ModuleGetInfo_Impl(void) @@ -75,10 +79,11 @@ void Test_OS_ModuleGetInfo_Impl(void) /* Test Case For: * int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ) */ - OS_module_prop_t module_prop; + OS_module_prop_t module_prop; + OS_object_token_t token = UT_TOKEN_0; memset(&module_prop, 0, sizeof(module_prop)); - OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(0, &module_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(&token, &module_prop), OS_SUCCESS); UtAssert_True(module_prop.addr.valid, "addresses in output valid"); /* @@ -86,9 +91,9 @@ void Test_OS_ModuleGetInfo_Impl(void) * but the boolean in the output struct should be false. */ memset(&module_prop, 0, sizeof(module_prop)); - UT_SetForceFail(UT_KEY(OCS_moduleInfoGet), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(0, &module_prop), OS_SUCCESS); - UT_ClearForceFail(UT_KEY(OCS_moduleInfoGet)); + UT_SetDefaultReturnValue(UT_KEY(OCS_moduleInfoGet), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(&token, &module_prop), OS_SUCCESS); + UT_ClearDefaultReturnValue(UT_KEY(OCS_moduleInfoGet)); UtAssert_True(!module_prop.addr.valid, "addresses in output not valid"); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c b/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c index bceac85b3..c606a95fb 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c @@ -43,10 +43,12 @@ void Test_OS_MutSemCreate_Impl(void) * Test Case For: * int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) */ - OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(0, 0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; - UT_SetForceFail(UT_KEY(OCS_semMInitialize), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(0, 0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(&token, 0), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OCS_semMInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(&token, 0), OS_SEM_FAILURE); } void Test_OS_MutSemDelete_Impl(void) @@ -55,7 +57,9 @@ void Test_OS_MutSemDelete_Impl(void) * Test Case For: * int32 OS_MutSemDelete_Impl (uint32 sem_id) */ - OSAPI_TEST_FUNCTION_RC(OS_MutSemDelete_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_MutSemDelete_Impl(&token), OS_SUCCESS); } void Test_OS_MutSemGive_Impl(void) @@ -64,7 +68,9 @@ void Test_OS_MutSemGive_Impl(void) * Test Case For: * int32 OS_MutSemGive_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_MutSemGive_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_MutSemGive_Impl(&token), OS_SUCCESS); } void Test_OS_MutSemTake_Impl(void) @@ -73,7 +79,9 @@ void Test_OS_MutSemTake_Impl(void) * Test Case For: * int32 OS_MutSemTake_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_MutSemTake_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_MutSemTake_Impl(&token), OS_SUCCESS); } void Test_OS_MutSemGetInfo_Impl(void) @@ -83,8 +91,10 @@ void Test_OS_MutSemGetInfo_Impl(void) * int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) */ OS_mut_sem_prop_t mut_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&mut_prop, 0xEE, sizeof(mut_prop)); - OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo_Impl(0, &mut_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo_Impl(&token, &mut_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-network.c b/src/unit-test-coverage/vxworks/src/coveragetest-network.c index e196dc5cc..e241c74f2 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-network.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-network.c @@ -49,7 +49,7 @@ void Test_OS_NetworkGetHostName_Impl(void) char buffer[16]; OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName_Impl(buffer, sizeof(buffer)), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_gethostname), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_gethostname), -1); OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName_Impl(buffer, sizeof(buffer)), OS_ERROR); } /* end OS_NetworkGetHostName_Impl */ @@ -63,10 +63,10 @@ void Test_OS_NetworkGetID_Impl(void) */ int32 IdBuf; - UT_SetForceFail(UT_KEY(OCS_hostGetByName), 1234); + UT_SetDefaultReturnValue(UT_KEY(OCS_hostGetByName), 1234); OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID_Impl(&IdBuf), OS_SUCCESS); UtAssert_True(IdBuf == 1234, "IdBuf (%ld) == 1234", (long)IdBuf); - UT_SetForceFail(UT_KEY(OCS_hostGetByName), OCS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_hostGetByName), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID_Impl(&IdBuf), OS_ERROR); } /* end OS_NetworkGetID_Impl */ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c b/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c index 7983ad49e..e736cbecf 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c @@ -49,12 +49,12 @@ void Test_OS_ModuleLoad_Impl(void) * int32 OS_ModuleLoad_Impl ( uint32 module_id, char *translated_path ) */ OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0, "local"), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_open), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0, "local"), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); - UT_SetForceFail(UT_KEY(OCS_loadModule), OCS_ERROR); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); + UT_SetDefaultReturnValue(UT_KEY(OCS_loadModule), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0, "local"), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_loadModule)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_loadModule)); } void Test_OS_ModuleUnload_Impl(void) @@ -63,9 +63,9 @@ void Test_OS_ModuleUnload_Impl(void) * int32 OS_ModuleUnload_Impl ( uint32 module_id ) */ OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_unldByModuleId), OCS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_unldByModuleId), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_unldByModuleId)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_unldByModuleId)); } void Test_OS_ModuleGetInfo_Impl(void) @@ -84,9 +84,9 @@ void Test_OS_ModuleGetInfo_Impl(void) * but the boolean in the output struct should be false. */ memset(&module_prop, 0, sizeof(module_prop)); - UT_SetForceFail(UT_KEY(OCS_moduleInfoGet), OCS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_moduleInfoGet), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(0, &module_prop), OS_SUCCESS); - UT_ClearForceFail(UT_KEY(OCS_moduleInfoGet)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_moduleInfoGet)); UtAssert_True(!module_prop.addr.valid, "addresses in output not valid"); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-queues.c b/src/unit-test-coverage/vxworks/src/coveragetest-queues.c index 7c059a148..f8f67afd4 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-queues.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-queues.c @@ -47,10 +47,12 @@ void Test_OS_QueueCreate_Impl(void) * Test Case For: * int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) */ - OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(0, 0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; - UT_SetForceFail(UT_KEY(OCS_msgQCreate), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(0, 0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(&token, 0), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OCS_msgQCreate), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(&token, 0), OS_ERROR); } void Test_OS_QueueDelete_Impl(void) @@ -59,10 +61,12 @@ void Test_OS_QueueDelete_Impl(void) * Test Case For: * int32 OS_QueueDelete_Impl (uint32 queue_id) */ - OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(&token), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_msgQDelete), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(0), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_msgQDelete), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(&token), OS_ERROR); } void Test_OS_QueueGet_Impl(void) @@ -71,23 +75,24 @@ void Test_OS_QueueGet_Impl(void) * Test Case For: * int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) */ - char Data[16]; - uint32 ActSz; + char Data[16]; + size_t ActSz; + OS_object_token_t token = UT_TOKEN_0; - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_PEND), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, 100), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_PEND), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, 100), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OS_Milli2Ticks), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, 100), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_Milli2Ticks), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, 100), OS_ERROR); - UT_SetForceFail(UT_KEY(OCS_msgQReceive), OCS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_msgQReceive), OCS_ERROR); OCS_errno = OCS_S_objLib_OBJ_TIMEOUT; - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_TIMEOUT); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_TIMEOUT); OCS_errno = OCS_S_objLib_OBJ_UNAVAILABLE; - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_EMPTY); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_EMPTY); OCS_errno = 0; - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_ERROR); } void Test_OS_QueuePut_Impl(void) @@ -96,14 +101,16 @@ void Test_OS_QueuePut_Impl(void) * Test Case For: * int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags) */ - char Data[16] = "Test"; - OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(0, Data, sizeof(Data), 0), OS_SUCCESS); + char Data[16] = "Test"; + OS_object_token_t token = UT_TOKEN_0; - UT_SetForceFail(UT_KEY(OCS_msgQSend), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(&token, Data, sizeof(Data), 0), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OCS_msgQSend), OCS_ERROR); OCS_errno = OCS_S_objLib_OBJ_UNAVAILABLE; - OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(0, Data, sizeof(Data), 0), OS_QUEUE_FULL); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(&token, Data, sizeof(Data), 0), OS_QUEUE_FULL); OCS_errno = 0; - OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(0, Data, sizeof(Data), 0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(&token, Data, sizeof(Data), 0), OS_ERROR); } void Test_OS_QueueGetInfo_Impl(void) @@ -112,9 +119,11 @@ void Test_OS_QueueGetInfo_Impl(void) * Test Case For: * int32 OS_QueueGetInfo_Impl (uint32 queue_id, OS_queue_prop_t *queue_prop) */ - OS_queue_prop_t queue_prop; + OS_queue_prop_t queue_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&queue_prop, 0xEE, sizeof(queue_prop)); - OSAPI_TEST_FUNCTION_RC(OS_QueueGetInfo_Impl(0, &queue_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetInfo_Impl(&token, &queue_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-shell.c b/src/unit-test-coverage/vxworks/src/coveragetest-shell.c index af2897453..2195ff349 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-shell.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-shell.c @@ -37,8 +37,9 @@ void Test_OS_ShellOutputToFile_Impl(void) * Test Case For: * int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) */ - int32 expected = OS_SUCCESS; - int32 actual; + int32 expected = OS_SUCCESS; + int32 actual; + OS_object_token_t token = UT_TOKEN_0; /* * The ShellOutputToFile will loop until the @@ -47,15 +48,15 @@ void Test_OS_ShellOutputToFile_Impl(void) */ UT_SetDeferredRetcode(UT_KEY(OCS_taskNameToId), 2, -1); - actual = OS_ShellOutputToFile_Impl(0, "TestCmd"); + actual = OS_ShellOutputToFile_Impl(&token, "TestCmd"); UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_shellGenericInit)) == 1, "shellGenericInit() called"); /* failure to open the output file */ - UT_SetForceFail(UT_KEY(OS_OpenCreate), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_ERROR); expected = OS_ERROR; - actual = OS_ShellOutputToFile_Impl(0, "TestCmd"); + actual = OS_ShellOutputToFile_Impl(&token, "TestCmd"); UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_ERROR", (long)actual); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c index 890fd480d..6bca6074b 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c @@ -33,16 +33,31 @@ #include #include -void Test_OS_SymbolLookup_Impl(void) +void Test_OS_GlobalSymbolLookup_Impl(void) { /* Test Case For: - * int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) + * int32 OS_GlobalSymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) */ cpuaddr SymAddr; - OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(NULL, NULL), OS_INVALID_POINTER); - UT_SetForceFail(UT_KEY(OCS_symFind), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_ERROR); + + OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(&SymAddr, "symname"), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(NULL, NULL), OS_INVALID_POINTER); + UT_SetDefaultReturnValue(UT_KEY(OCS_symFind), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(&SymAddr, "symname"), OS_ERROR); +} + +void Test_OS_ModuleSymbolLookup_Impl(void) +{ + /* Test Case For: + * int32 OS_ModuleSymbolLookup_Impl( uint32 local_id, cpuaddr *SymbolAddress, const char *SymbolName ) + */ + cpuaddr SymAddr; + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, &SymAddr, "symname"), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, NULL, NULL), OS_INVALID_POINTER); + UT_SetDefaultReturnValue(UT_KEY(OCS_symFind), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, &SymAddr, "symname"), OS_ERROR); } void Test_OS_SymTableIterator_Impl(void) @@ -54,12 +69,12 @@ void Test_OS_SymTableIterator_Impl(void) OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 1000), true); OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 101), false); - UT_SetForceFail(UT_KEY(OCS_strlen), OS_MAX_SYM_LEN + 10); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 1000), false); - UT_ClearForceFail(UT_KEY(OCS_strlen)); - UT_SetForceFail(UT_KEY(OCS_write), -1); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); + UT_SetDefaultReturnValue(UT_KEY(OCS_write), -1); OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 1000), false); - UT_ClearForceFail(UT_KEY(OCS_write)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_write)); } void Test_OS_SymbolTableDump_Impl(void) @@ -68,9 +83,9 @@ void Test_OS_SymbolTableDump_Impl(void) * int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 SizeLimit ) */ OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file", 10000), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_open), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file", 10000), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); } /* ------------------- End of test cases --------------------------------------*/ @@ -101,6 +116,7 @@ void Osapi_Test_Teardown(void) {} void UtTest_Setup(void) { ADD_TEST(OS_SymTableIterator_Impl); - ADD_TEST(OS_SymbolLookup_Impl); + ADD_TEST(OS_GlobalSymbolLookup_Impl); + ADD_TEST(OS_ModuleSymbolLookup_Impl); ADD_TEST(OS_SymbolTableDump_Impl); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c index 0fd7b96ab..8af36a00d 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c @@ -54,7 +54,7 @@ void Test_OS_VxWorksEntry(void) * Test Case For: * static int OS_VxWorksEntry(int arg) */ - OSAPI_TEST_FUNCTION_RC(UT_TaskTest_CallEntryPoint(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(UT_TaskTest_CallEntryPoint(OS_OBJECT_ID_UNDEFINED), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OS_TaskEntryPoint)) == 1, "OS_TaskEntryPoint() called"); } @@ -64,17 +64,19 @@ void Test_OS_TaskCreate_Impl(void) * Test Case For: * int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) */ + OS_object_token_t token = UT_TOKEN_0; + UT_SetDataBuffer(UT_KEY(OCS_malloc), TestHeap, sizeof(TestHeap), false); UT_SetDataBuffer(UT_KEY(OCS_free), TestHeap, sizeof(TestHeap), false); /* create task with stack size of 250 - this should invoke malloc() to get the stack. * The first call checks the failure path and ensures that a malloc failure gets handled */ OS_task_table[0].stack_size = 250; - UT_SetForceFail(UT_KEY(OCS_malloc), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0, 0), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_malloc), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, 0), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_malloc)); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0, OS_FP_ENABLED), OS_SUCCESS); + UT_ClearDefaultReturnValue(UT_KEY(OCS_malloc)); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 2, "malloc() called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 0, "free() not called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 1, "taskInit() called"); @@ -82,7 +84,7 @@ void Test_OS_TaskCreate_Impl(void) /* create again with smaller stack - this should re-use existing buffer */ OS_task_table[0].stack_size = 100; - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0, OS_FP_ENABLED), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 2, "malloc() not called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 0, "free() not called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 2, "taskInit() called"); @@ -90,15 +92,15 @@ void Test_OS_TaskCreate_Impl(void) /* create again with larger stack - this should free existing and malloc() new buffer */ OS_task_table[0].stack_size = 400; - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0, OS_FP_ENABLED), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 3, "malloc() called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 1, "free() called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 3, "taskInit() called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskActivate)) == 3, "taskActivate() called"); /* other failure modes */ - UT_SetForceFail(UT_KEY(OCS_taskInit), -1); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0, 0), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_taskInit), -1); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, 0), OS_ERROR); } void Test_OS_TaskMatch_Impl(void) @@ -107,10 +109,12 @@ void Test_OS_TaskMatch_Impl(void) * Test Case For: * int32 OS_TaskMatch_Impl(uint32 task_id) */ - UT_TaskTest_SetImplTaskId(0, OCS_taskIdSelf()); - OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(0), OS_SUCCESS); - UT_TaskTest_SetImplTaskId(0, (OCS_TASK_ID)0); - OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(0), OS_ERROR); + OS_object_token_t token = UT_TOKEN_0; + + UT_TaskTest_SetImplTaskId(UT_INDEX_0, OCS_taskIdSelf()); + OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(&token), OS_SUCCESS); + UT_TaskTest_SetImplTaskId(UT_INDEX_0, (OCS_TASK_ID)0); + OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(&token), OS_ERROR); } void Test_OS_TaskDelete_Impl(void) @@ -119,11 +123,25 @@ void Test_OS_TaskDelete_Impl(void) * Test Case For: * int32 OS_TaskDelete_Impl (uint32 task_id) */ - OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(&token), OS_SUCCESS); /* failure mode */ - UT_SetForceFail(UT_KEY(OCS_taskDelete), -1); - OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(0), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_taskDelete), -1); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(&token), OS_ERROR); +} + +void Test_OS_TaskDetach_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskDetach_Impl(const OS_object_token_t *token) + */ + OS_object_token_t token; + + /* no-op on VxWorks - always returns sucess */ + OSAPI_TEST_FUNCTION_RC(OS_TaskDetach_Impl(&token), OS_SUCCESS); } void Test_OS_TaskExit_Impl(void) @@ -144,10 +162,10 @@ void Test_OS_TaskDelay_Impl(void) */ OSAPI_TEST_FUNCTION_RC(OS_TaskDelay_Impl(100), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_taskDelay), OCS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_taskDelay), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_TaskDelay_Impl(100), OS_ERROR); - UT_SetForceFail(UT_KEY(OS_Milli2Ticks), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OS_Milli2Ticks), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_TaskDelay_Impl(100), OS_ERROR); } @@ -157,10 +175,12 @@ void Test_OS_TaskSetPriority_Impl(void) * Test Case For: * int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) */ - OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(0, 100), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; - UT_SetForceFail(UT_KEY(OCS_taskPrioritySet), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(0, 100), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(&token, OSAL_PRIORITY_C(100)), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OCS_taskPrioritySet), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(&token, OSAL_PRIORITY_C(100)), OS_ERROR); } void Test_OS_TaskRegister_Impl(void) @@ -184,7 +204,7 @@ void Test_OS_TaskGetId_Impl(void) memset(&id1, 0x11, sizeof(osal_id_t)); OS_global_task_table[1].active_id = id1; - TaskTcb = UT_TaskTest_GetTaskTcb(1); + TaskTcb = UT_TaskTest_GetTaskTcb(UT_INDEX_1); UT_SetDataBuffer(UT_KEY(OCS_taskTcb), &TaskTcb, sizeof(TaskTcb), false); id2 = OS_TaskGetId_Impl(); UtAssert_MemCmp(&id1, &id2, sizeof(osal_id_t), "OS_TaskGetId_Impl()"); @@ -196,9 +216,11 @@ void Test_OS_TaskGetInfo_Impl(void) * Test Case For: * int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) */ - OS_task_prop_t task_prop; + OS_task_prop_t task_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&task_prop, 0xEE, sizeof(task_prop)); - OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo_Impl(0, &task_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo_Impl(&token, &task_prop), OS_SUCCESS); } void Test_OS_TaskValidateSystemData_Impl(void) @@ -222,15 +244,16 @@ void Test_OS_TaskIdMatchSystemData_Impl(void) * Test Case For: * bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj) */ - OCS_TASK_ID test_sys_id; + OCS_TASK_ID test_sys_id; + OS_object_token_t token = UT_TOKEN_0; memset(&test_sys_id, 'x', sizeof(test_sys_id)); - UT_TaskTest_SetImplTaskId(0, test_sys_id); - OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, 0, NULL), true); + UT_TaskTest_SetImplTaskId(UT_INDEX_0, test_sys_id); + OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, &token, NULL), true); memset(&test_sys_id, 'y', sizeof(test_sys_id)); - OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, 0, NULL), false); + OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, &token, NULL), false); } /* ------------------- End of test cases --------------------------------------*/ @@ -269,6 +292,7 @@ void UtTest_Setup(void) ADD_TEST(OS_VxWorksEntry); ADD_TEST(OS_TaskMatch_Impl); ADD_TEST(OS_TaskDelete_Impl); + ADD_TEST(OS_TaskDetach_Impl); ADD_TEST(OS_TaskExit_Impl); ADD_TEST(OS_TaskDelay_Impl); ADD_TEST(OS_TaskSetPriority_Impl); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c index 92ad9198a..5455ecce4 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c @@ -41,7 +41,7 @@ void Test_OS_VxWorks_TimeBaseAPI_Impl_Init(void) * int32 OS_VxWorks_TimeBaseAPI_Impl_Init(void) */ OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TimeBaseAPI_Impl_Init(), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_sysClkRateGet), -1); + UT_SetDefaultReturnValue(UT_KEY(OCS_sysClkRateGet), -1); OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TimeBaseAPI_Impl_Init(), OS_ERROR); } @@ -50,7 +50,8 @@ void Test_OS_TimeBaseLock_Impl(void) /* Test Case For: * void OS_TimeBaseLock_Impl(uint32 local_id) */ - OS_TimeBaseLock_Impl(0); + OS_object_token_t token = UT_TOKEN_0; + OS_TimeBaseLock_Impl(&token); } void Test_OS_TimeBaseUnlock_Impl(void) @@ -58,13 +59,14 @@ void Test_OS_TimeBaseUnlock_Impl(void) /* Test Case For: * void OS_TimeBaseUnlock_Impl(uint32 local_id) */ - OS_TimeBaseUnlock_Impl(0); + OS_object_token_t token = UT_TOKEN_0; + OS_TimeBaseUnlock_Impl(&token); } static int32 UT_TimeBaseTest_TimeBaseRegHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) { - UT_TimeBaseTest_SetTimeBaseRegState(0, true); + UT_TimeBaseTest_SetTimeBaseRegState(UT_INDEX_0, true); return 0; } @@ -99,7 +101,8 @@ void Test_OS_TimeBaseCreate_Impl(void) /* Test Case For: * int32 OS_TimeBaseCreate_Impl(uint32 timer_id) */ - osal_id_t id; + osal_id_t id; + OS_object_token_t token = UT_TOKEN_0; /* * Test paths though the signal number assignment. @@ -107,29 +110,35 @@ void Test_OS_TimeBaseCreate_Impl(void) * This should be done first as it will assign the "external_sync" * and therefore cause future calls to skip this block. */ - memset(&id, 0x01, sizeof(id)); + id = OS_ObjectIdFromInteger(OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT); + + OS_global_timebase_table[0].active_id = id; + UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false); + + id = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(id) + 1); + OS_global_timebase_table[1].active_id = id; - UT_TimeBaseTest_Setup(1, OCS_SIGRTMIN, false); - UT_SetForceFail(UT_KEY(OCS_sigismember), true); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_UNAVAILABLE); + UT_TimeBaseTest_Setup(UT_INDEX_1, 1 + OCS_SIGRTMIN, false); + UT_SetDefaultReturnValue(UT_KEY(OCS_sigismember), true); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_UNAVAILABLE); UT_ResetState(UT_KEY(OCS_sigismember)); /* fail to initialize the sem */ - UT_SetForceFail(UT_KEY(OCS_semMInitialize), -1); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_INTERNAL); - UT_ClearForceFail(UT_KEY(OCS_semMInitialize)); + UT_SetDefaultReturnValue(UT_KEY(OCS_semMInitialize), -1); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_INTERNAL); + UT_ClearDefaultReturnValue(UT_KEY(OCS_semMInitialize)); /* fail to spawn the task */ - UT_SetForceFail(UT_KEY(OCS_taskSpawn), -1); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_INTERNAL); - UT_ClearForceFail(UT_KEY(OCS_taskSpawn)); + UT_SetDefaultReturnValue(UT_KEY(OCS_taskSpawn), -1); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_INTERNAL); + UT_ClearDefaultReturnValue(UT_KEY(OCS_taskSpawn)); /* * this call to TimeBaseCreate_Impl should also fail, because * this mimics the situation where the reg global is never * set past OS_TimerRegState_INIT */ - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_INTERNAL); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_INTERNAL); /* * Do Nominal/success case now. @@ -137,7 +146,7 @@ void Test_OS_TimeBaseCreate_Impl(void) * mimic registration success */ UT_SetHookFunction(UT_KEY(OCS_taskSpawn), UT_TimeBaseTest_TimeBaseRegHook, NULL); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_SUCCESS); /* * For coverage, call the OS_VxWorks_TimeBaseTask() function. @@ -147,14 +156,19 @@ void Test_OS_TimeBaseCreate_Impl(void) /* * Check outputs of OS_VxWorks_RegisterTimer() function. */ - UT_TimeBaseTest_ClearTimeBaseRegState(0); - UT_TimeBaseTest_CallRegisterTimer(0); - UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(0), "timer successfully registered"); - - UT_TimeBaseTest_ClearTimeBaseRegState(0); - UT_SetForceFail(UT_KEY(OCS_timer_create), -1); - UT_TimeBaseTest_CallRegisterTimer(0); - UtAssert_True(UT_TimeBaseTest_CheckTimeBaseErrorState(0), "timer registration failure state"); + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1); + UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); + UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer successfully registered"); + + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1); + UT_SetDefaultReturnValue(UT_KEY(OCS_timer_create), -1); + UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); + UtAssert_True(UT_TimeBaseTest_CheckTimeBaseErrorState(UT_INDEX_0), "timer registration failure state"); + + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); + UtAssert_True(!UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer registration bad ID"); } void Test_OS_VxWorks_SigWait(void) @@ -166,6 +180,7 @@ void Test_OS_VxWorks_SigWait(void) int signo = OCS_SIGRTMIN; struct OCS_itimerspec config_value; osal_id_t id; + OS_object_token_t token = UT_TOKEN_0; memset(&id, 0x02, sizeof(id)); OS_global_timebase_table[0].active_id = id; @@ -175,17 +190,17 @@ void Test_OS_VxWorks_SigWait(void) memset(&config_value, 0, sizeof(config_value)); UT_SetDataBuffer(UT_KEY(OCS_timer_settime), &config_value, sizeof(config_value), false); UT_SetDataBuffer(UT_KEY(OCS_timer_gettime), &config_value, sizeof(config_value), false); - UT_TimeBaseTest_Setup(0, signo, true); - OS_TimeBaseSet_Impl(0, 1111111, 2222222); + UT_TimeBaseTest_Setup(UT_INDEX_0, signo, true); + OS_TimeBaseSet_Impl(&token, 1111111, 2222222); UT_SetDataBuffer(UT_KEY(OCS_sigwait), &signo, sizeof(signo), false); - OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(0), 1111111); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 1111111); UT_SetDataBuffer(UT_KEY(OCS_sigwait), &signo, sizeof(signo), false); - OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(0), 2222222); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 2222222); UT_SetDataBuffer(UT_KEY(OCS_sigwait), &signo, sizeof(signo), false); - OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(0), 2222222); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 2222222); - UT_TimeBaseTest_Setup(0, 0, false); + UT_TimeBaseTest_Setup(UT_INDEX_0, 0, false); OS_global_timebase_table[0].active_id = OS_OBJECT_ID_UNDEFINED; OS_timebase_table[0].nominal_interval_time = 0; } @@ -195,13 +210,15 @@ void Test_OS_TimeBaseSet_Impl(void) /* Test Case For: * int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time) */ - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0, 1, 1), OS_ERR_NOT_IMPLEMENTED); + OS_object_token_t token = UT_TOKEN_0; - UT_TimeBaseTest_Setup(0, OCS_SIGRTMIN, false); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0, 1, 1), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_ERR_NOT_IMPLEMENTED); - UT_SetForceFail(UT_KEY(OCS_timer_settime), -1); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0, 1, 1), OS_TIMER_ERR_INVALID_ARGS); + UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OCS_timer_settime), -1); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_TIMER_ERR_INVALID_ARGS); } void Test_OS_TimeBaseDelete_Impl(void) @@ -209,8 +226,10 @@ void Test_OS_TimeBaseDelete_Impl(void) /* Test Case For: * int32 OS_TimeBaseDelete_Impl(uint32 timer_id) */ - UT_TimeBaseTest_Setup(0, OCS_SIGRTMIN, false); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete_Impl(&token), OS_SUCCESS); } void Test_OS_TimeBaseGetInfo_Impl(void) @@ -219,7 +238,9 @@ void Test_OS_TimeBaseGetInfo_Impl(void) * int32 OS_TimeBaseGetInfo_Impl (uint32 timer_id, OS_timebase_prop_t *timer_prop) */ OS_timebase_prop_t timer_prop; - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetInfo_Impl(0, &timer_prop), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetInfo_Impl(&token, &timer_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h b/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h index d51d0fb41..ac41fa602 100644 --- a/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h +++ b/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h @@ -25,8 +25,8 @@ * */ -#ifndef INCLUDE_OS_VXWORKS_COVERAGETEST_H_ -#define INCLUDE_OS_VXWORKS_COVERAGETEST_H_ +#ifndef OS_VXWORKS_COVERAGETEST_H +#define OS_VXWORKS_COVERAGETEST_H #include #include @@ -43,6 +43,26 @@ #define ADD_TEST(test) UtTest_Add((Test_##test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) +#define UT_INDEX_0 OSAL_INDEX_C(0) +#define UT_INDEX_1 OSAL_INDEX_C(1) +#define UT_INDEX_2 OSAL_INDEX_C(2) + +#define UT_TOKEN_0 \ + (OS_object_token_t) \ + { \ + .obj_id = (osal_id_t) {0x10000}, .obj_idx = 0 \ + } +#define UT_TOKEN_1 \ + (OS_object_token_t) \ + { \ + .obj_id = (osal_id_t) {0x10001}, .obj_idx = 1 \ + } +#define UT_TOKEN_2 \ + (OS_object_token_t) \ + { \ + .obj_id = (osal_id_t) {0x10002}, .obj_idx = 2 \ + } + /* Osapi_Test_Setup * * Purpose: @@ -51,4 +71,4 @@ void Osapi_Test_Setup(void); void Osapi_Test_Teardown(void); -#endif /* INCLUDE_OS_VXWORKS_COVERAGETEST_H_ */ +#endif /* OS_VXWORKS_COVERAGETEST_H */ diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-common-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-common-stubs.c index 3457f101d..27339e688 100644 --- a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-common-stubs.c +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-common-stubs.c @@ -31,7 +31,7 @@ #include #include -UT_DEFAULT_STUB(OS_API_Impl_Init, (uint32 idtype)) +UT_DEFAULT_STUB(OS_API_Impl_Init, (osal_objtype_t idtype)) int OS_VxWorks_GenericSemTake(OCS_SEM_ID vxid, int sys_ticks) { diff --git a/src/unit-tests/inc/ut_os_support.h b/src/unit-tests/inc/ut_os_support.h index 86e841b83..ff7c9144e 100644 --- a/src/unit-tests/inc/ut_os_support.h +++ b/src/unit-tests/inc/ut_os_support.h @@ -24,8 +24,8 @@ ** Date: May 2013 **================================================================================*/ -#ifndef _UT_OS_SUPPORT_H_ -#define _UT_OS_SUPPORT_H_ +#ifndef UT_OS_SUPPORT_H +#define UT_OS_SUPPORT_H /*--------------------------------------------------------------------------------* ** Includes @@ -109,8 +109,6 @@ static inline bool UtOsalImplemented(int32 Fn, const char *File, uint32 Line) /*--------------------------------------------------------------------------------*/ -#define UT_OS_LOG(...) UtAssert_Message(UTASSERT_CASETYPE_INFO, __FILE__, __LINE__, __VA_ARGS__); - /* * An osal_id_t value which is not OS_OBJECT_ID_UNDEFINED and also * not aliasing any other valid value/type. @@ -137,7 +135,7 @@ static inline bool UtOsalImplemented(int32 Fn, const char *File, uint32 Line) /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OS_SUPPORT_H_ */ +#endif /* UT_OS_SUPPORT_H */ /*================================================================================* ** End of File: ut_os_support.h diff --git a/src/unit-tests/oscore-test/ut_oscore_binsem_test.h b/src/unit-tests/oscore-test/ut_oscore_binsem_test.h index 591c207ca..081a87d3a 100644 --- a/src/unit-tests/oscore-test/ut_oscore_binsem_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_binsem_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSCORE_BINSEM_TEST_H_ -#define _UT_OSCORE_BINSEM_TEST_H_ +#ifndef UT_OSCORE_BINSEM_TEST_H +#define UT_OSCORE_BINSEM_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -64,7 +64,7 @@ void UT_os_bin_sem_get_info_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSCORE_BINSEM_TEST_H_ */ +#endif /* UT_OSCORE_BINSEM_TEST_H */ /*================================================================================* ** End of File: ut_oscore_binsem_test.h diff --git a/src/unit-tests/oscore-test/ut_oscore_countsem_test.c b/src/unit-tests/oscore-test/ut_oscore_countsem_test.c index b76651b9e..855d5e9f5 100644 --- a/src/unit-tests/oscore-test/ut_oscore_countsem_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_countsem_test.c @@ -125,7 +125,7 @@ void UT_os_count_sem_create_test() * The OSAL should define this for itself, but it currently does not. * (This macro is not currently defined in RTEMS) */ -#ifdef SEM_VALUE_MAX +#if defined SEM_VALUE_MAX && SEM_VALUE_MAX < UINT32_MAX res = OS_CountSemCreate(&count_sem_ids[0], "CountSem1", ((uint32)SEM_VALUE_MAX) + 1, 0); if (res == OS_INVALID_SEM_VALUE) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); diff --git a/src/unit-tests/oscore-test/ut_oscore_countsem_test.h b/src/unit-tests/oscore-test/ut_oscore_countsem_test.h index 3e011f7b2..6cad49f9c 100644 --- a/src/unit-tests/oscore-test/ut_oscore_countsem_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_countsem_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSCORE_COUNTSEM_TEST_H_ -#define _UT_OSCORE_COUNTSEM_TEST_H_ +#ifndef UT_OSCORE_COUNTSEM_TEST_H +#define UT_OSCORE_COUNTSEM_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -63,7 +63,7 @@ void UT_os_count_sem_get_info_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSCORE_COUNTSEM_TEST_H_ */ +#endif /* UT_OSCORE_COUNTSEM_TEST_H */ /*================================================================================* ** End of File: ut_oscore_countsem_test.h diff --git a/src/unit-tests/oscore-test/ut_oscore_misc_test.c b/src/unit-tests/oscore-test/ut_oscore_misc_test.c index 07b066140..4a33644e9 100644 --- a/src/unit-tests/oscore-test/ut_oscore_misc_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_misc_test.c @@ -88,12 +88,14 @@ *--------------------------------------------------------------------------------*/ void UT_os_apiinit_test() { - int32 res = 0; - const char *testDesc; - osal_id_t qId; - uint32 qDepth = 10, qSize = 4, qFlags = 0; - osal_id_t semIds[3]; - uint32 semInitValue = 1, semOptions = 0; + int32 res = 0; + const char * testDesc; + osal_id_t qId; + osal_blockcount_t qDepth = OSAL_BLOCKCOUNT_C(10); + size_t qSize = OSAL_SIZE_C(4); + uint32 qFlags = 0; + osal_id_t semIds[3]; + uint32 semInitValue = 1, semOptions = 0; /*-----------------------------------------------------*/ testDesc = "#1 Init-not-call-first"; @@ -159,7 +161,7 @@ void UT_os_apiinit_test() void UT_os_printf_test() { OS_printf_enable(); - UT_OS_LOG("OS_printf() - #1 Nominal [This is the expected stdout output after API call]\n"); + UtPrintf("OS_printf() - #1 Nominal [This is the expected stdout output after API call]\n"); OS_printf("OS_printf() - #1 Nominal [ This is the expected stdout output after API call]\n"); UT_OS_TEST_RESULT("#1 Nominal - Manual inspection required", UTASSERT_CASETYPE_MIR); @@ -182,7 +184,7 @@ void UT_os_printfenable_test() OS_printf_disable(); OS_printf_enable(); - UT_OS_LOG("OS_printf_enable() - #1 Nominal [This is the expected stdout output after API call]\n"); + UtPrintf("OS_printf_enable() - #1 Nominal [This is the expected stdout output after API call]\n"); OS_printf("OS_printf_enable() - #1 Nominal [This is the expected stdout output after API call]\n"); UT_OS_TEST_RESULT("#1 Nominal - Manual inspection required", UTASSERT_CASETYPE_MIR); @@ -203,18 +205,18 @@ void UT_os_printfenable_test() void UT_os_printfdisable_test() { OS_printf_enable(); - UT_OS_LOG("OS_printf_disable() - #1 Nominal [This is the expected stdout output before API call]\n"); + UtPrintf("OS_printf_disable() - #1 Nominal [This is the expected stdout output before API call]\n"); OS_printf("OS_printf_disable() - #1 Nominal [This is the expected stdout output before API call]\n"); OS_printf_disable(); - UT_OS_LOG("OS_printf_disable() - #1 Nominal [This is NOT the expected stdout output after API call]\n"); + UtPrintf("OS_printf_disable() - #1 Nominal [This is NOT the expected stdout output after API call]\n"); OS_printf("OS_printf_disable() - #1 Nominal [This is NOT the expected stdout output after API call]\n"); UT_OS_TEST_RESULT("#1 Nominal - Manual inspection required", UTASSERT_CASETYPE_MIR); /* Reset test environment */ OS_printf_enable(); - UT_OS_LOG("OS_printf_disable() - #1 Nominal [This is the expected stdout output after test reset]\n"); + UtPrintf("OS_printf_disable() - #1 Nominal [This is the expected stdout output after test reset]\n"); OS_printf("OS_printf_disable() - #1 Nominal [This is the expected stdout output after test reset]\n"); } @@ -284,12 +286,12 @@ void UT_os_getlocaltime_test() res = OS_GetLocalTime(&time_struct); if (res == OS_SUCCESS) { - UT_OS_LOG("\n"); + UtPrintf("\n"); for (i = 0; i < 5; i++) { - UT_OS_LOG("OS_GetLocalTime() - #3 Nominal "); - UT_OS_LOG("[Expecting output after API call to increase over time: %ld.%ld]\n", (long)time_struct.seconds, - (long)time_struct.microsecs); + UtPrintf("OS_GetLocalTime() - #3 Nominal "); + UtPrintf("[Expecting output after API call to increase over time: %ld.%ld]\n", + (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); OS_TaskDelay(20); OS_GetLocalTime(&time_struct); @@ -376,33 +378,31 @@ void UT_os_setlocaltime_test() { for (i = 0; i < 5; i++) { - UT_OS_LOG("OS_SetLocalTime() - #3 Nominal "); - UT_OS_LOG("[Expecting output before API call to increase over time: %ld.%ld]\n", (long)time_struct.seconds, - (long)time_struct.microsecs); + UtPrintf("OS_SetLocalTime() - #3 Nominal "); + UtPrintf("[Expecting output before API call to increase over time: %ld.%ld]\n", + (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); OS_TaskDelay(20); OS_GetLocalTime(&time_struct); } } - memset(&time_struct, 0x00, sizeof(time_struct)); - time_struct.seconds = 20000; - time_struct.microsecs = 123; + time_struct = OS_TimeAssembleFromNanoseconds(20000, 123000); res = OS_SetLocalTime(&time_struct); if (res == OS_SUCCESS) { - UT_OS_LOG("OS_SetLocalTime() - #3 Nominal [New time set at %ld.%ld]\n", (long)time_struct.seconds, - (long)time_struct.microsecs); + UtPrintf("OS_SetLocalTime() - #3 Nominal [New time set at %ld.%ld]\n", + (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); res = OS_GetLocalTime(&time_struct); if (res == OS_SUCCESS) { for (i = 0; i < 5; i++) { - UT_OS_LOG("OS_SetLocalTime() - #3 Nominal "); - UT_OS_LOG("[Expecting output after API call to increase over time: %ld.%ld]\n", - (long)time_struct.seconds, (long)time_struct.microsecs); + UtPrintf("OS_SetLocalTime() - #3 Nominal "); + UtPrintf("[Expecting output after API call to increase over time: %ld.%ld]\n", + (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); OS_TaskDelay(20); OS_GetLocalTime(&time_struct); diff --git a/src/unit-tests/oscore-test/ut_oscore_misc_test.h b/src/unit-tests/oscore-test/ut_oscore_misc_test.h index 1510f5c42..4cf6fb5c5 100644 --- a/src/unit-tests/oscore-test/ut_oscore_misc_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_misc_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSCORE_MISC_TEST_H_ -#define _UT_OSCORE_MISC_TEST_H_ +#ifndef UT_OSCORE_MISC_TEST_H +#define UT_OSCORE_MISC_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -68,7 +68,7 @@ void UT_os_heapgetinfo_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSCORE_MISC_TEST_H_ */ +#endif /* UT_OSCORE_MISC_TEST_H */ /*================================================================================* ** End of File: ut_oscore_misc_test.h diff --git a/src/unit-tests/oscore-test/ut_oscore_mutex_test.h b/src/unit-tests/oscore-test/ut_oscore_mutex_test.h index 6c0b30b1a..50fdec19b 100644 --- a/src/unit-tests/oscore-test/ut_oscore_mutex_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_mutex_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSCORE_MUTEX_TEST_H_ -#define _UT_OSCORE_MUTEX_TEST_H_ +#ifndef UT_OSCORE_MUTEX_TEST_H +#define UT_OSCORE_MUTEX_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -62,7 +62,7 @@ void UT_os_mut_sem_get_info_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSCORE_MUTEX_TEST_H_ */ +#endif /* UT_OSCORE_MUTEX_TEST_H */ /*================================================================================* ** End of File: ut_oscore_mutex_test.h diff --git a/src/unit-tests/oscore-test/ut_oscore_queue_test.c b/src/unit-tests/oscore-test/ut_oscore_queue_test.c index d47dc6629..c991f3324 100644 --- a/src/unit-tests/oscore-test/ut_oscore_queue_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_queue_test.c @@ -83,7 +83,7 @@ void UT_os_queue_create_test() /*-----------------------------------------------------*/ testDesc = "API not implemented"; - res = OS_QueueCreate(&queue_id, "Good", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "Good", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); @@ -95,7 +95,7 @@ void UT_os_queue_create_test() /*-----------------------------------------------------*/ testDesc = "#1 Null-pointer-arg-1"; - res = OS_QueueCreate(NULL, "Queue1", 10, 4, 0); + res = OS_QueueCreate(NULL, "Queue1", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -104,7 +104,7 @@ void UT_os_queue_create_test() /*-----------------------------------------------------*/ testDesc = "#2 Null-pointer-arg-2"; - res = OS_QueueCreate(&queue_id, NULL, 10, 4, 0); + res = OS_QueueCreate(&queue_id, NULL, OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -115,7 +115,7 @@ void UT_os_queue_create_test() memset(long_queue_name, 'X', sizeof(long_queue_name)); long_queue_name[sizeof(long_queue_name) - 1] = '\0'; - res = OS_QueueCreate(&queue_id, long_queue_name, 10, 4, 0); + res = OS_QueueCreate(&queue_id, long_queue_name, OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res == OS_ERR_NAME_TOO_LONG) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -129,7 +129,7 @@ void UT_os_queue_create_test() { memset(queue_name, '\0', sizeof(queue_name)); UT_os_sprintf(queue_name, "QUEUE%d", i); - res = OS_QueueCreate(&queue_id, queue_name, 2, 4, 0); + res = OS_QueueCreate(&queue_id, queue_name, OSAL_BLOCKCOUNT_C(2), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#4 No-free-IDs - Queue Create failed"; @@ -141,7 +141,7 @@ void UT_os_queue_create_test() if (test_setup_invalid == 0) { - res = OS_QueueCreate(&queue_id, "OneTooMany", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "OneTooMany", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res == OS_ERR_NO_FREE_IDS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -155,14 +155,14 @@ void UT_os_queue_create_test() testDesc = "#5 Duplicate-name"; /* Setup */ - res = OS_QueueCreate(&queue_id2, "DUPLICATE", 10, 4, 0); + res = OS_QueueCreate(&queue_id2, "DUPLICATE", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { UT_OS_TEST_RESULT("Queue Create failed", UTASSERT_CASETYPE_TSF); } else { - res = OS_QueueCreate(&queue_id, "DUPLICATE", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "DUPLICATE", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res == OS_ERR_NAME_TAKEN) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -180,7 +180,7 @@ void UT_os_queue_create_test() /*-----------------------------------------------------*/ testDesc = "#7 Nominal"; - res = OS_QueueCreate(&queue_id, "Good", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "Good", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res == OS_SUCCESS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -235,7 +235,7 @@ void UT_os_queue_delete_test() testDesc = "#3 Nominal"; /* Setup */ - res = OS_QueueCreate(&queue_id, "DeleteTest", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "DeleteTest", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#3 Nominal - Queue Create failed"; @@ -272,13 +272,13 @@ void UT_os_queue_get_test() osal_id_t queue_id; uint32 queue_data_out; uint32 queue_data_in; - uint32 size_copied; - uint32 data_size; + size_t size_copied; + size_t data_size; /*-----------------------------------------------------*/ testDesc = "API not implemented"; - res = OS_QueueGet(OS_OBJECT_ID_UNDEFINED, (void *)&queue_data_in, 4, &size_copied, OS_CHECK); + res = OS_QueueGet(OS_OBJECT_ID_UNDEFINED, (void *)&queue_data_in, sizeof(uint32), &size_copied, OS_CHECK); if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); @@ -288,7 +288,7 @@ void UT_os_queue_get_test() /*-----------------------------------------------------*/ testDesc = "#1 Invalid-ID-arg"; - res = OS_QueueGet(UT_OBJID_INCORRECT, (void *)&queue_data_in, 4, &size_copied, OS_CHECK); + res = OS_QueueGet(UT_OBJID_INCORRECT, (void *)&queue_data_in, sizeof(uint32), &size_copied, OS_CHECK); if (res == OS_ERR_INVALID_ID) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -298,7 +298,7 @@ void UT_os_queue_get_test() testDesc = "#2 Invalid-pointer-arg-1"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#2 Invalid-pointer-arg-1 - Queue Create failed"; @@ -306,7 +306,7 @@ void UT_os_queue_get_test() } else { - res = OS_QueueGet(queue_id, NULL, 4, &size_copied, OS_CHECK); + res = OS_QueueGet(queue_id, NULL, sizeof(uint32), &size_copied, OS_CHECK); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -319,7 +319,7 @@ void UT_os_queue_get_test() testDesc = "#3 Invalid-pointer-arg-2"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#3 Invalid-pointer-arg-2 - Queue Create failed"; @@ -327,7 +327,7 @@ void UT_os_queue_get_test() } else { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, NULL, OS_CHECK); + res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), NULL, OS_CHECK); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -340,7 +340,7 @@ void UT_os_queue_get_test() testDesc = "#4 Queue-empty"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueEmpty", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueueEmpty", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#4 Queue-empty - Queue Create failed"; @@ -348,7 +348,7 @@ void UT_os_queue_get_test() } else { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, &data_size, OS_CHECK); + res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, OS_CHECK); if (res == OS_QUEUE_EMPTY) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -361,7 +361,7 @@ void UT_os_queue_get_test() testDesc = "#5 Queue-timed-out"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueTimeout", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueueTimeout", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#5 Queue-timed-out - Queue Create failed"; @@ -369,7 +369,7 @@ void UT_os_queue_get_test() } else { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, &data_size, 2); + res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, 2); if (res == OS_QUEUE_TIMEOUT) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -382,7 +382,7 @@ void UT_os_queue_get_test() testDesc = "#6 Invalid-queue-size"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueuePut", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueuePut", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#6 Invalid-queue-size - Queue Create failed"; @@ -391,7 +391,7 @@ void UT_os_queue_get_test() else { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, 2, 0); + res = OS_QueuePut(queue_id, (void *)&queue_data_out, OSAL_SIZE_C(2), 0); if (res != OS_SUCCESS) { testDesc = "#6 Invalid-queue-size - Queue Put failed"; @@ -399,7 +399,7 @@ void UT_os_queue_get_test() } else { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, 3, &data_size, OS_CHECK); + res = OS_QueueGet(queue_id, (void *)&queue_data_in, OSAL_SIZE_C(3), &data_size, OS_CHECK); if (res == OS_QUEUE_INVALID_SIZE) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -417,7 +417,7 @@ void UT_os_queue_get_test() testDesc = "#8 Nominal Pend"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#8 Nominal Pend - Queue Create failed"; @@ -426,7 +426,7 @@ void UT_os_queue_get_test() else { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, 4, 0); + res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#8 Nominal Pend - Queue Put failed"; @@ -434,7 +434,7 @@ void UT_os_queue_get_test() } else { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, &data_size, OS_PEND); + res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, OS_PEND); if (res == OS_SUCCESS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -447,7 +447,7 @@ void UT_os_queue_get_test() testDesc = "#9 Nominal timeout"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#9 Nominal timeout - Queue Create failed"; @@ -456,7 +456,7 @@ void UT_os_queue_get_test() else { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, 4, 0); + res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#9 Nominal timeout - Queue Put failed"; @@ -464,7 +464,7 @@ void UT_os_queue_get_test() } else { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, &data_size, 20); + res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, 20); if (res == OS_SUCCESS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -477,7 +477,7 @@ void UT_os_queue_get_test() testDesc = "#10 Nominal check"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#10 Nominal check - Queue Create failed"; @@ -486,7 +486,7 @@ void UT_os_queue_get_test() else { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, 4, 0); + res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#10 Nominal check - Queue Put failed"; @@ -494,7 +494,7 @@ void UT_os_queue_get_test() } else { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, &data_size, OS_CHECK); + res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, OS_CHECK); if (res == OS_SUCCESS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -528,7 +528,7 @@ void UT_os_queue_put_test() /*-----------------------------------------------------*/ testDesc = "API not implemented"; - res = OS_QueuePut(OS_OBJECT_ID_UNDEFINED, (void *)&queue_data_out, 4, 0); + res = OS_QueuePut(OS_OBJECT_ID_UNDEFINED, (void *)&queue_data_out, sizeof(uint32), 0); if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); @@ -538,7 +538,7 @@ void UT_os_queue_put_test() /*-----------------------------------------------------*/ testDesc = "#1 Invalid-ID-arg"; - res = OS_QueuePut(UT_OBJID_INCORRECT, (void *)&queue_data_out, 4, 0); + res = OS_QueuePut(UT_OBJID_INCORRECT, (void *)&queue_data_out, sizeof(uint32), 0); if (res == OS_ERR_INVALID_ID) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -548,7 +548,7 @@ void UT_os_queue_put_test() testDesc = "#2 Invalid-pointer-arg"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueuePut", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueuePut", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#2 Invalid-pointer-arg - Queue Create failed"; @@ -556,7 +556,7 @@ void UT_os_queue_put_test() } else { - res = OS_QueuePut(queue_id, NULL, 4, 0); + res = OS_QueuePut(queue_id, NULL, sizeof(uint32), 0); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -573,7 +573,7 @@ void UT_os_queue_put_test() testDesc = "#4 Queue-full"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueuePut", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueuePut", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#4 Queue-full - Queue Create failed"; @@ -584,7 +584,7 @@ void UT_os_queue_put_test() queue_data_out = 0x11223344; for (i = 0; i < 100; i++) { - res = OS_QueuePut(queue_id, (void *)&queue_data_out, 4, 0); + res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); if (res == OS_QUEUE_FULL) break; } @@ -601,7 +601,7 @@ void UT_os_queue_put_test() testDesc = "#5 Nominal"; /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#5 Nominal - Queue Create failed"; @@ -610,7 +610,7 @@ void UT_os_queue_put_test() else { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, 4, 0); + res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); if (res == OS_SUCCESS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -690,7 +690,7 @@ void UT_os_queue_get_id_by_name_test() testDesc = "#5 Nominal"; /* Setup */ - res = OS_QueueCreate(&queue_id, "GetIDByName", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "GetIDByName", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#5 Nominal - Queue Create failed"; @@ -749,7 +749,7 @@ void UT_os_queue_get_info_test() testDesc = "#2 Invalid-pointer-arg"; /* Setup */ - res = OS_QueueCreate(&queue_id, "GetInfo", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "GetInfo", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#2 Invalid-pointer-arg - Queue Create failed"; @@ -770,7 +770,7 @@ void UT_os_queue_get_info_test() testDesc = "#3 Nominal"; /* Setup */ - res = OS_QueueCreate(&queue_id, "GetInfo", 10, 4, 0); + res = OS_QueueCreate(&queue_id, "GetInfo", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); if (res != OS_SUCCESS) { testDesc = "#3 Nominal - Queue Create failed"; diff --git a/src/unit-tests/oscore-test/ut_oscore_queue_test.h b/src/unit-tests/oscore-test/ut_oscore_queue_test.h index ab8305cbf..1a45d3e2e 100644 --- a/src/unit-tests/oscore-test/ut_oscore_queue_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_queue_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSCORE_QUEUE_TEST_H_ -#define _UT_OSCORE_QUEUE_TEST_H_ +#ifndef UT_OSCORE_QUEUE_TEST_H +#define UT_OSCORE_QUEUE_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -62,7 +62,7 @@ void UT_os_queue_get_info_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSCORE_QUEUE_TEST_H_ */ +#endif /* UT_OSCORE_QUEUE_TEST_H */ /*================================================================================* ** End of File: ut_oscore_queue_test.h diff --git a/src/unit-tests/oscore-test/ut_oscore_select_test.c b/src/unit-tests/oscore-test/ut_oscore_select_test.c index 567fc9fbc..3ebba4844 100644 --- a/src/unit-tests/oscore-test/ut_oscore_select_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_select_test.c @@ -64,7 +64,7 @@ char * fsAddrPtr = NULL; static osal_id_t setup_file(void) { osal_id_t id; - UT_SETUP(OS_mkfs(fsAddrPtr, "/ramdev3", "RAM3", 512, 20)); + UT_SETUP(OS_mkfs(fsAddrPtr, "/ramdev3", "RAM3", OSAL_SIZE_C(512), OSAL_BLOCKCOUNT_C(20))); UT_SETUP(OS_mount("/ramdev3", "/drive3")); UT_SETUP(OS_OpenCreate(&id, "/drive3/select_test.txt", OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE)); return id; diff --git a/src/unit-tests/oscore-test/ut_oscore_select_test.h b/src/unit-tests/oscore-test/ut_oscore_select_test.h index 1187f3ea7..467e5707a 100644 --- a/src/unit-tests/oscore-test/ut_oscore_select_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_select_test.h @@ -24,8 +24,8 @@ ** Date: March 2020 **================================================================================*/ -#ifndef _UT_OSCORE_SELECT_TEST_H_ -#define _UT_OSCORE_SELECT_TEST_H_ +#ifndef UT_OSCORE_SELECT_TEST_H +#define UT_OSCORE_SELECT_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -59,7 +59,7 @@ void UT_os_select_multi_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSCORE_SELECT_TEST_H_ */ +#endif /* UT_OSCORE_SELECT_TEST_H */ /*================================================================================* ** End of File: ut_oscore_select_test.h diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.c b/src/unit-tests/oscore-test/ut_oscore_task_test.c index 7f0cd5ae3..41dd84e80 100644 --- a/src/unit-tests/oscore-test/ut_oscore_task_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.c @@ -37,9 +37,6 @@ #define UT_TASK_STACK_SIZE 0x2000 #define UT_TASK_PRIORITY 111 -/* This is not global in the OSAL */ -#define MAX_PRIORITY 255 - /*--------------------------------------------------------------------------------* ** Data types **--------------------------------------------------------------------------------*/ @@ -58,7 +55,10 @@ extern char g_long_task_name[UT_OS_NAME_BUFF_SIZE]; uint32 g_task_result = 0; osal_id_t g_task_sync_sem; osal_id_t g_task_ids[UT_OS_TASK_LIST_LEN]; -uint32 g_task_stacks[UT_OS_TASK_LIST_LEN][UT_TASK_STACK_SIZE]; +struct +{ + uint32 words[UT_TASK_STACK_SIZE]; +} g_task_stacks[UT_OS_TASK_LIST_LEN]; /*--------------------------------------------------------------------------------* ** External function prototypes @@ -84,7 +84,7 @@ void generic_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("Starting GenericTask: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); + UtPrintf("Starting GenericTask: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); while (1) { @@ -113,8 +113,8 @@ void UT_os_task_create_test() /*-----------------------------------------------------*/ testDesc = "API not implemented"; - res = OS_TaskCreate(&g_task_ids[0], g_task_names[0], generic_test_task, g_task_stacks[0], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[0], g_task_names[0], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[0]), + sizeof(g_task_stacks[0]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); @@ -130,8 +130,8 @@ void UT_os_task_create_test() /*-----------------------------------------------------*/ testDesc = "#1 Null-pointer-arg-1"; - res = OS_TaskCreate(NULL, g_task_names[1], generic_test_task, g_task_stacks[1], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(NULL, g_task_names[1], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[1]), + sizeof(g_task_stacks[1]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -140,8 +140,8 @@ void UT_os_task_create_test() /*-----------------------------------------------------*/ testDesc = "#2 Null-pointer-arg-2"; - res = OS_TaskCreate(&g_task_ids[2], NULL, generic_test_task, g_task_stacks[2], UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, - 0); + res = OS_TaskCreate(&g_task_ids[2], NULL, generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), + sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -150,8 +150,8 @@ void UT_os_task_create_test() /*-----------------------------------------------------*/ testDesc = "#3 Null-pointer-arg-3"; - res = - OS_TaskCreate(&g_task_ids[3], g_task_names[3], NULL, g_task_stacks[3], UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], NULL, OSAL_STACKPTR_C(&g_task_stacks[3]), + sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -160,23 +160,13 @@ void UT_os_task_create_test() /*-----------------------------------------------------*/ testDesc = "#4 Name-too-long"; - res = OS_TaskCreate(&g_task_ids[4], g_long_task_name, generic_test_task, g_task_stacks[4], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[4], g_long_task_name, generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[4]), + sizeof(g_task_stacks[4]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res == OS_ERR_NAME_TOO_LONG) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - /*-----------------------------------------------------*/ - testDesc = "#5 Invalid-priority"; - - res = OS_TaskCreate(&g_task_ids[5], g_task_names[5], generic_test_task, g_task_stacks[5], UT_TASK_STACK_SIZE, - MAX_PRIORITY + 1, 0); - if (res == OS_ERR_INVALID_PRIORITY) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - /*-----------------------------------------------------*/ testDesc = "#6 No-free-IDs"; @@ -185,8 +175,8 @@ void UT_os_task_create_test() { memset(task_name, '\0', sizeof(task_name)); UT_os_sprintf(task_name, "CREATE_TASK%d", (int)i); - res = OS_TaskCreate(&g_task_ids[i], task_name, generic_test_task, g_task_stacks[i], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[i], task_name, generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[i]), + sizeof(g_task_stacks[i]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { break; @@ -211,8 +201,8 @@ void UT_os_task_create_test() testDesc = "#7 Duplicate-name"; /* Setup */ - res = OS_TaskCreate(&g_task_ids[7], g_task_names[7], generic_test_task, g_task_stacks[7], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[7], g_task_names[7], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[7]), + sizeof(g_task_stacks[7]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#7 Duplicate-name - Task-Create failed"; @@ -220,8 +210,8 @@ void UT_os_task_create_test() } else { - res = OS_TaskCreate(&g_task_ids[8], g_task_names[7], generic_test_task, g_task_stacks[8], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[8], g_task_names[7], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[8]), + sizeof(g_task_stacks[8]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res == OS_ERR_NAME_TAKEN) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -242,8 +232,8 @@ void UT_os_task_create_test() /*-----------------------------------------------------*/ testDesc = "#9 Nominal"; - res = OS_TaskCreate(&g_task_ids[9], g_task_names[9], generic_test_task, g_task_stacks[9], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[9], g_task_names[9], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[9]), + sizeof(g_task_stacks[9]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res == OS_SUCCESS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -300,8 +290,8 @@ void UT_os_task_delete_test() testDesc = "#3 Nominal"; /* Setup */ - res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, g_task_stacks[3], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[3]), + sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#3 Nominal - Task-Create failed"; @@ -332,7 +322,7 @@ void UT_os_task_delete_test() **--------------------------------------------------------------------------------*/ void delete_handler_callback(void) { - UT_OS_LOG("Task delete callback...\n"); + UtPrintf("Task delete callback...\n"); } /*--------------------------------------------------------------------------------*/ @@ -347,7 +337,7 @@ void delete_handler_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("Starting DeleteTest Task: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); + UtPrintf("Starting DeleteTest Task: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); g_task_result = OS_TaskInstallDeleteHandler(&delete_handler_callback); @@ -407,8 +397,9 @@ void UT_os_task_install_delete_handler_test(void) { OS_BinSemTake(g_task_sync_sem); - res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], delete_handler_test_task, g_task_stacks[2], - UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + res = + OS_TaskCreate(&g_task_ids[2], g_task_names[2], delete_handler_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), + sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#2 Nominal - Task-Create-failed"; @@ -452,7 +443,7 @@ void exit_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("Starting ExitTest Task: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); + UtPrintf("Starting ExitTest Task: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); /* ** The parent task will check to see if this task is valid. @@ -489,8 +480,8 @@ void UT_os_task_exit_test(void) { OS_BinSemTake(g_task_sync_sem); - res = OS_TaskCreate(&g_task_ids[1], g_task_names[1], exit_test_task, g_task_stacks[1], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[1], g_task_names[1], exit_test_task, OSAL_STACKPTR_C(&g_task_stacks[1]), + sizeof(g_task_stacks[1]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#1 Nominal - Task-Create failed"; @@ -579,8 +570,8 @@ void UT_os_task_set_priority_test() /*-----------------------------------------------------*/ testDesc = "API not implemented"; - res = OS_TaskCreate(&g_task_ids[0], g_task_names[0], generic_test_task, g_task_stacks[0], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[0], g_task_names[0], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[0]), + sizeof(g_task_stacks[0]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#0 API not implemented - Task-Create failed"; @@ -589,7 +580,7 @@ void UT_os_task_set_priority_test() } else { - res = OS_TaskSetPriority(g_task_ids[0], UT_TASK_PRIORITY); + res = OS_TaskSetPriority(g_task_ids[0], OSAL_PRIORITY_C(UT_TASK_PRIORITY)); if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); @@ -606,7 +597,7 @@ void UT_os_task_set_priority_test() /*-----------------------------------------------------*/ testDesc = "#1 Invalid-ID-arg"; - res = OS_TaskSetPriority(UT_OBJID_INCORRECT, 100); + res = OS_TaskSetPriority(UT_OBJID_INCORRECT, OSAL_PRIORITY_C(100)); if (res == OS_ERR_INVALID_ID) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -615,8 +606,8 @@ void UT_os_task_set_priority_test() /*-----------------------------------------------------*/ testDesc = "#2 Invalid-priority"; - res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], generic_test_task, g_task_stacks[2], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), + sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#2 Invalid-priority - Task-Create failed"; @@ -624,12 +615,6 @@ void UT_os_task_set_priority_test() } else { - res = OS_TaskSetPriority(g_task_ids[2], MAX_PRIORITY + 1); - if (res == OS_ERR_INVALID_PRIORITY) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - /* Delay to let child task run */ OS_TaskDelay(500); @@ -645,8 +630,8 @@ void UT_os_task_set_priority_test() /*-----------------------------------------------------*/ testDesc = "#4 Nominal"; - res = OS_TaskCreate(&g_task_ids[4], g_task_names[4], generic_test_task, g_task_stacks[4], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[4], g_task_names[4], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[4]), + sizeof(g_task_stacks[4]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#4 Nominal - Task-Create failed"; @@ -654,7 +639,7 @@ void UT_os_task_set_priority_test() } else { - res = OS_TaskSetPriority(g_task_ids[4], UT_TASK_PRIORITY - 10); + res = OS_TaskSetPriority(g_task_ids[4], OSAL_PRIORITY_C(UT_TASK_PRIORITY - 10)); if (res == OS_SUCCESS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -664,7 +649,7 @@ void UT_os_task_set_priority_test() OS_TaskDelay(500); /* Reset test environment */ - OS_TaskSetPriority(g_task_ids[4], UT_TASK_PRIORITY); + OS_TaskSetPriority(g_task_ids[4], OSAL_PRIORITY_C(UT_TASK_PRIORITY)); OS_TaskDelete(g_task_ids[4]); } @@ -690,7 +675,7 @@ void register_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("Starting RegisterTest Task: %s\n", task_prop.name); + UtPrintf("Starting RegisterTest Task: %s\n", task_prop.name); ; /* @@ -750,8 +735,8 @@ void UT_os_task_register_test(void) { OS_BinSemTake(g_task_sync_sem); - res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], register_test_task, g_task_stacks[3], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], register_test_task, OSAL_STACKPTR_C(&g_task_stacks[3]), + sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#3 Nominal - Task-Create failed"; @@ -790,7 +775,7 @@ void getid_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("OS_TaskGetId() - #1 Nominal [This is the returned task Id=%lx]\n", OS_ObjectIdToInteger(task_id)); + UtPrintf("OS_TaskGetId() - #1 Nominal [This is the returned task Id=%lx]\n", OS_ObjectIdToInteger(task_id)); while (1) { @@ -818,8 +803,8 @@ void UT_os_task_get_id_test() testDesc = "#1 Nominal"; /* Setup */ - res = OS_TaskCreate(&g_task_ids[1], g_task_names[1], getid_test_task, g_task_stacks[1], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[1], g_task_names[1], getid_test_task, OSAL_STACKPTR_C(&g_task_stacks[1]), + sizeof(g_task_stacks[1]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#1 Nominal - Task-Create failed"; @@ -829,8 +814,8 @@ void UT_os_task_get_id_test() { OS_TaskDelay(500); - UT_OS_LOG("OS_TaskGetId() - #1 Nominal [This is the expected task Id=%lx]\n", - OS_ObjectIdToInteger(g_task_ids[1])); + UtPrintf("OS_TaskGetId() - #1 Nominal [This is the expected task Id=%lx]\n", + OS_ObjectIdToInteger(g_task_ids[1])); res = OS_TaskDelete(g_task_ids[1]); /* Won't hurt if its already deleted */ @@ -902,8 +887,8 @@ void UT_os_task_get_id_by_name_test() testDesc = "#5 Nominal"; /* Setup */ - res = OS_TaskCreate(&g_task_ids[5], g_task_names[5], generic_test_task, g_task_stacks[5], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[5], g_task_names[5], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[5]), + sizeof(g_task_stacks[5]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#5 Nominal - Task-Create failed"; @@ -962,8 +947,8 @@ void UT_os_task_get_info_test() testDesc = "#2 Invalid-pointer-arg"; /* Setup */ - res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], generic_test_task, g_task_stacks[2], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), + sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#2 Invalid-pointer-arg - Task-Create failed"; @@ -988,8 +973,8 @@ void UT_os_task_get_info_test() testDesc = "#3 Nominal"; /* Setup */ - res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, g_task_stacks[3], UT_TASK_STACK_SIZE, - UT_TASK_PRIORITY, 0); + res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[3]), + sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); if (res != OS_SUCCESS) { testDesc = "#3 Nominal - Task-Create failed"; diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.h b/src/unit-tests/oscore-test/ut_oscore_task_test.h index 2a1a55df3..60b35ad5b 100644 --- a/src/unit-tests/oscore-test/ut_oscore_task_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSCORE_TASK_TEST_H_ -#define _UT_OSCORE_TASK_TEST_H_ +#ifndef UT_OSCORE_TASK_TEST_H +#define UT_OSCORE_TASK_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -69,7 +69,7 @@ void UT_os_task_get_id_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSCORE_TASK_TEST_H_ */ +#endif /* UT_OSCORE_TASK_TEST_H */ /*================================================================================* ** End of File: ut_oscore_task_test.h diff --git a/src/unit-tests/oscore-test/ut_oscore_test.h b/src/unit-tests/oscore-test/ut_oscore_test.h index 1be4ae0f9..2c412a6a0 100644 --- a/src/unit-tests/oscore-test/ut_oscore_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_test.h @@ -24,8 +24,8 @@ ** Date: May 2013 **================================================================================*/ -#ifndef _UT_OSCORE_TEST_H_ -#define _UT_OSCORE_TEST_H_ +#ifndef UT_OSCORE_TEST_H +#define UT_OSCORE_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -62,7 +62,7 @@ /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSCORE_TEST_H_ */ +#endif /* UT_OSCORE_TEST_H */ /*================================================================================* ** End of File: ut_oscore_test_posix.h diff --git a/src/unit-tests/osfile-test/ut_osfile_dirio_test.c b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c index 974b808bc..40540e824 100644 --- a/src/unit-tests/osfile-test/ut_osfile_dirio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c @@ -439,7 +439,7 @@ void UT_os_closedir_test() **--------------------------------------------------------------------------------*/ void UT_os_readdir_test() { - osal_id_t dirh; + osal_id_t dirh = OS_OBJECT_ID_UNDEFINED; const char *testDesc; strcpy(g_subdirNames[0], " "); @@ -566,7 +566,7 @@ void UT_os_readdir_test() **--------------------------------------------------------------------------------*/ void UT_os_rewinddir_test() { - osal_id_t dirh; + osal_id_t dirh = OS_OBJECT_ID_UNDEFINED; const char *testDesc; strcpy(g_subdirNames[0], " "); diff --git a/src/unit-tests/osfile-test/ut_osfile_dirio_test.h b/src/unit-tests/osfile-test/ut_osfile_dirio_test.h index e118631c8..04ff11525 100644 --- a/src/unit-tests/osfile-test/ut_osfile_dirio_test.h +++ b/src/unit-tests/osfile-test/ut_osfile_dirio_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSFILE_DIRIO_H_ -#define _UT_OSFILE_DIRIO_H_ +#ifndef UT_OSFILE_DIRIO_H +#define UT_OSFILE_DIRIO_H /*--------------------------------------------------------------------------------* ** Includes @@ -64,7 +64,7 @@ void UT_os_removedir_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSFILE_DIRIO_H_ */ +#endif /* UT_OSFILE_DIRIO_H */ /*================================================================================* ** End of File: ut_osfile_dirio.h diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c index 6ab152a27..df94fe0e2 100644 --- a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c @@ -116,7 +116,7 @@ void UT_os_initfs_test() /*-----------------------------------------------------*/ testDesc = "#2 Nominal"; - /* Call to OS_FS_Init() is inside OS_API_Init(); */ + /* Call to OS_FS_Init is inside OS_API_Init */ res = OS_API_Init(); if (res == OS_ERR_NOT_IMPLEMENTED) { @@ -804,9 +804,9 @@ void UT_os_readfile_test() OS_close(g_fDescs[0]); OS_remove(g_fNames[0]); - UT_OS_LOG("OS_read() success test -- Write to file:\n\t%s\n", g_writeBuff); + UtPrintf("OS_read() success test -- Write to file:\n\t%s\n", g_writeBuff); ; - UT_OS_LOG("OS_read() success test -- Read from file:\n\t%s\n", g_readBuff); + UtPrintf("OS_read() success test -- Read from file:\n\t%s\n", g_readBuff); ; UT_os_readfile_test_exit_tag: @@ -975,9 +975,9 @@ void UT_os_writefile_test() OS_close(g_fDescs[0]); OS_remove(g_fNames[0]); - UT_OS_LOG("OS_write() success test -- Write to file:\n\t%s\n", g_writeBuff); + UtPrintf("OS_write() success test -- Write to file:\n\t%s\n", g_writeBuff); ; - UT_OS_LOG("OS_write() success test -- Read from file:\n\t%s\n", g_readBuff); + UtPrintf("OS_write() success test -- Read from file:\n\t%s\n", g_readBuff); ; UT_os_writefile_test_exit_tag: @@ -1037,7 +1037,8 @@ void UT_os_writefile_test() void UT_os_lseekfile_test() { const char *testDesc; - int32 buffLen = 0, pos1 = 0, pos2 = 0, pos3 = 0; + size_t buffLen; + int32 pos1 = 0, pos2 = 0, pos3 = 0; /*-----------------------------------------------------*/ testDesc = "API not implemented"; @@ -1101,7 +1102,7 @@ void UT_os_lseekfile_test() memset(g_writeBuff, '\0', sizeof(g_writeBuff)); strcpy(g_writeBuff, "THE BROWN FOX JUMPS OVER THE LAZY DOG."); - buffLen = (int32)strlen(g_writeBuff); + buffLen = strlen(g_writeBuff); if (OS_write(g_fDescs[0], g_writeBuff, buffLen) != buffLen) { @@ -2056,11 +2057,12 @@ void UT_os_outputtofile_test() } } +UT_os_outputtofile_test_exit_tag: + /* Reset test environment */ OS_close(g_fDescs[0]); OS_remove(g_fNames[0]); -UT_os_outputtofile_test_exit_tag: return; } diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.h b/src/unit-tests/osfile-test/ut_osfile_fileio_test.h index 9db8da7f1..6f149a3ca 100644 --- a/src/unit-tests/osfile-test/ut_osfile_fileio_test.h +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSFILE_FILEIO_H_ -#define _UT_OSFILE_FILEIO_H_ +#ifndef UT_OSFILE_FILEIO_H +#define UT_OSFILE_FILEIO_H /*--------------------------------------------------------------------------------* ** Includes @@ -80,7 +80,7 @@ void UT_os_closefilebyname_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSFILE_FILEIO_H_ */ +#endif /* UT_OSFILE_FILEIO_H */ /*================================================================================* ** End of File: ut_osfile_fileio.h diff --git a/src/unit-tests/osfile-test/ut_osfile_test.c b/src/unit-tests/osfile-test/ut_osfile_test.c index a2c84d821..925fdb612 100644 --- a/src/unit-tests/osfile-test/ut_osfile_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_test.c @@ -76,10 +76,10 @@ int32 UT_os_setup_fs() { int32 res; - res = OS_mkfs(g_fsAddrPtr, g_devName, "RAM3", 512, 64); + res = OS_mkfs(g_fsAddrPtr, g_devName, "RAM3", OSAL_SIZE_C(512), OSAL_BLOCKCOUNT_C(64)); if (res != OS_SUCCESS) { - UT_OS_LOG("OS_mkfs() returns %d\n", (int)res); + UtPrintf("OS_mkfs() returns %d\n", (int)res); ; goto UT_os_setup_fs_exit_tag; } @@ -87,7 +87,7 @@ int32 UT_os_setup_fs() res = OS_mount(g_devName, g_mntName); if (res != OS_SUCCESS) { - UT_OS_LOG("OS_mount() returns %d\n", (int)res); + UtPrintf("OS_mount() returns %d\n", (int)res); ; OS_rmfs(g_devName); goto UT_os_setup_fs_exit_tag; diff --git a/src/unit-tests/osfile-test/ut_osfile_test.h b/src/unit-tests/osfile-test/ut_osfile_test.h index a5d2497e3..53459e6e4 100644 --- a/src/unit-tests/osfile-test/ut_osfile_test.h +++ b/src/unit-tests/osfile-test/ut_osfile_test.h @@ -24,8 +24,8 @@ ** Date: May 2013 **================================================================================*/ -#ifndef _UT_OSFILE_TEST_H_ -#define _UT_OSFILE_TEST_H_ +#ifndef UT_OSFILE_TEST_H +#define UT_OSFILE_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -57,7 +57,7 @@ /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSFILE_TEST_H_ */ +#endif /* UT_OSFILE_TEST_H */ /*================================================================================* ** End of File: ut_osfile_test.h diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c index 1002252fd..dd28ae4ee 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c @@ -44,8 +44,8 @@ extern char *g_fsAddrPtr; -extern int32 g_blkSize; -extern int32 g_blkCnt; +extern size_t g_blkSize; +extern osal_blockcount_t g_blkCnt; extern char g_fsLongName[UT_OS_PATH_BUFF_SIZE]; extern char g_physDriveName[UT_OS_PHYS_NAME_BUFF_SIZE]; @@ -141,8 +141,8 @@ void UT_os_initfs_test() /*-----------------------------------------------------*/ testDesc = "#1 Null-pointer-arg"; - if ((OS_initfs(g_fsAddrPtr, NULL, g_volNames[1], 0, 0) == OS_INVALID_POINTER) && - (OS_initfs(g_fsAddrPtr, g_devNames[1], NULL, 0, 0) == OS_INVALID_POINTER)) + if ((OS_initfs(g_fsAddrPtr, NULL, g_volNames[1], OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)) == OS_INVALID_POINTER) && + (OS_initfs(g_fsAddrPtr, g_devNames[1], NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)) == OS_INVALID_POINTER)) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); @@ -274,8 +274,8 @@ void UT_os_makefs_test() /*-----------------------------------------------------*/ testDesc = "#1 Null-pointer-arg"; - if ((OS_mkfs(g_fsAddrPtr, NULL, g_volNames[1], 0, 0) == OS_INVALID_POINTER) && - (OS_mkfs(g_fsAddrPtr, g_devNames[1], NULL, 0, 0) == OS_INVALID_POINTER)) + if ((OS_mkfs(g_fsAddrPtr, NULL, g_volNames[1], OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)) == OS_INVALID_POINTER) && + (OS_mkfs(g_fsAddrPtr, g_devNames[1], NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)) == OS_INVALID_POINTER)) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); @@ -1054,7 +1054,7 @@ void UT_os_checkfs_test() } /*--------------------------------------------------------------------------------* -** Syntax: int32 OS_fsBlocksFree(const char *name) +** Syntax: int32 OS_fsstatvolume(const char *name) ** Purpose: Returns the number of blocks free in a the file system ** Parameters: *name - a pointer to the name of the drive to check for free blocks ** Returns: OS_INVALID_POINTER if the pointer passed in is NULL @@ -1097,133 +1097,32 @@ void UT_os_checkfs_test() ** 7) Expect the returned value to be ** (a) greater than or equal to 0 ** --------------------------------------------------------------------------------*/ -void UT_os_fsblocksfree_test() +void UT_os_fsstatvolume_test(void) { - const char *testDesc; + const char * testDesc; + OS_statvfs_t statbuf; /*-----------------------------------------------------*/ testDesc = "API not implemented"; - if (OS_fsBlocksFree(NULL) == OS_ERR_NOT_IMPLEMENTED) + if (OS_FileSysStatVolume("/cf", &statbuf) == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_fsblocksfree_test_exit_tag; + goto UT_os_fsstatvolume_test_exit_tag; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if (OS_fsBlocksFree(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + testDesc = "#1a Null-pointer-arg"; - if (OS_fsBlocksFree(g_fsLongName) == OS_FS_ERR_PATH_TOO_LONG) + if (OS_FileSysStatVolume(NULL, &statbuf) == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; - - if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsblocksfree_test_exit_tag; - } - - if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-mount failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsblocksfree_test_exit_tag; - } - - if (OS_fsBlocksFree(g_mntNames[4]) >= 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_unmount(g_mntNames[4]); - OS_rmfs(g_devNames[4]); - -UT_os_fsblocksfree_test_exit_tag: - return; -} - -/*--------------------------------------------------------------------------------* -** Syntax: int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) -** Purpose: Returns the number of bytes free in a the file system -** Parameters: *name - a pointer to the name of the drive to check for free bytes -** *bytes_free - a pointer that will hold the number of bytes free -** Returns: OS_INVALID_POINTER if the pointer passed in is NULL -** OS_ERROR if the OS call failed -** OS_SUCCESS if succeeded -** OS_ERR_NOT_IMPLEMENTED if not implemented -** ----------------------------------------------------- -** Test #0: Not-implemented condition -** 1) Call this routine -** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test -** 3) Otherwise, continue. -** ----------------------------------------------------- -** Test #1: Null-pointer-arg condition -** 1) Call this routine with a null pointer as one of the arguments -** 2) Expect the returned value to be -** (a) OS_INVALID_POINTER -** ----------------------------------------------------- -** Test #2: Path-too-long-arg condition -** 1) Call this routine with a path name of length greater than Volume table's -** name as argument -** 2) Expect the returned value to be -** (a) OS_FS_ERR_PATH_TOO_LONG -** ----------------------------------------------------- -** Test #3: OS-call-failure condition -** 1) Setup the test to cause the OS call to fail inside this routine -** 2) Call this routine -** 3) Expect the returned value to be -** (a) OS_ERROR -** ----------------------------------------------------- -** Test#4: Nominal condition -** 1) Make sure no file system has been previously created -** 2) Call OS_mkfs -** 3) Expect the returned value to be -** (a) OS_SUCCESS -** 4) Call OS_mount with device name used in #2 -** 5) Expect the returned value to be -** (a) OS_SUCCESS -** 6) Call this routine with mount-point used in #4 -** 7) Expect the returned value to be -** (a) greater than or equal to 0 -** --------------------------------------------------------------------------------*/ -void UT_os_fsbytesfree_test() -{ - uint64 retBytes = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_fsBytesFree(NULL, NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_fsbytesfree_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + testDesc = "#1b Null-pointer-arg"; - if ((OS_fsBytesFree(NULL, &retBytes) == OS_INVALID_POINTER) && - (OS_fsBytesFree(g_mntNames[1], NULL) == OS_INVALID_POINTER)) + if (OS_FileSysStatVolume("/cf", NULL) == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); @@ -1231,7 +1130,7 @@ void UT_os_fsbytesfree_test() /*-----------------------------------------------------*/ testDesc = "#2 Path-too-long-arg"; - if (OS_fsBytesFree(g_fsLongName, &retBytes) == OS_FS_ERR_PATH_TOO_LONG) + if (OS_FileSysStatVolume(g_fsLongName, &statbuf) == OS_FS_ERR_PATH_TOO_LONG) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); @@ -1248,17 +1147,17 @@ void UT_os_fsbytesfree_test() { testDesc = "#4 Nominal - File-system-create failed"; UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsbytesfree_test_exit_tag; + goto UT_os_fsstatvolume_test_exit_tag; } if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS) { testDesc = "#4 Nominal - File-system-mount failed"; UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsbytesfree_test_exit_tag; + goto UT_os_fsstatvolume_test_exit_tag; } - if (OS_fsBytesFree(g_mntNames[4], &retBytes) == OS_SUCCESS) + if (OS_FileSysStatVolume(g_mntNames[4], &statbuf) >= 0) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); @@ -1267,7 +1166,7 @@ void UT_os_fsbytesfree_test() OS_unmount(g_mntNames[4]); OS_rmfs(g_devNames[4]); -UT_os_fsbytesfree_test_exit_tag: +UT_os_fsstatvolume_test_exit_tag: return; } diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h index 65e4e4f37..b2573eb66 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSFILESYS_DISKIO_TEST_H_ -#define _UT_OSFILESYS_DISKIO_TEST_H_ +#ifndef UT_OSFILESYS_DISKIO_TEST_H +#define UT_OSFILESYS_DISKIO_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -69,12 +69,11 @@ void UT_os_translatepath_test(void); void UT_os_checkfs_test(void); -void UT_os_fsblocksfree_test(void); -void UT_os_fsbytesfree_test(void); +void UT_os_fsstatvolume_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSFILESYS_DISKIO_TEST_H_ */ +#endif /* UT_OSFILESYS_DISKIO_TEST_H */ /*================================================================================* ** End of File: ut_osfilesys_diskio_test.h diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c index 719da6629..5a8496d72 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c @@ -51,8 +51,8 @@ char *g_fsAddrPtr = NULL; -int32 g_blkSize = UT_OS_FS_BLOCK_SIZE; -int32 g_blkCnt = UT_OS_FS_MAX_BLOCKS; +size_t g_blkSize = {UT_OS_FS_BLOCK_SIZE}; +osal_blockcount_t g_blkCnt = {UT_OS_FS_MAX_BLOCKS}; char g_fsLongName[UT_OS_PATH_BUFF_SIZE]; char g_physDriveName[UT_OS_PHYS_NAME_BUFF_SIZE]; @@ -135,8 +135,7 @@ void UtTest_Setup(void) UtTest_Add(UT_os_translatepath_test, NULL, NULL, "OS_TranslatePath (internal)"); UtTest_Add(UT_os_checkfs_test, NULL, NULL, "OS_chkfs"); - UtTest_Add(UT_os_fsblocksfree_test, NULL, NULL, "OS_fsBlocksFree"); - UtTest_Add(UT_os_fsbytesfree_test, NULL, NULL, "OS_fsBytesFree"); + UtTest_Add(UT_os_fsstatvolume_test, NULL, NULL, "OS_FileSysStatVolume"); } /*================================================================================* diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test.h b/src/unit-tests/osfilesys-test/ut_osfilesys_test.h index 71e1074bb..7e78dbd91 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_test.h +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test.h @@ -24,8 +24,8 @@ ** Date: May 2013 **================================================================================*/ -#ifndef _UT_OSFILESYS_TEST_H_ -#define _UT_OSFILESYS_TEST_H_ +#ifndef UT_OSFILESYS_TEST_H +#define UT_OSFILESYS_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -56,7 +56,7 @@ /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSFILESYS_TEST_H_ */ +#endif /* UT_OSFILESYS_TEST_H */ /*================================================================================* ** End of File: ut_osfilesys_test.h diff --git a/src/unit-tests/osloader-test/CMakeLists.txt b/src/unit-tests/osloader-test/CMakeLists.txt index 72152120b..1c3159d9f 100644 --- a/src/unit-tests/osloader-test/CMakeLists.txt +++ b/src/unit-tests/osloader-test/CMakeLists.txt @@ -19,4 +19,7 @@ while(MOD GREATER 0) PREFIX "" LIBRARY_OUTPUT_DIRECTORY utmod) add_dependencies(osal_loader_UT MODULE${MOD}) + foreach(TGT ${INSTALL_TARGET_LIST}) + install(TARGETS MODULE${MOD} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR}/utmod) + endforeach() endwhile(MOD GREATER 0) diff --git a/src/unit-tests/osloader-test/ut_osloader_module_test.c b/src/unit-tests/osloader-test/ut_osloader_module_test.c index ba8d6ffcc..9c5489097 100644 --- a/src/unit-tests/osloader-test/ut_osloader_module_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_module_test.c @@ -79,7 +79,7 @@ void UT_os_module_load_test() /*-----------------------------------------------------*/ testDesc = "API Not implemented"; - res = OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1); + res = OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); @@ -89,7 +89,7 @@ void UT_os_module_load_test() /*-----------------------------------------------------*/ testDesc = "#1 Null-pointer-arg-1"; - res = OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1); + res = OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -98,7 +98,7 @@ void UT_os_module_load_test() /*-----------------------------------------------------*/ testDesc = "#2 Null-pointer-arg-2"; - res = OS_ModuleLoad(&module_id, 0, UT_OS_GENERIC_MODULE_NAME1); + res = OS_ModuleLoad(&module_id, 0, UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -107,7 +107,7 @@ void UT_os_module_load_test() /*-----------------------------------------------------*/ testDesc = "#3 Null-pointer-arg-3"; - res = OS_ModuleLoad(&module_id, "TestModule", 0); + res = OS_ModuleLoad(&module_id, "TestModule", 0, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -121,7 +121,7 @@ void UT_os_module_load_test() { snprintf(module_name, sizeof(module_name), UT_OS_GENERIC_MODULE_NAME_TEMPLATE, i); snprintf(module_file_name, sizeof(module_file_name), UT_OS_GENERIC_MODULE_FILE_TEMPLATE, i); - res = OS_ModuleLoad(&module_id, module_name, module_file_name); + res = OS_ModuleLoad(&module_id, module_name, module_file_name, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res != OS_SUCCESS) { testDesc = "#4 No-free-IDs - Module Load failed"; @@ -133,7 +133,7 @@ void UT_os_module_load_test() if (test_setup_invalid == 0) { - res = OS_ModuleLoad(&module_id, "OneTooMany", UT_OS_GENERIC_MODULE_NAME2); + res = OS_ModuleLoad(&module_id, "OneTooMany", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res == OS_ERR_NO_FREE_IDS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -146,7 +146,7 @@ void UT_os_module_load_test() testDesc = "#5 Duplicate-name"; /* Setup */ - res = OS_ModuleLoad(&module_id2, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2); + res = OS_ModuleLoad(&module_id2, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res != OS_SUCCESS) { testDesc = "#5 Duplicate-name - Module Load failed"; @@ -154,7 +154,7 @@ void UT_os_module_load_test() } else { - res = OS_ModuleLoad(&module_id, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2); + res = OS_ModuleLoad(&module_id, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res == OS_ERR_NAME_TAKEN) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -172,7 +172,7 @@ void UT_os_module_load_test() /*-----------------------------------------------------*/ testDesc = "#7 Nominal"; - res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2); + res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res == OS_SUCCESS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else @@ -227,7 +227,7 @@ void UT_os_module_unload_test() testDesc = "#3 Nominal"; /* Setup */ - res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2); + res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res != OS_SUCCESS) { testDesc = "#3 Nominal - Module Load failed"; @@ -293,7 +293,7 @@ void UT_os_module_info_test() testDesc = "#3 Nominal"; /* Setup */ - res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2); + res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); if (res != OS_SUCCESS) { testDesc = "#3 Nominal - Module Load failed"; diff --git a/src/unit-tests/osloader-test/ut_osloader_module_test.h b/src/unit-tests/osloader-test/ut_osloader_module_test.h index c27ee25b1..70057ea10 100644 --- a/src/unit-tests/osloader-test/ut_osloader_module_test.h +++ b/src/unit-tests/osloader-test/ut_osloader_module_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSLOADER_MODULE_TEST_H_ -#define _UT_OSLOADER_MODULE_TEST_H_ +#ifndef UT_OSLOADER_MODULE_TEST_H +#define UT_OSLOADER_MODULE_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -59,7 +59,7 @@ void UT_os_module_info_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSLOADER_MODULE_TEST_H_ */ +#endif /* UT_OSLOADER_MODULE_TEST_H */ /*================================================================================* ** End of File: ut_osloader_module_test.h diff --git a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c index aa951f616..b81ddb1ec 100644 --- a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c @@ -109,10 +109,10 @@ void UT_os_symbol_lookup_test() UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + testDesc = "#4 Nominal, Global Symbols"; /* Setup */ - res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2); + res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_GLOBAL_SYMBOLS); if (res != OS_SUCCESS) { UT_OS_TEST_RESULT("#4 Nominal - Module Load failed", UTASSERT_CASETYPE_TSF); @@ -122,6 +122,8 @@ void UT_os_symbol_lookup_test() res = OS_SymbolLookup(&symbol_addr, "module1"); if (res == OS_SUCCESS) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + else if (res == OS_ERR_NOT_IMPLEMENTED) + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); @@ -133,6 +135,84 @@ void UT_os_symbol_lookup_test() return; } +/*--------------------------------------------------------------------------------* +** Syntax: OS_ModuleSymbolLookup +** Purpose: Returns the memory address of a symbol +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERROR if the symbol name is not found +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ + +void UT_os_module_symbol_lookup_test() +{ + int32 res = 0; + const char *testDesc; + cpuaddr symbol_addr; + osal_id_t module_id; + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, "main"); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); + goto UT_os_module_symbol_lookup_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-pointer-arg-1"; + + res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, 0, "main"); + if (res == OS_INVALID_POINTER) + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + else + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg-2"; + + res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, 0); + if (res == OS_INVALID_POINTER) + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + else + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + + /*-----------------------------------------------------*/ + /* Setup for remainder of tests */ + res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); + if (res != OS_SUCCESS) + { + UT_OS_TEST_RESULT("Module Load failed", UTASSERT_CASETYPE_TSF); + goto UT_os_module_symbol_lookup_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#3 Symbol-not-found"; + + res = OS_ModuleSymbolLookup(module_id, &symbol_addr, "ThisSymbolIsNotFound"); + if (res == OS_ERROR) + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + else + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal, Local Symbols"; + + res = OS_ModuleSymbolLookup(module_id, &symbol_addr, "module1"); + if (res == OS_SUCCESS) + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + else + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + + /* Reset test environment */ + res = OS_ModuleUnload(module_id); + +UT_os_module_symbol_lookup_test_exit_tag: + return; +} + /*--------------------------------------------------------------------------------* ** Syntax: OS_SymbolTableDump ** Purpose: Dumps the system symbol table to the given filename diff --git a/src/unit-tests/osloader-test/ut_osloader_symtable_test.h b/src/unit-tests/osloader-test/ut_osloader_symtable_test.h index eae16753a..5e572362a 100644 --- a/src/unit-tests/osloader-test/ut_osloader_symtable_test.h +++ b/src/unit-tests/osloader-test/ut_osloader_symtable_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSLOADER_SYMTABLE_TEST_H_ -#define _UT_OSLOADER_SYMTABLE_TEST_H_ +#ifndef UT_OSLOADER_SYMTABLE_TEST_H +#define UT_OSLOADER_SYMTABLE_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -54,11 +54,12 @@ **--------------------------------------------------------------------------------*/ void UT_os_symbol_lookup_test(void); +void UT_os_module_symbol_lookup_test(void); void UT_os_symbol_table_dump_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSLOADER_SYMTABLE_TEST_H_ */ +#endif /* UT_OSLOADER_SYMTABLE_TEST_H */ /*================================================================================* ** End of File: ut_osloader_symtable_test.h diff --git a/src/unit-tests/osloader-test/ut_osloader_test.c b/src/unit-tests/osloader-test/ut_osloader_test.c index f3821e748..7dc7d9c6c 100644 --- a/src/unit-tests/osloader-test/ut_osloader_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_test.c @@ -82,6 +82,7 @@ void UtTest_Setup(void) UtTest_Add(UT_os_module_unload_test, NULL, NULL, "OS_ModuleUnload"); UtTest_Add(UT_os_module_info_test, NULL, NULL, "OS_ModuleInfo"); + UtTest_Add(UT_os_module_symbol_lookup_test, NULL, NULL, "OS_ModuleSymbolLookup"); UtTest_Add(UT_os_symbol_lookup_test, NULL, NULL, "OS_SymbolLookup"); UtTest_Add(UT_os_symbol_table_dump_test, NULL, NULL, "OS_SymbolTableDump"); } diff --git a/src/unit-tests/osloader-test/ut_osloader_test.h b/src/unit-tests/osloader-test/ut_osloader_test.h index 07cca7b47..61c0175d6 100644 --- a/src/unit-tests/osloader-test/ut_osloader_test.h +++ b/src/unit-tests/osloader-test/ut_osloader_test.h @@ -24,8 +24,8 @@ ** Date: May 2013 **================================================================================*/ -#ifndef _UT_OSLOADER_TEST_H_ -#define _UT_OSLOADER_TEST_H_ +#ifndef UT_OSLOADER_TEST_H +#define UT_OSLOADER_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -57,7 +57,7 @@ /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSLOADER_TEST_H_ */ +#endif /* UT_OSLOADER_TEST_H */ /*================================================================================* ** End of File: ut_osloader_test.h diff --git a/src/unit-tests/osloader-test/ut_osloader_test_platforms.h b/src/unit-tests/osloader-test/ut_osloader_test_platforms.h index f15858a3b..0e62c9206 100644 --- a/src/unit-tests/osloader-test/ut_osloader_test_platforms.h +++ b/src/unit-tests/osloader-test/ut_osloader_test_platforms.h @@ -24,8 +24,8 @@ ** Date: November 2014 **================================================================================*/ -#ifndef _UT_OSLOADER_TEST_PLATFORMS_H_ -#define _UT_OSLOADER_TEST_PLATFORMS_H_ +#ifndef UT_OSLOADER_TEST_PLATFORMS_H +#define UT_OSLOADER_TEST_PLATFORMS_H /*--------------------------------------------------------------------------------* ** Includes @@ -63,7 +63,7 @@ /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSLOADER_TEST_PLATFORMS_H_ */ +#endif /* UT_OSLOADER_TEST_PLATFORMS_H */ /*================================================================================* ** End of File: ut_osloader_test_platforms.h diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c index c58b98780..1ce269883 100644 --- a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c @@ -105,7 +105,7 @@ void UT_os_networkgetid_test() /* NOTE: This API does not return error codes. * Any return value could be valid */ - UT_OS_LOG("OS_NetworkGetID() return value=%ld", (long)res); + UtPrintf("OS_NetworkGetID() return value=%ld", (long)res); UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_MIR); UT_os_networkgetid_test_exit_tag: @@ -177,7 +177,7 @@ void UT_os_networkgethostname_test() testDesc = "#2 Zero-name-length-arg"; res = OS_NetworkGetHostName(buffer, 0); - if (res == OS_ERROR) + if (res == OS_ERR_INVALID_SIZE) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.h b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.h index 1ecca7390..038aff40f 100644 --- a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.h +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSNETWORK_MISC_TEST_H_ -#define _UT_OSNETWORK_MISC_TEST_H_ +#ifndef UT_OSNETWORK_MISC_TEST_H +#define UT_OSNETWORK_MISC_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -58,7 +58,7 @@ void UT_os_networkgethostname_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSNETWORK_MISC_TEST_H_ */ +#endif /* UT_OSNETWORK_MISC_TEST_H */ /*================================================================================* ** End of File: ut_osnetwork_misc_test.h diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_test.h b/src/unit-tests/osnetwork-test/ut_osnetwork_test.h index 447e9a9a3..90a29fc72 100644 --- a/src/unit-tests/osnetwork-test/ut_osnetwork_test.h +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_test.h @@ -24,8 +24,8 @@ ** Date: May 2013 **================================================================================*/ -#ifndef _UT_OSNETWORK_TEST_H_ -#define _UT_OSNETWORK_TEST_H_ +#ifndef UT_OSNETWORK_TEST_H +#define UT_OSNETWORK_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -56,7 +56,7 @@ /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSNETWORK_TEST_H_ */ +#endif /* UT_OSNETWORK_TEST_H */ /*================================================================================* ** End of File: ut_osnetwork_test.h diff --git a/src/unit-tests/osprintf-test/CMakeLists.txt b/src/unit-tests/osprintf-test/CMakeLists.txt deleted file mode 100644 index 86abb7f0f..000000000 --- a/src/unit-tests/osprintf-test/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# CMake snippet for OSAL printf test - -set(TEST_MODULE_FILES - ut_osprintf.c - ut_osprintf_c.c - ut_osprintf_d.c - ut_osprintf_f.c - ut_osprintf_i.c - ut_osprintf_ld.c - ut_osprintf_lf.c - ut_osprintf_li.c - ut_osprintf_lu.c - ut_osprintf_lx.c - ut_osprintf_lx_uc.c - ut_osprintf_misc.c - ut_osprintf_offset.c - ut_osprintf_offset_dummy.c - ut_osprintf_p.c - ut_osprintf_printf.c - ut_osprintf_s.c - ut_osprintf_u.c - ut_osprintf_x.c - ut_osprintf_x_uc.c -) - -add_stubs(TEST_STUBS os) -add_osal_ut_exe(osal_osprintf_UT ${TEST_MODULE_FILES} ${TEST_STUBS}) - diff --git a/src/unit-tests/osprintf-test/ut_osprintf.c b/src/unit-tests/osprintf-test/ut_osprintf.c deleted file mode 100644 index f6da52c2b..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * ut_osprintf.c - * - * Created on: May 20, 2013 - * Author: Kevin McCluney - */ - -/* -** Includes -*/ -#include "ut_osprintf.h" -#ifdef UT_DO_OFFSET -#include "ut_osprintf_offset.h" -#endif - -#ifndef OSP_ARINC653 -#include - -FILE *UT_logfile; -#endif - -/* -** Global variables -*/ -unsigned OS_printf_enabled = 1; -int ut_passed; -int ut_failed; -char cMsg[UT_MAX_MESSAGE_LENGTH]; -char cNum[UT_MAX_MESSAGE_LENGTH]; -char strg_buf[BUF_LEN]; -char trunc_buf[BUF_LEN]; -char fill_strg[BUF_LEN]; - -/* -** Functions -*/ -#ifdef OSP_ARINC653 -int os_printf_main() -#else -int main() -#endif -{ - int i; - -#ifndef OSP_ARINC653 - UT_logfile = fopen("ut_osal_osprintf_log.txt", "w"); -#endif - -#ifdef OS_USE_EMBEDDED_PRINTF - UT_Text("Using replacement printf functions\n\n"); -#else - UT_Text("Using standard printf functions\n\n"); -#endif - - for (i = 0; i < BUF_LEN; i++) - { - fill_strg[i] = '*'; - } - - ut_passed = 0; - ut_failed = 0; - - /* Test sprintf and snprintf for each format */ - UT_osprintf_d(); - UT_osprintf_i(); - UT_osprintf_u(); - UT_osprintf_x(); - UT_osprintf_X(); - UT_osprintf_p(); - UT_osprintf_c(); - UT_osprintf_s(); - UT_osprintf_ld(); - UT_osprintf_li(); - UT_osprintf_lu(); - UT_osprintf_lx(); - UT_osprintf_lX(); - -#ifndef UT_NO_FLOAT - UT_osprintf_f(); - UT_osprintf_lf(); - UT_osprintf_misc(); -#endif - -#ifdef OS_USE_EMBEDDED_PRINTF - UT_osprintf_printf(); -#endif - - UT_ReportFailures(); - -#ifdef UT_DO_OFFSET - /* Calculate argument offsets for cFE variadic functions */ - UT_osprintf_CalcOffsets(); -#endif - -#ifndef OSP_ARINC653 - /* Ensure everything gets written */ - fflush(stdout); - fclose(UT_logfile); -#endif - - return 0; -} - -/* -** Initialize string buffer to all asterisks -*/ -void init_test(void) -{ - memcpy(strg_buf, fill_strg, BUF_LEN); -} - -/* -** Compare expected string output to actual string output; return -** pass/fail result -*/ -int check_test(char *expected, char *actual) -{ - int result = UT_PASS; - - if (memcmp(expected, actual, strlen(expected) + 1)) - { - strcpy(cMsg, " Mismatch: exp = ["); - strcat(cMsg, expected); - strcat(cMsg, "], act = ["); - strcat(cMsg, actual); - strcat(cMsg, "]\n"); - UT_Text(cMsg); - result = UT_FAIL; - } - - return result; -} - -/* -** Output text -*/ -void UT_Text(char *out_text) -{ -#ifdef OSP_ARINC653 - TUTF_print(out_text); - TUTF_print("\n"); -#else - fprintf(UT_logfile, "%s", out_text); - fflush(UT_logfile); -#endif -} - -/* -** Output result of a test -*/ -void UT_Report(int test, char *fun_name, char *info, char *test_num, char *test_seq) -{ - if (test == UT_PASS) - { -#ifdef UT_SHOW_PASS - strcpy(cMsg, "PASSED ["); - strcat(cMsg, fun_name); - strcat(cMsg, "."); - strcat(cMsg, test_num); - strcat(cMsg, "."); - strcat(cMsg, test_seq); - strcat(cMsg, "] "); - strcat(cMsg, info); - strcat(cMsg, "\n-----\n"); - UT_Text(cMsg); -#endif - ut_passed++; - } - else - { - strcpy(cMsg, "FAILED ["); - strcat(cMsg, fun_name); - strcat(cMsg, "."); - strcat(cMsg, test_num); - strcat(cMsg, "."); - strcat(cMsg, test_seq); - strcat(cMsg, "] "); - strcat(cMsg, info); - strcat(cMsg, "\n-----\n"); - UT_Text(cMsg); - ut_failed++; - } -} - -/* -** Convert an integer to its character representation -*/ -void UT_itoa(int value, char *string, int radix, int out_len) -{ - char revertedStr[50]; - int revertedLength = 0; - unsigned int length = 0; - unsigned int neg = 0; - unsigned int digit_value = 0; - unsigned int uvalue; - - if ((radix == 10) && (value < 0)) - { - neg = 1; - uvalue = -value; - } - else - { - uvalue = (unsigned int)value; - } - - revertedLength = 0; - - while (uvalue >= radix) - { - digit_value = uvalue % radix; - - if (digit_value >= 10) - { - revertedStr[revertedLength] = digit_value - 10 + 'a'; - } - else - { - revertedStr[revertedLength] = digit_value + '0'; - } - - uvalue /= radix; - revertedLength++; - } - - if (uvalue >= 10) - { - revertedStr[revertedLength] = uvalue - 10 + 'a'; - } - else - { - revertedStr[revertedLength] = uvalue + '0'; - } - - if (neg == 1) - { - string[length] = '-'; - length++; - } - - if (revertedLength < out_len - 1) - { - while (revertedLength < out_len - 1) - { - revertedLength++; - revertedStr[revertedLength] = '0'; - } - } - - while (revertedLength >= 0) - { - string[length] = revertedStr[revertedLength]; - revertedLength--; - length++; - } - - string[length] = '\0'; -} - -/* -** Output summary of test results (# of passed & failed tests) -*/ -void UT_ReportFailures(void) -{ - char cNum[10]; - - strcpy(cMsg, "\nosprintf PASSED "); - UT_itoa(ut_passed, cNum, 10, 0); - strcat(cMsg, cNum); - strcat(cMsg, " tests.\n"); - strcat(cMsg, "osprintf FAILED "); - UT_itoa(ut_failed, cNum, 10, 0); - strcat(cMsg, cNum); - strcat(cMsg, " tests.\n"); - UT_Text(cMsg); - -#ifndef OSP_ARINC653 - printf("\nosprintf PASSED %d tests.\nosprintf FAILED %d tests.\n\n", ut_passed, ut_failed); -#endif -} - -#ifdef OSP_ARINC653 -/* -** Stub function for OS_MutSemCreate() -*/ -int32 OS_MutSemCreate(uint32 *mutex_id, const char *mutex_name, uint32 options) -{ - return 0; -} - -/* -** Stub function for OS_MutSemGive() -*/ -int32 OS_MutSemGive(uint32 mutex_id) -{ - return 0; -} - -/* -** Stub function for OS_MutSemTake() -*/ -int32 OS_MutSemTake(uint32 mutex_id) -{ - return 0; -} -#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf.h b/src/unit-tests/osprintf-test/ut_osprintf.h deleted file mode 100644 index 1a691fd79..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * ut_osprintf.h - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#ifndef UT_OSPRINTF_H_ -#define UT_OSPRINTF_H_ - -/* -** Includes -*/ -#include -#include - -/* printf Replacement Unit Test Compiler Flags - - Define UT_SHOW_PASS in order to display passing tests; if undefined then - only the failed tests are displayed. In either case the total number of - tests passes and failed are displayed - - Define UT_NO_FLOAT to skip the tests for floating point printf's; - undefine to include these tests - - Define UT_DO_OFFSET when compiling on the GHS target to perform tests to - determine variable parameter offset values for the cFE variadic functions - - Define OSP_GHS to compile on the GHS platform - osprintf Compiler Flags - - Define OS_USE_EMBEDDED_PRINTF to test the replacement printf functions; - undefine it to test the standard printf functions - - Define OSP_ARINC653 if using embedded (replacement) printf functions - and compiling on the GHS target using cFE modified for ARINC653 -*/ - -#ifdef OS_USE_EMBEDDED_PRINTF -#include "osprintf.h" -#ifndef OSP_GHS -int putchar(int); -#endif -#else -#include -#endif - -#ifdef OSP_ARINC653 -#include "common_types.h" -#endif - -/* -** Macro Definitions -*/ -#define BUF_LEN 200 -#define UT_MAX_MESSAGE_LENGTH 300 -#define UT_TRUE 1 -#define UT_FALSE 0 -#define UT_PASS 0 -#define UT_FAIL 1 - -/* -** Function prototypes -*/ -void init_test(void); -int check_test(char *expected, char *actual); - -void UT_osprintf_d(void); -void UT_osprintf_i(void); -void UT_osprintf_u(void); -void UT_osprintf_x(void); -void UT_osprintf_X(void); -void UT_osprintf_p(void); -void UT_osprintf_c(void); -void UT_osprintf_s(void); -void UT_osprintf_ld(void); -void UT_osprintf_li(void); -void UT_osprintf_lu(void); -void UT_osprintf_lx(void); -void UT_osprintf_lX(void); - -#ifndef UT_NO_FLOAT -void UT_osprintf_f(void); -void UT_osprintf_lf(void); -void UT_osprintf_misc(void); -#endif - -#ifdef OS_USE_EMBEDDED_PRINTF -void UT_osprintf_printf(void); -#endif - -void UT_Text(char *out_text); -void UT_Report(int test, char *fun_name, char *info, char *test_num, char *test_seq); -void UT_itoa(int value, char *string, int radix, int out_len); -void UT_ReportFailures(void); - -#endif /* UT_OSPRINTF_H_ */ diff --git a/src/unit-tests/osprintf-test/ut_osprintf_c.c b/src/unit-tests/osprintf-test/ut_osprintf_c.c deleted file mode 100644 index 28990c2e4..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_c.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_c.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %c format - *****************************************************************************/ -void UT_osprintf_c(void) -{ - char *test_fmt = "c"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - char test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 'k', 1, "%c", "k", "%c"}, - {"02", 'w', 5, "$$$%c$$$", "$$$w$$$", "%c embedded"}, - {"03", '?', 19, "%20c", " ?", "%c with minimum field size"}, - {"04", 'Q', 2, "%.10c", "Q", "%c with maximum field size"}, - {"05", '>', 5, "%7.9c", " >", "%c with minimum and maximum field size"}, - {"06", '#', 17, "%-20c", "# ", "%c with left-justify"}, - {"07", 'H', 2, "%+c", "H", "%c with sign"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_d.c b/src/unit-tests/osprintf-test/ut_osprintf_d.c deleted file mode 100644 index ef33168d6..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_d.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_d.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %d format - *****************************************************************************/ -void UT_osprintf_d(void) -{ - char *test_fmt = "d"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 98765, 5, "%d", "98765", "%d only"}, - {"02", 46372, 8, "$$$%d$$$", "$$$46372$$$", "%d embedded, positive value"}, - {"03", 98765, 5, "% d", " 98765", "%d with space for sign, positive value"}, - {"04", 91827, 6, "%8d", " 91827", "%d with minimum field size > number of digits, positive value"}, - {"05", 91827, 4, "%4d", "91827", "%d with minimum field size < number of digits, positive value"}, - {"06", 33225, 8, "%.10d", "0000033225", "%d with precision field size > number of digits, positive value"}, - {"07", 33225, 5, "%.3d", "33225", "%d with precision field size < number of digits, positive value"}, - {"08", 12345, 8, "%9.7d", " 0012345", - "%d with minimum field size > precision field size > number of digits, positive value"}, - {"09", 12345, 6, "%9.3d", " 12345", - "%d with minimum field size > number of digits > precision field size, positive value"}, - {"10", 12345, 3, "%4.2d", "12345", - "%d with number of digits > minimum field size > precision field size, positive value"}, - {"11", 12345, 7, "%7.9d", "000012345", - "%d with precision field size > minimum field size > number of digits, positive value"}, - {"12", 12345, 8, "%3.9d", "000012345", - "%d with precision field size > number of digits > minimum field size, positive value"}, - {"13", 12345, 4, "%2.4d", "12345", - "%d with number of digits > precision field size > minimum field size, positive value"}, - {"14", 98765, 17, "%-.20d", "00000000000000098765", - "%d with left-justify and precision field size > number of digits, positive value"}, - {"15", 98765, 5, "%-.3d", "98765", - "%d with left-justify and precision field size < number of digits, positive value"}, - {"16", 98765, 4, "%+d", "+98765", "%d with sign, positive value"}, - {"17", 46372, 9, "$$$%+d$$$", "$$$+46372$$$", "%d sign and embedded, positive value"}, - {"18", 91827, 8, "%+8d", " +91827", "%d with sign and minimum field size > number of digits, positive value"}, - {"19", 91827, 5, "%+4d", "+91827", "%d with sign and minimum field size < number of digits, positive value"}, - {"20", 33225, 10, "%+.10d", "+0000033225", - "%d with sign and precision field size > number of digits, positive value"}, - {"21", 33225, 4, "%+.3d", "+33225", "%d with sign and precision field size < number of digits, positive value"}, - {"22", 12345, 6, "%+9.7d", " +0012345", - "%d with sign and minimum field size > precision field size > number of digits, positive value"}, - {"23", 12345, 7, "%+9.3d", " +12345", - "%d with sign and minimum field size > number of digits > precision field size, positive value"}, - {"24", 12345, 2, "%+4.2d", "+12345", - "%d with sign and number of digits > minimum field size > precision field size, positive value"}, - {"25", 12345, 6, "%+7.9d", "+000012345", - "%d with sign and precision field size > minimum field size > number of digits, positive value"}, - {"26", 12345, 8, "%+3.9d", "+000012345", - "%d with sign and precision field size > number of digits > minimum field size, positive value"}, - {"27", 12345, 5, "%+2.4d", "+12345", - "%d with sign and number of digits > precision field size > minimum field size, positive value"}, - {"28", 98765, 16, "%+-.20d", "+00000000000000098765", - "%d with sign and left-justify and precision field size > number of digits, positive value"}, - {"29", 98765, 5, "%+-.3d", "+98765", - "%d with sign and left-justify and precision field size < number of digits, positive value"}, - {"30", 98765, 3, "%+d", "+98765", "%d with sign, positive value"}, - {"31", -98765, 2, "%d", "-98765", "%d, negative value"}, - {"32", -46372, 8, "$$$%d$$$", "$$$-46372$$$", "%d embedded, negative value"}, - {"33", -98765, 5, "% d", "-98765", "%d with space for sign, negative value"}, - {"34", -91827, 9, "%10d", " -91827", "%d with minimum field size > number of digits, negative value"}, - {"35", -91827, 5, "%4d", "-91827", "%d with minimum field size < number of digits, negative value"}, - {"36", -33225, 7, "%.10d", "-0000033225", "%d with precision field size > number of digits, negative value"}, - {"37", -33225, 4, "%.3d", "-33225", "%d with precision field size < number of digits, negative value"}, - {"38", -12345, 8, "%9.7d", " -0012345", - "%d with minimum field size > precision field size > number of digits, negative value"}, - {"39", -12345, 9, "%9.3d", " -12345", - "%d with minimum field size > number of digits > precision field size, negative value"}, - {"40", -12345, 5, "%4.2d", "-12345", - "%d with number of digits > minimum field size > precision field size, negative value"}, - {"41", -12345, 7, "%7.9d", "-000012345", - "%d with precision field size > minimum field size > number of digits, negative value"}, - {"42", -12345, 8, "%3.9d", "-000012345", - "%d with precision field size > number of digits > minimum field size, negative value"}, - {"43", -12345, 5, "%2.4d", "-12345", - "%d with number of digits > precision field size > minimum field size, negative value"}, - {"44", -98765, 20, "%-.20d", "-00000000000000098765", - "%d with left-justify and precision field size > number of digits, negative value"}, - {"45", -98765, 5, "%-.3d", "-98765", - "%d with left-justify and precision field size < number of digits, negative value"}, - {"46", -98765, 6, "%+d", "-98765", "%d with sign, negative value"}, - {"47", -46372, 8, "$$$%+d$$$", "$$$-46372$$$", "%d sign and embedded, negative value"}, - {"48", -91827, 7, "%+8d", " -91827", "%d with sign and minimum field size > number of digits, negative value"}, - {"49", -91827, 5, "%+4d", "-91827", "%d with sign and minimum field size < number of digits, negative value"}, - {"50", -33225, 9, "%+.10d", "-0000033225", - "%d with sign and precision field size > number of digits, negative value"}, - {"51", -33225, 5, "%+.3d", "-33225", - "%d with sign and precision field size < number of digits, negative value"}, - {"52", -12345, 6, "%+9.7d", " -0012345", - "%d with sign and minimum field size > precision field size > number of digits, negative value"}, - {"53", -12345, 7, "%+9.3d", " -12345", - "%d with sign and minimum field size > number of digits > precision field size, negative value"}, - {"54", -12345, 5, "%+4.2d", "-12345", - "%d with sign and number of digits > minimum field size > precision field size, negative value"}, - {"55", -12345, 8, "%+7.9d", "-000012345", - "%d with sign and precision field size > minimum field size > number of digits, negative value"}, - {"56", -12345, 7, "%+3.9d", "-000012345", - "%d with sign and precision field size > number of digits > minimum field size, negative value"}, - {"57", -12345, 6, "%+2.4d", "-12345", - "%d with sign and number of digits > precision field size > minimum field size, negative value"}, - {"58", -98765, 13, "%+-.20d", "-00000000000000098765", - "%d with sign and left-justify and precision field size > number of digits, negative value"}, - {"59", -98765, 4, "%+-.3d", "-98765", - "%d with sign and left-justify and precision field size < number of digits, negative value"}, - {"60", -98765, 5, "%+d", "-98765", "%d with sign, negative value"}, - {"61", 0, 6, "%d", "0", "%d, zero value"}, - {"62", 162534, 5, "%08d", "00162534", "%d with zero padding, positive value"}, - {"63", -162534, 6, "%08d", "-0162534", "%d with zero padding, negative value"}, - {"64", 0, 6, "%04d", "0000", "%d, with zero padding, zero value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_f.c b/src/unit-tests/osprintf-test/ut_osprintf_f.c deleted file mode 100644 index 08ca59d6f..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_f.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_f.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %f format - *****************************************************************************/ -void UT_osprintf_f(void) -{ - char *test_fmt = "f"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - float test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 5.230, 6, "%f", "5.230000", "%f, positive value"}, - {"02", 2.1056, 9, "$$$%f$$$", "$$$2.105600$$$", "%f embedded, positive value"}, - {"03", 91827.3, 4, "%3f", "91827.296875", "%f with maximum field size, positive value"}, - {"04", 5.82345, 5, "%.3f", "5.823", "%f with minimum field size, positive value"}, - {"05", 12.6789, 8, "%9.5f", " 12.67890", "%f with minimum and maximum field size, positive value"}, - {"06", 65.5678, 13, "%-20.5f", "65.56780 ", "%f with left-justify, positive value"}, - {"07", 2.7944, 8, "%+f", "+2.794400", "%f with sign, positive value"}, - {"08", -0.6712237, 7, "%f", "-0.671224", "%f, negative value"}, - {"09", -7.1109, 8, "$$$%f$$$", "$$$-7.110900$$$", "%f embedded, negative value"}, - {"10", -918.987, 6, "%3f", "-918.987000", "%f with maximum field size, negative value"}, - {"11", -3.1415, 3, "%.2f", "-3.14", "%f with precision, negative value"}, - {"12", -1.23456, 6, "%9.7f", "-1.2345600", "%f with precision and maximum field size, negative value"}, - {"13", -65.65, 5, "%-8.3f", "-65.650 ", "%f with left-justify, negative value"}, - {"14", 0.0, 4, "%f", "0.000000", "%f, zero value"}, - {"15", 4.0, 6, "%7.0f", " 4", "%f, no fraction, positive value"}, - {"16", -56.0, 6, "%6.0f", " -56", "%f, no fraction, negative value"}, - {"17", 4887.12, 5, "%010.3f", "004887.120", "%f with zero padding, positive value"}, - {"18", -4887.12, 5, "%010.3f", "-04887.120", "%f with zero padding, negative value"}, - {"19", 0.0, 6, "%06.2f", "000.00", "%f, with zero padding, zero value"}, - {"20", 4.0, 6, "%07.0f", "0000004", "%f, zero padding, no fraction, positive value"}, - {"21", -56.0, 6, "%06.0f", "-00056", "%f, zero padding, no fraction, negative value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_i.c b/src/unit-tests/osprintf-test/ut_osprintf_i.c deleted file mode 100644 index 83ed728ca..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_i.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_i.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %i format - *****************************************************************************/ -void UT_osprintf_i(void) -{ - char *test_fmt = "i"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 98765, 5, "%i", "98765", "%i, positive value"}, - {"02", 46372, 9, "$$$%i$$$", "$$$46372$$$", "%i embedded, positive value"}, - {"03", 98765, 5, "% i", " 98765", "%i with space for sign, positive value"}, - {"04", 91827, 7, "%8i", " 91827", "%i with minimum field size > number of digits, positive value"}, - {"05", 91827, 2, "%4i", "91827", "%i with minimum field size < number of digits, positive value"}, - {"06", 33225, 7, "%.10i", "0000033225", "%i with precision field size > number of digits, positive value"}, - {"07", 33225, 3, "%.3i", "33225", "%i with precision field size < number of digits, positive value"}, - {"08", 12345, 5, "%9.7i", " 0012345", - "%i with minimum field size > precision field size > number of digits, positive value"}, - {"09", 12345, 5, "%9.3i", " 12345", - "%i with minimum field size > number of digits > precision field size, positive value"}, - {"10", 12345, 5, "%4.2i", "12345", - "%i with number of digits > minimum field size > precision field size, positive value"}, - {"11", 12345, 8, "%7.9i", "000012345", - "%i with precision field size > minimum field size > number of digits, positive value"}, - {"12", 12345, 7, "%3.9i", "000012345", - "%i with precision field size > number of digits > minimum field size, positive value"}, - {"13", 12345, 4, "%2.4i", "12345", - "%i with number of digits > precision field size > minimum field size, positive value"}, - {"14", 98765, 5, "%-.20i", "00000000000000098765", - "%i with left-justify and precision field size > number of digits, positive value"}, - {"15", 98765, 5, "%-.3i", "98765", - "%i with left-justify and precision field size < number of digits, positive value"}, - {"16", 98765, 5, "%+i", "+98765", "%i with sign, positive value"}, - {"17", 46372, 5, "$$$%+d$$$", "$$$+46372$$$", "%i sign and embedded, positive value"}, - {"18", 91827, 6, "%+8i", " +91827", "%i with sign and minimum field size > number of digits, positive value"}, - {"19", 91827, 4, "%+4i", "+91827", "%i with sign and minimum field size < number of digits, positive value"}, - {"20", 33225, 8, "%+.10i", "+0000033225", - "%i with sign and precision field size > number of digits, positive value"}, - {"21", 33225, 5, "%+.3i", "+33225", "%i with sign and precision field size < number of digits, positive value"}, - {"22", 12345, 5, "%+9.7i", " +0012345", - "%i with sign and minimum field size > precision field size > number of digits, positive value"}, - {"23", 12345, 5, "%+9.3i", " +12345", - "%i with sign and minimum field size > number of digits > precision field size, positive value"}, - {"24", 12345, 5, "%+4.2i", "+12345", - "%i with sign and number of digits > minimum field size > precision field size, positive value"}, - {"25", 12345, 8, "%+7.9i", "+000012345", - "%i with sign and precision field size > minimum field size > number of digits, positive value"}, - {"26", 12345, 7, "%+3.9i", "+000012345", - "%i with sign and precision field size > number of digits > minimum field size, positive value"}, - {"27", 12345, 5, "%+2.4i", "+12345", - "%i with sign and number of digits > precision field size > minimum field size, positive value"}, - {"28", 98765, 16, "%+-.20i", "+00000000000000098765", - "%i with sign and left-justify and precision field size > number of digits, positive value"}, - {"29", 98765, 5, "%+-.3i", "+98765", - "%i with sign and left-justify and precision field size < number of digits, positive value"}, - {"30", 98765, 4, "%+i", "+98765", "%i with sign, positive value"}, - {"31", -98765, 6, "%i", "-98765", "%i, negative value"}, - {"32", -46372, 6, "$$$%i$$$", "$$$-46372$$$", "%i embedded, negative value"}, - {"33", -98765, 5, "% i", "-98765", "%i with space for sign, negative value"}, - {"34", -91827, 9, "%10i", " -91827", "%i with minimum field size > number of digits, negative value"}, - {"35", -91827, 6, "%4i", "-91827", "%i with minimum field size < number of digits, negative value"}, - {"36", -33225, 9, "%.10i", "-0000033225", "%i with precision field size > number of digits, negative value"}, - {"37", -33225, 5, "%.3i", "-33225", "%i with precision field size < number of digits, negative value"}, - {"38", -12345, 8, "%9.7i", " -0012345", - "%i with minimum field size > precision field size > number of digits, negative value"}, - {"39", -12345, 7, "%9.3i", " -12345", - "%i with minimum field size > number of digits > precision field size, negative value"}, - {"40", -12345, 6, "%4.2i", "-12345", - "%i with number of digits > minimum field size > precision field size, negative value"}, - {"41", -12345, 7, "%7.9i", "-000012345", - "%i with precision field size > minimum field size > number of digits, negative value"}, - {"42", -12345, 8, "%3.9i", "-000012345", - "%i with precision field size > number of digits > minimum field size, negative value"}, - {"43", -12345, 5, "%2.4i", "-12345", - "%i with number of digits > precision field size > minimum field size, negative value"}, - {"44", -98765, 18, "%-.20i", "-00000000000000098765", - "%i with left-justify and precision field size > number of digits, negative value"}, - {"45", -98765, 5, "%-.3i", "-98765", - "%i with left-justify and precision field size < number of digits, negative value"}, - {"46", -98765, 6, "%+i", "-98765", "%i with sign, negative value"}, - {"47", -46372, 7, "$$$%+d$$$", "$$$-46372$$$", "%i sign and embedded, negative value"}, - {"48", -91827, 5, "%+8i", " -91827", "%i with sign and minimum field size > number of digits, negative value"}, - {"49", -91827, 5, "%+4i", "-91827", "%i with sign and minimum field size < number of digits, negative value"}, - {"50", -33225, 7, "%+.10i", "-0000033225", - "%i with sign and precision field size > number of digits, negative value"}, - {"51", -33225, 5, "%+.3i", "-33225", - "%i with sign and precision field size < number of digits, negative value"}, - {"52", -12345, 7, "%+9.7i", " -0012345", - "%i with sign and minimum field size > precision field size > number of digits, negative value"}, - {"53", -12345, 8, "%+9.3i", " -12345", - "%i with sign and minimum field size > number of digits > precision field size, negative value"}, - {"54", -12345, 4, "%+4.2i", "-12345", - "%i with sign and number of digits > minimum field size > precision field size, negative value"}, - {"55", -12345, 8, "%+7.9i", "-000012345", - "%i with sign and precision field size > minimum field size > number of digits, negative value"}, - {"56", -12345, 7, "%+3.9i", "-000012345", - "%i with sign and precision field size > number of digits > minimum field size, negative value"}, - {"57", -12345, 5, "%+2.4i", "-12345", - "%i with sign and number of digits > precision field size > minimum field size, negative value"}, - {"58", -98765, 19, "%+-.20i", "-00000000000000098765", - "%i with sign and left-justify and precision field size > number of digits, negative value"}, - {"59", -98765, 6, "%+-.3i", "-98765", - "%i with sign and left-justify and precision field size < number of digits, negative value"}, - {"60", -98765, 5, "%+i", "-98765", "%i with sign, negative value"}, - {"61", 0, 6, "%i", "0", "%i, zero value"}, - {"62", 162534, 5, "%08i", "00162534", "%i with zero padding, positive value"}, - {"63", -162534, 6, "%08i", "-0162534", "%i with zero padding, negative value"}, - {"64", 0, 6, "%04i", "0000", "%i, with zero padding, zero value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_ld.c b/src/unit-tests/osprintf-test/ut_osprintf_ld.c deleted file mode 100644 index 9236fa157..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_ld.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_ld.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %ld format - *****************************************************************************/ -void UT_osprintf_ld(void) -{ - char *test_fmt = "ld"; /* Test format character(s) */ - int i; - - struct - { - char * test_num; /* Test identifier; sequential numbers */ - long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 12798765, 5, "%ld", "12798765", "%ld, positive value"}, - {"02", 43246372, 9, "$$$%ld$$$", "$$$43246372$$$", "%ld embedded, positive value"}, - {"03", 63198765, 9, "% ld", " 63198765", "%ld with space for sign, positive value"}, - {"04", 77691827, 8, "%11ld", " 77691827", "%ld with minimum field size > number of digits, positive value"}, - {"05", 54691827, 5, "%4ld", "54691827", "%ld with minimum field size < number of digits, positive value"}, - {"06", 77833225, 7, "%.10ld", "0077833225", "%ld with precision field size > number of digits, positive value"}, - {"07", 99933225, 6, "%.3ld", "99933225", "%ld with precision field size < number of digits, positive value"}, - {"08", 12345789, 8, "%12.10ld", " 0012345789", - "%ld with minimum field size > precision field size > number of digits, positive value"}, - {"09", 12345987, 7, "%12.3ld", " 12345987", - "%ld with minimum field size > number of digits > precision field size, positive value"}, - {"10", 12345444, 8, "%4.2ld", "12345444", - "%ld with number of digits > minimum field size > precision field size, positive value"}, - {"11", 12345321, 10, "%10.12ld", "000012345321", - "%ld with precision field size > minimum field size > number of digits, positive value"}, - {"12", 12333345, 9, "%6.12ld", "000012333345", - "%ld with precision field size > number of digits > minimum field size, positive value"}, - {"13", 12345777, 8, "%2.4ld", "12345777", - "%ld with number of digits > precision field size > minimum field size, positive value"}, - {"14", 98765321, 15, "%-.20ld", "00000000000098765321", - "%ld with left-justify and precision field size > number of digits, positive value"}, - {"15", 98765111, 8, "%-.3ld", "98765111", - "%ld with left-justify and precision field size < number of digits, positive value"}, - {"16", 98765222, 8, "%+ld", "+98765222", "%ld with sign, positive value"}, - {"17", 46372333, 7, "$$$%+ld$$$", "$$$+46372333$$$", "%ld sign and embedded, positive value"}, - {"18", 91827444, 6, "%+11ld", " +91827444", - "%ld with sign and minimum field size > number of digits, positive value"}, - {"19", 91827555, 5, "%+4ld", "+91827555", - "%ld with sign and minimum field size < number of digits, positive value"}, - {"20", 33225666, 7, "%+.13ld", "+0000033225666", - "%ld with sign and precision field size > number of digits, positive value"}, - {"21", 33225777, 8, "%+.3ld", "+33225777", - "%ld with sign and precision field size < number of digits, positive value"}, - {"22", 12345888, 9, "%+12.10ld", " +0012345888", - "%ld with sign and minimum field size > precision field size > number of digits, positive value"}, - {"23", 12345999, 10, "%+12.3ld", " +12345999", - "%ld with sign and minimum field size > number of digits > precision field size, positive value"}, - {"24", 12345000, 8, "%+4.2ld", "+12345000", - "%ld with sign and number of digits > minimum field size > precision field size, positive value"}, - {"25", 12345121, 9, "%+10.12ld", "+000012345121", - "%ld with sign and precision field size > minimum field size > number of digits, positive value"}, - {"26", 12345232, 8, "%+6.12ld", "+000012345232", - "%ld with sign and precision field size > number of digits > minimum field size, positive value"}, - {"27", 12345343, 6, "%+2.4ld", "+12345343", - "%ld with sign and number of digits > precision field size > minimum field size, positive value"}, - {"28", 98765454, 19, "%+-.20ld", "+00000000000098765454", - "%ld with sign and left-justify and precision field size > number of digits, positive value"}, - {"29", 98765565, 7, "%+-.3ld", "+98765565", - "%ld with sign and left-justify and precision field size < number of digits, positive value"}, - {"30", 98765676, 8, "%+ld", "+98765676", "%ld with sign, positive value"}, - {"31", -98765787, 9, "%ld", "-98765787", "%ld, negative value"}, - {"32", -46372898, 10, "$$$%ld$$$", "$$$-46372898$$$", "%ld embedded, negative value"}, - {"33", -98765909, 9, "% ld", "-98765909", "%ld with space for sign, negative value"}, - {"34", -91827121, 8, "%13ld", " -91827121", - "%ld with minimum field size > number of digits, negative value"}, - {"35", -91827232, 5, "%4ld", "-91827232", "%ld with minimum field size < number of digits, negative value"}, - {"36", -33225343, 8, "%.13ld", "-0000033225343", - "%ld with precision field size > number of digits, negative value"}, - {"37", -33225454, 6, "%.3ld", "-33225454", "%ld with precision field size < number of digits, negative value"}, - {"38", -12345565, 7, "%12.10ld", " -0012345565", - "%ld with minimum field size > precision field size > number of digits, negative value"}, - {"39", -12345676, 8, "%12.4ld", " -12345676", - "%ld with minimum field size > number of digits > precision field size, negative value"}, - {"40", -12345787, 9, "%4.2ld", "-12345787", - "%ld with number of digits > minimum field size > precision field size, negative value"}, - {"41", -12345898, 11, "%7.12ld", "-000012345898", - "%ld with precision field size > minimum field size > number of digits, negative value"}, - {"42", -12345909, 10, "%3.12ld", "-000012345909", - "%ld with precision field size > number of digits > minimum field size, negative value"}, - {"43", -12345101, 9, "%2.4ld", "-12345101", - "%ld with number of digits > precision field size > minimum field size, negative value"}, - {"44", -98765292, 10, "%-.20ld", "-00000000000098765292", - "%ld with left-justify and precision field size > number of digits, negative value"}, - {"45", -98765383, 8, "%-.3ld", "-98765383", - "%ld with left-justify and precision field size < number of digits, negative value"}, - {"46", -98765474, 9, "%+ld", "-98765474", "%ld with sign, negative value"}, - {"47", -46372565, 8, "$$$%+ld$$$", "$$$-46372565$$$", "%ld sign and embedded, negative value"}, - {"48", -91827112, 7, "%+11ld", " -91827112", - "%ld with sign and minimum field size > number of digits, negative value"}, - {"49", -91827223, 6, "%+4ld", "-91827223", - "%ld with sign and minimum field size < number of digits, negative value"}, - {"50", -33225334, 11, "%+.13ld", "-0000033225334", - "%ld with sign and precision field size > number of digits, negative value"}, - {"51", -33225445, 9, "%+.3ld", "-33225445", - "%ld with sign and precision field size < number of digits, negative value"}, - {"52", -12345556, 11, "%+12.10ld", " -0012345556", - "%ld with sign and minimum field size > precision field size > number of digits, negative value"}, - {"53", -12345667, 10, "%+12.3ld", " -12345667", - "%ld with sign and minimum field size > number of digits > precision field size, negative value"}, - {"54", -12345778, 9, "%+4.2ld", "-12345778", - "%ld with sign and number of digits > minimum field size > precision field size, negative value"}, - {"55", -12345889, 10, "%+7.12ld", "-000012345889", - "%ld with sign and precision field size > minimum field size > number of digits, negative value"}, - {"56", -12345990, 9, "%+3.12ld", "-000012345990", - "%ld with sign and precision field size > number of digits > minimum field size, negative value"}, - {"57", -12345221, 8, "%+2.4ld", "-12345221", - "%ld with sign and number of digits > precision field size > minimum field size, negative value"}, - {"58", -98765332, 7, "%+-.20ld", "-00000000000098765332", - "%ld with sign and left-justify and precision field size > number of digits, negative value"}, - {"59", -98765443, 6, "%+-.3ld", "-98765443", - "%ld with sign and left-justify and precision field size < number of digits, negative value"}, - {"60", -98765554, 5, "%+ld", "-98765554", "%ld with sign, negative value"}, - {"61", 0, 6, "%ld", "0", "%ld, zero value"}, - {"62", 16253409, 5, "%010ld", "0016253409", "%ld with zero padding, positive value"}, - {"63", -16253409, 6, "%010ld", "-016253409", "%ld with zero padding, negative value"}, - {"64", 0, 6, "%012ld", "000000000000", "%ld, with zero padding, zero value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lf.c b/src/unit-tests/osprintf-test/ut_osprintf_lf.c deleted file mode 100644 index bba38dcd2..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_lf.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_lf.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %lf format - *****************************************************************************/ -void UT_osprintf_lf(void) -{ - char *test_fmt = "lf"; /* Test format character(s) */ - int i; - - struct - { - char * test_num; /* Test identifier; sequential numbers */ - double test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 9876543.125, 14, "%lf", "9876543.125000", "%lf, positive value"}, - {"02", 4637210.36, 12, "$$$%lf$$$", "$$$4637210.360000$$$", "%lf embedded, positive value"}, - {"03", 9182755.2756, 9, "%3lf", "9182755.275600", "%lf with maximum field size, positive value"}, - {"04", 12554.08, 5, "%.7lf", "12554.0800000", "%lf with precision, positive value"}, - {"05", 123456.2311, 11, "%9.7lf", "123456.2311000", - "%lf with precision and maximum field size, positive value"}, - {"06", 9876543.6765, 15, "%-20lf", "9876543.676500 ", "%lf with left-justify, positive value"}, - {"07", 9876543.001, 13, "%+lf", "+9876543.001000", "%lf with sign, positive value"}, - {"08", -9876543.1987, 12, "%lf", "-9876543.198700", "%lf, negative value"}, - {"09", -4637210.871, 14, "$$$%lf$$$", "$$$-4637210.871000$$$", "%lf embedded, negative value"}, - {"10", -9182755.22222, 15, "%3lf", "-9182755.222220", "%lf with maximum field size, negative value"}, - {"11", -3355.6109, 11, "%.5lf", "-3355.61090", "%lf with precision, negative value"}, - {"12", -123456.7, 14, "%15.4lf", " -123456.7000", - "%lf with precision and maximum field size, negative value"}, - {"13", -9876543.64388, 17, "%-20lf", "-9876543.643880 ", "%lf with left-justify, negative value"}, - {"14", 0.0, 4, "%lf", "0.000000", "%lf, zero value"}, - {"15", 123456789.0, 6, "%10.0lf", " 123456789", "%lf, no fraction, positive value"}, - {"16", -987654321.0, 6, "%12.0lf", " -987654321", "%lf, no fraction, negative value"}, - {"17", 34887.1255667, 5, "%020.4lf", "000000000034887.1256", "%lf with zero padding, positive value"}, - {"18", -34887.1255667, 5, "%020.4lf", "-00000000034887.1256", "%lf with zero padding, negative value"}, - {"19", 0.0, 6, "%09.4lf", "0000.0000", "%lf, with zero padding, zero value"}, - {"20", 467812.3, 6, "%9.0lf", " 467812", "%lf, no fraction, positive value"}, - {"21", -544446.0, 6, "%8.0lf", " -544446", "%lf, no fraction, negative value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_li.c b/src/unit-tests/osprintf-test/ut_osprintf_li.c deleted file mode 100644 index b366e3966..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_li.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_li.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %li format - *****************************************************************************/ -void UT_osprintf_li(void) -{ - char *test_fmt = "li"; /* Test format character(s) */ - int i; - - struct - { - char * test_num; /* Test identifier; sequential numbers */ - long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 12798765, 7, "%li", "12798765", "%li, positive value"}, - {"02", 43246372, 9, "$$$%li$$$", "$$$43246372$$$", "%li embedded, positive value"}, - {"03", 63198765, 8, "% li", " 63198765", "%li with space for sign, positive value"}, - {"04", 77691827, 7, "%11li", " 77691827", "%li with minimum field size > number of digits, positive value"}, - {"05", 54691827, 5, "%4li", "54691827", "%li with minimum field size < number of digits, positive value"}, - {"06", 77833225, 8, "%.10li", "0077833225", "%li with precision field size > number of digits, positive value"}, - {"07", 99933225, 5, "%.3li", "99933225", "%li with precision field size < number of digits, positive value"}, - {"08", 12345789, 10, "%12.10li", " 0012345789", - "%li with minimum field size > precision field size > number of digits, positive value"}, - {"09", 12345987, 12, "%12.3li", " 12345987", - "%li with minimum field size > number of digits > precision field size, positive value"}, - {"10", 12345444, 8, "%4.2li", "12345444", - "%li with number of digits > minimum field size > precision field size, positive value"}, - {"11", 12345321, 11, "%10.12li", "000012345321", - "%li with precision field size > minimum field size > number of digits, positive value"}, - {"12", 12333345, 7, "%6.12li", "000012333345", - "%li with precision field size > number of digits > minimum field size, positive value"}, - {"13", 12345777, 5, "%2.4li", "12345777", - "%li with number of digits > precision field size > minimum field size, positive value"}, - {"14", 98765321, 19, "%-.20li", "00000000000098765321", - "%li with left-justify and precision field size > number of digits, positive value"}, - {"15", 98765111, 7, "%-.3li", "98765111", - "%li with left-justify and precision field size < number of digits, positive value"}, - {"16", 98765222, 10, "%+li", "+98765222", "%li with sign, positive value"}, - {"17", 46372333, 9, "$$$%+li$$$", "$$$+46372333$$$", "%li sign and embedded, positive value"}, - {"18", 91827444, 8, "%+11li", " +91827444", - "%li with sign and minimum field size > number of digits, positive value"}, - {"19", 91827555, 7, "%+4li", "+91827555", - "%li with sign and minimum field size < number of digits, positive value"}, - {"20", 33225666, 2, "%+.13li", "+0000033225666", - "%li with sign and precision field size > number of digits, positive value"}, - {"21", 33225777, 5, "%+.3li", "+33225777", - "%li with sign and precision field size < number of digits, positive value"}, - {"22", 12345888, 9, "%+12.10li", " +0012345888", - "%li with sign and minimum field size > precision field size > number of digits, positive value"}, - {"23", 12345999, 8, "%+12.3li", " +12345999", - "%li with sign and minimum field size > number of digits > precision field size, positive value"}, - {"24", 12345000, 9, "%+4.2li", "+12345000", - "%li with sign and number of digits > minimum field size > precision field size, positive value"}, - {"25", 12345121, 11, "%+10.12li", "+000012345121", - "%li with sign and precision field size > minimum field size > number of digits, positive value"}, - {"26", 12345232, 10, "%+6.12li", "+000012345232", - "%li with sign and precision field size > number of digits > minimum field size, positive value"}, - {"27", 12345343, 7, "%+2.4li", "+12345343", - "%li with sign and number of digits > precision field size > minimum field size, positive value"}, - {"28", 98765454, 15, "%+-.20li", "+00000000000098765454", - "%li with sign and left-justify and precision field size > number of digits, positive value"}, - {"29", 98765565, 8, "%+-.3li", "+98765565", - "%li with sign and left-justify and precision field size < number of digits, positive value"}, - {"30", 98765676, 7, "%+li", "+98765676", "%li with sign, positive value"}, - {"31", -98765787, 6, "%li", "-98765787", "%li, negative value"}, - {"32", -46372898, 15, "$$$%li$$$", "$$$-46372898$$$", "%li embedded, negative value"}, - {"33", -98765909, 9, "% li", "-98765909", "%li with space for sign, negative value"}, - {"34", -91827121, 11, "%13li", " -91827121", - "%li with minimum field size > number of digits, negative value"}, - {"35", -91827232, 5, "%4li", "-91827232", "%li with minimum field size < number of digits, negative value"}, - {"36", -33225343, 8, "%.13li", "-0000033225343", - "%li with precision field size > number of digits, negative value"}, - {"37", -33225454, 7, "%.3li", "-33225454", "%li with precision field size < number of digits, negative value"}, - {"38", -12345565, 9, "%12.10li", " -0012345565", - "%li with minimum field size > precision field size > number of digits, negative value"}, - {"39", -12345676, 8, "%12.4li", " -12345676", - "%li with minimum field size > number of digits > precision field size, negative value"}, - {"40", -12345787, 4, "%4.2li", "-12345787", - "%li with number of digits > minimum field size > precision field size, negative value"}, - {"41", -12345898, 10, "%7.12li", "-000012345898", - "%li with precision field size > minimum field size > number of digits, negative value"}, - {"42", -12345909, 9, "%3.12li", "-000012345909", - "%li with precision field size > number of digits > minimum field size, negative value"}, - {"43", -12345101, 7, "%2.4li", "-12345101", - "%li with number of digits > precision field size > minimum field size, negative value"}, - {"44", -98765292, 18, "%-.20li", "-00000000000098765292", - "%li with left-justify and precision field size > number of digits, negative value"}, - {"45", -98765383, 7, "%-.3li", "-98765383", - "%li with left-justify and precision field size < number of digits, negative value"}, - {"46", -98765474, 8, "%+li", "-98765474", "%li with sign, negative value"}, - {"47", -46372565, 10, "$$$%+li$$$", "$$$-46372565$$$", "%li sign and embedded, negative value"}, - {"48", -91827112, 9, "%+11li", " -91827112", - "%li with sign and minimum field size > number of digits, negative value"}, - {"49", -91827223, 5, "%+4li", "-91827223", - "%li with sign and minimum field size < number of digits, negative value"}, - {"50", -33225334, 11, "%+.13li", "-0000033225334", - "%li with sign and precision field size > number of digits, negative value"}, - {"51", -33225445, 8, "%+.3li", "-33225445", - "%li with sign and precision field size < number of digits, negative value"}, - {"52", -12345556, 12, "%+12.10li", " -0012345556", - "%li with sign and minimum field size > precision field size > number of digits, negative value"}, - {"53", -12345667, 10, "%+12.3li", " -12345667", - "%li with sign and minimum field size > number of digits > precision field size, negative value"}, - {"54", -12345778, 6, "%+4.2li", "-12345778", - "%li with sign and number of digits > minimum field size > precision field size, negative value"}, - {"55", -12345889, 9, "%+7.12li", "-000012345889", - "%li with sign and precision field size > minimum field size > number of digits, negative value"}, - {"56", -12345990, 11, "%+3.12li", "-000012345990", - "%li with sign and precision field size > number of digits > minimum field size, negative value"}, - {"57", -12345221, 7, "%+2.4li", "-12345221", - "%li with sign and number of digits > precision field size > minimum field size, negative value"}, - {"58", -98765332, 15, "%+-.20li", "-00000000000098765332", - "%li with sign and left-justify and precision field size > number of digits, negative value"}, - {"59", -98765443, 7, "%+-.3li", "-98765443", - "%li with sign and left-justify and precision field size < number of digits, negative value"}, - {"60", -98765554, 5, "%+li", "-98765554", "%li with sign, negative value"}, - {"61", 0, 6, "%li", "0", "%li, zero value"}, - {"62", 16253409, 5, "%010li", "0016253409", "%li with zero padding, positive value"}, - {"63", -16253409, 6, "%010li", "-016253409", "%li with zero padding, negative value"}, - {"64", 0, 6, "%012li", "000000000000", "%li, with zero padding, zero value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lu.c b/src/unit-tests/osprintf-test/ut_osprintf_lu.c deleted file mode 100644 index 182c55620..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_lu.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_lu.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %lu format - *****************************************************************************/ -void UT_osprintf_lu(void) -{ - char *test_fmt = "lu"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 9876543, 6, "%lu", "9876543", "%lu, negative value"}, - {"02", 4637210, 12, "$$$%lu$$$", "$$$4637210$$$", "%lu embedded"}, - {"03", 9182755, 6, "%3lu", "9182755", "%lu with maximum field size"}, - {"04", 3322554, 10, "%.10lu", "0003322554", "%lu with minimum field size"}, - {"05", 123456, 8, "%9.7lu", " 0123456", "%lu with minimum and maximum field size"}, - {"06", 9876543, 16, "%-.20lu", "00000000000009876543", "%lu with left-justify"}, - {"07", 9876543, 5, "%+lu", "9876543", "%lu with sign"}, - {"08", -9876543, 8, "%lu", "4285090753", "%lu, negative value"}, - {"09", 0, 6, "%lu", "0", "%lu, zero value"}, - {"10", 162534098, 5, "%011lu", "00162534098", "%lu with zero padding"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lx.c b/src/unit-tests/osprintf-test/ut_osprintf_lx.c deleted file mode 100644 index 72678d73c..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_lx.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_lx.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %x format - *****************************************************************************/ -void UT_osprintf_lx(void) -{ - char *test_fmt = "lx"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 0x9a8b7c6d, 5, "%lx", "9a8b7c6d", "%lx"}, - {"02", 0xdd46ee21, 12, "$$$%lx$$$", "$$$dd46ee21$$$", "%lx embedded"}, - {"03", 0x9ccc8275, 7, "%3lx", "9ccc8275", "%lx with minimum field size < number of digits"}, - {"04", 0xbee33225, 10, "%.10lx", "00bee33225", "%lx with precision field size"}, - {"05", 0x123fdb, 7, "%9.7lx", " 0123fdb", "%lx with minimum and precision field size"}, - {"06", 0xabc6543f, 19, "%-.20lx", "000000000000abc6543f", "%lx with left-justify"}, - {"07", -9876543, 7, "%lx", "ff694bc1", "%lx, negative value"}, - {"08", 0x12b45, 5, "%8lx", " 12b45", "%lx with minimum field size > number of digits"}, - {"09", 0x12b45, 6, "%08lx", "00012b45", "%lx with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c b/src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c deleted file mode 100644 index ab98a17a4..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_lX.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %lX format - *****************************************************************************/ -void UT_osprintf_lX(void) -{ - char *test_fmt = "lx"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 0x9a8b7c6d, 8, "%lX", "9A8B7C6D", "%lX"}, - {"02", 0xdd46ee21, 8, "$$$%lX$$$", "$$$DD46EE21$$$", "%lX embedded"}, - {"03", 0x9ccc8275, 7, "%3lX", "9CCC8275", "%lX with minimum field size < number of digits"}, - {"04", 0xbee33225, 10, "%.10lX", "00BEE33225", "%lX with precision field size"}, - {"05", 0x123fdb, 7, "%9.7lX", " 0123FDB", "%lX with minimum and precision field size"}, - {"06", 0xabc6543f, 16, "%-.20lX", "000000000000ABC6543F", "%lX with left-justify"}, - {"07", -9876543, 5, "%lX", "FF694BC1", "%lX, negative value"}, - {"08", 0x12b45, 3, "%8lX", " 12B45", "%lX with minimum field size > number of digits"}, - {"09", 0x12b45, 2, "%08lX", "00012B45", "%lX with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_misc.c b/src/unit-tests/osprintf-test/ut_osprintf_misc.c deleted file mode 100644 index a191f1c79..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_misc.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_misc.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; - -/***************************************************************************** - * Test miscellaneous formats & combinations - *****************************************************************************/ -void UT_osprintf_misc(void) -{ - int test_int; - long test_long; - unsigned test_unsigned; - unsigned test_hex; - char * test_num = "misc"; - int return_value; - -#ifndef UT_NO_FLOAT - float test_float; - double test_double; - char test_char; -#endif - - /* Test representing percent character using %% */ - init_test(); - sprintf(strg_buf, "Show percent character .%%."); - UT_Report(check_test("Show percent character .%.", strg_buf), "SPRINTF", "Represent percent character using %%", - test_num, "01"); - - /* Test representing percent character using %%, truncated */ - init_test(); - snprintf(strg_buf, 11, "Show percent character .%%."); - UT_Report(check_test("Show perce", strg_buf), "SNPRINTF", "Represent percent character using %%, truncated", - test_num, "01"); - - /* Test format string ending with percent character */ - init_test(); - sprintf(strg_buf, "End with percent character %"); - UT_Report(check_test("End with percent character ", strg_buf), "SPRINTF", "End with percent character", test_num, - "02"); - - /* Test representing percent character using %%, truncated */ - init_test(); - snprintf(strg_buf, 11, "End with percent character %"); - UT_Report(check_test("End with p", strg_buf), "SNPRINTF", "End with percent character, truncated", test_num, "02"); - - /* Test null format string */ - init_test(); - sprintf(strg_buf, ""); - UT_Report(check_test("", strg_buf), "SPRINTF", "Null format string", test_num, "03"); - - /* Test representing percent character using %%, truncated */ - init_test(); - snprintf(strg_buf, 5, ""); - UT_Report(check_test("", strg_buf), "SNPRINTF", "Null format string", test_num, "03"); - - /* Test too many decimals in format width/precision modifier */ - init_test(); - return_value = sprintf(strg_buf, "Too many decimals"); - UT_Report(return_value < 0, "SPRINTF", "Invalid format string", test_num, "04"); - - /* Test too many decimals in format width/precision modifier, truncated */ - init_test(); - return_value = snprintf(strg_buf, 23, "Too many decimals"); - UT_Report(return_value < 0, "SNPRINTF", "Invalid format string", test_num, "04"); - - /* Test multiple parameters */ - init_test(); - test_int = 121; - test_long = -9876222; - test_unsigned = 5432; - test_hex = 72635; - sprintf(strg_buf, "Multiple parameters %d:%d, %d:%d, %d:%d, %d:%d", 1, test_int, 2, test_long, 3, test_unsigned, 4, - test_hex); - UT_Report(check_test("Multiple parameters 1:121, 2:-9876222, " - "3:5432, 4:72635", - strg_buf), - "SPRINTF", "Multiple parameters", test_num, "05"); - - /* Test multiple parameters, truncated */ - init_test(); - test_int = 121; - test_long = -9876222; - test_unsigned = 5432; - test_hex = 72635; - snprintf(strg_buf, 52, "Multiple parameters %d:%d, %d:%d, %d:%d, %d:%d", 1, test_int, 2, test_long, 3, - test_unsigned, 4, test_hex); - UT_Report(check_test("Multiple parameters 1:121, 2:-9876222, " - "3:5432, 4:72", - strg_buf), - "SNPRINTF", "Multiple parameters", test_num, "05"); - -#ifndef UT_NO_FLOAT - /* Test combination of types */ - init_test(); - test_int = -123; - test_long = 9876543; - test_unsigned = 4321; - test_hex = 0xa1b2; - test_float = -2.3456; - test_double = 6543.123456; - test_char = '$'; - sprintf(strg_buf, - "int = %d long = %ld uns = %u hex = 0x%x flt = %f " - "dbl = %lf chr = %c", - test_int, test_long, test_unsigned, test_hex, test_float, test_double, test_char); - UT_Report(check_test("int = -123 long = 9876543 uns = 4321 hex = " - "0xa1b2 flt = -2.345600 dbl = 6543.123456 " - "chr = $", - strg_buf), - "SPRINTF", "Combination of types", test_num, "06"); - - /* Test combination of types, truncated */ - init_test(); - test_int = -123; - test_long = 9876543; - test_unsigned = 4321; - test_hex = 0xa1b2; - test_float = -2.3456; - test_double = 6543.123456; - test_char = '$'; - snprintf(strg_buf, 16, - "int = %d long = %ld uns = %u hex = 0x%x flt = %f " - "dbl = %lf chr = %c", - test_int, test_long, test_unsigned, test_hex, test_float, test_double, test_char); - UT_Report(check_test("int = -123 lon", strg_buf), "SNPRINTF", "Combination of types, truncated", test_num, "06"); - - /* Test combination of types 2 */ - init_test(); - test_int = -123; - test_long = 9876543; - test_unsigned = 4321; - test_hex = 0xa1b2; - test_float = -2.3456; - test_double = 6543.123456; - test_char = '$'; - sprintf(strg_buf, "flt = %f dbl = %lf flt = %f", test_float, test_double, test_float); - UT_Report(check_test("flt = -2.345600 dbl = 6543.123456 flt = -2.345600", strg_buf), "SPRINTF", - "Combination of types 2", test_num, "07"); - - /* Test combination of types 2, truncated */ - init_test(); - test_int = -123; - test_long = 9876543; - test_unsigned = 4321; - test_hex = 0xa1b2; - test_float = -2.3456; - test_double = 6543.123456; - test_char = '$'; - snprintf(strg_buf, 10, "flt = %f dbl = %lf flt = %f", test_float, test_double, test_float); - UT_Report(check_test("flt = -2.", strg_buf), "SNPRINTF", "Combination of types 2", test_num, "07"); -#endif -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_offset.c b/src/unit-tests/osprintf-test/ut_osprintf_offset.c deleted file mode 100644 index f9874edb9..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_offset.c +++ /dev/null @@ -1,454 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Calculate offset, breakpoint, and skip values for the cFE and cFE unit - * test variadic functions. Note that some "dummy" function calls from - * the original function are needed in order for the correct offset, - * breakpoint, and skip values to be calculated. The ordering of these - * dummy functions must match that in the actual function - */ -#ifdef UT_DO_OFFSET - -#include "ut_osprintf.h" -#include "ut_osprintf_offset.h" - -extern char cMsg[]; -extern char cNum[]; - -extern int OS_printf_break; -extern int OS_printf_skip; -extern int OS_printf_enabled; - -unsigned long testPattern[12][10] = {{0x12ab34cd, 0x19999991, 0x18888881, 0x17777771, 0x16666661, 0x15555551, - 0x14444441, 0x13333331, 0x12222221, 0x11111111}, - {0x23bc45de, 0x29999992, 0x28888882, 0x27777772, 0x26666662, 0x25555552, - 0x24444442, 0x23333332, 0x22222222, 0x21111112}, - {0x34cd56ef, 0x39999993, 0x38888883, 0x37777773, 0x36666663, 0x35555553, - 0x34444443, 0x33333333, 0x32222223, 0x31111113}, - {0x45ab67cd, 0x49999994, 0x48888884, 0x47777774, 0x46666664, 0x45555554, - 0x44444444, 0x43333334, 0x42222224, 0x41111114}, - {0x56bc78de, 0x59999995, 0x58888885, 0x57777775, 0x56666665, 0x55555555, - 0x54444445, 0x53333335, 0x52222225, 0x51111115}, - {0x67cd78ef, 0x69999996, 0x68888886, 0x67777776, 0x66666666, 0x65555556, - 0x64444446, 0x63333336, 0x62222226, 0x61111116}, - {0x78ab9acd, 0x79999997, 0x78888887, 0x77777777, 0x76666667, 0x75555557, - 0x74444447, 0x73333337, 0x72222227, 0x71111117}, - {0x89bcabde, 0x89999998, 0x88888888, 0x87777778, 0x86666668, 0x85555558, - 0x84444448, 0x83333338, 0x82222228, 0x81111118}, - {0x9acdbcef, 0x99999999, 0x98888889, 0x97777779, 0x96666669, 0x95555559, - 0x94444449, 0x93333339, 0x92222229, 0x91111119}, - {0xababcdcd, 0xa999999a, 0xa888888a, 0xa777777a, 0xa666666a, 0xa555555a, - 0xa444444a, 0xa333333a, 0xa222222a, 0xa111111a}, - {0xbcbcdede, 0xb999999b, 0xb888888b, 0xb777777b, 0xb666666b, 0xb555555b, - 0xb444444b, 0xb333333b, 0xb222222b, 0xb111111b}, - {0xcdcdefef, 0xc999999c, 0xc888888c, 0xc777777c, 0xc666666c, 0xc555555c, - 0xc444444c, 0xc333333c, 0xc222222c, 0xc111111c}}; - -void UT_osprintf_CalcOffsets(void) -{ - CFE_TIME_SysTime_t Time = {0, 0}; - - /* Determine variadic offsets */ - CalcOffset_CFE_ES_WriteToSysLog("CFE_ES_WriteToSysLog test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", - testPattern[0][0], testPattern[0][1], testPattern[0][2], testPattern[0][3], - testPattern[0][4], testPattern[0][5], testPattern[0][6], testPattern[0][7], - testPattern[0][8], testPattern[0][9]); - CalcOffset_EVS_SendEvent(111, 222, "EVS_SendEvent test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[1][0], - testPattern[1][1], testPattern[1][2], testPattern[1][3], testPattern[1][4], - testPattern[1][5], testPattern[1][6], testPattern[1][7], testPattern[1][8], - testPattern[1][9]); - CalcOffset_CFE_EVS_SendEvent(333, 444, "CFE_EVS_SendEvent test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", - testPattern[2][0], testPattern[2][1], testPattern[2][2], testPattern[2][3], - testPattern[2][4], testPattern[2][5], testPattern[2][6], testPattern[2][7], - testPattern[2][8], testPattern[2][9]); - CalcOffset_CFE_EVS_SendEventWithAppID( - 555, 666, 7, "CFE_EVS_SendEventWithAppID test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[3][0], - testPattern[3][1], testPattern[3][2], testPattern[3][3], testPattern[3][4], testPattern[3][5], - testPattern[3][6], testPattern[3][7], testPattern[3][8], testPattern[3][9]); - CalcOffset_CFE_EVS_SendTimedEvent( - Time, 888, 999, "CFE_EVS_SendTimedEvent test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[4][0], - testPattern[4][1], testPattern[4][2], testPattern[4][3], testPattern[4][4], testPattern[4][5], - testPattern[4][6], testPattern[4][7], testPattern[4][8], testPattern[4][9]); - CalcOffset_OS_printf("OS_printf test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[5][0], testPattern[5][1], - testPattern[5][2], testPattern[5][3], testPattern[5][4], testPattern[5][5], testPattern[5][6], - testPattern[5][7], testPattern[5][8], testPattern[5][9]); - CalcOffset_OS_sprintf(cMsg, "OS_sprintf test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[6][0], - testPattern[6][1], testPattern[6][2], testPattern[6][3], testPattern[6][4], testPattern[6][5], - testPattern[6][6], testPattern[6][7], testPattern[6][8], testPattern[6][9]); - CalcOffset_OS_snprintf(cMsg, 100, "OS_snprintf test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[7][0], - testPattern[7][1], testPattern[7][2], testPattern[7][3], testPattern[7][4], - testPattern[7][5], testPattern[7][6], testPattern[7][7], testPattern[7][8], - testPattern[7][9]); - CalcOffset_OS_printf_stub("OS_printf stub test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[8][0], - testPattern[8][1], testPattern[8][2], testPattern[8][3], testPattern[8][4], - testPattern[8][5], testPattern[8][6], testPattern[8][7], testPattern[8][8], - testPattern[8][9]); - CalcOffset_CFE_ES_WriteToSysLog_stub("CFE_ES_WriteToSysLog stub test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", - testPattern[9][0], testPattern[9][1], testPattern[9][2], testPattern[9][3], - testPattern[9][4], testPattern[9][5], testPattern[9][6], testPattern[9][7], - testPattern[9][8], testPattern[9][9]); - CalcOffset_CFE_EVS_SendEvent_stub(333, 444, "CFE_EVS_SendEvent stub test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", - testPattern[10][0], testPattern[10][1], testPattern[10][2], testPattern[10][3], - testPattern[10][4], testPattern[10][5], testPattern[10][6], testPattern[10][7], - testPattern[10][8], testPattern[10][9]); - CalcOffset_CFE_EVS_SendEventWithAppID_stub( - 555, 666, 5, "CFE_EVS_SendEventWithAppID stub test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[11][0], - testPattern[11][1], testPattern[11][2], testPattern[11][3], testPattern[11][4], testPattern[11][5], - testPattern[11][6], testPattern[11][7], testPattern[11][8], testPattern[11][9]); -} - -void UT_ShowHex(unsigned char *ptr, int numBytes) -{ - int i, j; - unsigned char *bytePtr = (unsigned char *)ptr; - char hMsg[3000]; - - strcpy(hMsg, "args = "); - - for (i = 0, j = 1; i < numBytes; i++, j++) - { - UT_itoa(*bytePtr, cNum, 16, 2); - strcat(hMsg, cNum); - strcat(hMsg, " "); - bytePtr++; - - if (j == 4) - { - strcat(hMsg, "\n "); - j = 0; - } - } - - UT_Text(hMsg); -} - -/* Determine the offset, breakpoint, and skip values for a variadic function */ -void UT_CheckArgumentOffset(va_list ptr, int tpIndex) -{ - int i = 0; - int offset = -1; - int breakpoint = 0; - int skip = 0; - int max_allowed_offset = 20; - int max_allowed_skip = 100; - int num_parms = 10; - unsigned char *bytePtr = (unsigned char *)ptr; - unsigned char *testPtr = (void *)&testPattern[tpIndex][0]; - - /* - UT_ShowHex(ptr, 440); - */ - - while (offset < max_allowed_offset && i < sizeof(unsigned long)) - { - offset++; - - for (i = 0; i < sizeof(unsigned long); i++) - { - if (*(bytePtr + (offset * sizeof(va_list)) + i) != *(testPtr + i)) - { - break; - } - } - } - - if (offset == max_allowed_offset) - { - UT_Text(" Offset could not be determined\n"); - } - else - { - sprintf(cMsg, " Offset = %d\n", offset); - UT_Text(cMsg); - i = sizeof(unsigned long); - - /* Find breakpoint value */ - while (offset < max_allowed_offset + num_parms && i == sizeof(unsigned long)) - { - offset++; - breakpoint++; - testPtr += sizeof(unsigned long); - - for (i = 0; i < sizeof(unsigned long); i++) - { - if (*(bytePtr + (offset * sizeof(va_list)) + i) != *(testPtr + i)) - { - break; - } - } - } - - if (breakpoint == num_parms) - { - UT_Text(" No breakpoint found\n"); - } - else - { - sprintf(cMsg, " Breakpoint = %d\n", breakpoint); - UT_Text(cMsg); - - /* Find skip value */ - while (offset < max_allowed_offset + num_parms + max_allowed_skip && i < sizeof(unsigned long)) - { - offset++; - skip++; - - for (i = 0; i < sizeof(unsigned long); i++) - { - if (*(bytePtr + (offset * sizeof(va_list)) + i) != *(testPtr + i)) - { - break; - } - } - } - - if (skip == max_allowed_skip) - { - UT_Text(" Skip could not be determined\n"); - } - else - { - sprintf(cMsg, " Skip = %d\n", skip); - UT_Text(cMsg); - } - } - } -} - -/* Mimic actual CFE_ES_WriteToSysLog() */ -int32 CalcOffset_CFE_ES_WriteToSysLog(const char *SpecStringPtr, ...) -{ - char TmpString[CFE_ES_MAX_SYSLOG_MSG_SIZE]; - char MsgWithoutTime[CFE_EVS_MAX_MESSAGE_LENGTH]; - CFE_TIME_SysTime_t time = {0, 0}; - va_list Ptr; - - va_start(Ptr, SpecStringPtr, 0, 0, 0); - OS_vsnprintfDummy(MsgWithoutTime, 1, SpecStringPtr, Ptr); - CFE_TIME_PrintDummy(TmpString, time); - strcatDummy(TmpString, " "); - strncatDummy(TmpString, MsgWithoutTime, 1); - OS_printfDummy("%s", TmpString); - strlenDummy(TmpString); - strncpyDummy(TmpString, TmpString, 1); - strncpyDummy(TmpString, "\0", 1); - OS_printfDummy("Warning: Last System Log Message Truncated.\n"); - strlenDummy(TmpString); - strncpyDummy(TmpString, TmpString, 1); - - UT_Text("\nCFE_ES_WriteToSysLog Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 0); - va_end(Ptr); - return 0; -} - -/* Mimic actual EVS_SendEvent() */ -int32 CalcOffset_EVS_SendEvent(uint16 EventID, uint16 EventType, const char *Spec, ...) -{ - CFE_EVS_Packet_t EVS_Packet; - CFE_TIME_SysTime_t Time = {0, 0}; - va_list Ptr; - - EVS_IsFilteredDummy(0, EventID, EventType); - CFE_SB_InitMsgDummy(&EVS_Packet, 1, sizeof(CFE_EVS_Packet_t), 1); - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(EVS_Packet.Message, 1, Spec, Ptr); - CFE_TIME_GetTimeDummy(); - EVS_SendPacketDummy(0, Time, &EVS_Packet); - - UT_Text("\nEVS_SendEvent Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 1); - va_end(Ptr); - return 0; -} - -/* Mimic actual CFE_EVS_SendEvent() */ -int32 CalcOffset_CFE_EVS_SendEvent(uint16 EventID, uint16 EventType, const char *Spec, ...) -{ - CFE_EVS_Packet_t EVS_Packet; - uint32 AppID = 0; - CFE_TIME_SysTime_t Time = {0, 0}; - va_list Ptr; - - EVS_GetAppIDDummy(&AppID); - EVS_NotRegisteredDummy(AppID); - EVS_IsFilteredDummy(AppID, EventID, EventType); - CFE_SB_InitMsgDummy(&EVS_Packet, 1, sizeof(CFE_EVS_Packet_t), 1); - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(EVS_Packet.Message, 1, Spec, Ptr); - CFE_TIME_GetTimeDummy(); - EVS_SendPacketDummy(AppID, Time, &EVS_Packet); - - UT_Text("\nCFE_EVS_SendEvent Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 2); - va_end(Ptr); - return 0; -} - -/* Mimic actual CFE_EVS_SendEventWithAppID() */ -/* THIS IS RETURNING THE WRONG SKIP VALUE!!! (off by -2) */ -int32 CalcOffset_CFE_EVS_SendEventWithAppID(uint16 EventID, uint16 EventType, uint32 AppID, const char *Spec, ...) -{ - CFE_EVS_Packet_t EVS_Packet; - CFE_TIME_SysTime_t Time = {0, 0}; - va_list Ptr; - - EVS_NotRegisteredDummy(AppID); - EVS_IsFilteredDummy(AppID, EventID, EventType); - CFE_SB_InitMsgDummy(&EVS_Packet, 1, sizeof(CFE_EVS_Packet_t), 1); - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(EVS_Packet.Message, 1, Spec, Ptr); - CFE_TIME_GetTimeDummy(); - EVS_SendPacketDummy(AppID, Time, &EVS_Packet); - - UT_Text("\nCFE_EVS_SendEventWithAppID Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 3); - va_end(Ptr); - return 0; -} - -/* Mimic actual CFE_EVS_SendTimedEvent() */ -int32 CalcOffset_CFE_EVS_SendTimedEvent(CFE_TIME_SysTime_t Time, uint16 EventID, uint16 EventType, const char *Spec, - ...) -{ - CFE_EVS_Packet_t EVS_Packet; - uint32 AppID = 0; - va_list Ptr; - - EVS_GetAppIDDummy(&AppID); - EVS_NotRegisteredDummy(AppID); - EVS_IsFilteredDummy(AppID, EventID, EventType); - CFE_SB_InitMsgDummy(&EVS_Packet, 0, sizeof(CFE_EVS_Packet_t), 0); - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(EVS_Packet.Message, 0, Spec, Ptr); - EVS_SendPacketDummy(AppID, Time, &EVS_Packet); - - UT_Text("\nCFE_EVS_SendTimedEvent Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 4); - va_end(Ptr); - return 0; -} - -/* Mimic actual OS_printf() */ -void CalcOffset_OS_printf(const char *format, ...) -{ - va_list varg; - - va_start(varg, format, 0, 0, 0); - OS_vsnprintfDummy(0, -1, format, varg) - - UT_Text("\nOS_printf Argument Calculation:\n"); - UT_CheckArgumentOffset(varg, 5); - va_end(varg); -} - -/* Mimic actual and stub OS_sprintf() */ -int CalcOffset_OS_sprintf(char *out, const char *format, ...) -{ - va_list varg; - int length; - - va_start(varg, format, 0, 0, 0); - length = OS_vsnprintfDummy(out, -1, format, varg); - - UT_Text("\nOS_sprintf Argument Calculation:\n"); - UT_CheckArgumentOffset(varg, 6); - va_end(varg); - return (length); -} - -/* Mimic actual and stub OS_snprintf() */ -int CalcOffset_OS_snprintf(char *out, unsigned max_len, const char *format, ...) -{ - va_list varg; - int length; - - va_start(varg, format, 0, 0, 0); - length = OS_vsnprintfDummy(out, (int)max_len - 1, format, varg); - - UT_Text("\nOS_snprintf Argument Calculation:\n"); - UT_CheckArgumentOffset(varg, 7); - va_end(varg); - return (length); -} - -/* Mimic stub OS_printf() */ -void CalcOffset_OS_printf_stub(const char *string, ...) -{ - char tmpString[CFE_ES_MAX_SYSLOG_MSG_SIZE * 2]; - va_list ptr; - - va_start(ptr, string, 0, 0, 0); - OS_vsnprintfDummy(tmpString, CFE_ES_MAX_SYSLOG_MSG_SIZE * 2, string, ptr); - - UT_Text("\nOS_printf Stub Argument Calculation:\n"); - UT_CheckArgumentOffset(ptr, 8); - va_end(ptr); -} - -int32 CalcOffset_CFE_ES_WriteToSysLog_stub(const char *pSpecString, ...) -{ - char tmpString[CFE_ES_MAX_SYSLOG_MSG_SIZE]; - va_list ap; - - va_start(ap, pSpecString, 0, 0, 0); - OS_vsnprintfDummy(tmpString, CFE_ES_MAX_SYSLOG_MSG_SIZE, pSpecString, ap); - - UT_Text("\nCFE_ES_WriteToSysLog Stub Argument Calculation:\n"); - UT_CheckArgumentOffset(ap, 9); - va_end(ap); - return 0; -} - -/* Mimic stub CFE_EVS_SendEvent() */ -int32 CalcOffset_CFE_EVS_SendEvent_stub(uint16 EventID, uint16 EventType, const char *Spec, ...) -{ - char BigBuf[CFE_EVS_MAX_MESSAGE_LENGTH]; - va_list Ptr; - - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(BigBuf, CFE_EVS_MAX_MESSAGE_LENGTH, Spec, Ptr); - UT_AddEventToHistoryDummy(EventID); - - UT_Text("\nCFE_EVS_SendEvent Stub Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 10); - va_end(Ptr); - return 0; -} - -/* Mimic stub CFE_EVS_SendEventWithAppID() */ -int32 CalcOffset_CFE_EVS_SendEventWithAppID_stub(uint16 EventID, uint16 EventType, uint32 AppID, const char *Spec, ...) -{ - char BigBuf[CFE_EVS_MAX_MESSAGE_LENGTH]; - va_list Ptr; - - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(BigBuf, CFE_EVS_MAX_MESSAGE_LENGTH, Spec, Ptr); - UT_AddEventToHistoryDummy(EventID); - OS_snprintfDummy(cMsg, UT_MAX_MESSAGE_LENGTH, " CFE_EVS_SendEvent from app %lu: %u, %u - %s", AppID, EventID, - EventType, BigBuf); - - UT_Text("\nCFE_EVS_SendEventWithAppID Stub Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 11); - va_end(Ptr); - return 0; -} - -#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_offset.h b/src/unit-tests/osprintf-test/ut_osprintf_offset.h deleted file mode 100644 index f86c4c2cf..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_offset.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * ut_osprintf_offset.h - * - * Variadic argument offset calculation - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ -#ifdef UT_DO_OFFSET - -#ifndef UT_OSPRINTF_OFFSET_H_ -#define UT_OSPRINTF_OFFSET_H_ - -#include "common_types.h" -#include "osapi.h" -#include "cfe_es.h" -#include "cfe_sb.h" -#include "cfe_evs_task.h" -#include "cfe_time.h" -#include "cfe_mission_cfg.h" -#include "osprintf.h" - -void UT_ShowHex(unsigned char *, int); -void UT_CheckArgumentOffset(va_list, int); -void UT_osprintf_CalcOffsets(void); -int32 CalcOffset_CFE_ES_WriteToSysLog(const char *, ...); -int32 CalcOffset_EVS_SendEvent(uint16, uint16, const char *, ...); -int32 CalcOffset_CFE_EVS_SendEvent(uint16, uint16, const char *, ...); -int32 CalcOffset_CFE_EVS_SendEventWithAppID(uint16, uint16, uint32, const char *, ...); -int32 CalcOffset_CFE_EVS_SendTimedEvent(CFE_TIME_SysTime_t, uint16, uint16, const char *, ...); -void CalcOffset_OS_printf(const char *, ...); -int CalcOffset_OS_sprintf(char *, const char *, ...); -int CalcOffset_OS_snprintf(char *, unsigned, const char *, ...); -void CalcOffset_OS_printf_stub(const char *, ...); -int32 CalcOffset_CFE_ES_WriteToSysLog_stub(const char *, ...); -int32 CalcOffset_CFE_EVS_SendEvent_stub(uint16, uint16, const char *, ...); -int32 CalcOffset_CFE_EVS_SendEventWithAppID_stub(uint16, uint16, uint32, const char *, ...); -void CFE_TIME_PrintDummy(char *, CFE_TIME_SysTime_t); -unsigned char EVS_IsFilteredDummy(uint32, uint16, uint16); -void CFE_SB_InitMsgDummy(void *, uint16, uint16, unsigned char); -CFE_TIME_SysTime_t CFE_TIME_GetTimeDummy(void); -void EVS_SendPacketDummy(uint32, CFE_TIME_SysTime_t, CFE_EVS_Packet_t *); -long int EVS_GetAppIDDummy(uint32 *); -long int EVS_NotRegisteredDummy(uint32); -int OS_vsnprintfDummy(char *, int, const char *, ...); -void OS_printfDummy(const char *, ...); -int OS_snprintfDummy(char *, unsigned, const char *, ...); -char * strcatDummy(char *, const char *); -char * strncatDummy(char *, const char *, int); -char * strncpyDummy(char *, const char *, int); -int strlenDummy(const char *); -void UT_AddEventToHistoryDummy(uint16 EventID); - -#endif /* UT_OSPRINTF_OFFSET_H_ */ - -#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c b/src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c deleted file mode 100644 index d462d49a1..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef UT_DO_OFFSET - -#include "ut_osprintf.h" -#include "ut_osprintf_offset.h" - -void CFE_TIME_PrintDummy(char *PrintBuffer, CFE_TIME_SysTime_t TimeToPrint) {} - -unsigned char EVS_IsFilteredDummy(uint32 AppID, uint16 EventID, uint16 EventType) -{ - return 0; -} - -void CFE_SB_InitMsgDummy(void *MsgPtr, uint16 MsgId, uint16 Length, unsigned char Clear) {} - -CFE_TIME_SysTime_t CFE_TIME_GetTimeDummy(void) -{ - CFE_TIME_SysTime_t Time = {0, 0}; - - return Time; -} - -void EVS_SendPacketDummy(uint32 AppID, CFE_TIME_SysTime_t Time, CFE_EVS_Packet_t *EVS_PktPtr) {} - -long int EVS_GetAppIDDummy(uint32 *AppIdPtr) -{ - return 0; -} - -long int EVS_NotRegisteredDummy(uint32 AppID) -{ - return 0; -} - -int OS_vsnprintfDummy(char *out_buffer, int max_len, const char *format, ...) -{ - return 0; -} - -void OS_printfDummy(const char *format, ...) {} - -int OS_snprintfDummy(char *out_buffer, unsigned max_len, const char *format, ...) -{ - return 0; -} - -char *strcatDummy(char *out, const char *in) -{ - return out; -} - -char *strncatDummy(char *out, const char *in, int len) -{ - return out; -} - -char *strncpyDummy(char *out, const char *in, int len) -{ - return out; -} - -int strlenDummy(const char *in) -{ - return 0; -} - -void UT_AddEventToHistoryDummy(uint16 EventID) {} -#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_p.c b/src/unit-tests/osprintf-test/ut_osprintf_p.c deleted file mode 100644 index 4d5ce8ec9..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_p.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_p.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %p format - *****************************************************************************/ -void UT_osprintf_p(void) -{ - char *test_fmt = "p"; /* Test format character(s) */ - int i; - - struct - { - char * test_num; /* Test identifier; sequential numbers */ - long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 98765, 5, "%p", "0x181cd", "%p"}, - {"02", 46372, 10, "$$$%p$$$", "$$$0xb524$$$", "%p embedded"}, - {"03", 91827, 5, "%3p", "0x166b3", "%p with minimum field size"}, - {"04", 33225, 11, "%.10p", "0x00000081c9", "%p with precision field size"}, - {"05", 12345, 9, "%9.7p", "0x0003039", "%p with minimum and precision field size"}, - {"06", 98765, 19, "%-.20p", "0x000000000000000181cd", "%p with left-justify"}, - {"07", -98765, 8, "%p", "0xfffe7e33", "%p, negative value"}, - {"08", 4108, 4, "%8p", " 0x100c", "%p with minimum field size > number of digits"}, - {"09", 55220, 6, "%010p", "0x0000d7b4", "%p with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, (void *)osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, (void *)osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_s.c b/src/unit-tests/osprintf-test/ut_osprintf_s.c deleted file mode 100644 index 9ee055b4d..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_s.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_s.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %s format - *****************************************************************************/ -void UT_osprintf_s(void) -{ - char *test_fmt = "s"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - char test_val[30]; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", "123456789abcd", 7, "%s", "123456789abcd", "%s"}, - {"02", "123456789abcd", 7, "$$$%s$$$", "$$$123456789abcd$$$", "%s embedded"}, - {"03", "123456789abcd", 11, "%20s", " 123456789abcd", "%s with minimum field size"}, - {"04", "123456789abcd", 8, "%.10s", "123456789a", "%s with maximum field size"}, - {"05", "123456789abcd", 7, "%5.7s", "1234567", "%s with minimum and maximum field size"}, - {"06", "123456789abcd", 10, "%-20s", "123456789abcd ", "%s with left-justify"}, - {"07", "3456789abcd", 7, "%+s", "3456789abcd", "%s with sign"}, - {"08", "", 3, "%s", "", "%s with null string"}, - {"09", "123456789abcd", 11, "%020s", " 123456789abcd", "%s with minimum field size, ignore zero padding"}, - {"", "", 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_u.c b/src/unit-tests/osprintf-test/ut_osprintf_u.c deleted file mode 100644 index ff9bcafd8..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_u.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_u.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %u format - *****************************************************************************/ -void UT_osprintf_u(void) -{ - char *test_fmt = "u"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 98765, 5, "%u", "98765", "%u"}, - {"02", 46372, 10, "$$$%u$$$", "$$$46372$$$", "%u embedded"}, - {"03", 91827, 5, "%3u", "91827", "%u with maximum field size"}, - {"04", 33225, 8, "%.10u", "0000033225", "%u with minimum field size"}, - {"05", 12345, 7, "%9.7u", " 0012345", "%u with minimum and maximum field size"}, - {"06", 98765, 18, "%-.20u", "00000000000000098765", "%u with left-justify"}, - {"07", 98765, 5, "%+u", "98765", "%u with sign"}, - {"08", -98765, 8, "%u", "4294868531", "%u, negative value"}, - {"09", 0, 6, "%u", "0", "%u, zero value"}, - {"10", 162534, 5, "%08u", "00162534", "%u with zero padding"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_x.c b/src/unit-tests/osprintf-test/ut_osprintf_x.c deleted file mode 100644 index aebc3d671..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_x.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_x.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %x format - *****************************************************************************/ -void UT_osprintf_x(void) -{ - char *test_fmt = "x"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 0xa8b7, 3, "%x", "a8b7", "%x"}, - {"02", 0xff123, 10, "$$$%x$$$", "$$$ff123$$$", "%x embedded"}, - {"03", 0xd1827, 5, "%3x", "d1827", "%x with minimum field size < number of digits"}, - {"04", 0x3c225, 9, "%.10x", "000003c225", "%x with precision field size"}, - {"05", 0x12b45, 9, "%9.7x", " 0012b45", "%x with minimum and precision field size"}, - {"06", 0xe8a60, 19, "%-.20x", "000000000000000e8a60", "%x with left-justify"}, - {"07", -16, 7, "%x", "fffffff0", "%x, negative value"}, - {"08", 0x12b45, 3, "%8x", " 12b45", "%x with minimum field size > number of digits"}, - {"09", 0x12b45, 5, "%08x", "00012b45", "%x with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_x_uc.c b/src/unit-tests/osprintf-test/ut_osprintf_x_uc.c deleted file mode 100644 index ceac0202a..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_x_uc.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_X.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %X format - *****************************************************************************/ -void UT_osprintf_X(void) -{ - char *test_fmt = "x"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 0xa8b7, 3, "%X", "A8B7", "%X"}, - {"02", 0xff123, 10, "$$$%X$$$", "$$$FF123$$$", "%X embedded"}, - {"03", 0xd1827, 5, "%3X", "D1827", "%X with minimum field size < number of digits"}, - {"04", 0x3c225, 9, "%.10X", "000003C225", "%X with precision field size"}, - {"05", 0x12b45, 7, "%9.7X", " 0012B45", "%X with minimum and precision field size"}, - {"06", 0xe8a60, 19, "%-.20X", "000000000000000E8A60", "%X with left-justify"}, - {"07", -16, 7, "%X", "FFFFFFF0", "%X, negative value"}, - {"08", 0x12b45, 4, "%8X", " 12B45", "%X with minimum field size > number of digits"}, - {"09", 0x12b45, 5, "%08X", "00012B45", "%X with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/ostimer-test/ut_ostimer_test.c b/src/unit-tests/ostimer-test/ut_ostimer_test.c index 6b6716f37..dcbe25d10 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_test.c +++ b/src/unit-tests/ostimer-test/ut_ostimer_test.c @@ -78,7 +78,7 @@ void UT_os_timercallback(osal_id_t timerId) static int32 loopCnt = 0, res = 0; static uint32 prevIntervalTime = 0; static uint32 currIntervalTime = 0; - static OS_time_t currTime = {0, 0}, endTime = {0, 0}; + static OS_time_t currTime = {0}, endTime = {0}; if (OS_ObjectIdEqual(timerId, g_timerId)) { @@ -94,7 +94,7 @@ void UT_os_timercallback(osal_id_t timerId) OS_GetLocalTime(&endTime); - currIntervalTime = 1000000 * (endTime.seconds - currTime.seconds) + endTime.microsecs - currTime.microsecs; + currIntervalTime = OS_TimeGetTotalMicroseconds(OS_TimeSubtract(endTime, currTime)); if (currIntervalTime >= prevIntervalTime) deltaTime = currIntervalTime - prevIntervalTime; diff --git a/src/unit-tests/ostimer-test/ut_ostimer_test.h b/src/unit-tests/ostimer-test/ut_ostimer_test.h index 100e80b49..126611d5c 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_test.h +++ b/src/unit-tests/ostimer-test/ut_ostimer_test.h @@ -24,8 +24,8 @@ ** Date: May 2013 **================================================================================*/ -#ifndef _UT_OSTIMER_TEST_H_ -#define _UT_OSTIMER_TEST_H_ +#ifndef UT_OSTIMER_TEST_H +#define UT_OSTIMER_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -56,7 +56,7 @@ /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSTIMER_TEST_H_ */ +#endif /* UT_OSTIMER_TEST_H */ /*================================================================================* ** End of File: ut_ostimer_test.h diff --git a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c index d1e0a15e9..304da7d6b 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c +++ b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c @@ -318,7 +318,7 @@ void UT_os_timercreate_test() /*-----------------------------------------------------*/ testDesc = "#6 Invalid-arg"; - if (OS_TimerCreate(&g_timerIds[5], g_timerNames[5], &g_clkAccuracy, NULL) == OS_TIMER_ERR_INVALID_ARGS) + if (OS_TimerCreate(&g_timerIds[5], g_timerNames[5], &g_clkAccuracy, NULL) == OS_INVALID_POINTER) UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); @@ -550,7 +550,7 @@ void UT_os_timerset_test() intervalTime = 5; g_toleranceVal = 0; - UT_OS_LOG("\nOS_TimerSet() - #3 Interval-too-short (clk_accuracy=%d)\n", (int)g_clkAccuracy); + UtPrintf("\nOS_TimerSet() - #3 Interval-too-short (clk_accuracy=%d)\n", (int)g_clkAccuracy); res = OS_TimerSet(g_timerIds[3], startTime, intervalTime); if (res == OS_SUCCESS) { @@ -588,7 +588,7 @@ void UT_os_timerset_test() startTime = 1000; intervalTime = 500000; g_toleranceVal = intervalTime / 20; /* 5% */ - UT_OS_LOG("\nOS_TimerSet() - #1 Nominal condition (clk_accuracy=%d)\n", (int)g_clkAccuracy); + UtPrintf("\nOS_TimerSet() - #1 Nominal condition (clk_accuracy=%d)\n", (int)g_clkAccuracy); res = OS_TimerSet(g_timerIds[4], startTime, intervalTime); if (res == OS_SUCCESS) { diff --git a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.h b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.h index 22ad95c14..eec6a7e94 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.h +++ b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.h @@ -24,8 +24,8 @@ ** Date: April 2013 **================================================================================*/ -#ifndef _UT_OSTIMER_TIMERIO_TEST_H_ -#define _UT_OSTIMER_TIMERIO_TEST_H_ +#ifndef UT_OSTIMER_TIMERIO_TEST_H +#define UT_OSTIMER_TIMERIO_TEST_H /*--------------------------------------------------------------------------------* ** Includes @@ -64,7 +64,7 @@ void UT_os_timergetinfo_test(void); /*--------------------------------------------------------------------------------*/ -#endif /* _UT_OSTIMER_TIMERIO_TEST_H_ */ +#endif /* UT_OSTIMER_TIMERIO_TEST_H */ /*================================================================================* ** End of File: ut_ostimer_timerio_test.h diff --git a/src/ut-stubs/osapi-utstub-binsem.c b/src/ut-stubs/osapi-utstub-binsem.c index 77f94d94e..f2f1c746e 100644 --- a/src/ut-stubs/osapi-utstub-binsem.c +++ b/src/ut-stubs/osapi-utstub-binsem.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-binsem.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_BinSemAPI_Init, (void)) @@ -130,7 +131,7 @@ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initia if (status == OS_SUCCESS) { - *sem_id = UT_AllocStubObjId(UT_OBJTYPE_BINSEM); + *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_BINSEM); } else { @@ -195,9 +196,9 @@ int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetInfo), bin_prop, sizeof(*bin_prop)) < sizeof(*bin_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &bin_prop->creator); - strncpy(bin_prop->name, "Name", OS_MAX_API_NAME - 1); - bin_prop->name[OS_MAX_API_NAME - 1] = '\0'; + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &bin_prop->creator); + strncpy(bin_prop->name, "Name", sizeof(bin_prop->name) - 1); + bin_prop->name[sizeof(bin_prop->name) - 1] = '\0'; } return status; @@ -233,7 +234,7 @@ int32 OS_BinSemDelete(osal_id_t sem_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_BINSEM, sem_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_BINSEM, sem_id); } return status; @@ -287,7 +288,7 @@ int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_BINSEM, sem_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_BINSEM, sem_id); } return status; diff --git a/src/ut-stubs/osapi-utstub-bsp.c b/src/ut-stubs/osapi-utstub-bsp.c index cb0262844..126b5bb7f 100644 --- a/src/ut-stubs/osapi-utstub-bsp.c +++ b/src/ut-stubs/osapi-utstub-bsp.c @@ -30,6 +30,7 @@ * can be executed. */ +#include "osapi-bsp.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" /* @@ -55,7 +56,7 @@ uint32 OS_BSP_GetArgC(void) ------------------------------------------------------------------*/ char *const *OS_BSP_GetArgV(void) { - void *buffer; + void *buffer = NULL; int32 status; status = UT_DEFAULT_IMPL(OS_BSP_GetArgV); diff --git a/src/ut-stubs/osapi-utstub-clock.c b/src/ut-stubs/osapi-utstub-clock.c index 7aaa20498..b13ce4798 100644 --- a/src/ut-stubs/osapi-utstub-clock.c +++ b/src/ut-stubs/osapi-utstub-clock.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-clock.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" /***************************************************************************** @@ -51,9 +52,8 @@ int32 OS_GetLocalTime(OS_time_t *time_struct) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_GetLocalTime), time_struct, sizeof(*time_struct)) < sizeof(*time_struct)) { - count = UT_GetStubCount(UT_KEY(OS_GetLocalTime)); - time_struct->microsecs = 10000 * (count % 100); - time_struct->seconds = 1 + (count / 100); + count = UT_GetStubCount(UT_KEY(OS_GetLocalTime)); + *time_struct = OS_TimeAssembleFromNanoseconds(1 + (count / 100), 10000000 * (count % 100)); } return status; @@ -65,7 +65,7 @@ int32 OS_GetLocalTime(OS_time_t *time_struct) * Stub function for OS_SetLocalTime() * *****************************************************************************/ -int32 OS_SetLocalTime(OS_time_t *time_struct) +int32 OS_SetLocalTime(const OS_time_t *time_struct) { UT_Stub_RegisterContext(UT_KEY(OS_SetLocalTime), time_struct); diff --git a/src/ut-stubs/osapi-utstub-common.c b/src/ut-stubs/osapi-utstub-common.c index 6ebc96c8a..bd121f640 100644 --- a/src/ut-stubs/osapi-utstub-common.c +++ b/src/ut-stubs/osapi-utstub-common.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-common.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" /***************************************************************************** diff --git a/src/ut-stubs/osapi-utstub-countsem.c b/src/ut-stubs/osapi-utstub-countsem.c index f6cc0db10..31c7faaa7 100644 --- a/src/ut-stubs/osapi-utstub-countsem.c +++ b/src/ut-stubs/osapi-utstub-countsem.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-countsem.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_CountSemAPI_Init, (void)) @@ -54,7 +55,7 @@ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_init if (status == OS_SUCCESS) { - *sem_id = UT_AllocStubObjId(UT_OBJTYPE_COUNTSEM); + *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_COUNTSEM); } else { @@ -94,7 +95,7 @@ int32 OS_CountSemDelete(osal_id_t sem_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_COUNTSEM, sem_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_COUNTSEM, sem_id); } return status; @@ -166,7 +167,7 @@ int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_CountSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_COUNTSEM, sem_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_COUNTSEM, sem_id); } return status; @@ -200,9 +201,9 @@ int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_CountSemGetInfo), count_prop, sizeof(*count_prop)) < sizeof(*count_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &count_prop->creator); - strncpy(count_prop->name, "Name", OS_MAX_API_NAME - 1); - count_prop->name[OS_MAX_API_NAME - 1] = '\0'; + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &count_prop->creator); + strncpy(count_prop->name, "Name", sizeof(count_prop->name) - 1); + count_prop->name[sizeof(count_prop->name) - 1] = '\0'; } return status; diff --git a/src/ut-stubs/osapi-utstub-dir.c b/src/ut-stubs/osapi-utstub-dir.c index a918974d1..43ad38760 100644 --- a/src/ut-stubs/osapi-utstub-dir.c +++ b/src/ut-stubs/osapi-utstub-dir.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-dir.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_DirAPI_Init, (void)) @@ -85,7 +86,7 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) if (Status == OS_SUCCESS) { - *dir_id = UT_AllocStubObjId(UT_OBJTYPE_DIR); + *dir_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_DIR); } else { @@ -110,7 +111,7 @@ int32 OS_DirectoryClose(osal_id_t dir_id) if (Status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_DIR, dir_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_DIR, dir_id); } return Status; @@ -143,7 +144,7 @@ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) UT_Stub_RegisterContext(UT_KEY(OS_DirectoryRead), dirent); int32 Status; - uint32 CopySize; + size_t CopySize; Status = UT_DEFAULT_IMPL(OS_DirectoryRead); diff --git a/src/ut-stubs/osapi-utstub-errors.c b/src/ut-stubs/osapi-utstub-errors.c index 082881ae1..151b44cc4 100644 --- a/src/ut-stubs/osapi-utstub-errors.c +++ b/src/ut-stubs/osapi-utstub-errors.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-error.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name) diff --git a/src/ut-stubs/osapi-utstub-file.c b/src/ut-stubs/osapi-utstub-file.c index 710accaed..29a73f4c6 100644 --- a/src/ut-stubs/osapi-utstub-file.c +++ b/src/ut-stubs/osapi-utstub-file.c @@ -32,6 +32,8 @@ * can be executed. */ +#include "osapi-file.h" /* OSAL public API for this subsystem */ +#include "osapi-idmap.h" #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_FileAPI_Init, (void)) @@ -41,10 +43,10 @@ UT_DEFAULT_STUB(OS_FileAPI_Init, (void)) * Local Stub helper function for reading * *****************************************************************************/ -static int32 UT_GenericReadStub(const char *fname, UT_EntryKey_t fkey, void *buffer, uint32 bsize) +static int32 UT_GenericReadStub(const char *fname, UT_EntryKey_t fkey, void *buffer, size_t bsize) { int32 status; - uint32 CopySize; + size_t CopySize; status = UT_DefaultStubImpl(fname, fkey, 0x7FFFFFFF); @@ -79,10 +81,10 @@ static int32 UT_GenericReadStub(const char *fname, UT_EntryKey_t fkey, void *buf * Local Stub helper function for writing * *****************************************************************************/ -static int32 UT_GenericWriteStub(const char *fname, UT_EntryKey_t fkey, const void *buffer, uint32 bsize) +static int32 UT_GenericWriteStub(const char *fname, UT_EntryKey_t fkey, const void *buffer, size_t bsize) { int32 status; - uint32 CopySize; + size_t CopySize; status = UT_DefaultStubImpl(fname, fkey, 0x7FFFFFFF); @@ -124,7 +126,7 @@ int32 OS_creat(const char *path, int32 access) if (status == OS_SUCCESS) { - objid = UT_AllocStubObjId(UT_OBJTYPE_FILESTREAM); + objid = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); status = OS_ObjectIdToInteger(objid); } @@ -148,7 +150,7 @@ int32 OS_open(const char *path, int32 access, uint32 mode) if (status == OS_SUCCESS) { - objid = UT_AllocStubObjId(UT_OBJTYPE_FILESTREAM); + objid = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); status = OS_ObjectIdToInteger(objid); } @@ -173,7 +175,7 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc status = UT_DEFAULT_IMPL(OS_OpenCreate); if (status == OS_SUCCESS) { - *filedes = UT_AllocStubObjId(UT_OBJTYPE_FILESTREAM); + *filedes = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); } else { @@ -198,7 +200,7 @@ int32 OS_close(osal_id_t filedes) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_FILESTREAM, filedes); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_STREAM, filedes); } return status; @@ -209,7 +211,7 @@ int32 OS_close(osal_id_t filedes) * Stub function for OS_StreamRead() * *****************************************************************************/ -int32 OS_StreamRead(osal_id_t filedes, void *buffer, uint32 nbytes, int32 timeout) +int32 OS_StreamRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout) { return UT_GenericReadStub(__func__, UT_KEY(OS_StreamRead), buffer, nbytes); } @@ -219,7 +221,7 @@ int32 OS_StreamRead(osal_id_t filedes, void *buffer, uint32 nbytes, int32 timeou * Stub function for OS_StreamWrite() * *****************************************************************************/ -int32 OS_StreamWrite(osal_id_t filedes, const void *buffer, uint32 nbytes, int32 timeout) +int32 OS_StreamWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout) { return UT_GenericWriteStub(__func__, UT_KEY(OS_StreamWrite), buffer, nbytes); } @@ -229,7 +231,7 @@ int32 OS_StreamWrite(osal_id_t filedes, const void *buffer, uint32 nbytes, int32 * Stub function for OS_read() * *****************************************************************************/ -int32 OS_read(osal_id_t filedes, void *buffer, uint32 nbytes) +int32 OS_read(osal_id_t filedes, void *buffer, size_t nbytes) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_read), filedes); UT_Stub_RegisterContext(UT_KEY(OS_read), buffer); @@ -243,7 +245,7 @@ int32 OS_read(osal_id_t filedes, void *buffer, uint32 nbytes) * Stub function for OS_write() * *****************************************************************************/ -int32 OS_write(osal_id_t filedes, const void *buffer, uint32 nbytes) +int32 OS_write(osal_id_t filedes, const void *buffer, size_t nbytes) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_write), filedes); UT_Stub_RegisterContext(UT_KEY(OS_write), buffer); @@ -257,7 +259,7 @@ int32 OS_write(osal_id_t filedes, const void *buffer, uint32 nbytes) * Stub function for OS_TimedRead() * *****************************************************************************/ -int32 OS_TimedRead(osal_id_t filedes, void *buffer, uint32 nbytes, int32 timeout) +int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimedRead), filedes); UT_Stub_RegisterContext(UT_KEY(OS_TimedRead), buffer); @@ -272,7 +274,7 @@ int32 OS_TimedRead(osal_id_t filedes, void *buffer, uint32 nbytes, int32 timeout * Stub function for OS_TimedWrite() * *****************************************************************************/ -int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, uint32 nbytes, int32 timeout) +int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimedWrite), filedes); UT_Stub_RegisterContext(UT_KEY(OS_TimedWrite), buffer); @@ -416,7 +418,7 @@ int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) UT_Stub_RegisterContext(UT_KEY(OS_FDGetInfo), fd_prop); int32 status; - uint32 CopySize; + size_t CopySize; status = UT_DEFAULT_IMPL(OS_FDGetInfo); @@ -428,7 +430,7 @@ int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) { memset(fd_prop, 0, sizeof(*fd_prop)); fd_prop->IsValid = true; - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &fd_prop->User); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &fd_prop->User); } } diff --git a/src/ut-stubs/osapi-utstub-filesys.c b/src/ut-stubs/osapi-utstub-filesys.c index 12437d88c..57393fc7a 100644 --- a/src/ut-stubs/osapi-utstub-filesys.c +++ b/src/ut-stubs/osapi-utstub-filesys.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-filesys.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_FileSysAPI_Init, (void)) @@ -53,7 +54,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const if (status == OS_SUCCESS) { - *filesys_id = UT_AllocStubObjId(UT_OBJTYPE_FILESYS); + *filesys_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_FILESYS); } else { @@ -68,7 +69,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const * Stub function for OS_mkfs() * *****************************************************************************/ -int32 OS_mkfs(char *address, const char *devname, const char *volname, uint32 blocksize, uint32 numblocks) +int32 OS_mkfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks) { UT_Stub_RegisterContext(UT_KEY(OS_mkfs), address); UT_Stub_RegisterContext(UT_KEY(OS_mkfs), devname); @@ -104,7 +105,7 @@ int32 OS_rmfs(const char *devname) * Stub function for OS_initfs() * *****************************************************************************/ -int32 OS_initfs(char *address, const char *devname, const char *volname, uint32 blocksize, uint32 numblocks) +int32 OS_initfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks) { UT_Stub_RegisterContext(UT_KEY(OS_initfs), address); UT_Stub_RegisterContext(UT_KEY(OS_initfs), devname); @@ -152,6 +153,8 @@ int32 OS_unmount(const char *mountpoint) return status; } +#ifndef OSAL_OMIT_DEPRECATED + /***************************************************************************** * * Stub function for OS_fsBlocksFree() @@ -191,6 +194,31 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) return status; } +#endif /* OSAL_OMIT_DEPRECATED */ + +/***************************************************************************** + * + * Stub function for OS_FileSysStatVolume() + * + *****************************************************************************/ +int32 OS_FileSysStatVolume(const char *name, OS_statvfs_t *statbuf) +{ + UT_Stub_RegisterContext(UT_KEY(OS_FileSysStatVolume), name); + UT_Stub_RegisterContext(UT_KEY(OS_FileSysStatVolume), statbuf); + + int32 status; + + status = UT_DEFAULT_IMPL(OS_FileSysStatVolume); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_FileSysStatVolume), statbuf, sizeof(*statbuf)) < sizeof(*statbuf)) + { + memset(statbuf, 0, sizeof(*statbuf)); + } + + return status; +} + /***************************************************************************** * * Stub function for OS_chkfs() @@ -221,7 +249,8 @@ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) int32 status; status = UT_DEFAULT_IMPL(OS_FS_GetPhysDriveName); - strncpy(PhysDriveName, MountPoint, OS_FS_PHYS_NAME_LEN); + strncpy(PhysDriveName, MountPoint, OS_FS_PHYS_NAME_LEN - 1); + PhysDriveName[OS_FS_PHYS_NAME_LEN - 1] = 0; return status; } @@ -260,7 +289,8 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) if (status == OS_SUCCESS && VirtualPath != NULL && LocalPath != NULL && UT_Stub_CopyToLocal(UT_KEY(OS_TranslatePath), LocalPath, OS_MAX_LOCAL_PATH_LEN) == 0) { - strncpy(LocalPath, VirtualPath, OS_MAX_LOCAL_PATH_LEN); + strncpy(LocalPath, VirtualPath, OS_MAX_LOCAL_PATH_LEN - 1); + LocalPath[OS_MAX_LOCAL_PATH_LEN - 1] = 0; } return status; diff --git a/src/ut-stubs/osapi-utstub-heap.c b/src/ut-stubs/osapi-utstub-heap.c index 3fdf50c6d..bf3145f75 100644 --- a/src/ut-stubs/osapi-utstub-heap.c +++ b/src/ut-stubs/osapi-utstub-heap.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-heap.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" /***************************************************************************** @@ -51,9 +52,9 @@ int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop) UT_Stub_CopyToLocal(UT_KEY(OS_HeapGetInfo), heap_prop, sizeof(*heap_prop)) < sizeof(*heap_prop)) { /* Return some random data */ - heap_prop->free_bytes = (uint32)12345; - heap_prop->free_blocks = (uint32)6789; - heap_prop->largest_free_block = (uint32)100; + heap_prop->free_bytes = OSAL_SIZE_C(12345); + heap_prop->free_blocks = OSAL_BLOCKCOUNT_C(6789); + heap_prop->largest_free_block = OSAL_SIZE_C(100); } return status; diff --git a/src/ut-stubs/osapi-utstub-idmap.c b/src/ut-stubs/osapi-utstub-idmap.c index a1dbfbfbc..4521ba0e8 100644 --- a/src/ut-stubs/osapi-utstub-idmap.c +++ b/src/ut-stubs/osapi-utstub-idmap.c @@ -36,17 +36,29 @@ * OSAL itself (not for coverage testing other units). */ +#include "osapi-idmap.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" #include "os-shared-idmap.h" +/* + * UT Helper function to create a fake object lock token + */ +static void UT_TokenCompose(uint32 lock_mode, uint32 indx, osal_objtype_t objtype, OS_object_token_t *token) +{ + token->lock_mode = lock_mode; + token->obj_type = objtype; + token->obj_idx = indx; + UT_ObjIdCompose(indx, objtype, &token->obj_id); +} + UT_DEFAULT_STUB(OS_ObjectIdInit, (void)) /* Lock/Unlock for global tables */ -void OS_Lock_Global(uint32 idtype) +void OS_Lock_Global(OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_Lock_Global); } -void OS_Unlock_Global(uint32 idtype) +void OS_Unlock_Global(OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_Unlock_Global); } @@ -56,11 +68,11 @@ void OS_Unlock_Global(uint32 idtype) * Stub function for OS_GetMaxForObjectType() * *****************************************************************************/ -uint32 OS_GetMaxForObjectType(uint32 idtype) +uint32 OS_GetMaxForObjectType(osal_objtype_t idtype) { int32 max; - if (idtype > UT_OBJTYPE_NONE && idtype < UT_OBJTYPE_MAX) + if (idtype > OS_OBJECT_TYPE_UNDEFINED && idtype < OS_OBJECT_TYPE_USER) { max = OSAL_MAX_VALID_PER_TYPE; } @@ -77,11 +89,11 @@ uint32 OS_GetMaxForObjectType(uint32 idtype) * Stub function for OS_GetBaseForObjectType() * *****************************************************************************/ -uint32 OS_GetBaseForObjectType(uint32 idtype) +uint32 OS_GetBaseForObjectType(osal_objtype_t idtype) { int32 base; - if (idtype > UT_OBJTYPE_NONE && idtype < UT_OBJTYPE_MAX) + if (idtype > OS_OBJECT_TYPE_UNDEFINED && idtype < OS_OBJECT_TYPE_USER) { base = OSAL_MAX_VALID_PER_TYPE * (idtype - 1); } @@ -98,10 +110,11 @@ uint32 OS_GetBaseForObjectType(uint32 idtype) * Stub function for OS_ObjectIdToArrayIndex() * *****************************************************************************/ -int32 OS_ObjectIdToArrayIndex(uint32 idtype, osal_id_t id, uint32 *ArrayIndex) +int32 OS_ObjectIdToArrayIndex(osal_objtype_t idtype, osal_id_t id, osal_index_t *ArrayIndex) { - int32 Status; - UT_ObjType_t checktype; + int32 Status; + osal_objtype_t checktype; + uint32 tempserial; Status = UT_DEFAULT_IMPL(OS_ObjectIdToArrayIndex); @@ -109,28 +122,51 @@ int32 OS_ObjectIdToArrayIndex(uint32 idtype, osal_id_t id, uint32 *ArrayIndex) UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdToArrayIndex), ArrayIndex, sizeof(*ArrayIndex)) < sizeof(*ArrayIndex)) { /* this needs to output something valid or code will break */ - UT_ObjIdDecompose(id, ArrayIndex, &checktype); + UT_ObjIdDecompose(id, &tempserial, &checktype); + *ArrayIndex = OSAL_INDEX_C(tempserial); } return Status; } +/***************************************************************************** + * + * Stub function for OS_ObjectIdGlobalFromToken() + * + *****************************************************************************/ +OS_common_record_t *OS_ObjectIdGlobalFromToken(const OS_object_token_t *token) +{ + static OS_common_record_t fake_record; + int32 status; + OS_common_record_t * recptr = &fake_record; + + status = UT_DEFAULT_IMPL(OS_ObjectIdGlobalFromToken); + if (status == 0 && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGlobalFromToken), &recptr, sizeof(recptr)) < sizeof(recptr)) + { + /* This function should never return null */ + recptr = &fake_record; + } + + return recptr; +} + /***************************************************************************** * * Stub function for OS_ObjectIdFinalize() * *****************************************************************************/ -int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, osal_id_t *outid) +int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_object_token_t *token, osal_id_t *outid) { int32 Status; Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdFinalizeNew, operation_status); /* need to actually write something to the output buffer */ - if (Status == OS_SUCCESS && record != NULL && outid != NULL && + if (Status == OS_SUCCESS && token != NULL && outid != NULL && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdFinalizeNew), outid, sizeof(*outid)) < sizeof(*outid)) { - *outid = record->active_id; + *outid = token->obj_id; } return Status; @@ -141,7 +177,7 @@ int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, * Stub function for OS_ObjectIdFinalizeDelete() * *****************************************************************************/ -int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *record) +int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_object_token_t *token) { int32 Status; @@ -155,11 +191,10 @@ int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *reco * Stub function for OS_ObjectIdFindMatch() * *****************************************************************************/ -int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, - OS_common_record_t **record) +int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, + OS_object_token_t *token) { - int32 Status; - static OS_common_record_t fake_record; + int32 Status; /* by default this stub should return NAME_NOT_FOUND * unless the test case has set up otherwise. To set @@ -168,12 +203,10 @@ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, OS_ObjectM */ Status = UT_DEFAULT_IMPL(OS_ObjectIdGetBySearch); - if (Status == OS_SUCCESS && record != NULL && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetBySearch), record, sizeof(*record)) < sizeof(*record)) + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetBySearch), token, sizeof(*token)) < sizeof(*token)) { - memset(&fake_record, 0, sizeof(fake_record)); - UT_ObjIdCompose(1, idtype, &fake_record.active_id); - *record = &fake_record; + UT_TokenCompose(lock_mode, 1, idtype, token); } return Status; @@ -181,10 +214,40 @@ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, OS_ObjectM /***************************************************************************** * - * Stub function for OS_ObjectIdFindByName(, &fake_record.active_id) + * Stub function for OS_ObjectIdTransactionInit() * *****************************************************************************/ -int32 OS_ObjectIdFindByName(uint32 idtype, const char *name, osal_id_t *object_id) +int32 OS_ObjectIdTransactionInit(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_object_token_t *token) +{ + int32 Status; + + Status = UT_DEFAULT_IMPL(OS_ObjectIdTransactionInit); + + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdTransactionInit), token, sizeof(*token)) < sizeof(*token)) + { + memset(&token, 0, sizeof(token)); + } + + return Status; +} + +/***************************************************************************** + * + * Stub function for OS_ObjectIdTransactionCancel() + * + *****************************************************************************/ +void OS_ObjectIdTransactionCancel(OS_object_token_t *token) +{ + UT_DEFAULT_IMPL(OS_ObjectIdTransactionCancel); +} + +/***************************************************************************** + * + * Stub function for OS_ObjectIdFindByName() + * + *****************************************************************************/ +int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t *object_id) { int32 Status; @@ -206,32 +269,19 @@ int32 OS_ObjectIdFindByName(uint32 idtype, const char *name, osal_id_t *object_i /***************************************************************************** * - * Stub function for OS_ObjectIdGetByName(,object_id) + * Stub function for OS_ObjectIdGetByName() * *****************************************************************************/ -int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, uint32 idtype, const char *name, OS_common_record_t **record) +int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, OS_object_token_t *token) { - int32 Status; - OS_common_record_t * local_record; - static OS_common_record_t fake_record; + int32 Status; Status = UT_DEFAULT_IMPL(OS_ObjectIdGetByName); - if (Status == 0) + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetByName), token, sizeof(*token)) < sizeof(*token)) { - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetByName), &local_record, sizeof(local_record)) < - sizeof(local_record)) - { - memset(&fake_record, 0, sizeof(fake_record)); - local_record = &fake_record; - UT_ObjIdCompose(1, idtype, &fake_record.active_id); - } - - /* this needs to output something valid or code will break */ - if (record != NULL) - { - *record = local_record; - } + UT_TokenCompose(lock_mode, 1, idtype, token); } return Status; @@ -239,43 +289,18 @@ int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, uint32 idtype, const char * /***************************************************************************** * - * Stub function for OS_ObjectIdGetById(, &fake_record.active_id) + * Stub function for OS_ObjectIdGetById() * *****************************************************************************/ -int32 OS_ObjectIdGetById(OS_lock_mode_t check_mode, uint32 idtype, osal_id_t id, uint32 *array_index, - OS_common_record_t **record) +int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, OS_object_token_t *token) { - int32 Status; - uint32 local_id; - UT_ObjType_t checktype; - OS_common_record_t * local_record; - static OS_common_record_t fake_record; + int32 Status; Status = UT_DEFAULT_IMPL(OS_ObjectIdGetById); - if (Status == 0) + if (Status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetById), token, sizeof(*token)) < sizeof(*token)) { - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetById), &local_id, sizeof(local_id)) < sizeof(local_id)) - { - UT_ObjIdDecompose(id, &local_id, &checktype); - } - - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetById), &local_record, sizeof(local_record)) < sizeof(local_record)) - { - memset(&fake_record, 0, sizeof(fake_record)); - fake_record.active_id = id; - local_record = &fake_record; - } - - /* this needs to output something valid or code will break */ - if (array_index != NULL) - { - *array_index = local_id; - } - if (record != NULL) - { - *record = local_record; - } + UT_TokenCompose(lock_mode, OS_ObjectIdToInteger(id) & 0xFFFF, idtype, token); } return Status; @@ -283,16 +308,31 @@ int32 OS_ObjectIdGetById(OS_lock_mode_t check_mode, uint32 idtype, osal_id_t id, /***************************************************************************** * - * Stub function for OS_ObjectIdRefcountDecr() + * Stub function for OS_ObjectIdRelease() + * + *****************************************************************************/ +void OS_ObjectIdRelease(OS_object_token_t *token) +{ + UT_DEFAULT_IMPL(OS_ObjectIdRelease); +} + +/***************************************************************************** + * + * Stub function for OS_ObjectIdTransferToken() * *****************************************************************************/ -int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record) +void OS_ObjectIdTransferToken(OS_object_token_t *token_from, OS_object_token_t *token_to) { int32 Status; - Status = UT_DEFAULT_IMPL(OS_ObjectIdRefcountDecr); + Status = UT_DEFAULT_IMPL(OS_ObjectIdTransferToken); - return Status; + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdTransferToken), token_to, sizeof(*token_to)) < sizeof(*token_to)) + { + /* just copy it if nothing specified */ + *token_to = *token_from; + } } /***************************************************************************** @@ -300,7 +340,7 @@ int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record) * Stub function for OS_ObjectIdGetNext() * *****************************************************************************/ -int32 OS_ObjectIdGetNext(uint32 idtype, uint32 *curr_index, OS_common_record_t **record) +int32 OS_ObjectIdGetNext(osal_objtype_t idtype, uint32 *curr_index, OS_common_record_t **record) { int32 Status; uint32 local_id; @@ -347,35 +387,19 @@ int32 OS_ObjectIdGetNext(uint32 idtype, uint32 *curr_index, OS_common_record_t * /***************************************************************************** * - * Stub function for OS_ObjectIdAllocateNew(, &fake_record.active_id) + * Stub function for OS_ObjectIdAllocateNew() * *****************************************************************************/ -int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_index, OS_common_record_t **record) +int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token) { - int32 Status; - uint32 local_id; - OS_common_record_t * local_record; - static OS_common_record_t fake_record; + int32 Status; Status = UT_DEFAULT_IMPL(OS_ObjectIdAllocateNew); - if (Status == 0) + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdAllocateNew), token, sizeof(*token)) < sizeof(*token)) { - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdAllocateNew), &local_id, sizeof(local_id)) < sizeof(local_id)) - { - local_id = UT_GetStubCount(UT_KEY(OS_ObjectIdAllocateNew)) & 0xFFFF; - } - - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdAllocateNew), &local_record, sizeof(local_record)) < - sizeof(local_record)) - { - memset(&fake_record, 0, sizeof(fake_record)); - UT_ObjIdCompose(local_id, idtype, &fake_record.active_id); - local_record = &fake_record; - } - - *record = local_record; - *array_index = local_id; + UT_TokenCompose(OS_LOCK_MODE_GLOBAL, UT_GetStubCount(UT_KEY(OS_ObjectIdAllocateNew)), idtype, token); } return Status; @@ -389,7 +413,7 @@ int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_inde returns: status ---------------------------------------------------------------------------------------*/ -int32 OS_GetResourceName(osal_id_t object_id, char *buffer, uint32 buffer_size) +int32 OS_GetResourceName(osal_id_t object_id, char *buffer, size_t buffer_size) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_GetResourceName), object_id); UT_Stub_RegisterContext(UT_KEY(OS_GetResourceName), buffer); @@ -421,22 +445,23 @@ int32 OS_GetResourceName(osal_id_t object_id, char *buffer, uint32 buffer_size) returns: status ---------------------------------------------------------------------------------------*/ -int32 OS_ConvertToArrayIndex(osal_id_t object_id, uint32 *ArrayIndex) +int32 OS_ConvertToArrayIndex(osal_id_t object_id, osal_index_t *ArrayIndex) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ConvertToArrayIndex), object_id); UT_Stub_RegisterContext(UT_KEY(OS_ConvertToArrayIndex), ArrayIndex); - int32 return_code; + int32 return_code; + uint32 tempserial; return_code = UT_DEFAULT_IMPL(OS_ConvertToArrayIndex); if (return_code == OS_SUCCESS) { - UT_ObjType_t ObjType; - UT_ObjIdDecompose(object_id, ArrayIndex, &ObjType); - if (ObjType != UT_OBJTYPE_NONE && ObjType < UT_OBJTYPE_MAX) + osal_objtype_t ObjType; + UT_ObjIdDecompose(object_id, &tempserial, &ObjType); + if (ObjType != OS_OBJECT_TYPE_UNDEFINED && ObjType < OS_OBJECT_TYPE_USER) { - *ArrayIndex %= UT_MAXOBJS[ObjType]; + tempserial %= UT_MAXOBJS[ObjType]; } } else @@ -445,9 +470,11 @@ int32 OS_ConvertToArrayIndex(osal_id_t object_id, uint32 *ArrayIndex) * If set to fail, then set the output to something bizarre - if the code * actually tries to use this, chances are it will segfault and be fixed */ - *ArrayIndex = 0xDEADBEEFU; + tempserial = 0xDEADBEEFU; } + *ArrayIndex = OSAL_INDEX_C(tempserial); + return return_code; } /* end OS_ConvertToArrayIndex */ @@ -458,7 +485,8 @@ int32 OS_ConvertToArrayIndex(osal_id_t object_id, uint32 *ArrayIndex) returns: None ---------------------------------------------------------------------------------------*/ -void OS_ForEachObjectOfType(uint32 objtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg) +void OS_ForEachObjectOfType(osal_objtype_t objtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, + void *callback_arg) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ForEachObjectOfType), objtype); UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ForEachObjectOfType), creator_id); @@ -466,7 +494,7 @@ void OS_ForEachObjectOfType(uint32 objtype, osal_id_t creator_id, OS_ArgCallback UT_Stub_RegisterContext(UT_KEY(OS_ForEachObjectOfType), callback_arg); osal_id_t NextId; - uint32 IdSize; + size_t IdSize; /* Although this is "void", Invoke the default impl to log it and invoke any hooks */ UT_DEFAULT_IMPL(OS_ForEachObjectOfType); @@ -497,7 +525,7 @@ void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void UT_Stub_RegisterContext(UT_KEY(OS_ForEachObject), callback_arg); osal_id_t NextId; - uint32 IdSize; + size_t IdSize; /* Although this is "void", Invoke the default impl to log it and invoke any hooks */ UT_DEFAULT_IMPL(OS_ForEachObject); @@ -513,6 +541,77 @@ void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void } } +int32 OS_ObjectIdIteratorInit(OS_ObjectMatchFunc_t matchfunc, void *matcharg, osal_objtype_t objtype, + OS_object_iter_t *iter) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), matchfunc); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), matcharg); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), objtype); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), iter); + + int32 Status; + + Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdIteratorInit, 1); + + if (Status == 1 && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIteratorGetNext), iter, sizeof(*iter)) < sizeof(*iter)) + { + memset(iter, 0, sizeof(*iter)); + Status = OS_SUCCESS; + } + + return Status; +} + +int32 OS_ObjectIdIterateActive(osal_objtype_t objtype, OS_object_iter_t *iter) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIterateActive), objtype); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIterateActive), iter); + + int32 Status; + + Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdIterateActive, 1); + + if (Status == 1 && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIterateActive), iter, sizeof(*iter)) < sizeof(*iter)) + { + memset(iter, 0, sizeof(*iter)); + Status = OS_SUCCESS; + } + + return Status; +} + +bool OS_ObjectIdIteratorGetNext(OS_object_iter_t *iter) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorGetNext), iter); + + int32 Status; + + Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdIteratorGetNext, -1); + + if (Status == -1) + { + /* if test case has registered something, return true, otherwise return false */ + Status = (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIteratorGetNext), &iter->token, sizeof(iter->token)) == + sizeof(iter->token)); + } + + return (bool)Status; +} + +void OS_ObjectIdIteratorDestroy(OS_object_iter_t *iter) +{ + UT_DEFAULT_IMPL(OS_ObjectIdIteratorDestroy); +} + +int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t, void *)) +{ + int32 Status; + + Status = UT_DEFAULT_IMPL(OS_ObjectIdIteratorProcessEntry); + + return Status; +} + /*--------------------------------------------------------------------------------------- Name: OS_IdentifyObject @@ -520,55 +619,17 @@ void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void returns: The type of object that the ID represents ---------------------------------------------------------------------------------------*/ -uint32 OS_IdentifyObject(osal_id_t object_id) +osal_objtype_t OS_IdentifyObject(osal_id_t object_id) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_IdentifyObject), object_id); - UT_ObjType_t ObjType; - uint32 checkindx; - int32 DefaultType; + osal_objtype_t ObjType; + uint32 checkindx; + int32 DefaultType; UT_ObjIdDecompose(object_id, &checkindx, &ObjType); - switch (ObjType) - { - case UT_OBJTYPE_TASK: - DefaultType = OS_OBJECT_TYPE_OS_TASK; - break; - case UT_OBJTYPE_QUEUE: - DefaultType = OS_OBJECT_TYPE_OS_QUEUE; - break; - case UT_OBJTYPE_COUNTSEM: - DefaultType = OS_OBJECT_TYPE_OS_COUNTSEM; - break; - case UT_OBJTYPE_BINSEM: - DefaultType = OS_OBJECT_TYPE_OS_BINSEM; - break; - case UT_OBJTYPE_MUTEX: - DefaultType = OS_OBJECT_TYPE_OS_MUTEX; - break; - case UT_OBJTYPE_TIMECB: - DefaultType = OS_OBJECT_TYPE_OS_TIMECB; - break; - case UT_OBJTYPE_MODULE: - DefaultType = OS_OBJECT_TYPE_OS_MODULE; - break; - case UT_OBJTYPE_FILESTREAM: - DefaultType = OS_OBJECT_TYPE_OS_STREAM; - break; - case UT_OBJTYPE_TIMEBASE: - DefaultType = OS_OBJECT_TYPE_OS_TIMEBASE; - break; - case UT_OBJTYPE_DIR: - DefaultType = OS_OBJECT_TYPE_OS_DIR; - break; - case UT_OBJTYPE_FILESYS: - DefaultType = OS_OBJECT_TYPE_OS_FILESYS; - break; - default: - DefaultType = OS_OBJECT_TYPE_UNDEFINED; - break; - } + DefaultType = UT_DEFAULT_IMPL_RC(OS_IdentifyObject, ObjType); - return UT_DEFAULT_IMPL_RC(OS_IdentifyObject, DefaultType); + return DefaultType; } diff --git a/src/ut-stubs/osapi-utstub-module.c b/src/ut-stubs/osapi-utstub-module.c index e5d4e4054..e62c85d2b 100644 --- a/src/ut-stubs/osapi-utstub-module.c +++ b/src/ut-stubs/osapi-utstub-module.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-module.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_ModuleAPI_Init, (void)) @@ -80,11 +81,12 @@ int32 dummy_function(void) ** Returns either a user-defined status flag or OS_SUCCESS. ** ******************************************************************************/ -int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *filename) +int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *filename, uint32 flags) { UT_Stub_RegisterContext(UT_KEY(OS_ModuleLoad), module_id); UT_Stub_RegisterContext(UT_KEY(OS_ModuleLoad), module_name); UT_Stub_RegisterContext(UT_KEY(OS_ModuleLoad), filename); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ModuleLoad), flags); int32 status; @@ -92,7 +94,7 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f if (status == OS_SUCCESS) { - *module_id = UT_AllocStubObjId(UT_OBJTYPE_MODULE); + *module_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_MODULE); } else { @@ -132,7 +134,7 @@ int32 OS_ModuleUnload(osal_id_t module_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_MODULE, module_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_MODULE, module_id); } return status; @@ -228,7 +230,40 @@ int32 OS_SymbolLookup(cpuaddr *symbol_address, const char *symbol_name) * Stub function for OS_SymbolTableDump() * *****************************************************************************/ -int32 OS_SymbolTableDump(const char *filename, uint32 size_limit) +int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const char *symbol_name) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ModuleSymbolLookup), module_id); + UT_Stub_RegisterContext(UT_KEY(OS_ModuleSymbolLookup), symbol_address); + UT_Stub_RegisterContext(UT_KEY(OS_ModuleSymbolLookup), symbol_name); + + int32 status; + + /* + * Register the context so a hook can do something with the parameters + */ + + status = UT_DEFAULT_IMPL(OS_ModuleSymbolLookup); + + if (status != OS_SUCCESS) + { + *symbol_address = 0xDEADBEEFU; + } + else if (UT_Stub_CopyToLocal(UT_KEY(OS_ModuleSymbolLookup), symbol_address, sizeof(*symbol_address)) < + sizeof(*symbol_address)) + { + /* return the dummy function when test didn't register anything else */ + *symbol_address = (cpuaddr)&dummy_function; + } + + return status; +} + +/***************************************************************************** + * + * Stub function for OS_SymbolTableDump() + * + *****************************************************************************/ +int32 OS_SymbolTableDump(const char *filename, size_t size_limit) { UT_Stub_RegisterContext(UT_KEY(OS_SymbolTableDump), filename); UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SymbolTableDump), size_limit); diff --git a/src/ut-stubs/osapi-utstub-mutex.c b/src/ut-stubs/osapi-utstub-mutex.c index 0e3d28629..89912f6e6 100644 --- a/src/ut-stubs/osapi-utstub-mutex.c +++ b/src/ut-stubs/osapi-utstub-mutex.c @@ -30,6 +30,7 @@ * can be executed. */ +#include "osapi-mutex.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_MutexAPI_Init, (void)) @@ -69,7 +70,7 @@ int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) if (status == OS_SUCCESS) { - *sem_id = UT_AllocStubObjId(UT_OBJTYPE_MUTEX); + *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_MUTEX); } else { @@ -109,7 +110,7 @@ int32 OS_MutSemDelete(osal_id_t sem_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_MUTEX, sem_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_MUTEX, sem_id); } return status; @@ -194,7 +195,7 @@ int32 OS_MutSemGetIdByName(osal_id_t *sem_id, const char *sem_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_MutSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_MUTEX, sem_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_MUTEX, sem_id); } return status; @@ -228,9 +229,9 @@ int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_MutSemGetInfo), mut_prop, sizeof(*mut_prop)) < sizeof(*mut_prop)) { - strncpy(mut_prop->name, "Name", OS_MAX_API_NAME - 1); - mut_prop->name[OS_MAX_API_NAME - 1] = '\0'; - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &mut_prop->creator); + strncpy(mut_prop->name, "Name", sizeof(mut_prop->name) - 1); + mut_prop->name[sizeof(mut_prop->name) - 1] = '\0'; + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &mut_prop->creator); } return status; diff --git a/src/ut-stubs/osapi-utstub-network.c b/src/ut-stubs/osapi-utstub-network.c index de3c9a240..549ffb8bc 100644 --- a/src/ut-stubs/osapi-utstub-network.c +++ b/src/ut-stubs/osapi-utstub-network.c @@ -32,11 +32,12 @@ * can be executed. */ +#include "osapi-network.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_NetworkAPI_Init, (void)) -int32 OS_NetworkGetHostName(char *host_name, uint32 name_len) +int32 OS_NetworkGetHostName(char *host_name, size_t name_len) { UT_Stub_RegisterContext(UT_KEY(OS_NetworkGetHostName), host_name); UT_Stub_RegisterContextGenericArg(UT_KEY(OS_NetworkGetHostName), name_len); diff --git a/src/ut-stubs/osapi-utstub-printf.c b/src/ut-stubs/osapi-utstub-printf.c index 2ed283e95..52d162bcc 100644 --- a/src/ut-stubs/osapi-utstub-printf.c +++ b/src/ut-stubs/osapi-utstub-printf.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-printf.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" int32 OS_ConsoleAPI_Init(void) @@ -60,9 +61,17 @@ void OS_printf(const char *string, ...) UT_Stub_RegisterContext(UT_KEY(OS_printf), string); int32 status; - int32 length = strlen(string); + size_t length = strlen(string); va_list va; + char str[128]; + /* Output the message when in debug mode */ + va_start(va, string); + vsnprintf(str, sizeof(str), string, va); + UtDebug("OS_printf: %s", str); + va_end(va); + + /* Reset va list for next use */ va_start(va, string); status = UT_DefaultStubImplWithArgs(__func__, UT_KEY(OS_printf), 0, va); diff --git a/src/ut-stubs/osapi-utstub-queue.c b/src/ut-stubs/osapi-utstub-queue.c index bcd09e65b..faa7fe675 100644 --- a/src/ut-stubs/osapi-utstub-queue.c +++ b/src/ut-stubs/osapi-utstub-queue.c @@ -32,6 +32,8 @@ * can be executed. */ +#include "osapi-queue.h" /* OSAL public API for this subsystem */ +#include "osapi-idmap.h" #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_QueueAPI_Init, (void)) @@ -61,7 +63,8 @@ UT_DEFAULT_STUB(OS_QueueAPI_Init, (void)) ** or OS_SUCCESS. ** ******************************************************************************/ -int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, uint32 queue_depth, uint32 data_size, uint32 flags) +int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcount_t queue_depth, size_t data_size, + uint32 flags) { UT_Stub_RegisterContext(UT_KEY(OS_QueueCreate), queue_id); UT_Stub_RegisterContext(UT_KEY(OS_QueueCreate), queue_name); @@ -75,7 +78,7 @@ int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, uint32 queue_d if (status == OS_SUCCESS) { - *queue_id = UT_AllocStubObjId(UT_OBJTYPE_QUEUE); + *queue_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_QUEUE); } else { @@ -118,7 +121,7 @@ int32 OS_QueueDelete(osal_id_t queue_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_QUEUE, queue_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_QUEUE, queue_id); } return status; @@ -149,7 +152,7 @@ int32 OS_QueueDelete(osal_id_t queue_id) ** or OS_SUCCESS. ** ******************************************************************************/ -int32 OS_QueueGet(osal_id_t queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) +int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueueGet), queue_id); UT_Stub_RegisterContext(UT_KEY(OS_QueueGet), data); @@ -196,7 +199,7 @@ int32 OS_QueueGet(osal_id_t queue_id, void *data, uint32 size, uint32 *size_copi ** OS_INVALID_POINTER, OS_QUEUE_FULL, or OS_SUCCESS. ** ******************************************************************************/ -int32 OS_QueuePut(osal_id_t queue_id, const void *data, uint32 size, uint32 flags) +int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flags) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueuePut), queue_id); UT_Stub_RegisterContext(UT_KEY(OS_QueuePut), data); @@ -232,7 +235,7 @@ int32 OS_QueueGetIdByName(osal_id_t *queue_id, const char *queue_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_QueueGetIdByName), queue_id, sizeof(*queue_id)) < sizeof(*queue_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_QUEUE, queue_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_QUEUE, queue_id); } return status; @@ -266,9 +269,9 @@ int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_QueueGetInfo), queue_prop, sizeof(*queue_prop)) < sizeof(*queue_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &queue_prop->creator); - strncpy(queue_prop->name, "Name", OS_MAX_API_NAME - 1); - queue_prop->name[OS_MAX_API_NAME - 1] = '\0'; + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &queue_prop->creator); + strncpy(queue_prop->name, "Name", sizeof(queue_prop->name) - 1); + queue_prop->name[sizeof(queue_prop->name) - 1] = '\0'; } return status; diff --git a/src/ut-stubs/osapi-utstub-select.c b/src/ut-stubs/osapi-utstub-select.c index 96514bd33..eca0b48cd 100644 --- a/src/ut-stubs/osapi-utstub-select.c +++ b/src/ut-stubs/osapi-utstub-select.c @@ -30,6 +30,7 @@ * can be executed. */ +#include "osapi-select.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" /***************************************************************************** diff --git a/src/ut-stubs/osapi-utstub-sockets.c b/src/ut-stubs/osapi-utstub-sockets.c index 5563a0980..5a211c846 100644 --- a/src/ut-stubs/osapi-utstub-sockets.c +++ b/src/ut-stubs/osapi-utstub-sockets.c @@ -30,6 +30,7 @@ * can be executed. */ +#include "osapi-sockets.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_SocketAPI_Init, (void)) @@ -51,7 +52,7 @@ int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_ if (status == OS_SUCCESS) { - *sock_id = UT_AllocStubObjId(UT_OBJTYPE_SOCKET); + *sock_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); } return status; @@ -115,7 +116,7 @@ int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 timeo * Stub function for OS_SocketRecvFrom() * *****************************************************************************/ -int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) +int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketRecvFrom), sock_id); UT_Stub_RegisterContext(UT_KEY(OS_SocketRecvFrom), buffer); @@ -124,7 +125,7 @@ int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, uint32 buflen, OS_SockA UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketRecvFrom), timeout); int32 status; - uint32 CopySize; + size_t CopySize; status = UT_DEFAULT_IMPL(OS_SocketRecvFrom); @@ -159,7 +160,7 @@ int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, uint32 buflen, OS_SockA * Stub function for OS_SocketSendTo() * *****************************************************************************/ -int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr) +int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketSendTo), sock_id); UT_Stub_RegisterContext(UT_KEY(OS_SocketSendTo), buffer); @@ -167,7 +168,7 @@ int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, uint32 buflen, cons UT_Stub_RegisterContext(UT_KEY(OS_SocketSendTo), RemoteAddr); int32 status; - uint32 CopySize; + size_t CopySize; status = UT_DEFAULT_IMPL_RC(OS_SocketSendTo, 0x7FFFFFFF); @@ -208,7 +209,7 @@ int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_SocketGetIdByName), sock_id, sizeof(*sock_id)) < sizeof(*sock_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_SOCKET, sock_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_STREAM, sock_id); } return status; @@ -225,7 +226,7 @@ int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) UT_Stub_RegisterContext(UT_KEY(OS_SocketGetInfo), sock_prop); int32 status; - uint32 CopySize; + size_t CopySize; status = UT_DEFAULT_IMPL(OS_SocketGetInfo); @@ -235,8 +236,9 @@ int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_SocketGetInfo), sock_prop, sizeof(*sock_prop)); if (CopySize < sizeof(*sock_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &sock_prop->creator); - strncpy(sock_prop->name, "ut", sizeof(sock_prop->name)); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &sock_prop->creator); + strncpy(sock_prop->name, "ut", sizeof(sock_prop->name) - 1); + sock_prop->name[sizeof(sock_prop->name) - 1] = 0; } } @@ -260,7 +262,7 @@ int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) return status; } -int32 OS_SocketAddrToString(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr) +int32 OS_SocketAddrToString(char *buffer, size_t buflen, const OS_SockAddr_t *Addr) { UT_Stub_RegisterContext(UT_KEY(OS_SocketAddrToString), buffer); UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketAddrToString), buflen); diff --git a/src/ut-stubs/osapi-utstub-task.c b/src/ut-stubs/osapi-utstub-task.c index 097cf8083..ce3dc4c80 100644 --- a/src/ut-stubs/osapi-utstub-task.c +++ b/src/ut-stubs/osapi-utstub-task.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-task.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_TaskAPI_Init, (void)) @@ -52,13 +53,13 @@ UT_DEFAULT_STUB(OS_TaskAPI_Init, (void)) ** Returns either OS_SUCCESS or OS_ERROR. ** ******************************************************************************/ -int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, uint32 *stack_pointer, - uint32 stack_size, uint32 priority, uint32 flags) +int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, + osal_stackptr_t stack_pointer, size_t stack_size, osal_priority_t priority, uint32 flags) { UT_Stub_RegisterContext(UT_KEY(OS_TaskCreate), task_id); UT_Stub_RegisterContext(UT_KEY(OS_TaskCreate), task_name); UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), function_pointer); - UT_Stub_RegisterContext(UT_KEY(OS_TaskCreate), stack_pointer); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), stack_pointer); UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), stack_size); UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), priority); UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), flags); @@ -69,7 +70,7 @@ int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry f if (status == OS_SUCCESS) { - *task_id = UT_AllocStubObjId(UT_OBJTYPE_TASK); + *task_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TASK); } else { @@ -105,7 +106,7 @@ int32 OS_TaskDelete(osal_id_t task_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_TASK, task_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TASK, task_id); } return status; @@ -165,7 +166,7 @@ int32 OS_TaskDelay(uint32 millisecond) * Stub function for OS_TaskSetPriority() * *****************************************************************************/ -int32 OS_TaskSetPriority(osal_id_t task_id, uint32 new_priority) +int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskSetPriority), task_id); UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskSetPriority), new_priority); @@ -223,7 +224,7 @@ osal_id_t OS_TaskGetId(void) int32 status; status = UT_DEFAULT_IMPL_RC(OS_TaskGetId, 1); - UT_ObjIdCompose(status, UT_OBJTYPE_TASK, &TaskId); + UT_ObjIdCompose(status, OS_OBJECT_TYPE_OS_TASK, &TaskId); return TaskId; } @@ -245,7 +246,7 @@ int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TaskGetIdByName), task_id, sizeof(*task_id)) < sizeof(*task_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, task_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, task_id); } return status; @@ -280,11 +281,11 @@ int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TaskGetInfo), task_prop, sizeof(*task_prop)) < sizeof(*task_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &task_prop->creator); - task_prop->stack_size = 100; - task_prop->priority = 150; - strncpy(task_prop->name, "UnitTest", OS_MAX_API_NAME - 1); - task_prop->name[OS_MAX_API_NAME - 1] = '\0'; + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &task_prop->creator); + task_prop->stack_size = OSAL_SIZE_C(100); + task_prop->priority = OSAL_PRIORITY_C(150); + strncpy(task_prop->name, "UnitTest", sizeof(task_prop->name) - 1); + task_prop->name[sizeof(task_prop->name) - 1] = '\0'; } return status; @@ -315,7 +316,7 @@ int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TaskFindIdBySystemData), task_id, sizeof(*task_id)) < sizeof(*task_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, task_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, task_id); } return status; diff --git a/src/ut-stubs/osapi-utstub-time.c b/src/ut-stubs/osapi-utstub-time.c index e6783689d..e8478332a 100644 --- a/src/ut-stubs/osapi-utstub-time.c +++ b/src/ut-stubs/osapi-utstub-time.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-timer.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_TimerCbAPI_Init, (void)) @@ -56,7 +57,7 @@ int32 OS_TimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_t timebas if (status == OS_SUCCESS) { - *timer_id = UT_AllocStubObjId(UT_OBJTYPE_TIMECB); + *timer_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMECB); } else { @@ -85,7 +86,7 @@ int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *clock_ if (status == OS_SUCCESS) { - *timer_id = UT_AllocStubObjId(UT_OBJTYPE_TIMECB); + *timer_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMECB); } else { @@ -138,7 +139,7 @@ int32 OS_TimerDelete(osal_id_t timer_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_TIMECB, timer_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TIMECB, timer_id); } return status; @@ -161,7 +162,7 @@ int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TimerGetIdByName), timer_id, sizeof(*timer_id)) < sizeof(*timer_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TIMECB, timer_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TIMECB, timer_id); } return status; @@ -199,7 +200,7 @@ int32 OS_TimerGetInfo(osal_id_t timer_id, OS_timer_prop_t *timer_prop) UT_Stub_CopyToLocal(UT_KEY(OS_TimerGetInfo), timer_prop, sizeof(*timer_prop)) < sizeof(*timer_prop)) { memset(timer_prop, 0, sizeof(*timer_prop)); - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &timer_prop->creator); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &timer_prop->creator); } return status; diff --git a/src/ut-stubs/osapi-utstub-timebase.c b/src/ut-stubs/osapi-utstub-timebase.c index 96664c7bd..b439eb1e0 100644 --- a/src/ut-stubs/osapi-utstub-timebase.c +++ b/src/ut-stubs/osapi-utstub-timebase.c @@ -32,6 +32,7 @@ * can be executed. */ +#include "osapi-timebase.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" UT_DEFAULT_STUB(OS_TimeBaseAPI_Init, (void)) @@ -53,7 +54,7 @@ int32 OS_TimeBaseCreate(osal_id_t *timebase_id, const char *timebase_name, OS_Ti if (status == OS_SUCCESS) { - *timebase_id = UT_AllocStubObjId(UT_OBJTYPE_TIMEBASE); + *timebase_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMEBASE); } else { @@ -96,7 +97,7 @@ int32 OS_TimeBaseDelete(osal_id_t timebase_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_TIMEBASE, timebase_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id); } return status; @@ -119,7 +120,7 @@ int32 OS_TimeBaseGetIdByName(osal_id_t *timebase_id, const char *timebase_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetIdByName), timebase_id, sizeof(*timebase_id)) < sizeof(*timebase_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TIMEBASE, timebase_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id); } return status; @@ -142,9 +143,9 @@ int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_pro if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetInfo), timebase_prop, sizeof(*timebase_prop)) < sizeof(*timebase_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &timebase_prop->creator); - strncpy(timebase_prop->name, "Name", OS_MAX_API_NAME - 1); - timebase_prop->name[OS_MAX_API_NAME - 1] = '\0'; + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &timebase_prop->creator); + strncpy(timebase_prop->name, "Name", sizeof(timebase_prop->name) - 1); + timebase_prop->name[sizeof(timebase_prop->name) - 1] = '\0'; } return status; diff --git a/src/ut-stubs/utstub-helpers.c b/src/ut-stubs/utstub-helpers.c index ce6750e7d..4050b2726 100644 --- a/src/ut-stubs/utstub-helpers.c +++ b/src/ut-stubs/utstub-helpers.c @@ -34,19 +34,21 @@ #include "utstub-helpers.h" -const uint32 UT_MAXOBJS[UT_OBJTYPE_MAX] = {[UT_OBJTYPE_TASK] = OS_MAX_TASKS, - [UT_OBJTYPE_QUEUE] = OS_MAX_QUEUES, - [UT_OBJTYPE_COUNTSEM] = OS_MAX_COUNT_SEMAPHORES, - [UT_OBJTYPE_BINSEM] = OS_MAX_BIN_SEMAPHORES, - [UT_OBJTYPE_MUTEX] = OS_MAX_MUTEXES, - [UT_OBJTYPE_TIMECB] = OS_MAX_TIMERS, - [UT_OBJTYPE_MODULE] = OS_MAX_MODULES, - [UT_OBJTYPE_FILESTREAM] = OS_MAX_NUM_OPEN_FILES, - [UT_OBJTYPE_TIMEBASE] = OS_MAX_TIMEBASES, - [UT_OBJTYPE_FILESYS] = OS_MAX_FILE_SYSTEMS, - [UT_OBJTYPE_DIR] = OS_MAX_NUM_OPEN_DIRS}; - -static UT_ObjTypeState_t UT_ObjState[UT_OBJTYPE_MAX]; +#include "osapi-idmap.h" + +const uint32 UT_MAXOBJS[OS_OBJECT_TYPE_USER] = {[OS_OBJECT_TYPE_OS_TASK] = OS_MAX_TASKS, + [OS_OBJECT_TYPE_OS_QUEUE] = OS_MAX_QUEUES, + [OS_OBJECT_TYPE_OS_COUNTSEM] = OS_MAX_COUNT_SEMAPHORES, + [OS_OBJECT_TYPE_OS_BINSEM] = OS_MAX_BIN_SEMAPHORES, + [OS_OBJECT_TYPE_OS_MUTEX] = OS_MAX_MUTEXES, + [OS_OBJECT_TYPE_OS_TIMECB] = OS_MAX_TIMERS, + [OS_OBJECT_TYPE_OS_MODULE] = OS_MAX_MODULES, + [OS_OBJECT_TYPE_OS_STREAM] = OS_MAX_NUM_OPEN_FILES, + [OS_OBJECT_TYPE_OS_TIMEBASE] = OS_MAX_TIMEBASES, + [OS_OBJECT_TYPE_OS_FILESYS] = OS_MAX_FILE_SYSTEMS, + [OS_OBJECT_TYPE_OS_DIR] = OS_MAX_NUM_OPEN_DIRS}; + +static UT_ObjTypeState_t UT_ObjState[OS_OBJECT_TYPE_USER]; /** * Initialization function @@ -62,7 +64,7 @@ void UT_ClearAllStubObjects(void) /* * Helper function - "allocate" a fake object ID of the given type */ -osal_id_t UT_AllocStubObjId(UT_ObjType_t ObjType) +osal_id_t UT_AllocStubObjId(osal_objtype_t ObjType) { UT_ObjTypeState_t *StatePtr; uint8 ObjMask; @@ -71,7 +73,7 @@ osal_id_t UT_AllocStubObjId(UT_ObjType_t ObjType) UT_Stub_CallOnce(UT_ClearAllStubObjects); - if (ObjType == UT_OBJTYPE_NONE || ObjType >= UT_OBJTYPE_MAX) + if (ObjType == OS_OBJECT_TYPE_UNDEFINED || ObjType >= OS_OBJECT_TYPE_USER) { /* Code is broken, abort the test * (This signifies an error in the stub code itself hence the abort) @@ -113,11 +115,11 @@ osal_id_t UT_AllocStubObjId(UT_ObjType_t ObjType) /* * Helper function - "deallocate" a fake object ID of the given type */ -void UT_DeleteStubObjId(UT_ObjType_t ObjType, osal_id_t ObjId) +void UT_DeleteStubObjId(osal_objtype_t ObjType, osal_id_t ObjId) { UT_ObjTypeState_t *StatePtr; uint8 ObjMask; - UT_ObjType_t checktype; + osal_objtype_t checktype; uint32 checkidx; bool ObjWasValid; @@ -169,39 +171,16 @@ void UT_DeleteStubObjId(UT_ObjType_t ObjType, osal_id_t ObjId) } } -void UT_ObjIdCompose(uint32 indx, UT_ObjType_t objtype, osal_id_t *id) +void UT_ObjIdCompose(uint32 indx, osal_objtype_t objtype, osal_id_t *id) { /* note - the OS_ObjectIdFromInteger() is an inline function, * and therefore this uses the real thing and not a stub */ *id = OS_ObjectIdFromInteger((unsigned long)indx | ((0x4000UL | objtype) << 16)); } -void UT_ObjIdDecompose(osal_id_t id, uint32 *indx, UT_ObjType_t *objtype) +void UT_ObjIdDecompose(osal_id_t id, uint32 *indx, osal_objtype_t *objtype) { unsigned long idv = OS_ObjectIdToInteger(id); *indx = idv & 0xFFFFUL; *objtype = (idv >> 16) ^ 0x4000UL; } - -/* -** Report and close any sockets found open -** Moved here temporarily to ensure full compatibility with CFE implementation -** -** NOTE - this historically only checked for queues that were created but not -** cleaned up. Although the current impl could check for anything, only queues -** are done for now. -*/ -void UT_CheckForOpenSockets(void) -{ - UT_ObjTypeState_t *StatePtr; - uint32 i; - - StatePtr = &UT_ObjState[UT_OBJTYPE_QUEUE]; - for (i = 0; i <= StatePtr->LastIssueNumber; ++i) - { - if ((StatePtr->ValidBits[i >> 3] & (1 << (i & 0x07))) != 0) - { - UtAssert_Failed("UT_Queue %d left open.\n", (int)i); - } - } -} diff --git a/src/ut-stubs/utstub-helpers.h b/src/ut-stubs/utstub-helpers.h index 5d8997639..8ac67a561 100644 --- a/src/ut-stubs/utstub-helpers.h +++ b/src/ut-stubs/utstub-helpers.h @@ -32,8 +32,8 @@ * can be executed. */ -#ifndef __OSAPI_UTSTUB_INTERNAL_H_ -#define __OSAPI_UTSTUB_INTERNAL_H_ +#ifndef OSAPI_UTSTUB_INTERNAL_H +#define OSAPI_UTSTUB_INTERNAL_H /* * Commonly used C library headers @@ -43,30 +43,15 @@ /* * Include all relevant OSAPI (public) and UT-assert headers */ -#include "osapi.h" +#include "common_types.h" +#include "osapi-error.h" +#include "osapi-constants.h" +#include "osapi-idmap.h" #include "utstubs.h" #include "utbsp.h" #include "utassert.h" #include "uttools.h" -typedef enum -{ - UT_OBJTYPE_NONE = 0, - UT_OBJTYPE_TASK, - UT_OBJTYPE_QUEUE, - UT_OBJTYPE_COUNTSEM, - UT_OBJTYPE_BINSEM, - UT_OBJTYPE_MUTEX, - UT_OBJTYPE_TIMECB, - UT_OBJTYPE_MODULE, - UT_OBJTYPE_FILESTREAM, - UT_OBJTYPE_SOCKET, - UT_OBJTYPE_TIMEBASE, - UT_OBJTYPE_DIR, - UT_OBJTYPE_FILESYS, - UT_OBJTYPE_MAX -} UT_ObjType_t; - /* * A constant to use in stubs where no other value is applicable */ @@ -98,18 +83,12 @@ extern const uint32 UT_MAXOBJS[]; /* * Helper function - "allocate" a fake object ID of the given type */ -osal_id_t UT_AllocStubObjId(UT_ObjType_t ObjType); +osal_id_t UT_AllocStubObjId(osal_objtype_t ObjType); /* * Helper function - "deallocate" a fake object ID of the given type */ -void UT_DeleteStubObjId(UT_ObjType_t ObjType, osal_id_t ObjId); - -/* - * Helper function - Report any queue objects found open - * (for compatibility with CFE tests, only checks queues) - */ -void UT_CheckForOpenSockets(void); +void UT_DeleteStubObjId(osal_objtype_t ObjType, osal_id_t ObjId); /* * Helper function - Clear all OSAL UT stub objects @@ -121,7 +100,7 @@ void UT_ClearAllStubObjects(void); * Compose/Decompose a unit test object ID from an index and type. * This is the UT-specific version not related to the OSAL runtime version. */ -void UT_ObjIdCompose(uint32 indx, UT_ObjType_t objtype, osal_id_t *id); -void UT_ObjIdDecompose(osal_id_t id, uint32 *indx, UT_ObjType_t *objtype); +void UT_ObjIdCompose(uint32 indx, osal_objtype_t objtype, osal_id_t *id); +void UT_ObjIdDecompose(osal_id_t id, uint32 *indx, osal_objtype_t *objtype); #endif diff --git a/ut_assert/inc/utassert.h b/ut_assert/inc/utassert.h index 2cf56b747..8bf875cf3 100644 --- a/ut_assert/inc/utassert.h +++ b/ut_assert/inc/utassert.h @@ -31,8 +31,8 @@ * - All asserts must call the function UtAssert. */ -#ifndef _utassert_ -#define _utassert_ +#ifndef UTASSERT_H +#define UTASSERT_H /* * Includes @@ -90,50 +90,49 @@ typedef struct #define UtAssert_True(Expression, ...) UtAssertEx(Expression, UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Evaluates a expression as either true or false. true means the test passed, false means the test failed. */ -#define UtAssert_Bool(Expression, ...) \ - UtAssertEx(Expression, UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_Bool(Expression, ...) UtAssertEx(Expression, UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Asserts a test failure */ #define UtAssert_Failed(...) UtAssertEx(false, UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Compares two integers and determines if they are equal within a specified absolute tolerance. */ -#define UtAssert_IntegerCmpAbs(x, y, Tolerance, ...) \ - UtAssertEx((abs((x) - (y)) <= (Tolerance)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_IntegerCmpAbs(x, y, Tolerance, ...) \ + UtAssertEx((abs((x) - (y)) <= (Tolerance)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Compares two floating point numbers and determines if they are equal within a specified absolute tolerance. */ -#define UtAssert_DoubleCmpAbs(x, y, Tolerance, ...) \ - UtAssertEx((fabs((x) - (y)) <= (Tolerance)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_DoubleCmpAbs(x, y, Tolerance, ...) \ + UtAssertEx((fabs((x) - (y)) <= (Tolerance)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Compares two floating point numbers and determines if they are equal within a specified relative tolerance. */ -#define UtAssert_DoubleCmpRel(x, y, Ratio, ...) \ - UtAssertEx((fabs((x) - (y))/(x) <= (Ratio)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_DoubleCmpRel(x, y, Ratio, ...) \ + UtAssertEx((fabs((x) - (y)) / (x) <= (Ratio)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Compares two strings and determines if they are equal. */ -#define UtAssert_StrCmp(String1, String2, ...) \ - UtAssertEx((strcmp(String1, String2) == 0), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_StrCmp(String1, String2, ...) \ + UtAssertEx((strcmp(String1, String2) == 0), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Compares at most Length characters of two strings and determines if they are equal. */ -#define UtAssert_StrnCmp(String1, String2, Length, ...) \ - UtAssertEx((strncmp(String1, String2, Length) == 0), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_StrnCmp(String1, String2, Length, ...) \ + UtAssertEx((strncmp(String1, String2, Length) == 0), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Compares two regions of memory and determines if they are equal. */ -#define UtAssert_MemCmp(Memory1, Memory2, Length, ...) \ - UtAssertEx((memcmp(Memory1, Memory2, Length) == 0), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_MemCmp(Memory1, Memory2, Length, ...) \ + UtAssertEx((memcmp(Memory1, Memory2, Length) == 0), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Compares a region of memory to a static pattern and determines if they are equal. Note: Use UtMemSet to * fill a region of memory with a static pattern. */ -#define UtAssert_MemCmpValue(Memory, Value, Length, ...) \ - UtAssertEx((UtMemCmpValue(Memory, Value, Length)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_MemCmpValue(Memory, Value, Length, ...) \ + UtAssertEx((UtMemCmpValue(Memory, Value, Length)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Compares a region of memory to a byte count pattern and determines if they are equal. Note: Use UtMemFill to * fill a region of memory with a byte count pattern. */ -#define UtAssert_MemCmpCount(Memory, Length, ...) \ - UtAssertEx((UtMemCmpCount(Memory, Length)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_MemCmpCount(Memory, Length, ...) \ + UtAssertEx((UtMemCmpCount(Memory, Length)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* Compares a region of memory with the contents of a binary file and determines if they are equal. Note: Use * UtMem2BinFile to copy a region of memory to a binary file. */ -#define UtAssert_Mem2BinFileCmp(Memory, Filename, ...) \ - UtAssertEx((UtMem2BinFileCmp(Memory, Filename)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) +#define UtAssert_Mem2BinFileCmp(Memory, Filename, ...) \ + UtAssertEx((UtMem2BinFileCmp(Memory, Filename)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /* A wrapper around UtAssertEx that allows the user to specify the failure type and a more descriptive message */ #define UtAssert_Type(Type, Expression, ...) \ @@ -206,7 +205,7 @@ typedef struct } while (0) /** - * \brief Confirm an integer value is nonzero + * \brief Confirm an integer value is zero */ #define UtAssert_ZERO(actual) \ do \ @@ -272,13 +271,20 @@ bool UtAssertEx(bool Expression, UtAssert_CaseType_t CaseType, const char *File, void UtAssert_Abort(const char *Message); /** - * Output an informational message to the console/log file + * \brief Output an informational message to the console/log file * * Just like the standard printf except it will output to the given status channel (see utassert.h) * * This calls into the UT BSP function to actually write the message * to the current output device. This may be the console or a log file * or something else depending on what BSP is in use. + * + * \param MessageType Message case type + * \param File File name containing the message + * \param Line Line number containing the message + * \param Spec printf style format followed by args of message + * + * \sa Helper macros: UtPrintf(), UtDebug() */ void UtAssert_Message(uint8 MessageType, const char *File, uint32 Line, const char *Spec, ...) OS_PRINTF(4, 5); @@ -292,7 +298,7 @@ void UtAssert_Message(uint8 MessageType, const char *File, uint32 Line, const ch * * \param File File containing the test case * \param LineNum Line number containing the test case - * \param MessageType Should be set to either UT_MESSAGE_PASS or UT_MESSAGE_FAILURE. + * \param MessageType Message case type * \param SubsysName The subsystem under test (abbreviated name) * \param ShortDesc Short description of the test case * \param SegmentNum Sequence among the overall/global test Segments diff --git a/ut_assert/inc/utbsp.h b/ut_assert/inc/utbsp.h index 949c62347..27de86013 100644 --- a/ut_assert/inc/utbsp.h +++ b/ut_assert/inc/utbsp.h @@ -40,8 +40,8 @@ * and the way pass/fail determinations are made. */ -#ifndef _UTBSP_H_ -#define _UTBSP_H_ +#ifndef UTBSP_H +#define UTBSP_H #include "common_types.h" #include "utassert.h" @@ -100,4 +100,4 @@ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage); */ void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters); -#endif /* _UTBSP_H_ */ +#endif /* UTBSP_H */ diff --git a/ut_assert/inc/utlist.h b/ut_assert/inc/utlist.h index be834d128..e51d1f69b 100644 --- a/ut_assert/inc/utlist.h +++ b/ut_assert/inc/utlist.h @@ -24,8 +24,8 @@ * Purpose: This file contains functions to implement a generic linked list data structure. */ -#ifndef _utlist_ -#define _utlist_ +#ifndef UTLIST_H +#define UTLIST_H /* * Includes diff --git a/ut_assert/inc/utstubs.h b/ut_assert/inc/utstubs.h index 429c7519b..ad7601218 100644 --- a/ut_assert/inc/utstubs.h +++ b/ut_assert/inc/utstubs.h @@ -36,8 +36,8 @@ * */ -#ifndef _UTSTUBS_H_ -#define _UTSTUBS_H_ +#ifndef UTSTUBS_H +#define UTSTUBS_H #include #include "common_types.h" @@ -161,7 +161,7 @@ void UT_SetDeferredRetcode(UT_EntryKey_t FuncKey, int32 Count, int32 Retcode); * is false then the DataBuffer pointer is used directly, and must remain valid for the duration * of the current test case. */ -void UT_SetDataBuffer(UT_EntryKey_t FuncKey, void *DataBuffer, uint32 BufferSize, bool AllocateCopy); +void UT_SetDataBuffer(UT_EntryKey_t FuncKey, void *DataBuffer, size_t BufferSize, bool AllocateCopy); /** * Gets the data buffer for a given stub function @@ -177,8 +177,27 @@ void UT_SetDataBuffer(UT_EntryKey_t FuncKey, void *DataBuffer, uint32 BufferSize * \param BufferSize Set to Maximum Size of data buffer (output) * \param Position Set to current position in data buffer (output) */ -void UT_GetDataBuffer(UT_EntryKey_t FuncKey, void **DataBuffer, uint32 *MaxSize, uint32 *Position); +void UT_GetDataBuffer(UT_EntryKey_t FuncKey, void **DataBuffer, size_t *MaxSize, size_t *Position); +/** + * Set the default return value for the given stub function. + * User needs to use UT_ClearDefaultReturnValue to clear the value. + * + * \param FuncKey The stub function to add the return code to. + * \param Value Arbitrary return value (may or may not be used by the stub) + */ +void UT_SetDefaultReturnValue(UT_EntryKey_t FuncKey, int32 Value); + +/** + * Disable the default return for the given stub function + * + * This undoes the action of UT_SetDefaultReturnValue() + * + * \param FuncKey The stub function entry to clear. + */ +void UT_ClearDefaultReturnValue(UT_EntryKey_t FuncKey); + +#ifndef OSAL_OMIT_DEPRECATED /** * Enable or disable the forced failure mode for the given stub function * @@ -190,17 +209,22 @@ void UT_GetDataBuffer(UT_EntryKey_t FuncKey, void **DataBuffer, uint32 *MaxSize, * * \param FuncKey The stub function to add the return code to. * \param Value Arbitrary failure mode value (may or may not be used by the stub) + * + * @deprecated replaced by UT_SetDefaultReturnValue */ void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value); /** * Disable the forced failure mode for the given stub function * - * This undoes the action of UT_SetForceFail() + * This undoes the action of UT_SetDefaultReturnValue() * * \param FuncKey The stub function entry to clear. + * + * @deprecated replaced by UT_ClearDefaultReturnValue */ void UT_ClearForceFail(UT_EntryKey_t FuncKey); +#endif /** * Set a Hook function for a particular call @@ -293,11 +317,11 @@ bool UT_Stub_CheckDeferredRetcode(UT_EntryKey_t FuncKey, int32 *Retcode); /** * Check for a forced failure mode entry for the given stub function * - * If a UT_SetForceFail() option is in place for the given function this + * If a UT_SetDefaultReturnValue() option is in place for the given function this * will return true and increment the internal usage counter. * * \param FuncKey The stub function to check the return code. - * \param Value Set to the value supplied to UT_SetForceFail() + * \param Value Set to the value supplied to UT_SetDefaultReturnValue() * \returns true if force fail mode is active */ bool UT_Stub_CheckForceFail(UT_EntryKey_t FuncKey, int32 *Value); @@ -314,7 +338,7 @@ bool UT_Stub_CheckForceFail(UT_EntryKey_t FuncKey, int32 *Value); * \returns The actual size of data copied. If no data buffer is * supplied by the test harness this will return 0. */ -uint32 UT_Stub_CopyToLocal(UT_EntryKey_t FuncKey, void *LocalBuffer, uint32 MaxSize); +size_t UT_Stub_CopyToLocal(UT_EntryKey_t FuncKey, void *LocalBuffer, size_t MaxSize); /** * Copies data from a local buffer to the test-supplied buffer @@ -328,7 +352,7 @@ uint32 UT_Stub_CopyToLocal(UT_EntryKey_t FuncKey, void *LocalBuffer, uint32 MaxS * \returns The actual size of data copied. If no data buffer is * supplied by the test harness this will return 0. */ -uint32 UT_Stub_CopyFromLocal(UT_EntryKey_t FuncKey, const void *LocalBuffer, uint32 MaxSize); +size_t UT_Stub_CopyFromLocal(UT_EntryKey_t FuncKey, const void *LocalBuffer, size_t MaxSize); /** * Registers a single context element for the hook callback @@ -439,8 +463,15 @@ int32 UT_DefaultStubImpl(const char *FunctionName, UT_EntryKey_t FuncKey, int32 * * This version should be used on stubs that take no arguments * and are expected to return 0 in the nominal case + * + * NOTE - Adding a NULL to the va list is only done for the + * two macros that do not have a va list passed in by the + * caller and is NOT a general pattern. Hooks that handle + * va lists should utilize the UT_KEY to process + * va lists correctly based on the implementation (no + * general pattern should be assumed). */ -#define UT_DEFAULT_IMPL(FuncName) UT_DefaultStubImpl(#FuncName, UT_KEY(FuncName), 0) +#define UT_DEFAULT_IMPL(FuncName) UT_DefaultStubImpl(#FuncName, UT_KEY(FuncName), 0, NULL) /** * Macro to simplify usage of the UT_DefaultStubImpl() function @@ -451,8 +482,15 @@ int32 UT_DefaultStubImpl(const char *FunctionName, UT_EntryKey_t FuncKey, int32 * * This version should be used on stubs that take no arguments * and are expected to return nonzero in the nominal case + * + * NOTE - Adding a NULL to the va list is only done for the + * two macros that do not have a va list passed in by the + * caller and is NOT a general pattern. Hooks that handle + * va lists should utilize the UT_KEY to process + * va lists correctly based on the implementation (no + * general pattern should be assumed). */ -#define UT_DEFAULT_IMPL_RC(FuncName, Rc) UT_DefaultStubImpl(#FuncName, UT_KEY(FuncName), Rc) +#define UT_DEFAULT_IMPL_RC(FuncName, Rc) UT_DefaultStubImpl(#FuncName, UT_KEY(FuncName), Rc, NULL) /** * Macro to simplify usage of the UT_DefaultStubImpl() function @@ -502,4 +540,4 @@ int32 UT_DefaultStubImpl(const char *FunctionName, UT_EntryKey_t FuncKey, int32 return UT_DEFAULT_IMPL(FuncName); \ } -#endif /* _UTSTUBS_H_ */ +#endif /* UTSTUBS_H */ diff --git a/ut_assert/inc/uttest.h b/ut_assert/inc/uttest.h index fe56cd7fc..d79ac8bee 100644 --- a/ut_assert/inc/uttest.h +++ b/ut_assert/inc/uttest.h @@ -29,8 +29,8 @@ * test output define the macro UT_VERBOSE. */ -#ifndef _uttest_ -#define _uttest_ +#ifndef UTTEST_H +#define UTTEST_H #include @@ -43,6 +43,11 @@ * * Called by the user to register a new test case with the library. * + * Note: Nested addition of tests is not supported. Calling + * UtTest_Add from within a test function added using UtTest_Add + * will not cause the nested test to execute, and will be + * silently ignored. + * * \param Test Main test function to call. * \param Setup Setup function, called before the test function * \param Teardown Cleanup function, called after the test function diff --git a/ut_assert/inc/uttools.h b/ut_assert/inc/uttools.h index ecdaf9d6b..95db31dcd 100644 --- a/ut_assert/inc/uttools.h +++ b/ut_assert/inc/uttools.h @@ -24,8 +24,8 @@ * Purpose: This file contains functions to implement a set of tools for use in unit testing. */ -#ifndef _uttools_ -#define _uttools_ +#ifndef UTTOOLS_H +#define UTTOOLS_H /* * Includes diff --git a/ut_assert/src/utassert.c b/ut_assert/src/utassert.c index 677614cbf..a4a88ddda 100644 --- a/ut_assert/src/utassert.c +++ b/ut_assert/src/utassert.c @@ -79,12 +79,13 @@ void UtAssert_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCo char ReportBuffer[144]; snprintf(ReportBuffer, sizeof(ReportBuffer), - "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-4u N/A::%-4u\n", + "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-4u TTF::%-4u N/A::%-4u\n", (unsigned int)TestCounters->TestSegmentCount, SegmentName, (unsigned int)TestCounters->TotalTestCases, (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_PASS], (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE], (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_MIR], (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TSF], + (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TTF], (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_NA]); UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); diff --git a/ut_assert/src/utbsp.c b/ut_assert/src/utbsp.c index 5e8b7998e..3de0efae4 100644 --- a/ut_assert/src/utbsp.c +++ b/ut_assert/src/utbsp.c @@ -132,7 +132,8 @@ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) Prefix = "TSF"; break; case UTASSERT_CASETYPE_TTF: - Prefix = "TTF"; + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED | OS_BSP_CONSOLEMODE_BLUE; + Prefix = "TTF"; break; case UTASSERT_CASETYPE_NA: Prefix = "N/A"; diff --git a/ut_assert/src/utglobal.h b/ut_assert/src/utglobal.h index dcc569781..cc0c08e4c 100644 --- a/ut_assert/src/utglobal.h +++ b/ut_assert/src/utglobal.h @@ -28,8 +28,8 @@ * Includes */ -#ifndef INCLUDE_UTASSERT_GLOBAL_H_ -#define INCLUDE_UTASSERT_GLOBAL_H_ +#ifndef UTASSERT_GLOBAL_H +#define UTASSERT_GLOBAL_H #include "osapi.h" #include "utassert.h" @@ -64,4 +64,4 @@ typedef struct */ extern UtAssert_Global_t UtAssert_Global; -#endif /* INCLUDE_UTASSERT_GLOBAL_H_ */ +#endif /* UTASSERT_GLOBAL_H */ diff --git a/ut_assert/src/utstubs.c b/ut_assert/src/utstubs.c index 79693e2f6..a4376b444 100644 --- a/ut_assert/src/utstubs.c +++ b/ut_assert/src/utstubs.c @@ -69,8 +69,8 @@ typedef struct typedef struct { - uint32 Position; - uint32 TotalSize; + size_t Position; + size_t TotalSize; uint8 *BasePtr; } UT_BufferEntry_t; @@ -308,18 +308,18 @@ bool UT_Stub_CheckDeferredRetcode(UT_EntryKey_t FuncKey, int32 *Retcode) return (Result); } -void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value) +void UT_SetDefaultReturnValue(UT_EntryKey_t FuncKey, int32 Value) { UT_StubTableEntry_t *Rc; /* - * First find an existing force fail entry for the function. + * First find an existing default return value entry for the function. * In case one is already set we do not duplicate (unlike deferred codes) */ Rc = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_FORCE_FAIL); if (Rc == NULL) { - /* Creating force fail entry - repeat search and grab any unused slot */ + /* Creating default return value entry - repeat search and grab any unused slot */ Rc = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_UNUSED); } @@ -335,7 +335,7 @@ void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value) } } -void UT_ClearForceFail(UT_EntryKey_t FuncKey) +void UT_ClearDefaultReturnValue(UT_EntryKey_t FuncKey) { UT_StubTableEntry_t *StubPtr; @@ -346,6 +346,18 @@ void UT_ClearForceFail(UT_EntryKey_t FuncKey) } } +#ifndef OSAL_OMIT_DEPRECATED +void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value) +{ + UT_SetDefaultReturnValue(FuncKey, Value); +} + +void UT_ClearForceFail(UT_EntryKey_t FuncKey) +{ + UT_ClearDefaultReturnValue(FuncKey); +} +#endif + bool UT_GetStubRetcodeAndCount(UT_EntryKey_t FuncKey, int32 *Retcode, int32 *Count) { UT_StubTableEntry_t *StubPtr; @@ -401,7 +413,7 @@ bool UT_Stub_CheckForceFail(UT_EntryKey_t FuncKey, int32 *Value) return (Result); } -void UT_SetDataBuffer(UT_EntryKey_t FuncKey, void *DataBuffer, uint32 BufferSize, bool AllocateCopy) +void UT_SetDataBuffer(UT_EntryKey_t FuncKey, void *DataBuffer, size_t BufferSize, bool AllocateCopy) { UT_StubTableEntry_t *StubPtr; @@ -441,12 +453,12 @@ void UT_SetDataBuffer(UT_EntryKey_t FuncKey, void *DataBuffer, uint32 BufferSize } } -void UT_GetDataBuffer(UT_EntryKey_t FuncKey, void **DataBuffer, uint32 *MaxSize, uint32 *Position) +void UT_GetDataBuffer(UT_EntryKey_t FuncKey, void **DataBuffer, size_t *MaxSize, size_t *Position) { UT_StubTableEntry_t *StubPtr; void * ResultDataBuffer; - uint32 ResultMaxSize; - uint32 ResultPosition; + size_t ResultMaxSize; + size_t ResultPosition; StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_DATA_BUFFER); @@ -477,9 +489,9 @@ void UT_GetDataBuffer(UT_EntryKey_t FuncKey, void **DataBuffer, uint32 *MaxSize, } } -uint32 UT_Stub_CopyToLocal(UT_EntryKey_t FuncKey, void *LocalBuffer, uint32 MaxSize) +size_t UT_Stub_CopyToLocal(UT_EntryKey_t FuncKey, void *LocalBuffer, size_t MaxSize) { - uint32 ActualCopy; + size_t ActualCopy; UT_StubTableEntry_t *StubPtr; ActualCopy = 0; @@ -510,9 +522,9 @@ uint32 UT_Stub_CopyToLocal(UT_EntryKey_t FuncKey, void *LocalBuffer, uint32 MaxS return ActualCopy; } -uint32 UT_Stub_CopyFromLocal(UT_EntryKey_t FuncKey, const void *LocalBuffer, uint32 MaxSize) +size_t UT_Stub_CopyFromLocal(UT_EntryKey_t FuncKey, const void *LocalBuffer, size_t MaxSize) { - uint32 ActualCopy; + size_t ActualCopy; UT_StubTableEntry_t *StubPtr; ActualCopy = 0;