diff --git a/CMakeLists.txt b/CMakeLists.txt index 0008aae46..69eda30b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,6 +101,9 @@ add_subdirectory(ut_assert) # The Implementation-Specific BSP subdirectory should define # an OBJECT target named "osal_${OSAL_SYSTEM_BSPTYPE}_impl" add_subdirectory(src/bsp/${OSAL_SYSTEM_BSPTYPE} ${OSAL_SYSTEM_BSPTYPE}_impl) +target_include_directories(osal_${OSAL_SYSTEM_BSPTYPE}_impl PRIVATE + ${OSAL_SOURCE_DIR}/src/bsp/shared +) # Propagate the BSP-specific compile definitions and include directories # Apply these to the directory-scope COMPILE_DEFINITIONS and INCLUDE_DIRECTORIES @@ -127,6 +130,10 @@ endif (OSAL_BSP_INCLUDE_DIRECTORIES) # Define the external "osal_bsp" static library target add_library(osal_bsp STATIC + src/bsp/shared/osapi-bsp.c + src/bsp/shared/bsp_default_app_run.c + src/bsp/shared/bsp_default_app_startup.c + src/bsp/shared/bsp_default_symtab.c $ ) @@ -147,6 +154,7 @@ add_subdirectory(src/os/${OSAL_SYSTEM_OSTYPE} ${OSAL_SYSTEM_OSTYPE}_impl) # be referenced outside the OSAL code target_include_directories(osal_${OSAL_SYSTEM_OSTYPE}_impl PRIVATE ${OSAL_SOURCE_DIR}/src/os/shared + ${OSAL_SOURCE_DIR}/src/bsp/shared ) # Define the external "osal" static library target @@ -182,6 +190,9 @@ target_include_directories(osal INTERFACE ${OSAL_API_INCLUDE_DIRECTORIES} ) +# Link the OSAL with the BSP +target_link_libraries(osal osal_bsp) + # propagate the BSP-specific compile flags to OSAL external library target, if defined if (OSAL_BSP_COMPILE_DEFINITIONS) target_compile_definitions(osal INTERFACE @@ -218,7 +229,7 @@ if (ENABLE_UNIT_TESTS) function(add_osal_ut_exe TGTNAME) add_executable(${TGTNAME} ${ARGN}) - target_link_libraries(${TGTNAME} ut_assert ut_bsp osal) + target_link_libraries(${TGTNAME} ut_assert osal) add_test(${TGTNAME} ${TGTNAME}) foreach(TGT ${INSTALL_TARGET_LIST}) install(TARGETS ${TGTNAME} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR}) diff --git a/src/bsp/mcp750-vxworks/CMakeLists.txt b/src/bsp/mcp750-vxworks/CMakeLists.txt index 76526ad30..954cbefd4 100644 --- a/src/bsp/mcp750-vxworks/CMakeLists.txt +++ b/src/bsp/mcp750-vxworks/CMakeLists.txt @@ -4,9 +4,10 @@ # ###################################################################### -add_library(osal_mcp750-vxworks_impl OBJECT +add_library(osal_mcp750-vxworks_impl OBJECT src/bsp_start.c src/bsp_voltab.c + src/bsp_console.c ) target_include_directories(osal_mcp750-vxworks_impl PUBLIC @@ -22,10 +23,4 @@ target_compile_definitions(osal_mcp750-vxworks_impl PUBLIC "MCP750" ) -add_library(ut_bsp STATIC EXCLUDE_FROM_ALL - ut-src/bsp_ut.c - ut-src/bsp_ut_voltab.c -) -target_include_directories(ut_bsp PRIVATE ${UT_ASSERT_SOURCE_DIR}/inc) - diff --git a/src/bsp/mcp750-vxworks/src/bsp_console.c b/src/bsp/mcp750-vxworks/src/bsp_console.c new file mode 100644 index 000000000..710b1a007 --- /dev/null +++ b/src/bsp/mcp750-vxworks/src/bsp_console.c @@ -0,0 +1,52 @@ +/****************************************************************************** +** File: bsp_console.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** OSAL BSP debug console abstraction +** +******************************************************************************/ + +#include +#include +#include + +#include "mcp750_bsp_internal.h" +#include "bsp-impl.h" + +/**************************************************************************************** + BSP CONSOLE IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*---------------------------------------------------------------- + OS_BSP_ConsoleOutput_Impl + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +{ + while (DataLen > 0) + { + putchar(*Str); + ++Str; + --DataLen; + } +} + +/*---------------------------------------------------------------- + OS_BSP_ConsoleSetMode_Impl() definition + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits) +{ + /* ignored; not implemented */ +} + + diff --git a/src/bsp/mcp750-vxworks/src/bsp_start.c b/src/bsp/mcp750-vxworks/src/bsp_start.c index 177825684..6c47c4eaf 100644 --- a/src/bsp/mcp750-vxworks/src/bsp_start.c +++ b/src/bsp/mcp750-vxworks/src/bsp_start.c @@ -1,15 +1,15 @@ /****************************************************************************** ** File: bsp_start.c ** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. ** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. ** ** Purpose: -** +** ** OSAL main entry point. ** ** History: @@ -19,23 +19,10 @@ /* ** Include Files */ -#include #include -#include -#include "vxWorks.h" -#include "sysLib.h" -#include "taskLib.h" - -/* -** OSAL includes -*/ -#include "common_types.h" -#include "osapi.h" +#include -/* -** External Declarations -*/ -void OS_Application_Startup(void); +#include "mcp750_bsp_internal.h" /****************************************************************************** ** Function: OS_BSPMain() @@ -47,30 +34,32 @@ void OS_Application_Startup(void); ** (none) ** ** Return: -** (none) +** integer return code, with zero indicating normal exit, nonzero +** indicating an off-nominal condition */ -void OS_BSPMain( void ) +int OS_BSPMain(void) { - int TicksPerSecond; - - /* - ** Delay for one second. - */ - TicksPerSecond = sysClkRateGet(); - (void) taskDelay( TicksPerSecond ); + /* + * Initially clear the global object (this contains return code) + */ + memset(&OS_BSP_Global, 0, sizeof(OS_BSP_Global)); - OS_printf("Starting Up OSAPI App.\n"); - - /* - ** Call OSAL entry point. - */ - OS_Application_Startup(); + /* + * Call application specific entry point. + * This should set up all user tasks and resources, then return + */ + OS_Application_Startup(); - /* - ** Exit the main thread. - ** in VxWorks we can delete all of the OS tasks if we want. - */ + /* + * OS_Application_Run() implements the background task. + * The user application may provide this, or a default implementation + * is used which just calls OS_IdleLoop(). + */ + OS_Application_Run(); + /* + * Return to shell with the current status code + */ + return OS_BSP_Global.AppStatus; } - diff --git a/src/bsp/mcp750-vxworks/src/mcp750_bsp_internal.h b/src/bsp/mcp750-vxworks/src/mcp750_bsp_internal.h new file mode 100644 index 000000000..7b6d84363 --- /dev/null +++ b/src/bsp/mcp750-vxworks/src/mcp750_bsp_internal.h @@ -0,0 +1,27 @@ +/****************************************************************************** +** File: mcp750_bsp_internal.h +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Header file for internal data to the MCP750 BSP +** +******************************************************************************/ + +#ifndef _MCP750_BSP_INTERNAL_H_ +#define _MCP750_BSP_INTERNAL_H_ + +/* +** OSAL includes +*/ +#include "osapi.h" +#include "bsp-impl.h" + +#endif /* _MCP750_BSP_INTERNAL_H_ */ diff --git a/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c b/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c deleted file mode 100644 index 1b1890418..000000000 --- a/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c +++ /dev/null @@ -1,222 +0,0 @@ -/****************************************************************************** -** File: bsp_ut.c -** -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Purpose: -** BSP unit test implementation functions. -** -** History: -** Created on: Feb 10, 2015 -** -******************************************************************************/ - -/* - * NOTE - This entire source file is only relevant for unit testing. - * It should not be included in a "normal" BSP build. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "osapi.h" -#include "utbsp.h" -#include "uttest.h" - -/* -** Local Variables -*/ -uint32 TestVerbosity = (2 << UTASSERT_CASETYPE_PASS) - 1; - -/* - * Long jump buffer to implement ABORT - * - * (a fatal testing error that should - * stop execution and return to console) - */ -static jmp_buf AbortBuf; - -void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u %s", (unsigned int)SegmentNumber, SegmentName); - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, ReportBuffer); -} - -void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) -{ - const char *Prefix; - - if ((TestVerbosity >> MessageType) & 1) - { - switch(MessageType) - { - case UTASSERT_CASETYPE_ABORT: - Prefix = "ABORT"; - break; - case UTASSERT_CASETYPE_FAILURE: - Prefix = "FAIL"; - break; - case UTASSERT_CASETYPE_MIR: - Prefix = "MIR"; - break; - case UTASSERT_CASETYPE_TSF: - Prefix = "TSF"; - break; - case UTASSERT_CASETYPE_TTF: - Prefix = "TTF"; - break; - case UTASSERT_CASETYPE_NA: - Prefix = "N/A"; - break; - case UTASSERT_CASETYPE_BEGIN: - printf("\n"); /* add a bit of extra whitespace between tests */ - Prefix = "BEGIN"; - break; - case UTASSERT_CASETYPE_END: - Prefix = "END"; - break; - case UTASSERT_CASETYPE_PASS: - Prefix = "PASS"; - break; - case UTASSERT_CASETYPE_INFO: - Prefix = "INFO"; - break; - case UTASSERT_CASETYPE_DEBUG: - Prefix = "DEBUG"; - break; - default: - Prefix = "OTHER"; - break; - } - - printf("[%5s] %s\n",Prefix,OutputMessage); - } - - /* - * If any ABORT (major failure) message is thrown, - * then use longjmp() to go back to the main routine and exit. - */ - if (MessageType == UTASSERT_CASETYPE_ABORT) - { - longjmp(AbortBuf, -1); - } -} - -void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 TestSeq, uint8 MessageType, const char *SubsysName, const char *ShortDesc) -{ - uint32 FileLen; - const char *BasePtr; - char ReportBuffer[128]; - - FileLen = strlen(File); - BasePtr = File + FileLen; - while (FileLen > 0) - { - --BasePtr; - --FileLen; - if (*BasePtr == '/' || *BasePtr == '\\') - { - ++BasePtr; - break; - } - } - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u.%03u %s:%u - %s", - (unsigned int)SegmentNum, (unsigned int)TestSeq, - BasePtr, (unsigned int)LineNum, ShortDesc); - - UT_BSP_DoText(MessageType, ReportBuffer); -} - -void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCounter_t *TestCounters) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), - "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-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_NA]); - - - UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); -} - -void UT_BSP_Setup(void) -{ - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "VxWorks UNIT TEST"); -} - - -void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters) -{ - /* - * Only output a "summary" if there is more than one test Segment. - * Otherwise it is a duplicate of the report already given. - */ - if (TestCounters->TestSegmentCount > 1) - { - UT_BSP_DoTestSegmentReport("SUMMARY", TestCounters); - } - - printf("COMPLETE: %u tests Segment(s) executed\n\n", (unsigned int)TestCounters->TestSegmentCount); -} - -/****************************************************************************** -** Function: RunTest() -** -** Purpose: -** BSP Unit Test Application entry point. -** -** Arguments: -** (none) -** -** Return: -** 0 on successful test, or nonzero if any errors occurred. -*/ - -int RunTest(void) -{ - int RetVal; - - RetVal = setjmp(AbortBuf); - - if (RetVal == 0) - { - /* - ** Call application specific entry point. - */ - OS_Application_Startup(); - - /* - ** The OS_Application_Run function is part of UT Assert library - */ - OS_Application_Run(); - - RetVal = (UtAssert_GetCounters()->CaseCount[UTASSERT_CASETYPE_FAILURE] + - UtAssert_GetCounters()->CaseCount[UTASSERT_CASETYPE_TSF]); - } - - return RetVal; -} - diff --git a/src/bsp/mcp750-vxworks/ut-src/bsp_ut_voltab.c b/src/bsp/mcp750-vxworks/ut-src/bsp_ut_voltab.c deleted file mode 100644 index 0cc20947c..000000000 --- a/src/bsp/mcp750-vxworks/ut-src/bsp_ut_voltab.c +++ /dev/null @@ -1,67 +0,0 @@ -/* -** File : bsp_voltab.c -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Author : Nicholas Yanchik / GSFC Code 582 -** -** BSP Volume table for file systems -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ -#include "common_types.h" -#include "osapi.h" - - -/* -** volume table. -*/ -OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = -{ - -/* Dev Name Phys Dev Vol Type Volatile? Free? IsMounted? Volname MountPt BlockSz */ - -/* RAM Disk */ -{"/ramdev0", " ", RAM_DISK, true, true, false, " ", " ", 0 }, - -/* non-volatile Disk -- Auto-Mapped to an existing CF disk */ -{"/eedev0", "CF:0", FS_BASED, false, false, true, "CF", "/cf", 512 }, - -/* -** Spare RAM disks to be used for SSR and other RAM disks -*/ -{"/ramdev1", " ", RAM_DISK, true, true, false, " ", " ", 0 }, -{"/ramdev2", " ", RAM_DISK, true, true, false, " ", " ", 0 }, -{"/ramdev3", " ", RAM_DISK, true, true, false, " ", " ", 0 }, -{"/ramdev4", " ", RAM_DISK, true, true, false, " ", " ", 0 }, -{"/ramdev5", " ", RAM_DISK, true, true, false, " ", " ", 0 }, - - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 } -}; - -/* - * An example of a static symbol loader table - * Only used if OS_STATIC_LOADER is enabled in osconfig.h - */ -OS_static_symbol_record_t OS_STATIC_SYMBOL_TABLE[] = -{ - { "OS_Application_Startup", OS_Application_Startup }, - { NULL, NULL } -}; - - diff --git a/src/bsp/pc-linux/CMakeLists.txt b/src/bsp/pc-linux/CMakeLists.txt index 81f6fd86a..783c96800 100644 --- a/src/bsp/pc-linux/CMakeLists.txt +++ b/src/bsp/pc-linux/CMakeLists.txt @@ -8,9 +8,10 @@ # enough to be applied to non-PC systems running embedded Linux, such # as Raspberry Pi, BeagleBoard, Zync, or custom hardware. -add_library(osal_pc-linux_impl OBJECT +add_library(osal_pc-linux_impl OBJECT src/bsp_start.c src/bsp_voltab.c + src/bsp_console.c ) # OSAL needs conformance to at least POSIX.1c (aka POSIX 1995) - this includes all the @@ -23,18 +24,6 @@ add_library(osal_pc-linux_impl OBJECT # # See http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html # for a more detailed description of the feature test macros and available values -target_compile_definitions(osal_pc-linux_impl PUBLIC +target_compile_definitions(osal_pc-linux_impl PUBLIC _XOPEN_SOURCE=600 ) - -add_library(ut_bsp STATIC EXCLUDE_FROM_ALL - ut-src/bsp_ut.c - ut-src/bsp_ut_voltab.c -) -target_include_directories(ut_bsp PRIVATE - ${UT_ASSERT_SOURCE_DIR}/inc -) -target_compile_definitions(ut_bsp PUBLIC - _XOPEN_SOURCE=600 -) - diff --git a/src/bsp/pc-linux/build_options.cmake b/src/bsp/pc-linux/build_options.cmake index 588661a96..c0a7a5c07 100644 --- a/src/bsp/pc-linux/build_options.cmake +++ b/src/bsp/pc-linux/build_options.cmake @@ -6,9 +6,9 @@ -# Linux system libraries required for the final link of applications using OSAL -target_link_libraries(osal - pthread dl rt +# Linux system libraries required for the final link of applications using OSAL +target_link_libraries(osal_bsp + pthread dl rt ) # C flags that should be used when (re-) compiling code for unit testing. diff --git a/src/bsp/pc-linux/src/bsp_console.c b/src/bsp/pc-linux/src/bsp_console.c new file mode 100644 index 000000000..94e7041be --- /dev/null +++ b/src/bsp/pc-linux/src/bsp_console.c @@ -0,0 +1,102 @@ +/****************************************************************************** +** File: bsp_console.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** OSAL BSP debug console abstraction +** +******************************************************************************/ + +#include +#include +#include +#include + +#include "pclinux_bsp_internal.h" +#include "bsp-impl.h" + +/*---------------------------------------------------------------- + OS_BSP_ExecTput() + + Helper function: Use the system "tput" utility to set the given + console capability. + + This uses a fork/exec to invoke the external command which outputs + the control sequence directly to the controlling terminal. + + It is assumed that this will only be used during debug/testing. + Otherwise it would be preferable to cache the control strings to + avoid repetitive fork/exec operations. + ------------------------------------------------------------------*/ +static void OS_BSP_ExecTput(const char *cap, const char *param) +{ + pid_t cpid; + int status; + + cpid = fork(); + if (cpid < 0) + { + return; + } + if (cpid == 0) + { + execlp("tput", "tput", cap, param, NULL); + exit(EXIT_FAILURE); + } + waitpid(cpid, &status, 0); +} + +/**************************************************************************************** + BSP CONSOLE IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*---------------------------------------------------------------- + OS_BSP_ConsoleOutput_Impl + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +{ + /* writes the raw data directly to STDOUT_FILENO (unbuffered) */ + write(STDOUT_FILENO, Str, DataLen); +} + +/*---------------------------------------------------------------- + OS_BSP_ConsoleSetMode_Impl() definition + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits) +{ + char param[32]; + + if (OS_BSP_PcLinuxGlobal.EnableTermControl) + { + if (ModeBits == OS_BSP_CONSOLEMODE_NORMAL) + { + OS_BSP_ExecTput("sgr0", NULL); + } + else + { + if ((ModeBits & OS_BSP_CONSOLEMODE_HIGHLIGHT) == 0) + { + /* no highlight (standout) text */ + OS_BSP_ExecTput("rmso", NULL); + } + else + { + /* set highlight (standout) text */ + OS_BSP_ExecTput("smso", NULL); + } + + snprintf(param, sizeof(param), "%d", OS_BSP_CONSOLEMODE_TO_ANSICOLOR(ModeBits)); + OS_BSP_ExecTput("setaf", param); + } + } +} diff --git a/src/bsp/pc-linux/src/bsp_start.c b/src/bsp/pc-linux/src/bsp_start.c index 9836e6e98..50d080fcb 100644 --- a/src/bsp/pc-linux/src/bsp_start.c +++ b/src/bsp/pc-linux/src/bsp_start.c @@ -2,42 +2,136 @@ ** File: bsp_start.c ** ** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. ** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. ** ** ** Purpose: ** OSAL BSP main entry point. ** ** History: -** 2005/07/26 A. Cudmore | Initial version for linux +** 2005/07/26 A. Cudmore | Initial version for linux ** ******************************************************************************/ -/* -** OSAL includes -*/ -#include "osapi.h" +#include +#include +#include +#include +#include +#include -/* -** Types and prototypes for this module -*/ +#include "pclinux_bsp_internal.h" -/* -** External Declarations -*/ -void OS_Application_Startup(void); - -/* -** Global variables -*/ +OS_BSP_PcLinuxGlobalData_t OS_BSP_PcLinuxGlobal; + +/* --------------------------------------------------------- + OS_BSP_Initialize() + + Helper function to auto-create any missing FS_BASED mount + points listed in OS_VolumeTable. If these do not actually + exist then app code may fail. + --------------------------------------------------------- */ +void OS_BSP_Initialize(void) +{ + mode_t mode; + uint32 i; + struct stat statbuf; + FILE *fp; + char buffer[32]; + + /* + ** Create local directories for "disk" mount points + ** See bsp_voltab for the values + ** + ** NOTE - the voltab table is poorly designed here; values of "0" are valid + ** and will translate into an entry that is actually used. In particular the + ** "free" flag has to be actually initialized to TRUE to say its NOT valid. + ** So in the case of an entry that has been zeroed out (i.e. bss section) it + ** will be treated as a valid entry. + ** + ** Checking that the DeviceName starts with a leading slash '/' is a workaround + ** for this, and may be the only way to detect an entry that is uninitialized. + */ + mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO; + for (i = 0; i < NUM_TABLE_ENTRIES; ++i) + { + if (OS_VolumeTable[i].VolumeType == FS_BASED && + OS_VolumeTable[i].PhysDevName[0] != 0 && + OS_VolumeTable[i].DeviceName[0] == '/') + + { + if (stat(OS_VolumeTable[i].PhysDevName, &statbuf) < 0) + { + BSP_DEBUG("Creating mount point: %s\n", OS_VolumeTable[i].PhysDevName); + mkdir(OS_VolumeTable[i].PhysDevName, mode); + } + } + } + + /* + * If not running as root, check /proc/sys/fs/mqueue/msg_max + * + * This special file represents the max depth of a POSIX message queue for an unprivileged user. + * + * In order to facilitate running in simulation mode without any need for root access -- + * this will allow the OSAL to successfully create message queues by truncating anything larger than this size. + * + * No need to check _LINUX_OS_ here; if the file fails to open, i.e. if not on Linux and the file does not exist, + * then leave well enough alone and don't do anything. + */ + if (geteuid() != 0) + { + fp = fopen("/proc/sys/fs/mqueue/msg_max","r"); + if (fp) + { + if (fgets(buffer,sizeof(buffer),fp) != NULL) + { + OS_BSP_Global.MaxQueueDepth = strtoul(buffer, NULL, 10); + BSP_DEBUG("Maximum user msg queue depth = %u\n", (unsigned int)OS_BSP_Global.MaxQueueDepth); + } + fclose(fp); + } + } +} + +/* --------------------------------------------------------- + OS_BSP_GetReturnStatus() + + Helper function to convert an OSAL status code into + a code suitable for returning to the OS. + --------------------------------------------------------- */ +int OS_BSP_GetReturnStatus(void) +{ + int retcode; + + switch (OS_BSP_Global.AppStatus) + { + case OS_SUCCESS: + /* translate OS_SUCCESS to the system EXIT_SUCCESS value (usually 0) */ + retcode = EXIT_SUCCESS; + break; + + case OS_ERROR: + /* translate OS_ERROR to the system EXIT_FAILURE value (usually 1) */ + retcode = EXIT_FAILURE; + break; + + default: + /* any other value will be passed through (implementation-defined) */ + /* Range is limited to 0-127, however */ + retcode = OS_BSP_Global.AppStatus & 0x7F; + break; + } + + return retcode; +} - /****************************************************************************** ** Function: main() ** @@ -53,23 +147,56 @@ void OS_Application_Startup(void); int main(int argc, char *argv[]) { - /* - ** OS_API_Init is called by OS_Application_Startup - ** Also note that OS_API_Init now also takes care of signal masking - */ - - /* - ** Call application specific entry point. - */ - OS_Application_Startup(); - - /* - ** OS_IdleLoop() will wait forever and return if - ** someone calls OS_ApplicationShutdown(true) - */ - OS_IdleLoop(); - - /* Should typically never get here */ - return(EXIT_SUCCESS); -} + /* + * Initially clear the global objects + */ + memset(&OS_BSP_Global, 0, sizeof(OS_BSP_Global)); + memset(&OS_BSP_PcLinuxGlobal, 0, sizeof(OS_BSP_PcLinuxGlobal)); + /* + * Save the argc/argv arguments for future use. + * In particular the UT-specific logic uses this + * to control verbosity. + * + * Note that the first argument (0) is the command name. The + * first "real" argument is at position 1. + * + * The first arg is ignored to be more consistent with other platforms + * where this is not passed in. + */ + if (argc > 1) + { + OS_BSP_Global.ArgC = argc - 1; + OS_BSP_Global.ArgV = &argv[1]; + } + + /* + * Only attempt terminal control if the stdout is a TTY + * and the TERM environment variable is set + */ + if (getenv("TERM") != NULL) + { + OS_BSP_PcLinuxGlobal.EnableTermControl = isatty(STDOUT_FILENO); + } + + /* + * Auto-Create any missing FS_BASED mount points specified in OS_VolumeTable + */ + OS_BSP_Initialize(); + + /* + * Call application specific entry point. + * This should set up all user tasks and resources, then return + */ + OS_Application_Startup(); + + /* + * OS_Application_Run() implements the background task. + * The user application may provide this, or a default implementation + * is used which just calls OS_IdleLoop(). + */ + OS_Application_Run(); + + /* Should typically never get here */ + return OS_BSP_GetReturnStatus(); +} diff --git a/src/bsp/pc-linux/src/bsp_voltab.c b/src/bsp/pc-linux/src/bsp_voltab.c index 7f3019dd5..ca881b265 100644 --- a/src/bsp/pc-linux/src/bsp_voltab.c +++ b/src/bsp/pc-linux/src/bsp_voltab.c @@ -17,9 +17,8 @@ /**************************************************************************************** INCLUDE FILES ****************************************************************************************/ -#include "common_types.h" -#include "osapi.h" +#include "pclinux_bsp_internal.h" /* ** volume table. @@ -48,5 +47,3 @@ OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = {"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 } }; - - diff --git a/src/bsp/pc-linux/src/pclinux_bsp_internal.h b/src/bsp/pc-linux/src/pclinux_bsp_internal.h new file mode 100644 index 000000000..460df5c98 --- /dev/null +++ b/src/bsp/pc-linux/src/pclinux_bsp_internal.h @@ -0,0 +1,37 @@ +/****************************************************************************** +** File: pclinux_bsp_internal.h +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Header file for internal data to the PC-LINUX BSP +** +******************************************************************************/ + +#ifndef _PCLINUX_BSP_INTERNAL_H_ +#define _PCLINUX_BSP_INTERNAL_H_ + +#include "osapi.h" +#include "bsp-impl.h" + +/* +** BSP types +*/ +typedef struct +{ + bool EnableTermControl; /**< Will be set "true" when invoked from a TTY device, false otherwise */ +} OS_BSP_PcLinuxGlobalData_t; + +/* + * Global Data object + */ +extern OS_BSP_PcLinuxGlobalData_t OS_BSP_PcLinuxGlobal; + +#endif /* _PCLINUX_BSP_INTERNAL_H_ */ diff --git a/src/bsp/pc-linux/ut-src/bsp_ut.c b/src/bsp/pc-linux/ut-src/bsp_ut.c deleted file mode 100644 index a9cb1449f..000000000 --- a/src/bsp/pc-linux/ut-src/bsp_ut.c +++ /dev/null @@ -1,362 +0,0 @@ -/****************************************************************************** -** File: bsp_ut.c -** -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Purpose: -** BSP unit test implementation functions. -** -** History: -** Created on: Feb 10, 2015 -** -******************************************************************************/ - -/* - * NOTE - This entire source file is only relevant for unit testing. - * It should not be included in a "normal" BSP build. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "osapi.h" -#include "utbsp.h" -#include "uttest.h" - -static const char BSP_TERMCODE_HIGHLIGHT[] = "\x1b[31m"; -static const char BSP_TERMCODE_NORMAL[] = "\x1b[0m"; -static const char BSP_TERMCODE_NONE[] = ""; - -/* -** External Declarations -*/ -extern OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES]; - -/* -** Local Variables -*/ -static int32 NumUserOptions = 0; -static char **FirstUserOption = NULL; -static uint32 CurrVerbosity = (2 << UTASSERT_CASETYPE_PASS) - 1; -static bool EnableTermCodes = false; - -/* - * UT_BSP_GetTotalOptions: See details in prototype - */ -int32 UT_BSP_GetTotalOptions(void) -{ - return NumUserOptions; -} - -/* - * UT_BSP_GetOptionString: See details in prototype - */ -const char * UT_BSP_GetOptionString(int32 OptionNum) -{ - if (OptionNum >= NumUserOptions) - { - return NULL; - } - - return FirstUserOption[OptionNum]; -} - - - -void UT_BSP_ParseCommandLine(int argc, char *argv[]) -{ - uint8 UserShift; - int opt; - - UserShift = UTASSERT_CASETYPE_NONE; - while ((opt = getopt(argc, argv, "v:qd")) != -1) - { - switch (opt) { - case 'd': - UserShift = UTASSERT_CASETYPE_DEBUG; - break; - case 'q': - UserShift = UTASSERT_CASETYPE_FAILURE; - break; - case 'v': - UserShift = atoi(optarg); - break; - default: /* '?' */ - fprintf(stderr, "Usage: %s [-v verbosity] [-d] [-q]\n", - argv[0]); - exit(EXIT_FAILURE); - } - if (UserShift > 0 && UserShift < UTASSERT_CASETYPE_MAX) - { - CurrVerbosity = (2 << UserShift) - 1; - } - } - - if (optind < argc) - { - NumUserOptions = argc - optind; - FirstUserOption = &argv[optind]; - } -} - -void UT_BSP_Setup(void) -{ - int mode; - uint32 i; - struct stat statbuf; - - /* - * Enable terminal codes only if stdout is actually terminal. - * This should prevent log files from having escape codes, for - * when output is redirected to a file. - */ - EnableTermCodes = isatty(STDOUT_FILENO); - - - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "PC-LINUX UNIT TEST"); - - /* - ** Create local directories for "disk" mount points - ** See bsp_voltab for the values - ** - ** NOTE - the voltab table is poorly designed here; values of "0" are valid - ** and will translate into an entry that is actually used. In particular the - ** "free" flag has to be actually initialized to TRUE to say its NOT valid. - ** So in the case of an entry that has been zeroed out (i.e. bss section) it - ** will be treated as a valid entry. - ** - ** Checking that the DeviceName starts with a leading slash '/' is a workaround - ** for this, and may be the only way to detect an entry that is uninitialized. - */ - mode = S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO; - for (i=0; i < NUM_TABLE_ENTRIES; ++i) - { - if (OS_VolumeTable[i].VolumeType == FS_BASED && - OS_VolumeTable[i].PhysDevName[0] != 0 && - OS_VolumeTable[i].DeviceName[0] == '/') - - { - if (stat(OS_VolumeTable[i].PhysDevName, &statbuf) < 0) - { - printf("Creating mount point directory: %s\n", - OS_VolumeTable[i].PhysDevName); - mkdir(OS_VolumeTable[i].PhysDevName, mode); - } - } - } -} - -void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u %s", (unsigned int)SegmentNumber, SegmentName); - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, ReportBuffer); -} - -void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) -{ - const char *Prefix; - const char *ControlCodeStart = NULL; - const char *ControlCodeEnd = NULL; - - if ((CurrVerbosity >> MessageType) & 1) - { - switch(MessageType) - { - case UTASSERT_CASETYPE_ABORT: - Prefix = "ABORT"; - break; - case UTASSERT_CASETYPE_FAILURE: - ControlCodeStart = BSP_TERMCODE_HIGHLIGHT; - Prefix = "FAIL"; - break; - case UTASSERT_CASETYPE_MIR: - Prefix = "MIR"; - break; - case UTASSERT_CASETYPE_TSF: - Prefix = "TSF"; - break; - case UTASSERT_CASETYPE_TTF: - Prefix = "TTF"; - break; - case UTASSERT_CASETYPE_NA: - Prefix = "N/A"; - break; - case UTASSERT_CASETYPE_BEGIN: - printf("\n"); /* add a bit of extra whitespace between tests */ - Prefix = "BEGIN"; - break; - case UTASSERT_CASETYPE_END: - Prefix = "END"; - break; - case UTASSERT_CASETYPE_PASS: - Prefix = "PASS"; - break; - case UTASSERT_CASETYPE_INFO: - Prefix = "INFO"; - break; - case UTASSERT_CASETYPE_DEBUG: - Prefix = "DEBUG"; - break; - default: - Prefix = "OTHER"; - break; - } - - if (!EnableTermCodes || ControlCodeStart == NULL) - { - ControlCodeStart = BSP_TERMCODE_NONE; - ControlCodeEnd = BSP_TERMCODE_NONE; - } - else if (ControlCodeEnd == NULL) - { - ControlCodeEnd = BSP_TERMCODE_NORMAL; - } - printf("[%s%5s%s] %s\n",ControlCodeStart,Prefix,ControlCodeEnd,OutputMessage); - } - - /* - * If any ABORT (major failure) message is thrown, - * then actually call abort() to stop the test and dump a core - */ - if (MessageType == UTASSERT_CASETYPE_ABORT) - { - abort(); - } -} - -void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 TestSeq, uint8 MessageType, const char *SubsysName, const char *ShortDesc) -{ - uint32 FileLen; - const char *BasePtr; - char ReportBuffer[128]; - - FileLen = strlen(File); - BasePtr = File + FileLen; - while (FileLen > 0) - { - --BasePtr; - --FileLen; - if (*BasePtr == '/' || *BasePtr == '\\') - { - ++BasePtr; - break; - } - } - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u.%03u %s:%u - %s", - (unsigned int)SegmentNum, (unsigned int)TestSeq, - BasePtr, (unsigned int)LineNum, ShortDesc); - - UT_BSP_DoText(MessageType, ReportBuffer); -} - -void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCounter_t *TestCounters) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), - "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-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_NA]); - - - UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); -} - -void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters) -{ - int status = 0; - - /* - * Only output a "summary" if there is more than one test Segment. - * Otherwise it is a duplicate of the report already given. - */ - if (TestCounters->TestSegmentCount > 1) - { - UT_BSP_DoTestSegmentReport("SUMMARY", TestCounters); - } - - printf("COMPLETE: %u tests Segment(s) executed\n\n", (unsigned int)TestCounters->TestSegmentCount); - - /* - * The Linux UT BSP allows at least a 7 bit status code to be returned to the OS (i.e. the exit status - * of the process). This is useful to report pass/fail. Because we have multiple bits, we can make - * descriptive exit status codes to indicate what went wrong. Anything nonzero represents failure. - * - * Consider Failures as well as "TSF" (setup failures) to be grounds for returning nonzero (bad) status. - * Also the lack of ANY test cases should produce a bad status. - * - * "MIR" results should not produce a bad status -- these may have worked fine, we do not know. - * - * Likewise "N/A" tests are simply not applicable, so we just ignore them. - */ - - if (TestCounters->TotalTestCases == 0) - { - status |= 0x01; - } - - if (TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE] > 0) - { - status |= 0x02; - } - - if (TestCounters->CaseCount[UTASSERT_CASETYPE_TSF] > 0) - { - status |= 0x04; - } - - exit(status); -} - -/****************************************************************************** -** Function: main() -** -** Purpose: -** BSP Unit Test Application entry point. -** -** Arguments: -** (none) -** -** Return: -** (none) -*/ - -int main(int argc, char *argv[]) -{ - UT_BSP_ParseCommandLine(argc, argv); - - /* - ** Call application specific entry point. - */ - OS_Application_Startup(); - - /* - ** The OS_Application_Run function is part of UT Assert library - */ - OS_Application_Run(); - - /* Should typically never get here */ - return(EXIT_SUCCESS); -} - diff --git a/src/bsp/pc-linux/ut-src/bsp_ut_voltab.c b/src/bsp/pc-linux/ut-src/bsp_ut_voltab.c deleted file mode 100644 index a1256a461..000000000 --- a/src/bsp/pc-linux/ut-src/bsp_ut_voltab.c +++ /dev/null @@ -1,65 +0,0 @@ -/* -** File : bsp_voltab.c -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Author : Nicholas Yanchik / GSFC Code 582 -** -** BSP Volume table for file systems -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ -#include "common_types.h" -#include "osapi.h" - - -/* -** volume table. -*/ -OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = -{ -/* Dev Name Phys Dev Vol Type Volatile? Free? IsMounted? Volname MountPt BlockSz */ -{"/ramdev0", "./ram0", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev1", "./ram1", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev2", "./ram2", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev3", "./ram3", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev4", "./ram4", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev5", "./ram5", FS_BASED, true, true, false, " ", " ", 0 }, - -/* -** The following entry is a "pre-mounted" path to a non-volatile device -*/ -{"/eedev0", "./eeprom1", FS_BASED, false, false, true, "CF", "/cf", 512 }, - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 } -}; - - -/* - * An example of a static symbol loader table - * Only used if OS_STATIC_LOADER is enabled in osconfig.h - */ -#ifdef OS_STATIC_LOADER -OS_static_symbol_record_t OS_STATIC_SYMBOL_TABLE[] = -{ - { "OS_Application_Startup", OS_Application_Startup }, - { NULL, NULL } -}; -#endif - - - diff --git a/src/bsp/pc-rtems/CMakeLists.txt b/src/bsp/pc-rtems/CMakeLists.txt index 0e53dd48a..7d003a861 100644 --- a/src/bsp/pc-rtems/CMakeLists.txt +++ b/src/bsp/pc-rtems/CMakeLists.txt @@ -4,13 +4,8 @@ # ###################################################################### -add_library(osal_pc-rtems_impl OBJECT +add_library(osal_pc-rtems_impl OBJECT src/bsp_start.c src/bsp_voltab.c + src/bsp_console.c ) - -add_library(ut_bsp STATIC EXCLUDE_FROM_ALL - ut-src/bsp_ut.c - ut-src/bsp_ut_voltab.c -) -target_include_directories(ut_bsp PRIVATE ${UT_ASSERT_SOURCE_DIR}/inc) diff --git a/src/bsp/pc-rtems/build_options.cmake b/src/bsp/pc-rtems/build_options.cmake index f5d26ce06..1690376ff 100644 --- a/src/bsp/pc-rtems/build_options.cmake +++ b/src/bsp/pc-rtems/build_options.cmake @@ -5,7 +5,7 @@ ########################################################################## # Link the RTEMS BSP with the "rtemscpu" system library -target_link_libraries(osal +target_link_libraries(osal_bsp rtemscpu ) diff --git a/src/bsp/pc-rtems/src/bsp_console.c b/src/bsp/pc-rtems/src/bsp_console.c new file mode 100644 index 000000000..cc90cbba8 --- /dev/null +++ b/src/bsp/pc-rtems/src/bsp_console.c @@ -0,0 +1,49 @@ +/****************************************************************************** +** File: bsp_console.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** OSAL BSP debug console abstraction +** +******************************************************************************/ + +#include +#include +#include +#include + +#include "pcrtems_bsp_internal.h" +#include "bsp-impl.h" + +/**************************************************************************************** + BSP CONSOLE IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*---------------------------------------------------------------- + OS_BSP_ConsoleOutput_Impl + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +{ + /* writes the raw data directly to STDOUT_FILENO (unbuffered) */ + write(STDOUT_FILENO, Str, DataLen); +} + +/*---------------------------------------------------------------- + OS_BSP_ConsoleSetMode_Impl() definition + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits) +{ + /* no-op on RTEMS */ +} + + diff --git a/src/bsp/pc-rtems/src/bsp_start.c b/src/bsp/pc-rtems/src/bsp_start.c index 9f143505e..bcce3f6e2 100644 --- a/src/bsp/pc-rtems/src/bsp_start.c +++ b/src/bsp/pc-rtems/src/bsp_start.c @@ -2,12 +2,12 @@ ** File: bsp_start.c ** ** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. ** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. ** ** ** Purpose: @@ -22,42 +22,30 @@ */ #include #include +#include #include +#include +#include #include #include #include #include #include +#include #include #include #include #include #include +#include -/* -** External Declarations -*/ -void OS_Application_Startup(void); - -extern rtems_status_code rtems_ide_part_table_initialize (const char* ); - -/* -** cFE includes -*/ -#include "common_types.h" -#include "osapi.h" - -#ifdef _UNIT_TEST_ -#include "utbsp.h" -#include "uttest.h" -#endif - -#define RTEMS_NUMBER_OF_RAMDISKS 1 - +#include "pcrtems_bsp_internal.h" /* -** Global variables +** External Declarations */ +extern rtems_status_code rtems_ide_part_table_initialize(const char *); +extern int rtems_rtl_shell_command (int argc, char* argv[]); /* * The RAM Disk configuration. @@ -66,7 +54,7 @@ rtems_ramdisk_config rtems_ramdisk_configuration[RTEMS_NUMBER_OF_RAMDISKS]; /* * The number of RAM Disk configurations. -*/ + */ size_t rtems_ramdisk_configuration_size = RTEMS_NUMBER_OF_RAMDISKS; /* @@ -82,126 +70,307 @@ rtems_driver_address_table rtems_ramdisk_io_ops = .control_entry = rtems_blkdev_generic_ioctl }; -rtems_id RtemsTimerId; - /* - * The RTEMS shell needs a function to check the validity of a login username/password - * This is just a stub that always passes. + * Additional shell commands for the RTL functionality */ -bool BSP_Login_Check(const char *user, const char *passphrase) -{ - return true; -} +rtems_shell_cmd_t rtems_shell_RTL_Command = { + .name = "rtl", + .usage = "rtl COMMAND...", + .topic = "misc", + .command = rtems_rtl_shell_command +}; +rtems_shell_cmd_t rtems_shell_dlopen_Command = { + .name = "dlopen", + .usage = "dlopen COMMAND...", + .topic = "misc", + .command = shell_dlopen +}; +rtems_shell_cmd_t rtems_shell_dlsym_Command = { + .name = "dlsym", + .usage = "dlsym COMMAND...", + .topic = "misc", + .command = shell_dlsym +}; /* -** 1 HZ Timer "ISR" +** Global variables */ -int timer_count = 0; +OS_BSP_PcRtemsGlobalData_t OS_BSP_PcRtemsGlobal; -void BSP_Setup(void) +void OS_BSP_Setup(void) { - int status; - -#ifdef _UNIT_TEST_ - UT_BSP_Setup("PC-RTEMS UNIT TEST"); -#endif - - OS_printf( "\n\n*** RTEMS Info ***\n" ); - OS_printf("%s", _Copyright_Notice ); - OS_printf("%s\n\n", _RTEMS_version ); - OS_printf(" Stack size=%d\n", (int)Configuration.stack_space_size ); - OS_printf(" Workspace size=%d\n", (int) Configuration.work_space_size ); - OS_printf("\n"); - OS_printf( "*** End RTEMS info ***\n\n" ); - - /* - ** Create the RTEMS Root file system - */ - status = rtems_create_root_fs(); - if (status != RTEMS_SUCCESSFUL) - { - OS_printf("Creating Root file system failed: %s\n",rtems_status_text(status)); - } - - /* - ** create the directory mountpoints - */ - status = mkdir("/ram", S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO); /* For ramdisk mountpoint */ - if (status != RTEMS_SUCCESSFUL) - { - OS_printf("mkdir failed: %s\n", strerror (errno)); - } - - status = mkdir("/cf", S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO); /* For EEPROM mountpoint */ - if (status != RTEMS_SUCCESSFUL) - { - OS_printf("mkdir failed: %s\n", strerror (errno)); - return; - } - - /* - * Register the IDE partition table. + int status; + unsigned int i; + struct stat statbuf; + const char * cfpart; + const char * cmdlinestr; + const char * cmdp; + char * cmdi, *cmdo; + + 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); + if (cmdlinestr != NULL) + { + printf(" Bootloader Command Line: %s\n", cmdlinestr); + } + + printf("\n"); + printf("*** End RTEMS info ***\n\n"); + + /* + * Parse command line string (passed in from bootloader) + * + * Known arguments are handled here, and unknown args are + * saved for the UT application. + * + * Batch mode is intended for non-interative execution. + * + * It does two things: + * - do not start the shell task + * - when tests are complete, shutdown the executive + * + * The BSP should be configured with these options to + * make this most useful: + * USE_COM1_AS_CONSOLE=1 + * BSP_PRESS_KEY_FOR_RESET=0 + * BSP_RESET_BOARD_AT_EXIT=1 + * + * This way all the test output will be sent to COM1 + * and then immediately resets the CPU when done. + * + * When running under QEMU the "-no-reboot" flag is + * also useful to shutdown QEMU rather than resetting. + */ + if (cmdlinestr != NULL) + { + cmdp = cmdlinestr; + cmdo = NULL; + cmdi = NULL; + + while (1) + { + if (isgraph((int)*cmdp)) + { + if (cmdo == NULL) + { + cmdo = OS_BSP_PcRtemsGlobal.UserArgBuffer; + } + else + { + ++cmdo; + } + if (cmdi == NULL) + { + cmdi = cmdo; + } + *cmdo = *cmdp; + } + else if (cmdi != NULL) + { + ++cmdo; + *cmdo = 0; + if (strcmp(cmdi, "--batch-mode") == 0) + { + OS_BSP_PcRtemsGlobal.BatchMode = true; + } + else if (OS_BSP_Global.ArgC < RTEMS_MAX_USER_OPTIONS) + { + /* save other args for app */ + OS_BSP_Global.ArgV[OS_BSP_Global.ArgC] = cmdi; + ++OS_BSP_Global.ArgC; + } + cmdi = NULL; + } + + if (*cmdp == 0) + { + break; + } + + ++cmdp; + } + } + + /* + ** Create the RTEMS Root file system */ - status = rtems_ide_part_table_initialize ("/dev/hda"); - if (status != RTEMS_SUCCESSFUL) - { - OS_printf ("error: ide partition table not found: %s / %s\n", - rtems_status_text (status),strerror(errno)); - } - - status = mount("/dev/hda1", "/cf", - RTEMS_FILESYSTEM_TYPE_DOSFS, - RTEMS_FILESYSTEM_READ_WRITE, - NULL); - if (status < 0) - { - OS_printf ("mount failed: %s\n", strerror (errno)); - } + status = rtems_create_root_fs(); + if (status != RTEMS_SUCCESSFUL) + { + printf("Creating Root file system failed: %s\n", rtems_status_text(status)); + } + + /* + * Register the IDE partition table. + */ + status = rtems_ide_part_table_initialize("/dev/hda"); + if (status != RTEMS_SUCCESSFUL) + { + /* note this is not necessarily an error, it just means there + * will be no persistent storage in this instance. The IMFS + * is still available. */ + BSP_DEBUG("warning: /dev/hda partition table not found: %s / %s\n", rtems_status_text(status), strerror(errno)); + BSP_DEBUG("Persistent storage will NOT be mounted\n"); + cfpart = NULL; + } + else + { + cfpart = "/dev/hda1"; + } + + /* + ** Create local directories for "disk" mount points + ** See bsp_voltab for the values + ** + ** NOTE - the voltab table is poorly designed here; values of "0" are valid + ** and will translate into an entry that is actually used. In particular the + ** "free" flag has to be actually initialized to TRUE to say its NOT valid. + ** So in the case of an entry that has been zeroed out (i.e. bss section) it + ** will be treated as a valid entry. + ** + ** Checking that the DeviceName starts with a leading slash '/' is a workaround + ** for this, and may be the only way to detect an entry that is uninitialized. + */ + for (i = 0; i < NUM_TABLE_ENTRIES; ++i) + { + if (OS_VolumeTable[i].VolumeType == FS_BASED && OS_VolumeTable[i].PhysDevName[0] != 0 && + OS_VolumeTable[i].DeviceName[0] == '/') + + { + if (stat(OS_VolumeTable[i].PhysDevName, &statbuf) < 0) + { + status = mkdir(OS_VolumeTable[i].PhysDevName, + S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO); /* For ramdisk mountpoint */ + if (status < 0) + { + printf("mkdir failed: %s\n", strerror(errno)); + } + } + if (cfpart != NULL && strcmp(OS_VolumeTable[i].MountPoint, "/cf") == 0) + { + status = mount(cfpart, OS_VolumeTable[i].PhysDevName, RTEMS_FILESYSTEM_TYPE_DOSFS, + RTEMS_FILESYSTEM_READ_WRITE, NULL); + if (status < 0) + { + printf("mount failed: %s\n", strerror(errno)); + } + } + } + } + + /* + * Start the shell now, before any application starts. + * This way, if there is an issue with the application startup, + * the shell can still be used to debug the system. + * + * The shell is _NOT_ started if the "--batch-mode" switch is + * given (this means to run completely autonomous) + */ + if (!OS_BSP_PcRtemsGlobal.BatchMode) + { + status = rtems_shell_init("SHLL", RTEMS_MINIMUM_STACK_SIZE * 4, RTEMS_SHELL_PRIORITY, "/dev/console", false, + false, NULL); + if (status < 0) + { + printf("shell init failed: %d / %s\n", status, strerror(errno)); + } + + /* give a small delay to let the shell start, + avoids having the login prompt show up mid-test, + and gives a little time for pending output to actually + be sent to the console in case of a slow port */ + rtems_task_wake_after(50); + } + + printf("\n\n"); +} + +/* --------------------------------------------------------- + OS_BSP_GetReturnStatus() + Helper function to convert an OSAL status code into + a code suitable for returning to the OS. + --------------------------------------------------------- */ +rtems_status_code OS_BSP_GetReturnStatus(void) +{ + rtems_status_code retcode; + const char * StatusStr; + + switch (OS_BSP_Global.AppStatus) + { + case OS_SUCCESS: + /* translate OS_SUCCESS to the system RTEMS_SUCCESSFUL value */ + StatusStr = "SUCCESS"; + retcode = RTEMS_SUCCESSFUL; + break; + + default: + /* translate anything else to a generic non-success code, + * this basically just means the main task exited */ + StatusStr = "ERROR"; + retcode = RTEMS_TASK_EXITTED; + break; + } + + printf("\nApplication exit status: %s (%d)\n\n", StatusStr, (int)OS_BSP_Global.AppStatus); + rtems_task_wake_after(100); + + return retcode; } /* -** A simple entry point to start from the loader -*/ -rtems_task Init( - rtems_task_argument ignored -) + ** A simple entry point to start from the loader + */ +rtems_task Init(rtems_task_argument ignored) { - BSP_Setup(); - - if (rtems_shell_init("SHLL", RTEMS_MINIMUM_STACK_SIZE * 4, 100, "/dev/console", false, false, BSP_Login_Check) < 0) - { - OS_printf ("shell init failed: %s\n", strerror (errno)); - } - - /* - ** Call application specific entry point. - ** This is supposed to call OS_API_Init() - */ - OS_Application_Startup(); - -#ifdef _UNIT_TEST_ - - /* - ** In unit test mode, call the UtTest_Run function (part of UT Assert library) - */ - UtTest_Run(); - UT_BSP_EndTest(UtAssert_GetCounters()); - -#else - - /* - ** OS_IdleLoop() will wait forever and return if - ** someone calls OS_ApplicationShutdown(true) - */ - OS_IdleLoop(); - -#endif - + /* + * Initially clear the global object + */ + memset(&OS_BSP_Global, 0, sizeof(OS_BSP_Global)); + memset(&OS_BSP_PcRtemsGlobal, 0, sizeof(OS_BSP_PcRtemsGlobal)); + + /* + * Perform BSP setup - + * Initialize the root file system, create mount points, etc. + */ + OS_BSP_Setup(); + + /* + * Call application specific entry point. + * This should set up all user tasks and resources, then return + */ + OS_Application_Startup(); + + /* + * OS_Application_Run() implements the background task. + * The user application may provide this, or a default implementation + * is used which just calls OS_IdleLoop(). + */ + OS_Application_Run(); + + /* + * Not calling exit() under RTEMS, this simply shuts down the executive, + * forcing the user to reboot the system. + * + * Calling suspend causes execution to get stuck here, but the RTEMS + * shell thread will still be active so the user can poke around, read results, + * then use a shell command to reboot when ready. + */ + while (!OS_BSP_PcRtemsGlobal.BatchMode) + { + printf("\n\nInit thread idle.\nPress for shell or reset machine...\n\n"); + rtems_task_suspend(rtems_task_self()); + } + + rtems_shutdown_executive(OS_BSP_GetReturnStatus()); } - /* configuration information */ /* @@ -211,43 +380,46 @@ rtems_task Init( #define CONFIGURE_INIT #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_FLOATING_POINT | RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(TASK_INTLEVEL)) #define CONFIGURE_INIT_TASK_STACK_SIZE (20*1024) -#define CONFIGURE_INIT_TASK_PRIORITY 120 +#define CONFIGURE_INIT_TASK_PRIORITY 10 /* - * Note that these resources are shared with RTEMS itself (e.g. the shell) - * so they should be allocated slightly higher than the limits in osconfig.h + * Note that these resources are shared with RTEMS itself (e.g. the init task, the shell) + * so they should be allocated slightly higher than the user limits in osconfig.h + * + * Many RTEMS services use tasks internally, including the idle task, BSWP, ATA driver, + * low level console I/O, the shell, TCP/IP network stack, and DHCP (if enabled). + * Many of these also use semaphores for synchronization. + * + * Budgeting for additional: + * 8 internal tasks + * 2 internal timers + * 4 internal queues + * 16 internal semaphores + * */ -#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 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 + 4) +#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_EXECUTIVE_RAM_SIZE (1024*1024) +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) +#define CONFIGURE_MAXIMUM_DRIVERS 10 +#define CONFIGURE_MAXIMUM_POSIX_KEYS 4 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER - #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 100 - #define CONFIGURE_FILESYSTEM_RFS #define CONFIGURE_FILESYSTEM_IMFS #define CONFIGURE_FILESYSTEM_DOSFS #define CONFIGURE_FILESYSTEM_DEVFS - #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK - -#define CONFIGURE_MICROSECONDS_PER_TICK 10000 - -#define CONFIGURE_MAXIMUM_DRIVERS 10 - #define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER -#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 9 -#define CONFIGURE_MAXIMUM_POSIX_KEYS 4 +#define CONFIGURE_EXECUTIVE_RAM_SIZE (8*1024*1024) +#define CONFIGURE_MICROSECONDS_PER_TICK 10000 +#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 9 #include @@ -255,6 +427,10 @@ rtems_task Init( #define CONFIGURE_SHELL_COMMANDS_ALL #define CONFIGURE_SHELL_MOUNT_MSDOS -#include +#define CONFIGURE_SHELL_USER_COMMANDS \ + &rtems_shell_RTL_Command, \ + &rtems_shell_dlopen_Command, \ + &rtems_shell_dlsym_Command +#include diff --git a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h new file mode 100644 index 000000000..de2ae50f7 --- /dev/null +++ b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h @@ -0,0 +1,59 @@ +/****************************************************************************** +** File: pcrtems_bsp_internal.h +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Header file for internal data to the PC-RTEMS BSP +** +******************************************************************************/ + +#ifndef _PCRTEMS_BSP_INTERNAL_H_ +#define _PCRTEMS_BSP_INTERNAL_H_ + +/* +** OSAL includes +*/ +#include "osapi.h" +#include "bsp-impl.h" + +/* + * BSP compile-time tuning + */ +#define RTEMS_MAX_USER_OPTIONS 4 +#define RTEMS_NUMBER_OF_RAMDISKS 1 +#define RTEMS_MAX_CMDLINE 256 + +/* + * For debugging, it is helpful to keep the shell + * priority relatively high. But this may cause the + * shell activity to preempt the actual realtime tasks. + */ +#ifdef NDEBUG +#define RTEMS_SHELL_PRIORITY 100 +#else +#define RTEMS_SHELL_PRIORITY 5 +#endif + +/* +** BSP types +*/ +typedef struct +{ + char UserArgBuffer[RTEMS_MAX_CMDLINE]; + bool BatchMode; +} OS_BSP_PcRtemsGlobalData_t; + +/* + * Global Data object + */ +extern OS_BSP_PcRtemsGlobalData_t OS_BSP_PcRtemsGlobal; + +#endif /* _PCRTEMS_BSP_INTERNAL_H_ */ diff --git a/src/bsp/pc-rtems/ut-src/bsp_ut.c b/src/bsp/pc-rtems/ut-src/bsp_ut.c deleted file mode 100644 index 26d82cba2..000000000 --- a/src/bsp/pc-rtems/ut-src/bsp_ut.c +++ /dev/null @@ -1,530 +0,0 @@ -/****************************************************************************** -** File: bsp_ut.c -** -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Purpose: -** BSP unit test implementation functions. -** -** History: -** Created on: Feb 10, 2015 -** -******************************************************************************/ - -/* - * NOTE - This entire source file is only relevant for unit testing. - * It should not be included in a "normal" BSP build. - */ - -#define _USING_RTEMS_INCLUDES_ - -/* -** Include Files -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "osapi.h" -#include "utbsp.h" -#include "uttest.h" - -/* -** External Declarations -*/ -extern OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES]; - -void OS_Application_Startup(void); - -#define RTEMS_NUMBER_OF_RAMDISKS 1 -#define RTEMS_UT_MAX_USER_OPTIONS 4 -#define RTEMS_UT_MAX_CMDLINE 256 - -/* -** Global variables -*/ - -/* - * The RAM Disk configuration. - */ -rtems_ramdisk_config rtems_ramdisk_configuration[RTEMS_NUMBER_OF_RAMDISKS]; - -/* - * The number of RAM Disk configurations. -*/ -size_t rtems_ramdisk_configuration_size = RTEMS_NUMBER_OF_RAMDISKS; - -/* -** RAM Disk IO op table. -*/ -rtems_driver_address_table rtems_ramdisk_io_ops = -{ - .initialization_entry = ramdisk_initialize, - .open_entry = rtems_blkdev_generic_open, - .close_entry = rtems_blkdev_generic_close, - .read_entry = rtems_blkdev_generic_read, - .write_entry = rtems_blkdev_generic_write, - .control_entry = rtems_blkdev_generic_ioctl -}; - -/* - * Under RTEMS there is no notion of command-line arguments like in pc-linux, - * so it is not as easy to change this value at runtime. For now the default - * will show all messages except debug. - * - * It may be possible to set this value using the shell... - */ -static bool BatchMode = false; -static int32 UserArgc = 0; -static char UserArgBuffer[RTEMS_UT_MAX_CMDLINE]; -static char *UserArgv[RTEMS_UT_MAX_USER_OPTIONS] = { NULL }; -static uint32 CurrVerbosity = (2 << UTASSERT_CASETYPE_PASS) - 1; - -/* - * UT_BSP_GetTotalOptions: See details in prototype - */ -int32 UT_BSP_GetTotalOptions(void) -{ - return UserArgc; -} - -/* - * UT_BSP_GetOptionString: See details in prototype - */ -const char * UT_BSP_GetOptionString(int32 OptionNum) -{ - if (OptionNum >= UserArgc) - { - return NULL; - } - - return UserArgv[OptionNum]; -} - - -void UT_BSP_Setup(void) -{ - int status; - int i; - struct stat statbuf; - const char *cmdlinestr; - const char *cmdp; - char *cmdi, *cmdo; - - 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 ); - if (cmdlinestr != NULL) - { - printf(" Bootloader Command Line: %s\n", cmdlinestr); - } - printf("\n"); - printf( "*** End RTEMS info ***\n\n" ); - - /* - * Parse command line string (passed in from bootloader) - * - * Known arguments are handled here, and unknown args are - * saved for the UT application. - * - * Batch mode is intended for non-interative execution. - * - * It does two things: - * - do not start the shell task - * - when tests are complete, shutdown the executive - * - * The BSP should be configured with these options to - * make this most useful: - * USE_COM1_AS_CONSOLE=1 - * BSP_PRESS_KEY_FOR_RESET=0 - * BSP_RESET_BOARD_AT_EXIT=1 - * - * This way all the test output will be sent to COM1 - * and then immediately resets the CPU when done. - * - * When running under QEMU the "-no-reboot" flag is - * also useful to shutdown QEMU rather than resetting. - */ - if (cmdlinestr != NULL) - { - cmdp = cmdlinestr; - cmdo = NULL; - cmdi = NULL; - while (1) - { - if (isgraph((int)*cmdp)) - { - if (cmdo == NULL) - { - cmdo = UserArgBuffer; - } - else - { - ++cmdo; - } - if (cmdi == NULL) - { - cmdi = cmdo; - } - *cmdo = *cmdp; - } - else if (cmdi != NULL) - { - ++cmdo; - *cmdo = 0; - if (strcmp(cmdi,"--batch-mode") == 0) - { - BatchMode = true; - } - else if (UserArgc < RTEMS_UT_MAX_USER_OPTIONS) - { - /* save other args for app */ - UserArgv[UserArgc] = cmdi; - ++UserArgc; - } - cmdi = NULL; - } - - if (*cmdp == 0) - { - break; - } - - ++cmdp; - } - } - - /* - ** Create the RTEMS Root file system - */ - status = rtems_create_root_fs(); - if (status != RTEMS_SUCCESSFUL) - { - printf("Creating Root file system failed: %s\n",rtems_status_text(status)); - } - - /* - ** create the directory mountpoints - */ - - /* - ** Create local directories for "disk" mount points - ** See bsp_voltab for the values - ** - ** NOTE - the voltab table is poorly designed here; values of "0" are valid - ** and will translate into an entry that is actually used. In particular the - ** "free" flag has to be actually initialized to TRUE to say its NOT valid. - ** So in the case of an entry that has been zeroed out (i.e. bss section) it - ** will be treated as a valid entry. - ** - ** Checking that the DeviceName starts with a leading slash '/' is a workaround - ** for this, and may be the only way to detect an entry that is uninitialized. - */ - for (i=0; i < NUM_TABLE_ENTRIES; ++i) - { - if (OS_VolumeTable[i].VolumeType == FS_BASED && - OS_VolumeTable[i].PhysDevName[0] != 0 && - OS_VolumeTable[i].DeviceName[0] == '/') - - { - if (stat(OS_VolumeTable[i].PhysDevName, &statbuf) < 0) - { - printf("Creating mount point directory: %s\n", - OS_VolumeTable[i].PhysDevName); - status = mkdir(OS_VolumeTable[i].PhysDevName, S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO); /* For ramdisk mountpoint */ - if (status != RTEMS_SUCCESSFUL) - { - printf("mkdir failed: %s\n", strerror (errno)); - } - } - } - } - - if (!BatchMode) - { - status = rtems_shell_init("SHLL", RTEMS_MINIMUM_STACK_SIZE * 4, 100, "/dev/console", false, false, NULL); - if (status < 0) - { - printf ("shell init failed: %s\n", strerror (errno)); - } - - } - - printf("\n\n"); - - /* give a small delay to let the shell start, - avoids having the login prompt show up mid-test, - and gives a little time for pending output to actually - be sent to the console in case of a slow port */ - rtems_task_wake_after(50); - - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "PC-RTEMS UNIT TEST"); -} - - -void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u %s", (unsigned int)SegmentNumber, SegmentName); - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, ReportBuffer); -} - -void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) -{ - const char *Prefix; - - if ((CurrVerbosity >> MessageType) & 1) - { - switch(MessageType) - { - case UTASSERT_CASETYPE_ABORT: - Prefix = "ABORT"; - break; - case UTASSERT_CASETYPE_FAILURE: - Prefix = "FAIL"; - break; - case UTASSERT_CASETYPE_MIR: - Prefix = "MIR"; - break; - case UTASSERT_CASETYPE_TSF: - Prefix = "TSF"; - break; - case UTASSERT_CASETYPE_TTF: - Prefix = "TTF"; - break; - case UTASSERT_CASETYPE_NA: - Prefix = "N/A"; - break; - case UTASSERT_CASETYPE_BEGIN: - printf("\n"); /* add a bit of extra whitespace between tests */ - Prefix = "BEGIN"; - break; - case UTASSERT_CASETYPE_END: - Prefix = "END"; - break; - case UTASSERT_CASETYPE_PASS: - Prefix = "PASS"; - break; - case UTASSERT_CASETYPE_INFO: - Prefix = "INFO"; - break; - case UTASSERT_CASETYPE_DEBUG: - Prefix = "DEBUG"; - break; - default: - Prefix = "OTHER"; - break; - } - printf("[%5s] %s\n",Prefix,OutputMessage); - } - - /* - * If any ABORT (major failure) message is thrown, - * then actually call abort() to stop the test and dump a core - */ - if (MessageType == UTASSERT_CASETYPE_ABORT) - { - abort(); - } -} - -void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 TestSeq, uint8 MessageType, const char *SubsysName, const char *ShortDesc) -{ - uint32 FileLen; - const char *BasePtr; - char ReportBuffer[128]; - - FileLen = strlen(File); - BasePtr = File + FileLen; - while (FileLen > 0) - { - --BasePtr; - --FileLen; - if (*BasePtr == '/' || *BasePtr == '\\') - { - ++BasePtr; - break; - } - } - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u.%03u %s:%u - %s", - (unsigned int)SegmentNum, (unsigned int)TestSeq, - BasePtr, (unsigned int)LineNum, ShortDesc); - - UT_BSP_DoText(MessageType, ReportBuffer); -} - -void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCounter_t *TestCounters) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), - "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-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_NA]); - - - UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); -} - -void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters) -{ - const char *Overall; - - /* - * Only output a "summary" if there is more than one test Segment. - * Otherwise it is a duplicate of the report already given. - */ - if (TestCounters->TestSegmentCount > 1) - { - UT_BSP_DoTestSegmentReport("SUMMARY", TestCounters); - } - - printf("COMPLETE: %u test segment(s) executed\n", (unsigned int)TestCounters->TestSegmentCount); - - /* - * Since this test is probably not running directly on the - * host but rather on a separate target or emulator, we cannot - * rely on a return code / exit status to identify pass/fail - * as is done on the Linux UT. - * - * This outputs a simplified "RESULT: " line as the - * final output line. A test script can grep for this line. - */ - if (TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE] > 0 || - TestCounters->CaseCount[UTASSERT_CASETYPE_ABORT] > 0) - { - Overall = "FAILURE"; - } - else if (TestCounters->CaseCount[UTASSERT_CASETYPE_TSF] > 0 || - TestCounters->CaseCount[UTASSERT_CASETYPE_TTF] > 0) - { - Overall = "TSF/TTF"; - } - else if (TestCounters->CaseCount[UTASSERT_CASETYPE_PASS] > 0) - { - Overall = "SUCCESS"; - } - else - { - /* no tests failed, but no tests passed either... */ - Overall = "UNKNOWN"; - } - - printf("RESULT: %s\n", Overall); - - /* - * Not calling exit() under RTEMS, this simply shuts down the executive, - * forcing the user to reboot the system. - * - * Calling suspend causes execution to get stuck here, but the RTEMS - * shell thread will still be active so the user can poke around, read results, - * then use a shell command to reboot when ready. - */ - while (!BatchMode) - { - printf("\n\nTesting thread now idle.\nPress for shell or reset machine...\n\n"); - rtems_task_suspend(rtems_task_self()); - } -} - - -/* -** A simple entry point to start from the loader -*/ -rtems_task Init( - rtems_task_argument ignored -) -{ - /* - ** Call application specific entry point. - ** This is supposed to call OS_API_Init() - */ - OS_Application_Startup(); - - /* - ** The OS_Application_Run function is part of UT Assert library - */ - OS_Application_Run(); - - rtems_shutdown_executive(UtAssert_GetFailCount() != 0); -} - - -/* configuration information */ - -/* -** RTEMS OS Configuration defintions -*/ -#define TASK_INTLEVEL 0 -#define CONFIGURE_INIT -#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_FLOATING_POINT | RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(TASK_INTLEVEL)) -#define CONFIGURE_INIT_TASK_STACK_SIZE (20*1024) -#define CONFIGURE_INIT_TASK_PRIORITY 120 - -/* - * Note that these resources are shared with RTEMS itself (e.g. the shell) - * so they should be allocated slightly higher than the limits in osconfig.h - */ -#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 4) -#define CONFIGURE_MAXIMUM_TIMERS (OS_MAX_TIMERS + 2) -#define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 2) -#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES (OS_MAX_QUEUES + 2) - - -#define CONFIGURE_EXECUTIVE_RAM_SIZE (1024*1024) - -#define CONFIGURE_RTEMS_INIT_TASKS_TABLE -#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER -#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER - -#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) - -#define CONFIGURE_FILESYSTEM_RFS -#define CONFIGURE_FILESYSTEM_IMFS -#define CONFIGURE_FILESYSTEM_DEVFS - -#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK - -#define CONFIGURE_MICROSECONDS_PER_TICK 10000 -#define CONFIGURE_MAXIMUM_DRIVERS 10 -#define CONFIGURE_MAXIMUM_POSIX_KEYS 4 - -#include - -#define CONFIGURE_SHELL_COMMANDS_INIT -#define CONFIGURE_SHELL_COMMANDS_ALL - -#include - - diff --git a/src/bsp/pc-rtems/ut-src/bsp_ut_voltab.c b/src/bsp/pc-rtems/ut-src/bsp_ut_voltab.c deleted file mode 100644 index 9c9a67ad4..000000000 --- a/src/bsp/pc-rtems/ut-src/bsp_ut_voltab.c +++ /dev/null @@ -1,61 +0,0 @@ -/* -** File : bsp_voltab.c -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** BSP Volume table for file systems -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ -#include "common_types.h" -#include "osapi.h" - -/* -** volume table. This table has the OS_ name, since it belongs to the OSAL, not the CFE_PSP -*/ -OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = -{ -/* Dev Name Phys Dev Vol Type Volatile? Free? IsMounted? Volname MountPt BlockSz */ - -/* Two virtual RAM disks for testing purposes - file system tests use these */ -{ "/ramdev0", "/ram0", FS_BASED, true, true, false, " ", "/drive0", 512 }, -{ "/ramdev1", "/ram1", FS_BASED, true, true, false, " ", "/drive1", 512 }, - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 } - -}; - -/* - * An example of a static symbol loader table - * Only used if OS_STATIC_LOADER is enabled in osconfig.h - */ -#ifdef OS_STATIC_LOADER -OS_static_symbol_record_t OS_STATIC_SYMBOL_TABLE[] = -{ - { "OS_Application_Startup", OS_Application_Startup }, - { NULL, NULL } -}; -#endif - - diff --git a/src/bsp/shared/bsp-impl.h b/src/bsp/shared/bsp-impl.h new file mode 100644 index 000000000..f2d0d9f37 --- /dev/null +++ b/src/bsp/shared/bsp-impl.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/** + * \file bsp-impl.h + * \author joseph.p.hickey@nasa.gov + * + * Purpose: Contains functions prototype definitions and variables declarations + * for the OSAL BSP layer + * + * This is used to provide an abstract notion of certain platform-specific features: + * + * - Startup arguments/options. These are optional strings containing any + * passed-in parameters from a bootloader/shell/etc. Not all platforms + * support this notion, but this provides a consistent access method for + * those platforms that do pass startup options. + * + * - Exit code. This is the "status" passed back to the operating system + * if/when the application terminates. This is a numeric value with + * platform-defined meaning. + * + * - Low-level console output. Provide direct, synchronous access to the + * BSP-provided console or debug terminal device. + */ + +#ifndef _osapi_bsp_impl_ +#define _osapi_bsp_impl_ + +#include "osapi.h" + +/* + * A set of simplified console control options + * + * These constants are used with the OS_BSP_ConsoleSetMode_Impl() API + * to allow debug console text to be output with additional attributes + * on platforms that support it. + * + * This is NOT intended as a full terminal control abstraction, + * just enough to draw visual attention to certain messages on + * platforms that support it. + */ +#define OS_BSP_CONSOLEMODE_NORMAL 0x0 /**< Default output mode - clears any previously-set attributes */ +#define OS_BSP_CONSOLEMODE_RED 0x1 /**< Red text, if terminal supports color */ +#define OS_BSP_CONSOLEMODE_GREEN 0x2 /**< Green text, if terminal supports color */ +#define OS_BSP_CONSOLEMODE_BLUE 0x4 /**< Blue text, if terminal supports color */ +#define OS_BSP_CONSOLEMODE_HIGHLIGHT 0x8 /**< Highlighted/Emphasis text, if terminal supports it */ + +#define OS_BSP_CONSOLEMODE_TO_ANSICOLOR(x) ((x) & 0x07) + +/* + * Macro for BSP debug messages, similar to OS_DEBUG in OSAL code. + * + * This is also controlled by the OS_DEBUG_PRINTF compile-time option, + * except it does not reference the OSAL global variables like OS_DEBUG does. + * + * (This global is likely not initialized at the time the BSP code executes, + * and are also generally not accessible from BSP code) + */ +#if defined(OS_DEBUG_PRINTF) +#define BSP_DEBUG(...) \ + do \ + { \ + printf("%s():", __func__); \ + printf(__VA_ARGS__); \ + } while (0) +#else +/* Debug printfs are not compiled in at all */ +#define BSP_DEBUG(...) +#endif + +/* +** Common/Abstract BSP state data +*/ +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) */ +} OS_BSP_GlobalData_t; + +/* + * Common/Abstracted BSP state data + */ +extern OS_BSP_GlobalData_t OS_BSP_Global; + +/* + * Volume Table declaration (supplied by BSP; typically defined in bsp_voltab.c) + */ +extern OS_VolumeInfo_t OS_VolumeTable[NUM_TABLE_ENTRIES]; + +/********************************************************************/ +/* INTERNAL BSP IMPLEMENTATION FUNCTIONS */ +/********************************************************************/ + +/*---------------------------------------------------------------- + Function: OS_BSP_ConsoleOutput_Impl + + Purpose: Low level raw console data output. Writes a sequence of + characters directly to the BSP debug terminal or console device. + + The string is not required to be null terminated, and + any control characters will be passed through. Any + non-printable ASCII codes will have platform-defined + interpretation. + + Note: This should write the string as-is without buffering. + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen); + +/*---------------------------------------------------------------- + Function: OS_BSP_ConsoleSetMode_Impl + + Purpose: Set the console output mode, if supported by the BSP. + + Causes any future text written to the debug console to + be colored/highlighted accordingly. Intended for use + with test applications where certain messages may need + visual distinction (e.g. failures). + + See the OS_BSP_CONSOLEMODE constants for possible values. + Values may be bitwise OR'ed together. + + This call is ignored if the BSP does not support console + control codes. + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits); + +/********************* + END bsp-impl.h + *********************/ +#endif /* _osapi_bsp_impl_ */ diff --git a/src/bsp/shared/bsp_default_app_run.c b/src/bsp/shared/bsp_default_app_run.c new file mode 100644 index 000000000..0dd067eef --- /dev/null +++ b/src/bsp/shared/bsp_default_app_run.c @@ -0,0 +1,32 @@ +/****************************************************************************** +** File: bsp_app_run.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2015, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Application run default implementation. +** +** NOTE: This is isolated in a separate compilation unit, so that a user +** application may directly provide an OS_Application_Run() implementation +** which will override this default. +** +******************************************************************************/ + +#include "osapi.h" +#include "bsp-impl.h" + +/* + * The default implementation of OS_Application_Run() + * just calls the OS_IdleLoop() provided by OSAL. + */ +void OS_Application_Run(void) +{ + OS_IdleLoop(); +} diff --git a/src/bsp/shared/bsp_default_app_startup.c b/src/bsp/shared/bsp_default_app_startup.c new file mode 100644 index 000000000..e6174ec0a --- /dev/null +++ b/src/bsp/shared/bsp_default_app_startup.c @@ -0,0 +1,41 @@ +/****************************************************************************** +** File: bsp_app_startup.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2015, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Application startup default implementation. +** +** NOTE: This is isolated in a separate compilation unit, so that a user +** application may directly provide an OS_Application_Startup() implementation +** which will override this default. +** +******************************************************************************/ + +#include +#include "osapi.h" + +#include "bsp-impl.h" + +/* + * The default implementation of OS_Application_Startup() + * just calls the OS_API_Init() provided by OSAL. + */ +void OS_Application_Startup(void) +{ + int32 Status; + + Status = OS_API_Init(); + if (Status != OS_SUCCESS) + { + BSP_DEBUG("Error: OS_API_Init() failed with status=%d\n", (int)Status); + OS_ApplicationExit(Status); + } +} diff --git a/src/bsp/shared/bsp_default_symtab.c b/src/bsp/shared/bsp_default_symtab.c new file mode 100644 index 000000000..a8a9f1e2a --- /dev/null +++ b/src/bsp/shared/bsp_default_symtab.c @@ -0,0 +1,31 @@ +/****************************************************************************** +** File: bsp_symtab.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2015, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Application static symbol table default implementation. +** +** NOTE: This is isolated in a separate compilation unit, so that a user +** application may directly provide an OS_STATIC_SYMBOL_TABLE definition +** which will override this default. +** +******************************************************************************/ + +#include "osapi.h" +#include "bsp-impl.h" + + +OS_static_symbol_record_t OS_STATIC_SYMBOL_TABLE[] = +{ + { "OS_Application_Startup", OS_Application_Startup }, + { "OS_Application_Run", OS_Application_Run }, + { NULL, NULL } +}; diff --git a/src/bsp/shared/osapi-bsp.c b/src/bsp/shared/osapi-bsp.c new file mode 100644 index 000000000..9e9bf5178 --- /dev/null +++ b/src/bsp/shared/osapi-bsp.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/** + * \file osapi-common.c + * \author joseph.p.hickey@nasa.gov + * + * Purpose: + * This file contains some of the OS APIs abstraction layer code + * that is shared/common across all OS-specific implementations. + * + * Instantiates the global object tables and the overall OSAL + * init/teardown logic such as OS_API_Init() and OS_ApplicationExit(). + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ +#include +#include +#include + +/* + * User defined include files + */ +#include "common_types.h" +#include "bsp-impl.h" + +/* + * BSP Global Data Object + */ +OS_BSP_GlobalData_t OS_BSP_Global; + +/* + ********************************************************************************* + * PUBLIC API (application-callable functions) + ********************************************************************************* + */ + +/*---------------------------------------------------------------- + OS_BSP_GetArgC + See full description in header + ------------------------------------------------------------------*/ +uint32 OS_BSP_GetArgC(void) +{ + return OS_BSP_Global.ArgC; +} + +/*---------------------------------------------------------------- + OS_BSP_GetArgV + See full description in header + ------------------------------------------------------------------*/ +char * const * OS_BSP_GetArgV(void) +{ + return OS_BSP_Global.ArgV; +} + +/*---------------------------------------------------------------- + OS_BSP_SetExitCode + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_SetExitCode(int32 code) +{ + OS_BSP_Global.AppStatus = code; +} + diff --git a/src/os/inc/osapi-os-core.h b/src/os/inc/osapi-os-core.h index 2378ed5f3..728508424 100644 --- a/src/os/inc/osapi-os-core.h +++ b/src/os/inc/osapi-os-core.h @@ -1527,4 +1527,59 @@ void OS_printf_disable(void); 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); + + + #endif diff --git a/src/os/posix/osapi.c b/src/os/posix/osapi.c index 5a73f141e..5a78c9b33 100644 --- a/src/os/posix/osapi.c +++ b/src/os/posix/osapi.c @@ -25,6 +25,7 @@ ***************************************************************************************/ #include "os-posix.h" +#include "bsp-impl.h" #include /* @@ -177,7 +178,7 @@ static void OS_NoopSigHandler (int signal) } /* end OS_NoopSigHandler */ - + /*---------------------------------------------------------------- * * Function: OS_Lock_Global_Impl @@ -221,7 +222,7 @@ int32 OS_Lock_Global_Impl(uint32 idtype) return OS_SUCCESS; } /* end OS_Lock_Global_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_Unlock_Global_Impl @@ -367,7 +368,7 @@ int32 OS_API_Impl_Init(uint32 idtype) return(return_code); } /* end OS_API_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_IdleLoop_Impl @@ -389,7 +390,7 @@ void OS_IdleLoop_Impl() sigsuspend(&POSIX_GlobalVars.NormalSigMask); } /* end OS_IdleLoop_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_ApplicationShutdown_Impl @@ -726,7 +727,7 @@ int32 OS_Posix_TaskAPI_Impl_Init(void) return OS_SUCCESS; } /* end OS_Posix_TaskAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_Posix_InternalTaskCreate_Impl @@ -851,7 +852,7 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t return OS_SUCCESS; } /* end OS_Posix_InternalTaskCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskCreate_Impl @@ -878,7 +879,7 @@ int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) return return_code; } /* end OS_TaskCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskMatch_Impl @@ -897,7 +898,7 @@ int32 OS_TaskMatch_Impl(uint32 task_id) return OS_SUCCESS; } /* end OS_TaskMatch_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskDelete_Impl @@ -919,7 +920,7 @@ int32 OS_TaskDelete_Impl (uint32 task_id) } /* end OS_TaskDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskExit_Impl @@ -934,7 +935,7 @@ void OS_TaskExit_Impl() } /* end OS_TaskExit_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskDelay_Impl @@ -974,7 +975,7 @@ int32 OS_TaskDelay_Impl(uint32 millisecond) } } /* end OS_TaskDelay_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskSetPriority_Impl @@ -1008,7 +1009,7 @@ int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) return OS_SUCCESS; } /* end OS_TaskSetPriority_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskRegister_Impl @@ -1039,7 +1040,7 @@ int32 OS_TaskRegister_Impl(uint32 global_task_id) return return_code; } /* end OS_TaskRegister_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskGetId_Impl @@ -1057,7 +1058,7 @@ uint32 OS_TaskGetId_Impl (void) return(self_record.value); } /* end OS_TaskGetId_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskGetInfo_Impl @@ -1108,50 +1109,28 @@ int32 OS_Posix_QueueAPI_Impl_Init(void) { memset(OS_impl_queue_table, 0, sizeof(OS_impl_queue_table)); - /* - * Initialize this to zero to indicate no limit - * (would have expected osconfig.h to specify an upper limit, but it does not) - */ - POSIX_GlobalVars.TruncateQueueDepth = 0; - /* * Automatic truncation is dependent on the OSAL_DEBUG_PERMISSIVE_MODE compile-time define - so * creating a too-large message queue on a target without OSAL_DEBUG_PERMISSIVE_MODE will fail * with an OS error as intended. */ #ifdef OSAL_DEBUG_PERMISSIVE_MODE - { - FILE *fp; - char buffer[32]; - - /* - * If running on Linux, /proc/sys/fs/mqueue/msg_max represents the max depth of a posix message queue for a user. - * - * In order to facilitate running in simulation mode without any need for root access -- - * this will allow the OSAL to successfully create message queues by truncating anything larger than this size. - * - * No need to check _LINUX_OS_ here; if the file fails to open, i.e. if not on Linux and the file does not exist, - * then leave well enough alone and don't do anything. - */ - - fp = fopen("/proc/sys/fs/mqueue/msg_max","r"); - if (fp) - { - if (fgets(buffer,sizeof(buffer),fp) != NULL) - { - POSIX_GlobalVars.TruncateQueueDepth = strtoul(buffer, NULL, 10); - OS_DEBUG("Maximum user msg queue depth = %u\n", (unsigned int)POSIX_GlobalVars.TruncateQueueDepth); - } - fclose(fp); - } - } + /* + * Use the BSP-provided limit + */ + POSIX_GlobalVars.TruncateQueueDepth = OS_BSP_Global.MaxQueueDepth; +#else + /* + * Initialize this to zero to indicate no limit + */ + POSIX_GlobalVars.TruncateQueueDepth = 0; #endif return OS_SUCCESS; } /* end OS_Posix_QueueAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_QueueCreate_Impl @@ -1231,7 +1210,7 @@ int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) return return_code; } /* end OS_QueueCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_QueueDelete_Impl @@ -1258,7 +1237,7 @@ int32 OS_QueueDelete_Impl (uint32 queue_id) return return_code; } /* end OS_QueueDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_QueueGet_Impl @@ -1358,7 +1337,7 @@ int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_c return return_code; } /* end OS_QueueGet_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_QueuePut_Impl @@ -1432,7 +1411,7 @@ int32 OS_Posix_BinSemAPI_Impl_Init(void) return OS_SUCCESS; } /* end OS_Posix_BinSemAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemCreate_Impl @@ -1556,7 +1535,7 @@ int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) } /* end OS_BinSemCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemDelete_Impl @@ -1597,7 +1576,7 @@ int32 OS_BinSemDelete_Impl (uint32 sem_id) } /* end OS_BinSemDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemGive_Impl @@ -1640,7 +1619,7 @@ int32 OS_BinSemGive_Impl ( uint32 sem_id ) return OS_SUCCESS; } /* end OS_BinSemGive_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemFlush_Impl @@ -1744,7 +1723,7 @@ static int32 OS_GenericBinSemTake_Impl (OS_impl_binsem_internal_record_t *sem, c return return_code; } /* end OS_GenericBinSemTake_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemTake_Impl @@ -1758,7 +1737,7 @@ int32 OS_BinSemTake_Impl ( uint32 sem_id ) return (OS_GenericBinSemTake_Impl (&OS_impl_bin_sem_table[sem_id], NULL)); } /* end OS_BinSemTake_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemTimedWait_Impl @@ -1779,7 +1758,7 @@ int32 OS_BinSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) return (OS_GenericBinSemTake_Impl (&OS_impl_bin_sem_table[sem_id], &ts)); } /* end OS_BinSemTimedWait_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemGetInfo_Impl @@ -1819,7 +1798,7 @@ int32 OS_Posix_CountSemAPI_Impl_Init(void) return OS_SUCCESS; } /* end OS_Posix_CountSemAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemCreate_Impl @@ -1844,7 +1823,7 @@ int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 op } /* end OS_CountSemCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemDelete_Impl @@ -1864,7 +1843,7 @@ int32 OS_CountSemDelete_Impl (uint32 sem_id) } /* end OS_CountSemDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemGive_Impl @@ -1884,7 +1863,7 @@ int32 OS_CountSemGive_Impl ( uint32 sem_id ) } /* end OS_CountSemGive_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemTake_Impl @@ -1903,7 +1882,7 @@ int32 OS_CountSemTake_Impl ( uint32 sem_id ) return OS_SUCCESS; } /* end OS_CountSemTake_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemTimedWait_Impl @@ -1939,7 +1918,7 @@ int32 OS_CountSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) return result; } /* end OS_CountSemTimedWait_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemGetInfo_Impl @@ -1966,7 +1945,7 @@ int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) MUTEX API ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_Posix_MutexAPI_Impl_Init @@ -1980,7 +1959,7 @@ int32 OS_Posix_MutexAPI_Impl_Init(void) return OS_SUCCESS; } /* end OS_Posix_MutexAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemCreate_Impl @@ -2042,7 +2021,7 @@ int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) return OS_SUCCESS; } /* end OS_MutSemCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemDelete_Impl @@ -2066,7 +2045,7 @@ int32 OS_MutSemDelete_Impl (uint32 sem_id) } /* end OS_MutSemDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemGive_Impl @@ -2091,7 +2070,7 @@ int32 OS_MutSemGive_Impl ( uint32 sem_id ) return OS_SUCCESS; } /* end OS_MutSemGive_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemTake_Impl @@ -2116,7 +2095,7 @@ int32 OS_MutSemTake_Impl ( uint32 sem_id ) return OS_SUCCESS; } /* end OS_MutSemTake_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemGetInfo_Impl @@ -2137,7 +2116,7 @@ int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) INT API ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_IntAttachHandler_Impl @@ -2151,7 +2130,7 @@ int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry Interru return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntAttachHandler_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntUnlock_Impl @@ -2165,7 +2144,7 @@ int32 OS_IntUnlock_Impl (int32 IntLevel) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntUnlock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntLock_Impl @@ -2178,7 +2157,7 @@ int32 OS_IntLock_Impl ( void ) { return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntLock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntEnable_Impl @@ -2192,7 +2171,7 @@ int32 OS_IntEnable_Impl(int32 Level) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntEnable_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntDisable_Impl @@ -2206,7 +2185,7 @@ int32 OS_IntDisable_Impl(int32 Level) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntDisable_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntSetMask_Impl @@ -2220,7 +2199,7 @@ int32 OS_IntSetMask_Impl ( uint32 MaskSetting ) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntSetMask_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntGetMask_Impl @@ -2321,7 +2300,7 @@ static int OS_PriorityRemap(uint32 InputPri) return OutputPri; } /* end OS_PriorityRemap */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcAttachHandler_Impl @@ -2338,7 +2317,7 @@ int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry Except */ return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcAttachHandler_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcEnable_Impl @@ -2354,7 +2333,7 @@ int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber) */ return(OS_SUCCESS); } /* end OS_FPUExcEnable_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcDisable_Impl @@ -2371,7 +2350,7 @@ int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber) return(OS_SUCCESS); } /* end OS_FPUExcDisable_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcSetMask_Impl @@ -2388,7 +2367,7 @@ int32 OS_FPUExcSetMask_Impl(uint32 mask) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcSetMask_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcGetMask_Impl @@ -2412,7 +2391,7 @@ int32 OS_FPUExcGetMask_Impl(uint32 *mask) /* use the portable version of OS_ConsoleWrite_Impl() */ #include "../portable/os-impl-console-directwrite.c" - + /*---------------------------------------------------------------- * * Function: OS_ConsoleWakeup_Impl @@ -2459,7 +2438,7 @@ static void* OS_ConsoleTask_Entry(void* arg) } return NULL; } /* end OS_ConsoleTask_Entry */ - + /*---------------------------------------------------------------- * * Function: OS_ConsoleCreate_Impl diff --git a/src/unit-test-coverage/CMakeLists.txt b/src/unit-test-coverage/CMakeLists.txt index 6579e877e..b4128112a 100644 --- a/src/unit-test-coverage/CMakeLists.txt +++ b/src/unit-test-coverage/CMakeLists.txt @@ -104,7 +104,7 @@ include_directories(${CMAKE_SOURCE_DIR}/ut-stubs/inc) # This removes the need to use the "real" CFE PSP and also provides the necessary # UT output functions that UT assert may rely upon to report test messages # This is the OSAL BSP but with the _UNIT_TEST_ macro defined so it may have UT-specific features -aux_source_directory(${OSAL_SOURCE_DIR}/src/bsp/${OSALCOVERAGE_HOST_BSPTYPE}/ut-src BSPFILES) +aux_source_directory(${OSAL_SOURCE_DIR}/src/bsp/${OSALCOVERAGE_HOST_BSPTYPE}/src BSPFILES) add_library(ut_bsp STATIC ${BSPFILES}) # The "utassert" library is the core GSFC-provided unit test library diff --git a/src/ut-stubs/CMakeLists.txt b/src/ut-stubs/CMakeLists.txt index b0beec441..0482c6580 100644 --- a/src/ut-stubs/CMakeLists.txt +++ b/src/ut-stubs/CMakeLists.txt @@ -5,50 +5,49 @@ ###################################################################### # -# This works in conjunction with the UT Assert library to +# This works in conjunction with the UT Assert library to # provide "stub" versions of all calls in the OSAL public API. # # NOTE: There is no separate public include directory for the stubs. # By definition, the stubs must implement the same public API that the -# normal OSAL library implements. Therefore, only the standard OSAL +# normal OSAL library implements. Therefore, only the standard OSAL # header files are used. add_library(ut_osapi_stubs STATIC utstub-helpers.c - osapi-utstub-binsem.c - osapi-utstub-clock.c - osapi-utstub-common.c - osapi-utstub-countsem.c - osapi-utstub-dir.c + osapi-utstub-binsem.c + osapi-utstub-clock.c + osapi-utstub-common.c + osapi-utstub-countsem.c + osapi-utstub-dir.c osapi-utstub-errors.c - osapi-utstub-file.c - osapi-utstub-filesys.c - osapi-utstub-fpu.c - osapi-utstub-heap.c + osapi-utstub-file.c + osapi-utstub-filesys.c + osapi-utstub-fpu.c + osapi-utstub-heap.c osapi-utstub-idmap.c - osapi-utstub-interrupts.c - osapi-utstub-module.c - osapi-utstub-mutex.c - osapi-utstub-network.c - osapi-utstub-printf.c - osapi-utstub-queue.c - osapi-utstub-select.c - osapi-utstub-sockets.c - osapi-utstub-task.c + osapi-utstub-interrupts.c + osapi-utstub-module.c + osapi-utstub-mutex.c + osapi-utstub-network.c + osapi-utstub-printf.c + osapi-utstub-queue.c + osapi-utstub-select.c + osapi-utstub-sockets.c + osapi-utstub-task.c osapi-utstub-time.c osapi-utstub-timebase.c ) # Some of the internal API definitions in stubs are based on -# types/definitions in the os-impl.h internal header file. +# types/definitions in the os-impl.h internal header file. target_include_directories(ut_osapi_stubs PRIVATE ${OSAL_SOURCE_DIR}/src/os/shared ) - + # These stubs must always link to UT Assert. # This also implicitly adds the path to the UT Assert header files. target_link_libraries(ut_osapi_stubs ut_assert) - \ No newline at end of file diff --git a/ut_assert/CMakeLists.txt b/ut_assert/CMakeLists.txt index 9ae28bad0..21c94b3d2 100644 --- a/ut_assert/CMakeLists.txt +++ b/ut_assert/CMakeLists.txt @@ -23,6 +23,7 @@ project(UT_ASSERT C) add_library(ut_assert STATIC EXCLUDE_FROM_ALL src/utassert.c + src/utbsp.c src/utlist.c src/utstubs.c src/uttest.c @@ -32,10 +33,13 @@ add_library(ut_assert STATIC EXCLUDE_FROM_ALL target_include_directories(ut_assert PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) +target_include_directories(ut_assert PRIVATE + "${OSAL_SOURCE_DIR}/src/bsp/shared" +) target_compile_definitions(ut_assert PUBLIC "_UNIT_TEST_" ) -target_link_libraries(ut_assert ut_bsp) +target_link_libraries(ut_assert osal_bsp) diff --git a/ut_assert/inc/utbsp.h b/ut_assert/inc/utbsp.h index 95ab9bde5..c52291fc6 100644 --- a/ut_assert/inc/utbsp.h +++ b/ut_assert/inc/utbsp.h @@ -30,7 +30,6 @@ * and the way pass/fail determinations are made. */ - #ifndef _UTBSP_H_ #define _UTBSP_H_ @@ -41,20 +40,6 @@ * Functions implemented by the UT-specific BSP **************************************************************/ -/** - * Gets the number of additional user-supplied options - * - * For instance, this would be command line parameters on platforms that have a command line. - */ -int32 UT_BSP_GetTotalOptions(void); - -/** - * Gets the text string associated with a specific user-supplied option - * - * For instance, this would be command line parameters on platforms that have a command line. - */ -const char * UT_BSP_GetOptionString(int32 OptionNum); - /* * Note - functions here are not typically directly called by UT code, they * are used by the framework to implement the common functions. @@ -94,7 +79,6 @@ void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName); */ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage); - /** * The BSP single test case reporting function. * @@ -111,7 +95,8 @@ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage); * \param SegmentNum Sequence among the overall/global test Segments * \param TestDescr Sequence within the current test Segment */ -void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 SegmentSeq, uint8 MessageType, const char *SubsysName, const char *ShortDesc); +void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 SegmentSeq, uint8 MessageType, + const char *SubsysName, const char *ShortDesc); /** * The BSP overall test reporting function. @@ -137,5 +122,4 @@ void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCoun */ void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters); - #endif /* _UTBSP_H_ */ diff --git a/ut_assert/src/utbsp.c b/ut_assert/src/utbsp.c new file mode 100644 index 000000000..1744af8c2 --- /dev/null +++ b/ut_assert/src/utbsp.c @@ -0,0 +1,248 @@ +/****************************************************************************** +** File: utbsp.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2015, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Unit test BSP interface functions. +** +******************************************************************************/ + +#include +#include +#include +#include + +#include "utbsp.h" +#include "uttest.h" + +#include "bsp-impl.h" + +/* +** Local Variables +*/ +typedef struct +{ + uint32 CurrVerbosity; +} BSP_UT_GlobalData_t; + +BSP_UT_GlobalData_t BSP_UT_Global; + +void UT_BSP_Setup(void) +{ + uint8 UserShift; + uint32 ArgC; + char *const *ArgV; + + memset(&BSP_UT_Global, 0, sizeof(BSP_UT_Global)); + + UserShift = UTASSERT_CASETYPE_NONE; + ArgC = OS_BSP_GetArgC(); + if (ArgC > 0) + { + ArgV = OS_BSP_GetArgV(); + while (ArgC > 0) + { + --ArgC; + + if (strcmp(ArgV[0], "-d") == 0) + { + UserShift = UTASSERT_CASETYPE_DEBUG; + } + if (strcmp(ArgV[0], "-q") == 0) + { + UserShift = UTASSERT_CASETYPE_FAILURE; + } + if (strcmp(ArgV[0], "-v") == 0 && ArgC > 0) + { + --ArgC; + UserShift = strtoul(ArgV[1], NULL, 0); + ++ArgV; + } + + ++ArgV; + } + } + + if (UserShift == UTASSERT_CASETYPE_NONE || UserShift >= UTASSERT_CASETYPE_MAX) + { + UserShift = UTASSERT_CASETYPE_PASS; + } + + BSP_UT_Global.CurrVerbosity = (2 << UserShift) - 1; + + UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "UNIT TEST"); +} + +void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName) +{ + char ReportBuffer[128]; + + snprintf(ReportBuffer, sizeof(ReportBuffer), "%02u %s", (unsigned int)SegmentNumber, SegmentName); + UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, ReportBuffer); +} + +void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) +{ + const char *Prefix; + char Buffer[16]; + uint32 TermModeBits = OS_BSP_CONSOLEMODE_NORMAL; + uint32 MsgEnabled = BSP_UT_Global.CurrVerbosity >> MessageType; + + if (MsgEnabled & 1) + { + switch (MessageType) + { + case UTASSERT_CASETYPE_ABORT: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED; + Prefix = "ABORT"; + break; + case UTASSERT_CASETYPE_FAILURE: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED; + Prefix = "FAIL"; + break; + case UTASSERT_CASETYPE_MIR: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED | OS_BSP_CONSOLEMODE_GREEN; + Prefix = "MIR"; + break; + case UTASSERT_CASETYPE_TSF: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED | OS_BSP_CONSOLEMODE_BLUE; + Prefix = "TSF"; + break; + case UTASSERT_CASETYPE_TTF: + Prefix = "TTF"; + break; + case UTASSERT_CASETYPE_NA: + Prefix = "N/A"; + break; + case UTASSERT_CASETYPE_BEGIN: + OS_BSP_ConsoleOutput_Impl("\n", 1); /* add a bit of extra whitespace between tests */ + Prefix = "BEGIN"; + break; + case UTASSERT_CASETYPE_END: + Prefix = "END"; + break; + case UTASSERT_CASETYPE_PASS: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_GREEN; + Prefix = "PASS"; + break; + case UTASSERT_CASETYPE_INFO: + Prefix = "INFO"; + break; + case UTASSERT_CASETYPE_DEBUG: + Prefix = "DEBUG"; + break; + default: + Prefix = "OTHER"; + break; + } + + if (MsgEnabled <= 1) + { + TermModeBits = OS_BSP_CONSOLEMODE_NORMAL; + } + + snprintf(Buffer, sizeof(Buffer), "[%5s]", Prefix); + + if (TermModeBits != OS_BSP_CONSOLEMODE_NORMAL) + { + OS_BSP_ConsoleSetMode_Impl(TermModeBits); + } + + OS_BSP_ConsoleOutput_Impl(Buffer, strlen(Buffer)); + + if (TermModeBits != OS_BSP_CONSOLEMODE_NORMAL) + { + OS_BSP_ConsoleSetMode_Impl(OS_BSP_CONSOLEMODE_NORMAL); + } + + OS_BSP_ConsoleOutput_Impl(" ", 1); + OS_BSP_ConsoleOutput_Impl(OutputMessage, strlen(OutputMessage)); + OS_BSP_ConsoleOutput_Impl("\n", 1); + } + + /* + * If any ABORT (major failure) message is thrown, + * then actually call abort() to stop the test and dump a core + */ + if (MessageType == UTASSERT_CASETYPE_ABORT) + { + abort(); + } +} + +void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 TestSeq, uint8 MessageType, + const char *SubsysName, const char *ShortDesc) +{ + uint32 FileLen; + const char *BasePtr; + char ReportBuffer[128]; + + FileLen = strlen(File); + BasePtr = File + FileLen; + while (FileLen > 0) + { + --BasePtr; + --FileLen; + if (*BasePtr == '/' || *BasePtr == '\\') + { + ++BasePtr; + break; + } + } + + snprintf(ReportBuffer, sizeof(ReportBuffer), "%02u.%03u %s:%u - %s", (unsigned int)SegmentNum, + (unsigned int)TestSeq, BasePtr, (unsigned int)LineNum, ShortDesc); + + UT_BSP_DoText(MessageType, ReportBuffer); +} + +void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCounter_t *TestCounters) +{ + char ReportBuffer[128]; + + snprintf(ReportBuffer, sizeof(ReportBuffer), + "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-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_NA]); + + UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); +} + +void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters) +{ + char Message[128]; + + /* + * Only output a "summary" if there is more than one test Segment. + * Otherwise it is a duplicate of the report already given. + */ + if (TestCounters->TestSegmentCount > 1) + { + UT_BSP_DoTestSegmentReport("SUMMARY", TestCounters); + } + + snprintf(Message, sizeof(Message), "COMPLETE: %u tests Segment(s) executed\n\n", + (unsigned int)TestCounters->TestSegmentCount); + OS_BSP_ConsoleOutput_Impl(Message, strlen(Message)); + + if (TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE] > 0) + { + OS_BSP_SetExitCode(OS_ERROR); + } + else + { + OS_BSP_SetExitCode(OS_SUCCESS); + } +}