From 00b08cd96dad5e21e039c3d208ccf1403b69620c Mon Sep 17 00:00:00 2001 From: Alan Cudmore Date: Thu, 6 Feb 2014 22:09:06 -0500 Subject: [PATCH] Merged OSAL 4.1 files (developed outsid of git) --- build/unit-tests/Makefile | 33 + build/unit-tests/oscore-test/Makefile | 107 + build/unit-tests/osfile-test/Makefile | 107 + build/unit-tests/osfilesys-test/Makefile | 106 + build/unit-tests/osloader-test/Makefile | 105 + build/unit-tests/osloader-test/Modules.mak | 22 + build/unit-tests/osnetwork-test/Makefile | 107 + build/unit-tests/ostimer-test/Makefile | 105 + src/bsp/genppc-vxworks6.4/config/osconfig.h | 172 ++ src/bsp/mcf5235-rtems/config/osconfig.h | 171 ++ src/bsp/pc-linux-ut/config/osconfig.h | 171 ++ src/bsp/pc-linux-ut/make/compiler-opts.mak | 95 + src/bsp/pc-linux-ut/make/link-rules.mak | 36 + src/bsp/pc-linux-ut/make/ut-modules.mak | 17 + src/bsp/pc-linux-ut/src/bsp.mak | 22 + src/bsp/pc-linux-ut/src/bsp_start.c | 91 + src/bsp/pc-linux-ut/src/bsp_voltab.c | 52 + src/bsp/pc-linux/config/osconfig.h | 171 ++ src/bsp/sis-rtems/config/osconfig.h | 172 ++ .../oscore-test/ut_oscore_binsem_test.c | 817 +++++ .../oscore-test/ut_oscore_binsem_test.h | 51 + .../oscore-test/ut_oscore_countsem_test.c | 754 +++++ .../oscore-test/ut_oscore_countsem_test.h | 50 + .../oscore-test/ut_oscore_misc_test.c | 725 +++++ .../oscore-test/ut_oscore_misc_test.h | 56 + .../oscore-test/ut_oscore_mutex_test.c | 656 ++++ .../oscore-test/ut_oscore_mutex_test.h | 49 + .../oscore-test/ut_oscore_queue_test.c | 829 +++++ .../oscore-test/ut_oscore_queue_test.h | 49 + .../oscore-test/ut_oscore_task_test.c | 1178 ++++++++ .../oscore-test/ut_oscore_task_test.h | 56 + src/unit-tests/oscore-test/ut_oscore_test.c | 275 ++ src/unit-tests/oscore-test/ut_oscore_test.h | 50 + .../oscore-test/ut_oscore_test_arinc653.c | 300 ++ .../oscore-test/ut_oscore_test_platforms.h | 66 + .../osfile-test/ut_osfile_dirio_test.c | 946 ++++++ .../osfile-test/ut_osfile_dirio_test.h | 51 + .../osfile-test/ut_osfile_fileio_test.c | 2685 +++++++++++++++++ .../osfile-test/ut_osfile_fileio_test.h | 67 + src/unit-tests/osfile-test/ut_osfile_test.c | 177 ++ src/unit-tests/osfile-test/ut_osfile_test.h | 50 + .../osfile-test/ut_osfile_test_arinc653.c | 200 ++ .../osfile-test/ut_osfile_test_platforms.h | 82 + .../osfilesys-test/ut_osfilesys_diskio_test.c | 1324 ++++++++ .../osfilesys-test/ut_osfilesys_diskio_test.h | 60 + .../osfilesys-test/ut_osfilesys_test.c | 152 + .../osfilesys-test/ut_osfilesys_test.h | 45 + .../ut_osfilesys_test_arinc653.c | 149 + src/unit-tests/osloader-test/ut_module.c | 8 + .../osloader-test/ut_osloader_module_test.c | 454 +++ .../osloader-test/ut_osloader_module_test.h | 47 + .../osloader-test/ut_osloader_symtable_test.c | 273 ++ .../osloader-test/ut_osloader_symtable_test.h | 45 + .../osloader-test/ut_osloader_test.c | 72 + .../osloader-test/ut_osloader_test.h | 50 + .../osloader-test/ut_osloader_test_arinc653.c | 7 + .../osnetwork-test/ut_osnetwork_misc_test.c | 278 ++ .../osnetwork-test/ut_osnetwork_misc_test.h | 45 + .../osnetwork-test/ut_osnetwork_test.c | 67 + .../osnetwork-test/ut_osnetwork_test.h | 49 + .../ut_osnetwork_test_arinc653.c | 3 + src/unit-tests/osprintf-test/ut_osprintf.c | 279 ++ src/unit-tests/osprintf-test/ut_osprintf.h | 87 + src/unit-tests/osprintf-test/ut_osprintf_c.c | 70 + src/unit-tests/osprintf-test/ut_osprintf_d.c | 128 + src/unit-tests/osprintf-test/ut_osprintf_f.c | 84 + src/unit-tests/osprintf-test/ut_osprintf_i.c | 128 + src/unit-tests/osprintf-test/ut_osprintf_ld.c | 127 + src/unit-tests/osprintf-test/ut_osprintf_lf.c | 84 + src/unit-tests/osprintf-test/ut_osprintf_li.c | 127 + src/unit-tests/osprintf-test/ut_osprintf_lu.c | 73 + src/unit-tests/osprintf-test/ut_osprintf_lx.c | 72 + .../osprintf-test/ut_osprintf_lx_uc.c | 72 + .../osprintf-test/ut_osprintf_misc.c | 152 + .../osprintf-test/ut_osprintf_offset.c | 210 ++ .../osprintf-test/ut_osprintf_offset.h | 61 + .../osprintf-test/ut_osprintf_offset_dummy.c | 75 + src/unit-tests/osprintf-test/ut_osprintf_p.c | 72 + .../osprintf-test/ut_osprintf_printf.c | 37 + src/unit-tests/osprintf-test/ut_osprintf_s.c | 72 + src/unit-tests/osprintf-test/ut_osprintf_u.c | 73 + src/unit-tests/osprintf-test/ut_osprintf_x.c | 72 + .../osprintf-test/ut_osprintf_x_uc.c | 72 + src/unit-tests/ostimer-test/ut_ostimer_test.c | 238 ++ src/unit-tests/ostimer-test/ut_ostimer_test.h | 45 + .../ostimer-test/ut_ostimer_test_arinc653.c | 219 ++ .../ostimer-test/ut_ostimer_test_platforms.h | 176 ++ .../ostimer-test/ut_ostimer_timerio_test.c | 885 ++++++ .../ostimer-test/ut_ostimer_timerio_test.h | 51 + src/unit-tests/shared/shared.mak | 25 + src/unit-tests/shared/ut_os_stub_platforms.h | 118 + src/unit-tests/shared/ut_os_stubs.c | 433 +++ src/unit-tests/shared/ut_os_stubs.h | 182 ++ src/unit-tests/shared/ut_oscore_stubs.c | 48 + src/unit-tests/shared/ut_osfile_stubs.c | 237 ++ src/unit-tests/shared/ut_osfilesys_stubs.c | 113 + src/unit-tests/shared/ut_osloader_stubs.c | 96 + src/unit-tests/shared/ut_osnetwork_stubs.c | 54 + src/unit-tests/shared/ut_ostimer_stubs.c | 108 + src/unit-tests/shared/ut_psp_voltab_stubs.c | 69 + .../shared/ut_psp_voltab_stubs_arinc653.c | 62 + 101 files changed, 20595 insertions(+) create mode 100644 build/unit-tests/Makefile create mode 100644 build/unit-tests/oscore-test/Makefile create mode 100644 build/unit-tests/osfile-test/Makefile create mode 100644 build/unit-tests/osfilesys-test/Makefile create mode 100644 build/unit-tests/osloader-test/Makefile create mode 100644 build/unit-tests/osloader-test/Modules.mak create mode 100644 build/unit-tests/osnetwork-test/Makefile create mode 100644 build/unit-tests/ostimer-test/Makefile create mode 100644 src/bsp/genppc-vxworks6.4/config/osconfig.h create mode 100644 src/bsp/mcf5235-rtems/config/osconfig.h create mode 100644 src/bsp/pc-linux-ut/config/osconfig.h create mode 100644 src/bsp/pc-linux-ut/make/compiler-opts.mak create mode 100644 src/bsp/pc-linux-ut/make/link-rules.mak create mode 100644 src/bsp/pc-linux-ut/make/ut-modules.mak create mode 100644 src/bsp/pc-linux-ut/src/bsp.mak create mode 100644 src/bsp/pc-linux-ut/src/bsp_start.c create mode 100644 src/bsp/pc-linux-ut/src/bsp_voltab.c create mode 100644 src/bsp/pc-linux/config/osconfig.h create mode 100644 src/bsp/sis-rtems/config/osconfig.h create mode 100644 src/unit-tests/oscore-test/ut_oscore_binsem_test.c create mode 100644 src/unit-tests/oscore-test/ut_oscore_binsem_test.h create mode 100644 src/unit-tests/oscore-test/ut_oscore_countsem_test.c create mode 100644 src/unit-tests/oscore-test/ut_oscore_countsem_test.h create mode 100644 src/unit-tests/oscore-test/ut_oscore_misc_test.c create mode 100644 src/unit-tests/oscore-test/ut_oscore_misc_test.h create mode 100644 src/unit-tests/oscore-test/ut_oscore_mutex_test.c create mode 100644 src/unit-tests/oscore-test/ut_oscore_mutex_test.h create mode 100644 src/unit-tests/oscore-test/ut_oscore_queue_test.c create mode 100644 src/unit-tests/oscore-test/ut_oscore_queue_test.h create mode 100644 src/unit-tests/oscore-test/ut_oscore_task_test.c create mode 100644 src/unit-tests/oscore-test/ut_oscore_task_test.h create mode 100644 src/unit-tests/oscore-test/ut_oscore_test.c create mode 100644 src/unit-tests/oscore-test/ut_oscore_test.h create mode 100644 src/unit-tests/oscore-test/ut_oscore_test_arinc653.c create mode 100644 src/unit-tests/oscore-test/ut_oscore_test_platforms.h create mode 100644 src/unit-tests/osfile-test/ut_osfile_dirio_test.c create mode 100644 src/unit-tests/osfile-test/ut_osfile_dirio_test.h create mode 100644 src/unit-tests/osfile-test/ut_osfile_fileio_test.c create mode 100644 src/unit-tests/osfile-test/ut_osfile_fileio_test.h create mode 100644 src/unit-tests/osfile-test/ut_osfile_test.c create mode 100644 src/unit-tests/osfile-test/ut_osfile_test.h create mode 100644 src/unit-tests/osfile-test/ut_osfile_test_arinc653.c create mode 100644 src/unit-tests/osfile-test/ut_osfile_test_platforms.h create mode 100644 src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c create mode 100644 src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h create mode 100644 src/unit-tests/osfilesys-test/ut_osfilesys_test.c create mode 100644 src/unit-tests/osfilesys-test/ut_osfilesys_test.h create mode 100644 src/unit-tests/osfilesys-test/ut_osfilesys_test_arinc653.c create mode 100644 src/unit-tests/osloader-test/ut_module.c create mode 100644 src/unit-tests/osloader-test/ut_osloader_module_test.c create mode 100644 src/unit-tests/osloader-test/ut_osloader_module_test.h create mode 100644 src/unit-tests/osloader-test/ut_osloader_symtable_test.c create mode 100644 src/unit-tests/osloader-test/ut_osloader_symtable_test.h create mode 100644 src/unit-tests/osloader-test/ut_osloader_test.c create mode 100644 src/unit-tests/osloader-test/ut_osloader_test.h create mode 100644 src/unit-tests/osloader-test/ut_osloader_test_arinc653.c create mode 100644 src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c create mode 100644 src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.h create mode 100644 src/unit-tests/osnetwork-test/ut_osnetwork_test.c create mode 100644 src/unit-tests/osnetwork-test/ut_osnetwork_test.h create mode 100644 src/unit-tests/osnetwork-test/ut_osnetwork_test_arinc653.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf.h create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_c.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_d.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_f.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_i.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_ld.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_lf.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_li.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_lu.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_lx.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_misc.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_offset.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_offset.h create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_p.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_printf.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_s.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_u.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_x.c create mode 100644 src/unit-tests/osprintf-test/ut_osprintf_x_uc.c create mode 100644 src/unit-tests/ostimer-test/ut_ostimer_test.c create mode 100644 src/unit-tests/ostimer-test/ut_ostimer_test.h create mode 100644 src/unit-tests/ostimer-test/ut_ostimer_test_arinc653.c create mode 100644 src/unit-tests/ostimer-test/ut_ostimer_test_platforms.h create mode 100644 src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c create mode 100644 src/unit-tests/ostimer-test/ut_ostimer_timerio_test.h create mode 100644 src/unit-tests/shared/shared.mak create mode 100644 src/unit-tests/shared/ut_os_stub_platforms.h create mode 100644 src/unit-tests/shared/ut_os_stubs.c create mode 100644 src/unit-tests/shared/ut_os_stubs.h create mode 100644 src/unit-tests/shared/ut_oscore_stubs.c create mode 100644 src/unit-tests/shared/ut_osfile_stubs.c create mode 100644 src/unit-tests/shared/ut_osfilesys_stubs.c create mode 100644 src/unit-tests/shared/ut_osloader_stubs.c create mode 100644 src/unit-tests/shared/ut_osnetwork_stubs.c create mode 100644 src/unit-tests/shared/ut_ostimer_stubs.c create mode 100644 src/unit-tests/shared/ut_psp_voltab_stubs.c create mode 100644 src/unit-tests/shared/ut_psp_voltab_stubs_arinc653.c diff --git a/build/unit-tests/Makefile b/build/unit-tests/Makefile new file mode 100644 index 000000000..d0111eedc --- /dev/null +++ b/build/unit-tests/Makefile @@ -0,0 +1,33 @@ +all: + make -C oscore-test + make -C osloader-test + make -C osloader-test -f Modules.mak + make -C osfilesys-test + make -C osfile-test + make -C osnetwork-test + make -C ostimer-test + +clean: + make -C oscore-test clean + make -C osloader-test clean + make -C osloader-test -f Modules.mak clean + make -C osfilesys-test clean + make -C osfile-test clean + make -C osnetwork-test clean + make -C ostimer-test clean + +depend: + make -C oscore-test depend + make -C osloader-test depend + make -C osfilesys-test depend + make -C osfile-test depend + make -C osnetwork-test depend + make -C ostimer-test depend + +gcov: + make -C oscore-test gcov + make -C ostimer-test gcov + make -C osfilesys-test gcov + make -C osfile-test gcov + make -C osloader-test gcov + make -C osnetwork-test gcov diff --git a/build/unit-tests/oscore-test/Makefile b/build/unit-tests/oscore-test/Makefile new file mode 100644 index 000000000..6e6045bbf --- /dev/null +++ b/build/unit-tests/oscore-test/Makefile @@ -0,0 +1,107 @@ +############################################################################### +# File: OSAL Application Makefile +# +# +# History: +# +############################################################################### +# +# Subsystem produced by this makefile. +# +APPTARGET = oscore-test + +# +# Unit test object files +# +OBJS = ut_oscore_test.o ut_oscore_task_test.o ut_oscore_binsem_test.o ut_oscore_mutex_test.o \ + ut_oscore_countsem_test.o ut_oscore_queue_test.o ut_oscore_misc_test.o + +# +# Core object files +# +OBJS += osapi.o osfileapi.o osfilesys.o osloader.o osnetwork.o ostimer.o + +# +# BSP Object files +# +OBJS += bsp_start.o bsp_voltab.o + +# +# Unit test shared object files +# +OBJS += ut_os_stubs.o + +# +# Source files required to build subsystem; used to generate dependencies. +# As long as there are no assembly files this can be automated. +# +SOURCES = $(OBJS:.o=.c) + +## +## Specify extra C Flags needed to build this subsystem +## +LOCAL_COPTS = + +## +## EXEDIR is defined here, just in case it needs to be different for a custom +## build +## +EXEDIR=./ + +######################################################################## +# Should not have to change below this line, except for customized +# directory structures +######################################################################## +# +# no core objects, since all objs for unit tests are built in this directory +# +CORE_OBJS = + +## +## Include all necessary make rules +## Any of these can be copied to a local file and +## changed if needed. +## +## +## osal-config.mak contians arch, BSP, and OS selection +## +include ../../osal-config.mak +## +## debug-opts.mak contains debug switches +## +include ../../debug-opts.mak +## +## compiler-opts.mak contains compiler definitions and switches/defines +## +include $(OSAL_SRC)/bsp/$(BSP)/make/compiler-opts.mak + +## +## Setup the include path for this subsystem +## The OS specific includes are in the build-rules.make file +## +## If this subsystem needs include files from another app, add the path here. +## +INCLUDE_PATH = \ +-I$(OSAL_SRC)/inc \ +-I$(OSAL_SRC)/os/inc \ +-I$(OSAL_SRC)/unit-tests/shared \ +-I$(OSAL_SRC)/unit-tests/$(APPTARGET) \ +-I../../inc + +## +## Define the VPATH make variable. +## This can be modified to include source from another directory. +## If there is no corresponding app in the apps directory, then this can be discarded, or +## if the mission chooses to put the src in another directory such as "src", then that can be +## added here as well. +## +VPATH = $(OSAL_SRC)/unit-tests/$(APPTARGET) +VPATH += $(OSAL_SRC)/unit-tests/shared +VPATH += $(OSAL_SRC)/os/$(OS) +VPATH += $(OSAL_SRC)/bsp/$(BSP)/src + +## +## Include the common make rules for building an OSAL Application +## +include $(OSAL_SRC)/make/app-rules.mak + diff --git a/build/unit-tests/osfile-test/Makefile b/build/unit-tests/osfile-test/Makefile new file mode 100644 index 000000000..9c12e7653 --- /dev/null +++ b/build/unit-tests/osfile-test/Makefile @@ -0,0 +1,107 @@ +############################################################################### +# File: OSAL Application Makefile +# +# +# History: +# +############################################################################### +# +# Subsystem produced by this makefile. +# +APPTARGET = osfile-test + +# +# Object files required to build subsystem. +# +OBJS = ut_osfile_dirio_test.o ut_osfile_fileio_test.o ut_osfile_test.o + +# +# Core object files +# +OBJS += osapi.o osfileapi.o osfilesys.o osloader.o osnetwork.o ostimer.o + +# +# BSP Object files +# +OBJS += bsp_start.o bsp_voltab.o + +# +# Unit test shared object files +# +OBJS += ut_os_stubs.o + +# +# Source files required to build subsystem; used to generate dependencies. +# As long as there are no assembly files this can be automated. +# +SOURCES = $(OBJS:.o=.c) + +## +## Specify extra C Flags needed to build this subsystem +## +LOCAL_COPTS = + + +## +## EXEDIR is defined here, just in case it needs to be different for a custom +## build +## +EXEDIR=./ + +######################################################################## +# Should not have to change below this line, except for customized +# directory structures +######################################################################## + +CORE_OBJS = + +## +## Include all necessary make rules +## Any of these can be copied to a local file and +## changed if needed. +## +## +## osal-config.mak contians arch, BSP, and OS selection +## +include ../../osal-config.mak +## +## debug-opts.mak contains debug switches +## +include ../../debug-opts.mak +## +## compiler-opts.mak contains compiler definitions and switches/defines +## +include $(OSAL_SRC)/bsp/$(BSP)/make/compiler-opts.mak + +## +## Setup the include path for this subsystem +## The OS specific includes are in the build-rules.make file +## +## If this subsystem needs include files from another app, add the path here. +## +INCLUDE_PATH = \ +-I$(OSAL_SRC)/inc \ +-I$(OSAL_SRC)/os/inc \ +-I$(OSAL_SRC)/unit-tests/shared \ +-I$(OSAL_SRC)/unit-tests/$(APPTARGET) \ +-I../../inc + +## +## Define the VPATH make variable. +## This can be modified to include source from another directory. +## If there is no corresponding app in the apps directory, then this can be discarded, or +## if the mission chooses to put the src in another directory such as "src", then that can be +## added here as well. +## +VPATH = $(OSAL_SRC)/unit-tests/$(APPTARGET) +VPATH += $(OSAL_SRC)/unit-tests/shared +VPATH += $(OSAL_SRC)/os/$(OS) +VPATH += $(OSAL_SRC)/bsp/$(BSP)/src + + +## +## Include the common make rules for building an OSAL Application +## +include $(OSAL_SRC)/make/app-rules.mak + + diff --git a/build/unit-tests/osfilesys-test/Makefile b/build/unit-tests/osfilesys-test/Makefile new file mode 100644 index 000000000..2fff6e88a --- /dev/null +++ b/build/unit-tests/osfilesys-test/Makefile @@ -0,0 +1,106 @@ +############################################################################### +# File: OSAL Application Makefile +# +# +# History: +# +############################################################################### +# +# Subsystem produced by this makefile. +# +APPTARGET = osfilesys-test + +# +# Object files required to build subsystem. +# +OBJS = ut_osfilesys_diskio_test.o ut_osfilesys_test.o + +# +# Core object files +# +OBJS += osapi.o osfileapi.o osfilesys.o osloader.o osnetwork.o ostimer.o + +# +# BSP Object files +# +OBJS += bsp_start.o bsp_voltab.o + +# +# Unit test shared object files +# +OBJS += ut_os_stubs.o + + +# +# Source files required to build subsystem; used to generate dependencies. +# As long as there are no assembly files this can be automated. +# +SOURCES = $(OBJS:.o=.c) + +## +## Specify extra C Flags needed to build this subsystem +## +LOCAL_COPTS = + +## +## EXEDIR is defined here, just in case it needs to be different for a custom +## build +## +EXEDIR=./ + +######################################################################## +# Should not have to change below this line, except for customized +# directory structures +######################################################################## + +CORE_OBJS = + +## +## Include all necessary make rules +## Any of these can be copied to a local file and +## changed if needed. +## +## +## osal-config.mak contians arch, BSP, and OS selection +## +include ../../osal-config.mak +## +## debug-opts.mak contains debug switches +## +include ../../debug-opts.mak +## +## compiler-opts.mak contains compiler definitions and switches/defines +## +include $(OSAL_SRC)/bsp/$(BSP)/make/compiler-opts.mak + +## +## Setup the include path for this subsystem +## The OS specific includes are in the build-rules.make file +## +## If this subsystem needs include files from another app, add the path here. +## +INCLUDE_PATH = \ +-I$(OSAL_SRC)/inc \ +-I$(OSAL_SRC)/os/inc \ +-I$(OSAL_SRC)/unit-tests/shared \ +-I$(OSAL_SRC)/unit-tests/$(APPTARGET) \ +-I../../inc + +## +## Define the VPATH make variable. +## This can be modified to include source from another directory. +## If there is no corresponding app in the apps directory, then this can be discarded, or +## if the mission chooses to put the src in another directory such as "src", then that can be +## added here as well. +## +VPATH = $(OSAL_SRC)/unit-tests/$(APPTARGET) +VPATH += $(OSAL_SRC)/unit-tests/shared +VPATH += $(OSAL_SRC)/os/$(OS) +VPATH += $(OSAL_SRC)/bsp/$(BSP)/src + +## +## Include the common make rules for building an OSAL Application +## +include $(OSAL_SRC)/make/app-rules.mak + + diff --git a/build/unit-tests/osloader-test/Makefile b/build/unit-tests/osloader-test/Makefile new file mode 100644 index 000000000..88ea471ce --- /dev/null +++ b/build/unit-tests/osloader-test/Makefile @@ -0,0 +1,105 @@ +############################################################################### +# File: OSAL Application Makefile +# +# +# History: +# +############################################################################### +# +# Subsystem produced by this makefile. +# +APPTARGET = osloader-test + +# +# Object files required to build subsystem. +# +OBJS = ut_osloader_module_test.o ut_osloader_symtable_test.o ut_osloader_test.o + +# +# Core object files +# +OBJS += osapi.o osfileapi.o osfilesys.o osloader.o osnetwork.o ostimer.o + +# +# BSP Object files +# +OBJS += bsp_start.o bsp_voltab.o + +# +# Unit test shared object files +# +OBJS += ut_os_stubs.o + +# +# Source files required to build subsystem; used to generate dependencies. +# As long as there are no assembly files this can be automated. +# +SOURCES = $(OBJS:.o=.c) + +## +## Specify extra C Flags needed to build this subsystem +## +LOCAL_COPTS = + + +## +## EXEDIR is defined here, just in case it needs to be different for a custom +## build +## +EXEDIR=./ + +######################################################################## +# Should not have to change below this line, except for customized +# directory structures +######################################################################## + +CORE_OBJS = + +## +## Include all necessary make rules +## Any of these can be copied to a local file and +## changed if needed. +## +## +## osal-config.mak contians arch, BSP, and OS selection +## +include ../../osal-config.mak +## +## debug-opts.mak contains debug switches +## +include ../../debug-opts.mak +## +## compiler-opts.mak contains compiler definitions and switches/defines +## +include $(OSAL_SRC)/bsp/$(BSP)/make/compiler-opts.mak + +## +## Setup the include path for this subsystem +## The OS specific includes are in the build-rules.make file +## +## If this subsystem needs include files from another app, add the path here. +## +INCLUDE_PATH = \ +-I$(OSAL_SRC)/inc \ +-I$(OSAL_SRC)/os/inc \ +-I$(OSAL_SRC)/unit-tests/shared \ +-I$(OSAL_SRC)/unit-tests/$(APPTARGET) \ +-I../../inc + +## +## Define the VPATH make variable. +## This can be modified to include source from another directory. +## If there is no corresponding app in the apps directory, then this can be discarded, or +## if the mission chooses to put the src in another directory such as "src", then that can be +## added here as well. +## +VPATH = $(OSAL_SRC)/unit-tests/$(APPTARGET) +VPATH += $(OSAL_SRC)/unit-tests/shared +VPATH += $(OSAL_SRC)/os/$(OS) +VPATH += $(OSAL_SRC)/bsp/$(BSP)/src + +## +## Include the common make rules for building an OSAL Application +## +include $(OSAL_SRC)/make/app-rules.mak + diff --git a/build/unit-tests/osloader-test/Modules.mak b/build/unit-tests/osloader-test/Modules.mak new file mode 100644 index 000000000..43a876ea8 --- /dev/null +++ b/build/unit-tests/osloader-test/Modules.mak @@ -0,0 +1,22 @@ +# +# MakeModules.mak +# +# This makefile compiles the loadable modules for the os loader unit test +# The compile is OS specific, so it must include a makefile from the bsp directory + +# +# osal-config.mak contians BSP and OS selection +# +include ../../osal-config.mak + +# +# MODULE_SRC sets the path to the source code needed +# +MODULE_SRC = $(OSAL_SRC)/unit-tests/osloader-test + +# +# Include the target OS specific rules +# +include $(OSAL_SRC)/bsp/$(BSP)/make/ut-modules.mak + + diff --git a/build/unit-tests/osnetwork-test/Makefile b/build/unit-tests/osnetwork-test/Makefile new file mode 100644 index 000000000..b962be482 --- /dev/null +++ b/build/unit-tests/osnetwork-test/Makefile @@ -0,0 +1,107 @@ +############################################################################### +# File: OSAL Application Makefile +# +# +# History: +# +############################################################################### +# +# Subsystem produced by this makefile. +# +APPTARGET = osnetwork-test + +# +# Object files required to build subsystem. +# +OBJS = ut_osnetwork_misc_test.o ut_osnetwork_test.o + +# +# Core object files +# +OBJS += osapi.o osfileapi.o osfilesys.o osloader.o osnetwork.o ostimer.o + +# +# BSP Object files +# +OBJS += bsp_start.o bsp_voltab.o + +# +# Unit test shared object files +# +OBJS += ut_os_stubs.o + + +# +# Source files required to build subsystem; used to generate dependencies. +# As long as there are no assembly files this can be automated. +# +SOURCES = $(OBJS:.o=.c) + +## +## Specify extra C Flags needed to build this subsystem +## +LOCAL_COPTS = + + +## +## EXEDIR is defined here, just in case it needs to be different for a custom +## build +## +EXEDIR=./ + +######################################################################## +# Should not have to change below this line, except for customized +# directory structures +######################################################################## + +CORE_OBJS = + +## +## Include all necessary make rules +## Any of these can be copied to a local file and +## changed if needed. +## +## +## osal-config.mak contians arch, BSP, and OS selection +## +include ../../osal-config.mak +## +## debug-opts.mak contains debug switches +## +include ../../debug-opts.mak +## +## compiler-opts.mak contains compiler definitions and switches/defines +## +include $(OSAL_SRC)/bsp/$(BSP)/make/compiler-opts.mak + +## +## Setup the include path for this subsystem +## The OS specific includes are in the build-rules.make file +## +## If this subsystem needs include files from another app, add the path here. +## +INCLUDE_PATH = \ +-I$(OSAL_SRC)/inc \ +-I$(OSAL_SRC)/os/inc \ +-I$(OSAL_SRC)/unit-tests/shared \ +-I$(OSAL_SRC)/unit-tests/$(APPTARGET) \ +-I../../inc + +## +## Define the VPATH make variable. +## This can be modified to include source from another directory. +## If there is no corresponding app in the apps directory, then this can be discarded, or +## if the mission chooses to put the src in another directory such as "src", then that can be +## added here as well. +## +VPATH = $(OSAL_SRC)/unit-tests/$(APPTARGET) +VPATH += $(OSAL_SRC)/unit-tests/shared +VPATH += $(OSAL_SRC)/os/$(OS) +VPATH += $(OSAL_SRC)/bsp/$(BSP)/src + +## +## Include the common make rules for building an OSAL Application +## +include $(OSAL_SRC)/make/app-rules.mak + + diff --git a/build/unit-tests/ostimer-test/Makefile b/build/unit-tests/ostimer-test/Makefile new file mode 100644 index 000000000..5298e8b69 --- /dev/null +++ b/build/unit-tests/ostimer-test/Makefile @@ -0,0 +1,105 @@ +############################################################################### +# File: OSAL Application Makefile +# +# +# History: +# +############################################################################### +# +# Subsystem produced by this makefile. +# +APPTARGET = ostimer-test + +# +# Object files required to build subsystem. +# +OBJS = ut_ostimer_test.o ut_ostimer_timerio_test.o + +# +# Core object files +# +OBJS += osapi.o osfileapi.o osfilesys.o osloader.o osnetwork.o ostimer.o + +# +# BSP Object files +# +OBJS += bsp_start.o bsp_voltab.o + +# +# Unit test shared object files +# +OBJS += ut_os_stubs.o + +# +# Source files required to build subsystem; used to generate dependencies. +# As long as there are no assembly files this can be automated. +# +SOURCES = $(OBJS:.o=.c) + +## +## Specify extra C Flags needed to build this subsystem +## +LOCAL_COPTS = + + +## +## EXEDIR is defined here, just in case it needs to be different for a custom +## build +## +EXEDIR=./ + +######################################################################## +# Should not have to change below this line, except for customized +# directory structures +######################################################################## + +CORE_OBJS = + +## +## Include all necessary make rules +## Any of these can be copied to a local file and +## changed if needed. +## +## +## osal-config.mak contians arch, BSP, and OS selection +## +include ../../osal-config.mak +## +## debug-opts.mak contains debug switches +## +include ../../debug-opts.mak +## +## compiler-opts.mak contains compiler definitions and switches/defines +## +include $(OSAL_SRC)/bsp/$(BSP)/make/compiler-opts.mak + +## +## Setup the include path for this subsystem +## The OS specific includes are in the build-rules.make file +## +## If this subsystem needs include files from another app, add the path here. +## +INCLUDE_PATH = \ +-I$(OSAL_SRC)/inc \ +-I$(OSAL_SRC)/os/inc \ +-I$(OSAL_SRC)/unit-tests/shared \ +-I$(OSAL_SRC)/unit-tests/$(APPTARGET) \ +-I../../inc + +## +## Define the VPATH make variable. +## This can be modified to include source from another directory. +## If there is no corresponding app in the apps directory, then this can be discarded, or +## if the mission chooses to put the src in another directory such as "src", then that can be +## added here as well. +## +VPATH = $(OSAL_SRC)/unit-tests/$(APPTARGET) +VPATH += $(OSAL_SRC)/unit-tests/shared +VPATH += $(OSAL_SRC)/os/$(OS) +VPATH += $(OSAL_SRC)/bsp/$(BSP)/src + +## +## Include the common make rules for building an OSAL Application +## +include $(OSAL_SRC)/make/app-rules.mak + diff --git a/src/bsp/genppc-vxworks6.4/config/osconfig.h b/src/bsp/genppc-vxworks6.4/config/osconfig.h new file mode 100644 index 000000000..933e7b97c --- /dev/null +++ b/src/bsp/genppc-vxworks6.4/config/osconfig.h @@ -0,0 +1,172 @@ +/****************************************************************************** +** File: osconfig.h +** $Id: osconfig.h 1.2 2013/12/16 13:06:18GMT-05:00 acudmore Exp $ +** +** Purpose: +** This header file contains the OS API configuration parameters. +** +** Author: A. Cudmore +** +** Notes: +** +** $Date: 2013/12/16 13:06:18GMT-05:00 $ +** $Revision: 1.2 $ +** $Log: osconfig.h $ +** Revision 1.2 2013/12/16 13:06:18GMT-05:00 acudmore +** use OS_FS_PHYS_NAME_LEN macro instead of hard-coded value +** Revision 1.1 2013/07/19 14:04:17GMT-05:00 acudmore +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/bsp/genppc-vxworks6.4/config/project.pj +** Revision 1.8 2011/12/05 12:41:15GMT-05:00 acudmore +** Removed OS_MEM_TABLE_SIZE parameter +** Revision 1.7 2009/07/14 14:24:53EDT acudmore +** Added parameter for local path size. +** Revision 1.6 2009/07/07 14:01:02EDT acudmore +** Changed OS_MAX_NUM_OPEN_FILES to 50 to preserve data/telmetry space +** Revision 1.5 2009/07/07 13:58:22EDT acudmore +** Added OS_STATIC_LOADER define to switch between static and dynamic loaders. +** Revision 1.4 2009/06/04 11:43:43EDT rmcgraw +** DCR8290:1 Increased settings for max tasks,queues,sems and modules +** Revision 1.3 2008/08/20 15:49:37EDT apcudmore +** Add OS_MAX_TIMERS parameter for Timer API +** Revision 1.2 2008/06/20 15:17:56EDT apcudmore +** Added conditional define for Module Loader API configuration +** Revision 1.1 2008/04/20 22:35:19EDT ruperera +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/build/inc/project.pj +** Revision 1.6 2008/02/12 13:27:59EST apcudmore +** New API updates: +** - fixed RTEMS osapi compile error +** - related makefile fixes +** - header file parameter update +** +** Revision 1.1 2005/06/09 10:57:58EDT rperera +** Initial revision +** +******************************************************************************/ + +#ifndef _osconfig_ +#define _osconfig_ + +/* +** Platform Configuration Parameters for the OS API +*/ + +#define OS_MAX_TASKS 64 +#define OS_MAX_QUEUES 64 +#define OS_MAX_COUNT_SEMAPHORES 20 +#define OS_MAX_BIN_SEMAPHORES 20 +#define OS_MAX_MUTEXES 20 + +/* +** Maximum length for an absolute path name +*/ +#define OS_MAX_PATH_LEN 64 + +/* +** Maximum length for a local or host path/filename. +** This parameter can consist of the OSAL filename/path + +** the host OS physical volume name or path. +*/ +#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) + + +/* +** The maxium length allowed for a object (task,queue....) name +*/ +#define OS_MAX_API_NAME 20 + +/* +** The maximum length for a file name +*/ +#define OS_MAX_FILE_NAME 20 + +/* +** These defines are for OS_printf +*/ +#define OS_BUFFER_SIZE 172 +#define OS_BUFFER_MSG_DEPTH 100 + +/* This #define turns on a utility task that + * will read the statements to print from + * the OS_printf function. If you want OS_printf + * to print the text out itself, comment this out + * + * NOTE: The Utility Task #defines only have meaning + * on the VxWorks operating systems + */ + +#define OS_UTILITY_TASK_ON + + +#ifdef OS_UTILITY_TASK_ON + #define OS_UTILITYTASK_STACK_SIZE 2048 + /* some room is left for other lower priority tasks */ + #define OS_UTILITYTASK_PRIORITY 245 +#endif + + +/* +** the size of a command that can be passed to the underlying OS +*/ +#define OS_MAX_CMD_LEN 1000 + +/* +** This define will include the OS network API. +** It should be turned off for targtets that do not have a network stack or +** device ( like the basic RAD750 vxWorks BSP ) +*/ +#define OS_INCLUDE_NETWORK + +/* +** This is the maximum number of open file descriptors allowed at a time +*/ +#define OS_MAX_NUM_OPEN_FILES 50 + +/* +** This defines the filethe input command of OS_ShellOutputToFile +** is written to in the VxWorks6 port +*/ +#define OS_SHELL_CMD_INPUT_FILE_NAME "/ram/OS_ShellCmd.in" + +/* +** This define sets the queue implentation of the Linux port to use sockets +** commenting this out makes the Linux port use the POSIX message queues. +*/ +/* #define OSAL_SOCKET_QUEUE */ + +/* +** Module loader/symbol table is optional +*/ +#define OS_INCLUDE_MODULE_LOADER + +#ifdef OS_INCLUDE_MODULE_LOADER + /* + ** This define sets the size of the OS Module Table, which keeps track of the loaded modules in + ** the running system. This define must be set high enough to support the maximum number of + ** loadable modules in the system. If the the table is filled up at runtime, a new module load + ** would fail. + */ + #define OS_MAX_MODULES 20 + + /* + ** The Static Loader define is used for switching between the Dynamic and Static loader implementations. + */ + /* #define OS_STATIC_LOADER */ + +#endif + + +/* +** This define sets the maximum symbol name string length. It is used in implementations that +** support the symbols and symbol lookup. +*/ +#define OS_MAX_SYM_LEN 64 + + +/* +** This define sets the maximum number of timers available +*/ +#define OS_MAX_TIMERS 5 + +#endif diff --git a/src/bsp/mcf5235-rtems/config/osconfig.h b/src/bsp/mcf5235-rtems/config/osconfig.h new file mode 100644 index 000000000..c6c8fa0b5 --- /dev/null +++ b/src/bsp/mcf5235-rtems/config/osconfig.h @@ -0,0 +1,171 @@ +/****************************************************************************** +** File: osconfig.h +** $Id: osconfig.h 1.2 2013/12/16 13:06:47GMT-05:00 acudmore Exp $ +** +** Purpose: +** This header file contains the OS API configuration parameters. +** +** Author: A. Cudmore +** +** Notes: +** +** $Date: 2013/12/16 13:06:47GMT-05:00 $ +** $Revision: 1.2 $ +** $Log: osconfig.h $ +** Revision 1.2 2013/12/16 13:06:47GMT-05:00 acudmore +** use OS_FS_PHYS_NAME_LEN macro instead of hard-coded value +** Revision 1.1 2013/07/19 14:04:41GMT-05:00 acudmore +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/bsp/mcf5235-rtems/config/project.pj +** Revision 1.8 2011/12/05 12:41:15GMT-05:00 acudmore +** Removed OS_MEM_TABLE_SIZE parameter +** Revision 1.7 2009/07/14 14:24:53EDT acudmore +** Added parameter for local path size. +** Revision 1.6 2009/07/07 14:01:02EDT acudmore +** Changed OS_MAX_NUM_OPEN_FILES to 50 to preserve data/telmetry space +** Revision 1.5 2009/07/07 13:58:22EDT acudmore +** Added OS_STATIC_LOADER define to switch between static and dynamic loaders. +** Revision 1.4 2009/06/04 11:43:43EDT rmcgraw +** DCR8290:1 Increased settings for max tasks,queues,sems and modules +** Revision 1.3 2008/08/20 15:49:37EDT apcudmore +** Add OS_MAX_TIMERS parameter for Timer API +** Revision 1.2 2008/06/20 15:17:56EDT apcudmore +** Added conditional define for Module Loader API configuration +** Revision 1.1 2008/04/20 22:35:19EDT ruperera +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/build/inc/project.pj +** Revision 1.6 2008/02/12 13:27:59EST apcudmore +** New API updates: +** - fixed RTEMS osapi compile error +** - related makefile fixes +** - header file parameter update +** +** Revision 1.1 2005/06/09 10:57:58EDT rperera +** Initial revision +** +******************************************************************************/ + +#ifndef _osconfig_ +#define _osconfig_ + +/* +** Platform Configuration Parameters for the OS API +*/ + +#define OS_MAX_TASKS 64 +#define OS_MAX_QUEUES 64 +#define OS_MAX_COUNT_SEMAPHORES 20 +#define OS_MAX_BIN_SEMAPHORES 20 +#define OS_MAX_MUTEXES 20 + +/* +** Maximum length for an absolute path name +*/ +#define OS_MAX_PATH_LEN 64 + +/* +** Maximum length for a local or host path/filename. +** This parameter can consist of the OSAL filename/path + +** the host OS physical volume name or path. +*/ +#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) + +/* +** The maxium length allowed for a object (task,queue....) name +*/ +#define OS_MAX_API_NAME 20 + +/* +** The maximum length for a file name +*/ +#define OS_MAX_FILE_NAME 20 + +/* +** These defines are for OS_printf +*/ +#define OS_BUFFER_SIZE 172 +#define OS_BUFFER_MSG_DEPTH 100 + +/* This #define turns on a utility task that + * will read the statements to print from + * the OS_printf function. If you want OS_printf + * to print the text out itself, comment this out + * + * NOTE: The Utility Task #defines only have meaning + * on the VxWorks operating systems + */ + +#define OS_UTILITY_TASK_ON + + +#ifdef OS_UTILITY_TASK_ON + #define OS_UTILITYTASK_STACK_SIZE 2048 + /* some room is left for other lower priority tasks */ + #define OS_UTILITYTASK_PRIORITY 245 +#endif + + +/* +** the size of a command that can be passed to the underlying OS +*/ +#define OS_MAX_CMD_LEN 1000 + +/* +** This define will include the OS network API. +** It should be turned off for targtets that do not have a network stack or +** device ( like the basic RAD750 vxWorks BSP ) +*/ +#undef OS_INCLUDE_NETWORK + +/* +** This is the maximum number of open file descriptors allowed at a time +*/ +#define OS_MAX_NUM_OPEN_FILES 50 + +/* +** This defines the filethe input command of OS_ShellOutputToFile +** is written to in the VxWorks6 port +*/ +#define OS_SHELL_CMD_INPUT_FILE_NAME "/ram/OS_ShellCmd.in" + +/* +** This define sets the queue implentation of the Linux port to use sockets +** commenting this out makes the Linux port use the POSIX message queues. +*/ +/* #define OSAL_SOCKET_QUEUE */ + +/* +** Module loader/symbol table is optional +*/ +#undef OS_INCLUDE_MODULE_LOADER + +#ifdef OS_INCLUDE_MODULE_LOADER + /* + ** This define sets the size of the OS Module Table, which keeps track of the loaded modules in + ** the running system. This define must be set high enough to support the maximum number of + ** loadable modules in the system. If the the table is filled up at runtime, a new module load + ** would fail. + */ + #define OS_MAX_MODULES 10 + + /* + ** The Static Loader define is used for switching between the Dynamic and Static loader implementations. + */ + /* #define OS_STATIC_LOADER */ + +#endif + + +/* +** This define sets the maximum symbol name string length. It is used in implementations that +** support the symbols and symbol lookup. +*/ +#define OS_MAX_SYM_LEN 64 + + +/* +** This define sets the maximum number of timers available +*/ +#define OS_MAX_TIMERS 5 + +#endif diff --git a/src/bsp/pc-linux-ut/config/osconfig.h b/src/bsp/pc-linux-ut/config/osconfig.h new file mode 100644 index 000000000..82e54b62a --- /dev/null +++ b/src/bsp/pc-linux-ut/config/osconfig.h @@ -0,0 +1,171 @@ +/****************************************************************************** +** File: osconfig.h +** $Id: osconfig.h 1.2 2013/12/16 13:07:41GMT-05:00 acudmore Exp $ +** +** Purpose: +** This header file contains the OS API configuration parameters. +** +** Author: A. Cudmore +** +** Notes: +** +** $Date: 2013/12/16 13:07:41GMT-05:00 $ +** $Revision: 1.2 $ +** $Log: osconfig.h $ +** Revision 1.2 2013/12/16 13:07:41GMT-05:00 acudmore +** use OS_FS_PHYS_NAME_LEN macro instead of hard-coded value +** Revision 1.1 2013/07/19 14:07:02GMT-05:00 acudmore +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/bsp/pc-linux-ut/config/project.pj +** Revision 1.8 2011/12/05 12:41:15GMT-05:00 acudmore +** Removed OS_MEM_TABLE_SIZE parameter +** Revision 1.7 2009/07/14 14:24:53EDT acudmore +** Added parameter for local path size. +** Revision 1.6 2009/07/07 14:01:02EDT acudmore +** Changed OS_MAX_NUM_OPEN_FILES to 50 to preserve data/telmetry space +** Revision 1.5 2009/07/07 13:58:22EDT acudmore +** Added OS_STATIC_LOADER define to switch between static and dynamic loaders. +** Revision 1.4 2009/06/04 11:43:43EDT rmcgraw +** DCR8290:1 Increased settings for max tasks,queues,sems and modules +** Revision 1.3 2008/08/20 15:49:37EDT apcudmore +** Add OS_MAX_TIMERS parameter for Timer API +** Revision 1.2 2008/06/20 15:17:56EDT apcudmore +** Added conditional define for Module Loader API configuration +** Revision 1.1 2008/04/20 22:35:19EDT ruperera +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/build/inc/project.pj +** Revision 1.6 2008/02/12 13:27:59EST apcudmore +** New API updates: +** - fixed RTEMS osapi compile error +** - related makefile fixes +** - header file parameter update +** +** Revision 1.1 2005/06/09 10:57:58EDT rperera +** Initial revision +** +******************************************************************************/ + +#ifndef _osconfig_ +#define _osconfig_ + +/* +** Platform Configuration Parameters for the OS API +*/ + +#define OS_MAX_TASKS 64 +#define OS_MAX_QUEUES 64 +#define OS_MAX_COUNT_SEMAPHORES 20 +#define OS_MAX_BIN_SEMAPHORES 20 +#define OS_MAX_MUTEXES 20 + +/* +** Maximum length for an absolute path name +*/ +#define OS_MAX_PATH_LEN 64 + +/* +** Maximum length for a local or host path/filename. +** This parameter can consist of the OSAL filename/path + +** the host OS physical volume name or path. +*/ +#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) + +/* +** The maxium length allowed for a object (task,queue....) name +*/ +#define OS_MAX_API_NAME 20 + +/* +** The maximum length for a file name +*/ +#define OS_MAX_FILE_NAME 20 + +/* +** These defines are for OS_printf +*/ +#define OS_BUFFER_SIZE 172 +#define OS_BUFFER_MSG_DEPTH 100 + +/* This #define turns on a utility task that + * will read the statements to print from + * the OS_printf function. If you want OS_printf + * to print the text out itself, comment this out + * + * NOTE: The Utility Task #defines only have meaning + * on the VxWorks operating systems + */ + +#define OS_UTILITY_TASK_ON + + +#ifdef OS_UTILITY_TASK_ON + #define OS_UTILITYTASK_STACK_SIZE 2048 + /* some room is left for other lower priority tasks */ + #define OS_UTILITYTASK_PRIORITY 245 +#endif + + +/* +** the size of a command that can be passed to the underlying OS +*/ +#define OS_MAX_CMD_LEN 1000 + +/* +** This define will include the OS network API. +** It should be turned off for targtets that do not have a network stack or +** device ( like the basic RAD750 vxWorks BSP ) +*/ +#define OS_INCLUDE_NETWORK + +/* +** This is the maximum number of open file descriptors allowed at a time +*/ +#define OS_MAX_NUM_OPEN_FILES 50 + +/* +** This defines the filethe input command of OS_ShellOutputToFile +** is written to in the VxWorks6 port +*/ +#define OS_SHELL_CMD_INPUT_FILE_NAME "/ram/OS_ShellCmd.in" + +/* +** This define sets the queue implentation of the Linux port to use sockets +** commenting this out makes the Linux port use the POSIX message queues. +*/ +/* #define OSAL_SOCKET_QUEUE */ + +/* +** Module loader/symbol table is optional +*/ +#define OS_INCLUDE_MODULE_LOADER + +#ifdef OS_INCLUDE_MODULE_LOADER + /* + ** This define sets the size of the OS Module Table, which keeps track of the loaded modules in + ** the running system. This define must be set high enough to support the maximum number of + ** loadable modules in the system. If the the table is filled up at runtime, a new module load + ** would fail. + */ + #define OS_MAX_MODULES 10 + + /* + ** The Static Loader define is used for switching between the Dynamic and Static loader implementations. + */ + /* #define OS_STATIC_LOADER */ + +#endif + + +/* +** This define sets the maximum symbol name string length. It is used in implementations that +** support the symbols and symbol lookup. +*/ +#define OS_MAX_SYM_LEN 64 + + +/* +** This define sets the maximum number of timers available +*/ +#define OS_MAX_TIMERS 5 + +#endif diff --git a/src/bsp/pc-linux-ut/make/compiler-opts.mak b/src/bsp/pc-linux-ut/make/compiler-opts.mak new file mode 100644 index 000000000..b0c995a63 --- /dev/null +++ b/src/bsp/pc-linux-ut/make/compiler-opts.mak @@ -0,0 +1,95 @@ +############################################################################### +## compiler-opts.mak - compiler definitions and options for building the OSAL +## +## Target: x86 PC Linux +## +## Modifications: +## +############################################################################### +## +## Warning Level Configuration +## +## WARNINGS=-Wall -ansi -pedantic -Wstrict-prototypes +WARNINGS=-Wall -pedantic -Wstrict-prototypes + +## +## Host OS Include Paths ( be sure to put the -I switch in front of each directory ) +## +SYSINCS= + +## +## Target Defines for the OS, Hardware Arch, etc.. +## +TARGET_DEFS=-D__ix86__ -D_ix86_ -D_LINUX_OS_ -D$(OS) -DX86PC -D_OSAL_UNIT_TEST_ -DBUILD=$(BUILD) -D_REENTRANT -D _EMBED_ + +## +## Endian Defines +## +ENDIAN_DEFS=-D_EL -DENDIAN=_EL -DSOFTWARE_LITTLE_BIT_ORDER + +## +## Compiler Architecture Switches +## +ARCH_OPTS = -pg -fprofile-arcs -ftest-coverage + +## +## Application specific compiler switches +## +ifeq ($(BUILD_TYPE),CFE_APP) + APP_COPTS= + APP_ASOPTS= +else + APP_COPTS= + APP_ASOPTS= +endif + +## +## Extra Cflags for Assembly listings, etc. +## +LIST_OPTS = + + +## +## gcc options for dependancy generation +## +COPTS_D = $(APP_COPTS) $(ENDIAN_DEFS) $(TARGET_DEFS) $(ARCH_OPTS) $(SYSINCS) $(WARNINGS) + +## +## General gcc options that apply to compiling and dependency generation. +## +COPTS=$(LIST_OPTS) $(COPTS_D) + +## +## Extra defines and switches for assembly code +## +ASOPTS = $(APP_ASOPTS) -P -xassembler-with-cpp + +## +## Application file extention type +## This is the defined application extention. +## +APP_EXT = bin + +################################################################################# +## Host Development System and Toolchain defintions +## + +## +## Host OS utils +## +RM=rm -f +CP=cp + +## +## Compiler tools +## +COMPILER=gcc +ASSEMBLER=as +LINKER=ld +AR=ar +NM=nm +SIZE=size +OBJCOPY=objcopy +OBJDUMP=objdump + +## End configuration options ## diff --git a/src/bsp/pc-linux-ut/make/link-rules.mak b/src/bsp/pc-linux-ut/make/link-rules.mak new file mode 100644 index 000000000..fb14a99e1 --- /dev/null +++ b/src/bsp/pc-linux-ut/make/link-rules.mak @@ -0,0 +1,36 @@ +############################################################################### +# File: link-rules.mak +# +# Purpose: +# Makefile for linking code and producing an executable image. +# +# History: +# +############################################################################### + + +## +## Linker flags that are needed +## +LDFLAGS = -pg -fprofile-arcs -ftest-coverage + +## +## Libraries to link in +## Cygwin cannot use the -lrt switch +## Older versions of linux may not have this as well. +## +OSTYPE := $(shell uname -s) +ifeq ($(OSTYPE),Linux) + LIBS = -lpthread -lrt -ldl +else + LIBS = -lpthread -ldl +endif + + +## +## OSAL Core Link Rule +## +$(APPTARGET).$(APP_EXT): $(OBJS) + $(COMPILER) $(DEBUG_FLAGS) -o $(APPTARGET).$(APP_EXT) $(OBJS) $(CORE_OBJS) $(LDFLAGS) $(LIBS) + + diff --git a/src/bsp/pc-linux-ut/make/ut-modules.mak b/src/bsp/pc-linux-ut/make/ut-modules.mak new file mode 100644 index 000000000..df7482bc5 --- /dev/null +++ b/src/bsp/pc-linux-ut/make/ut-modules.mak @@ -0,0 +1,17 @@ + +default:: + mkdir -p eeprom1 + gcc -shared -Wall -g -O0 -DMODULE_NAME=module0 -o eeprom1/MODULE0.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module1 -o eeprom1/MODULE1.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module2 -o eeprom1/MODULE2.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module3 -o eeprom1/MODULE3.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module4 -o eeprom1/MODULE4.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module5 -o eeprom1/MODULE5.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module6 -o eeprom1/MODULE6.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module7 -o eeprom1/MODULE7.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module8 -o eeprom1/MODULE8.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module9 -o eeprom1/MODULE9.so $(MODULE_SRC)/ut_module.c + gcc -shared -Wall -g -O0 -DMODULE_NAME=module10 -o eeprom1/MODULE10.so $(MODULE_SRC)/ut_module.c + +clean:: + rm -rf eeprom1 diff --git a/src/bsp/pc-linux-ut/src/bsp.mak b/src/bsp/pc-linux-ut/src/bsp.mak new file mode 100644 index 000000000..7e9dc72c9 --- /dev/null +++ b/src/bsp/pc-linux-ut/src/bsp.mak @@ -0,0 +1,22 @@ +############################################################################### +# File: bsp.mak +# +# Purpose: +# Compile Board Support Package routines for the Linux desktop build +# +# History: +# +############################################################################### + +# Subsystem produced by this makefile. +TARGET = bsp.o + +#============================================================================== +# Object files required to build subsystem. +OBJS = bsp_start.o bsp_voltab.o + +#============================================================================== +# Source files required to build subsystem; used to generate dependencies. +SOURCES = bsp_start.c bsp_voltab.c + + diff --git a/src/bsp/pc-linux-ut/src/bsp_start.c b/src/bsp/pc-linux-ut/src/bsp_start.c new file mode 100644 index 000000000..0705ef27e --- /dev/null +++ b/src/bsp/pc-linux-ut/src/bsp_start.c @@ -0,0 +1,91 @@ +/****************************************************************************** +** 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. +** +** 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 +** +******************************************************************************/ + +/* +** Include Files +*/ +#include +#include +#include +#include +#include +#include +#include + +/* +** OSAL includes +*/ +#include "common_types.h" +#include "osapi.h" + +/* +** Types and prototypes for this module +*/ + +/* +** External Declarations +*/ +void OS_Application_Startup(void); + +/* +** Global variables +*/ + + +/****************************************************************************** +** Function: main() +** +** Purpose: +** BSP Application entry point. +** +** Arguments: +** (none) +** +** Return: +** (none) +*/ + +int main(void) +{ + int mode; + int status; + + /* + ** Create local directories for "disk" mount points + ** See bsp_voltab for the values + */ + printf("Making directories: ram0, ram1, eeprom1 for OSAL mount points\n"); + mode = S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO; + status = mkdir("ram0", mode); + status = mkdir("ram1", mode); + status = mkdir("eeprom1", mode); + + /* + ** OS_API_Init is called by OS_Application_Startup + */ + + /* + ** Call application specific entry point. + */ + OS_Application_Startup(); + + return(0); +} + diff --git a/src/bsp/pc-linux-ut/src/bsp_voltab.c b/src/bsp/pc-linux-ut/src/bsp_voltab.c new file mode 100644 index 000000000..7d831e1a9 --- /dev/null +++ b/src/bsp/pc-linux-ut/src/bsp_voltab.c @@ -0,0 +1,52 @@ +/* +** 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 }, + +/* +** 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 }, +{"unused", "unused", FS_BASED, TRUE, TRUE, FALSE, " ", " ", 0 } +}; + + + diff --git a/src/bsp/pc-linux/config/osconfig.h b/src/bsp/pc-linux/config/osconfig.h new file mode 100644 index 000000000..dfe5adc17 --- /dev/null +++ b/src/bsp/pc-linux/config/osconfig.h @@ -0,0 +1,171 @@ +/****************************************************************************** +** File: osconfig.h +** $Id: osconfig.h 1.2 2013/12/16 13:07:17GMT-05:00 acudmore Exp $ +** +** Purpose: +** This header file contains the OS API configuration parameters. +** +** Author: A. Cudmore +** +** Notes: +** +** $Date: 2013/12/16 13:07:17GMT-05:00 $ +** $Revision: 1.2 $ +** $Log: osconfig.h $ +** Revision 1.2 2013/12/16 13:07:17GMT-05:00 acudmore +** use OS_FS_PHYS_NAME_LEN macro instead of hard-coded value +** Revision 1.1 2013/07/19 14:05:01GMT-05:00 acudmore +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/bsp/pc-linux/config/project.pj +** Revision 1.8 2011/12/05 12:41:15GMT-05:00 acudmore +** Removed OS_MEM_TABLE_SIZE parameter +** Revision 1.7 2009/07/14 14:24:53EDT acudmore +** Added parameter for local path size. +** Revision 1.6 2009/07/07 14:01:02EDT acudmore +** Changed OS_MAX_NUM_OPEN_FILES to 50 to preserve data/telmetry space +** Revision 1.5 2009/07/07 13:58:22EDT acudmore +** Added OS_STATIC_LOADER define to switch between static and dynamic loaders. +** Revision 1.4 2009/06/04 11:43:43EDT rmcgraw +** DCR8290:1 Increased settings for max tasks,queues,sems and modules +** Revision 1.3 2008/08/20 15:49:37EDT apcudmore +** Add OS_MAX_TIMERS parameter for Timer API +** Revision 1.2 2008/06/20 15:17:56EDT apcudmore +** Added conditional define for Module Loader API configuration +** Revision 1.1 2008/04/20 22:35:19EDT ruperera +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/build/inc/project.pj +** Revision 1.6 2008/02/12 13:27:59EST apcudmore +** New API updates: +** - fixed RTEMS osapi compile error +** - related makefile fixes +** - header file parameter update +** +** Revision 1.1 2005/06/09 10:57:58EDT rperera +** Initial revision +** +******************************************************************************/ + +#ifndef _osconfig_ +#define _osconfig_ + +/* +** Platform Configuration Parameters for the OS API +*/ + +#define OS_MAX_TASKS 64 +#define OS_MAX_QUEUES 64 +#define OS_MAX_COUNT_SEMAPHORES 20 +#define OS_MAX_BIN_SEMAPHORES 20 +#define OS_MAX_MUTEXES 20 + +/* +** Maximum length for an absolute path name +*/ +#define OS_MAX_PATH_LEN 64 + +/* +** Maximum length for a local or host path/filename. +** This parameter can consist of the OSAL filename/path + +** the host OS physical volume name or path. +*/ +#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) + +/* +** The maxium length allowed for a object (task,queue....) name +*/ +#define OS_MAX_API_NAME 20 + +/* +** The maximum length for a file name +*/ +#define OS_MAX_FILE_NAME 20 + +/* +** These defines are for OS_printf +*/ +#define OS_BUFFER_SIZE 172 +#define OS_BUFFER_MSG_DEPTH 100 + +/* This #define turns on a utility task that + * will read the statements to print from + * the OS_printf function. If you want OS_printf + * to print the text out itself, comment this out + * + * NOTE: The Utility Task #defines only have meaning + * on the VxWorks operating systems + */ + +#define OS_UTILITY_TASK_ON + + +#ifdef OS_UTILITY_TASK_ON + #define OS_UTILITYTASK_STACK_SIZE 2048 + /* some room is left for other lower priority tasks */ + #define OS_UTILITYTASK_PRIORITY 245 +#endif + + +/* +** the size of a command that can be passed to the underlying OS +*/ +#define OS_MAX_CMD_LEN 1000 + +/* +** This define will include the OS network API. +** It should be turned off for targtets that do not have a network stack or +** device ( like the basic RAD750 vxWorks BSP ) +*/ +#define OS_INCLUDE_NETWORK + +/* +** This is the maximum number of open file descriptors allowed at a time +*/ +#define OS_MAX_NUM_OPEN_FILES 50 + +/* +** This defines the filethe input command of OS_ShellOutputToFile +** is written to in the VxWorks6 port +*/ +#define OS_SHELL_CMD_INPUT_FILE_NAME "/ram/OS_ShellCmd.in" + +/* +** This define sets the queue implentation of the Linux port to use sockets +** commenting this out makes the Linux port use the POSIX message queues. +*/ +/* #define OSAL_SOCKET_QUEUE */ + +/* +** Module loader/symbol table is optional +*/ +#define OS_INCLUDE_MODULE_LOADER + +#ifdef OS_INCLUDE_MODULE_LOADER + /* + ** This define sets the size of the OS Module Table, which keeps track of the loaded modules in + ** the running system. This define must be set high enough to support the maximum number of + ** loadable modules in the system. If the the table is filled up at runtime, a new module load + ** would fail. + */ + #define OS_MAX_MODULES 20 + + /* + ** The Static Loader define is used for switching between the Dynamic and Static loader implementations. + */ + /* #define OS_STATIC_LOADER */ + +#endif + + +/* +** This define sets the maximum symbol name string length. It is used in implementations that +** support the symbols and symbol lookup. +*/ +#define OS_MAX_SYM_LEN 64 + + +/* +** This define sets the maximum number of timers available +*/ +#define OS_MAX_TIMERS 5 + +#endif diff --git a/src/bsp/sis-rtems/config/osconfig.h b/src/bsp/sis-rtems/config/osconfig.h new file mode 100644 index 000000000..d231b4767 --- /dev/null +++ b/src/bsp/sis-rtems/config/osconfig.h @@ -0,0 +1,172 @@ +/****************************************************************************** +** File: osconfig.h +** $Id: osconfig.h 1.2 2013/12/16 13:08:05GMT-05:00 acudmore Exp $ +** +** Purpose: +** This header file contains the OS API configuration parameters. +** +** Author: A. Cudmore +** +** Notes: +** +** $Date: 2013/12/16 13:08:05GMT-05:00 $ +** $Revision: 1.2 $ +** $Log: osconfig.h $ +** Revision 1.2 2013/12/16 13:08:05GMT-05:00 acudmore +** use OS_FS_PHYS_NAME_LEN macro instead of hard-coded value +** Revision 1.1 2013/07/19 14:05:44GMT-05:00 acudmore +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/bsp/sis-rtems/config/project.pj +** Revision 1.8 2011/12/05 12:41:15GMT-05:00 acudmore +** Removed OS_MEM_TABLE_SIZE parameter +** Revision 1.7 2009/07/14 14:24:53EDT acudmore +** Added parameter for local path size. +** Revision 1.6 2009/07/07 14:01:02EDT acudmore +** Changed OS_MAX_NUM_OPEN_FILES to 50 to preserve data/telmetry space +** Revision 1.5 2009/07/07 13:58:22EDT acudmore +** Added OS_STATIC_LOADER define to switch between static and dynamic loaders. +** Revision 1.4 2009/06/04 11:43:43EDT rmcgraw +** DCR8290:1 Increased settings for max tasks,queues,sems and modules +** Revision 1.3 2008/08/20 15:49:37EDT apcudmore +** Add OS_MAX_TIMERS parameter for Timer API +** Revision 1.2 2008/06/20 15:17:56EDT apcudmore +** Added conditional define for Module Loader API configuration +** Revision 1.1 2008/04/20 22:35:19EDT ruperera +** Initial revision +** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/build/inc/project.pj +** Revision 1.6 2008/02/12 13:27:59EST apcudmore +** New API updates: +** - fixed RTEMS osapi compile error +** - related makefile fixes +** - header file parameter update +** +** Revision 1.1 2005/06/09 10:57:58EDT rperera +** Initial revision +** +******************************************************************************/ + +#ifndef _osconfig_ +#define _osconfig_ + +/* +** Platform Configuration Parameters for the OS API +*/ + +#define OS_MAX_TASKS 64 +#define OS_MAX_QUEUES 64 +#define OS_MAX_COUNT_SEMAPHORES 20 +#define OS_MAX_BIN_SEMAPHORES 20 +#define OS_MAX_MUTEXES 20 + +/* +** Maximum length for an absolute path name +*/ +#define OS_MAX_PATH_LEN 64 + +/* +** Maximum length for a local or host path/filename. +** This parameter can consist of the OSAL filename/path + +** the host OS physical volume name or path. +*/ +#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) + + +/* +** The maxium length allowed for a object (task,queue....) name +*/ +#define OS_MAX_API_NAME 20 + +/* +** The maximum length for a file name +*/ +#define OS_MAX_FILE_NAME 20 + +/* +** These defines are for OS_printf +*/ +#define OS_BUFFER_SIZE 172 +#define OS_BUFFER_MSG_DEPTH 100 + +/* This #define turns on a utility task that + * will read the statements to print from + * the OS_printf function. If you want OS_printf + * to print the text out itself, comment this out + * + * NOTE: The Utility Task #defines only have meaning + * on the VxWorks operating systems + */ + +#define OS_UTILITY_TASK_ON + + +#ifdef OS_UTILITY_TASK_ON + #define OS_UTILITYTASK_STACK_SIZE 2048 + /* some room is left for other lower priority tasks */ + #define OS_UTILITYTASK_PRIORITY 245 +#endif + + +/* +** the size of a command that can be passed to the underlying OS +*/ +#define OS_MAX_CMD_LEN 1000 + +/* +** This define will include the OS network API. +** It should be turned off for targtets that do not have a network stack or +** device ( like the basic RAD750 vxWorks BSP ) +*/ +#undef OS_INCLUDE_NETWORK + +/* +** This is the maximum number of open file descriptors allowed at a time +*/ +#define OS_MAX_NUM_OPEN_FILES 50 + +/* +** This defines the filethe input command of OS_ShellOutputToFile +** is written to in the VxWorks6 port +*/ +#define OS_SHELL_CMD_INPUT_FILE_NAME "/ram/OS_ShellCmd.in" + +/* +** This define sets the queue implentation of the Linux port to use sockets +** commenting this out makes the Linux port use the POSIX message queues. +*/ +/* #define OSAL_SOCKET_QUEUE */ + +/* +** Module loader/symbol table is optional +*/ +#undef OS_INCLUDE_MODULE_LOADER + +#ifdef OS_INCLUDE_MODULE_LOADER + /* + ** This define sets the size of the OS Module Table, which keeps track of the loaded modules in + ** the running system. This define must be set high enough to support the maximum number of + ** loadable modules in the system. If the the table is filled up at runtime, a new module load + ** would fail. + */ + #define OS_MAX_MODULES 10 + + /* + ** The Static Loader define is used for switching between the Dynamic and Static loader implementations. + */ + /* #define OS_STATIC_LOADER */ + +#endif + + +/* +** This define sets the maximum symbol name string length. It is used in implementations that +** support the symbols and symbol lookup. +*/ +#define OS_MAX_SYM_LEN 64 + + +/* +** This define sets the maximum number of timers available +*/ +#define OS_MAX_TIMERS 5 + +#endif diff --git a/src/unit-tests/oscore-test/ut_oscore_binsem_test.c b/src/unit-tests/oscore-test/ut_oscore_binsem_test.c new file mode 100644 index 000000000..dfc6c62e8 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_binsem_test.c @@ -0,0 +1,817 @@ +/*================================================================================* +** File: ut_oscore_binsem_test.c +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_oscore_binsem_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: OS_BinSemCreate +** Purpose: Creates a binary semaphore +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_TAKEN if the name passed in has already been used +** OS_ERR_NO_FREE_IDS if there are no more free binary semaphore ids +** OS_SEM_FAILURE if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_bin_sem_create_test() +{ + int i; + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 test_setup_invalid = 0; + char sem_name[OS_MAX_API_NAME]; + char long_sem_name[OS_MAX_API_NAME+5]; + uint32 sem_ids[OS_MAX_BIN_SEMAPHORES+1]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_BinSemCreate(&sem_ids[0], "Good", 1, 0 ); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_bin_sem_create_test_exit_tag; + } + + /* Clean up */ + res = OS_BinSemDelete(sem_ids[0]); + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg-1"; + + res = OS_BinSemCreate(NULL, "BinSem1", 1, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Null-pointer-arg-2"; + + res = OS_BinSemCreate(&sem_ids[0], NULL, 1, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-too-long"; + + memset(long_sem_name, 'X', sizeof(long_sem_name)); + long_sem_name[sizeof(long_sem_name)-1] = '\0'; + res = OS_BinSemCreate(&sem_ids[0], long_sem_name, 1, 0); + if (res == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 No-free-IDs"; + + /* Setup */ + for ( i = 0; i< OS_MAX_BIN_SEMAPHORES; i++ ) + { + memset(sem_name, '\0', sizeof(sem_name)); + UT_os_sprintf(sem_name, "BINSEM%d", i); + + res = OS_BinSemCreate(&sem_ids[i], sem_name, 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#4 No-free-IDs - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + test_setup_invalid = 1; + break; + } + } + + if ( test_setup_invalid == 0 ) + { + res = OS_BinSemCreate(&sem_ids[OS_MAX_BIN_SEMAPHORES], "OneTooMany", 1, 0); + if (res == OS_ERR_NO_FREE_IDS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + } + + /* Reset test environment */ + for ( i = 0; i< OS_MAX_BIN_SEMAPHORES; i++ ) + { + res = OS_BinSemDelete(sem_ids[i]); /* Ignore errors, does not matter here */ + } + + /*-----------------------------------------------------*/ + testDesc = "#5 Duplicate-name"; + + /* Setup */ + res = OS_BinSemCreate(&sem_ids[0], "DUPLICATE", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 Duplicate-name - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemCreate(&sem_ids[0], "DUPLICATE", 1, 0); + if (res == OS_ERR_NAME_TAKEN) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_BinSemDelete(sem_ids[0]); + } + + /*-----------------------------------------------------*/ + testDesc = "#6 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#7 Nominal"; + + res = OS_BinSemCreate(&sem_ids[0], "Good", 1, 0); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_BinSemDelete(sem_ids[0]); + +UT_os_bin_sem_create_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_BinSemCreate", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_BinSemDelete +** Purpose: Deletes a binary semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in does not exist +** OS_SEM_FAILURE if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_bin_sem_delete_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 bin_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_BinSemDelete(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_bin_sem_delete_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_BinSemDelete(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&bin_sem_id, "DeleteTest", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemDelete(bin_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + +UT_os_bin_sem_delete_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_BinSemDelete", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_BinSemFlush +** Purpose: Releases all the tasks waiting on the given semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore id +** OS_SEM_FAILURE if the semaphore was not previously init'd or is not in the +** array of semaphores defined by the system +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_bin_sem_flush_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 bin_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_BinSemFlush(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_bin_sem_flush_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_BinSemFlush(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&bin_sem_id, "FlushTest", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemFlush(bin_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_BinSemDelete(bin_sem_id); + } + +UT_os_bin_sem_flush_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_BinSemFlush", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_BinSemGive +** Purpose: Gives back a binary semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore id +** OS_SEM_FAILURE if the semaphore was not previously init'd or is not in the +** array of semaphores defined by the system +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_bin_sem_give_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 bin_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_BinSemGive(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_bin_sem_give_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_BinSemGive(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&bin_sem_id, "GiveTest", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemGive(bin_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_BinSemDelete(bin_sem_id); + } + +UT_os_bin_sem_give_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_BinSemGive", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_BinSemTake +** Purpose: Reserves a binary semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore id +** OS_SEM_FAILURE if the semaphore was not previously init'd or is not in the +** array of semaphores defined by the system +** OS_SEM_FAILURE if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_bin_sem_take_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 bin_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_BinSemTake(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_bin_sem_take_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_BinSemTake(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&bin_sem_id, "TakeTest", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemTake(bin_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_BinSemDelete(bin_sem_id); + } + +UT_os_bin_sem_take_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_BinSemTake", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_BinSemTimedWait +** Purpose: Reserves a binary semaphore with a timeout +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore id +** OS_SEM_FAILURE if the OS call failed +** OS_SEM_TIMEOUT if the semaphore was not relinquished in time +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_bin_sem_timed_wait_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 bin_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_BinSemTimedWait(0,1000); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_bin_sem_timed_wait_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_BinSemTimedWait(99999, 1000); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Sem-take-timed-out"; + + /* Setup */ + res = OS_BinSemCreate(&bin_sem_id, "TimedWait", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Sem-take-timed-out - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemTake(bin_sem_id); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Sem-take-timed-out - Bin Sem Take failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemTimedWait(bin_sem_id,1000); + if ( res == OS_SEM_TIMEOUT ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + } + res = OS_BinSemDelete(bin_sem_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&bin_sem_id, "TimedWait", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#4 Nominal - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemTimedWait(bin_sem_id,1000); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_BinSemDelete(bin_sem_id); + } + +UT_os_bin_sem_timed_wait_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_BinSemTimedWait", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_BinSemGetIdByName +** Purpose: Returns the id of a given binary semaphore name +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_NOT_FOUND if the name passed in was not found in the binary +** semaphore table +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_bin_sem_get_id_by_name_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 bin_sem_id; + char long_sem_name[OS_MAX_API_NAME+5]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_BinSemGetIdByName(0, "InvalidName"); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_bin_sem_get_id_by_name_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-pointer-arg-1"; + + res = OS_BinSemGetIdByName(NULL, "InvalidName"); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg-2"; + + res = OS_BinSemGetIdByName(&bin_sem_id, NULL); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-too-long"; + + memset(long_sem_name, 'Y', sizeof(long_sem_name)); + long_sem_name[sizeof(long_sem_name)-1] = '\0'; + res = OS_BinSemGetIdByName(&bin_sem_id, long_sem_name); + if ( res == OS_ERR_NAME_TOO_LONG ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-not-found"; + + res = OS_BinSemGetIdByName(&bin_sem_id, "NameNotFound"); + if ( res == OS_ERR_NAME_NOT_FOUND ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&bin_sem_id, "GetIDByName", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 Nominal - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemGetIdByName(&bin_sem_id, "GetIDByName"); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_BinSemDelete(bin_sem_id); + } + +UT_os_bin_sem_get_id_by_name_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_BinSemGetIdByName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_BinSemGetInfo +** Purpose: Returns semaphore information about the given binary semaphore id +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore id +** OS_SUCCESS if succeeded +** Test #1: TBD +**--------------------------------------------------------------------------------*/ +void UT_os_bin_sem_get_info_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 bin_sem_id; + OS_bin_sem_prop_t bin_sem_prop; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_BinSemGetInfo(0, &bin_sem_prop); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_bin_sem_get_info_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_BinSemGetInfo(99999, &bin_sem_prop); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg"; + + /* Setup */ + res = OS_BinSemCreate(&bin_sem_id, "GetInfo", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#2 Invalid-pointer-arg - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemGetInfo(bin_sem_id, NULL); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_BinSemDelete(bin_sem_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&bin_sem_id, "GetInfo", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Bin Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemGetInfo(bin_sem_id, &bin_sem_prop); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_BinSemDelete(bin_sem_id); + } + +UT_os_bin_sem_get_info_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_BinSemGetInfo", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_oscore_binsem_test.c +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_binsem_test.h b/src/unit-tests/oscore-test/ut_oscore_binsem_test.h new file mode 100644 index 000000000..2368f0fa7 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_binsem_test.h @@ -0,0 +1,51 @@ +/*================================================================================* +** File: ut_oscore_binsem_test.h +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSCORE_BINSEM_TEST_H_ +#define _UT_OSCORE_BINSEM_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_bin_sem_create_test(void); +void UT_os_bin_sem_delete_test(void); +void UT_os_bin_sem_flush_test(void); +void UT_os_bin_sem_give_test(void); +void UT_os_bin_sem_timed_wait_test(void); +void UT_os_bin_sem_take_test(void); +void UT_os_bin_sem_get_id_by_name_test(void); +void UT_os_bin_sem_get_info_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSCORE_BINSEM_TEST_H_ */ + +/*================================================================================* +** End of File: ut_oscore_binsem_test.h +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_countsem_test.c b/src/unit-tests/oscore-test/ut_oscore_countsem_test.c new file mode 100644 index 000000000..71aa94672 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_countsem_test.c @@ -0,0 +1,754 @@ +/*================================================================================* +** File: ut_oscore_countsem_test.c +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_oscore_countsem_test.h" +#include "ut_oscore_test_platforms.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: OS_CountSemCreate +** Purpose: Creates a counting semaphore +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_TAKEN if the name passed in has already been used +** OS_ERR_NO_FREE_IDS if there are no more free counting semaphore ids +** OS_SEM_FAILURE if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_count_sem_create_test() +{ + int i; + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 count_sem_ids[OS_MAX_COUNT_SEMAPHORES+1]; + char sem_name[OS_MAX_API_NAME]; + char long_sem_name[OS_MAX_API_NAME+5]; + uint32 test_setup_invalid = 0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_CountSemCreate(&count_sem_ids[0], "Good", 1, 0 ); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_count_sem_create_test_exit_tag; + } + + /* Clean up */ + res = OS_CountSemDelete(count_sem_ids[0]); + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg-1"; + + res = OS_CountSemCreate(NULL, "CountSem1", 1, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Null-pointer-arg-2"; + + res = OS_CountSemCreate(&count_sem_ids[0], NULL, 1, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-too-long"; + + memset(long_sem_name, 'X', sizeof(long_sem_name)); + long_sem_name[sizeof(long_sem_name)-1] = '\0'; + res = OS_CountSemCreate(&count_sem_ids[0], long_sem_name, 1, 0); + if (res == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Initial-count-too-high"; + + res = OS_CountSemCreate(&count_sem_ids[0], "CountSem1", SEM_VALUE_MAX + 1, 0); + if (res == OS_INVALID_SEM_VALUE) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 No-free-IDs"; + + /* Setup */ + for ( i = 0; i< OS_MAX_COUNT_SEMAPHORES; i++ ) + { + memset(sem_name, '\0', sizeof(sem_name)); + UT_os_sprintf(sem_name, "COUNTSEM%d", i); + res = OS_CountSemCreate(&count_sem_ids[i], sem_name, 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 No-free-IDs - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + test_setup_invalid = 1; + break; + } + } + + if ( test_setup_invalid == 0 ) + { + res = OS_CountSemCreate(&count_sem_ids[OS_MAX_COUNT_SEMAPHORES], "OneTooMany", 1, 0); + if (res == OS_ERR_NO_FREE_IDS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /* Reset test environment */ + for ( i = 0; i< OS_MAX_COUNT_SEMAPHORES; i++ ) + { + res = OS_CountSemDelete(count_sem_ids[i]); /* Ignore errors, does not matter here */ + } + + /*-----------------------------------------------------*/ + testDesc = "#6 Duplicate-name"; + + /* Setup */ + res = OS_CountSemCreate(&count_sem_ids[0], "DUPLICATE", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#6 Duplicate-name - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + } + else + { + res = OS_CountSemCreate(&count_sem_ids[1], "DUPLICATE", 1, 0); + if (res == OS_ERR_NAME_TAKEN) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_CountSemDelete(count_sem_ids[0]); + res = OS_CountSemDelete(count_sem_ids[1]); + } + + /*-----------------------------------------------------*/ + testDesc = "#7 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#8 Nominal"; + + res = OS_CountSemCreate(&count_sem_ids[0], "Good", 1, 0); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_CountSemDelete(count_sem_ids[0]); + +UT_os_count_sem_create_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_CountSemCreate", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_CountSemDelete +** Purpose: Deletes a counting semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid counting semaphore id +** OS_SEM_FAILURE if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_count_sem_delete_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 count_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_CountSemDelete(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_count_sem_delete_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_CountSemDelete(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_CountSemCreate(&count_sem_id, "DeleteTest", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_CountSemDelete(count_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + +UT_os_count_sem_delete_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_CountSemDelete", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_CountSemGive +** Purpose: Gives back a counting semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid counting semaphore id +** OS_SEM_FAILURE if the semaphore was not previously init'd or is not in the +** array of semaphores defined by the system +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_count_sem_give_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 count_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_CountSemGive(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_count_sem_give_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_CountSemGive(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_CountSemCreate(&count_sem_id, "GiveTest", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_CountSemGive(count_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_CountSemDelete(count_sem_id); + } + +UT_os_count_sem_give_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_CountSemGive", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_CountSemTake +** Purpose: Reserves a counting semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid counting semaphore id +** OS_SEM_FAILURE if the semaphore was not previously init'd +** OS_SEM_FAILURE if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_count_sem_take_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 count_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_CountSemTake(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_count_sem_take_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_CountSemTake(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_CountSemCreate(&count_sem_id, "TakeTest", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_CountSemTake(count_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + res = OS_CountSemDelete(count_sem_id); + } + +UT_os_count_sem_take_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_CountSemTake", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_CountSemTimedWait +** Purpose: Reserves a counting semaphore with a timeout +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid counting semaphore id +** OS_SEM_FAILURE if the OS call failed +** OS_SEM_TIMEOUT if the semaphore was not relinquished in time +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_count_sem_timed_wait_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 count_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_CountSemTimedWait(0,1000); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_count_sem_timed_wait_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_CountSemTimedWait(99999, 1000); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Sem-take-timed-out"; + + /* Setup */ + res = OS_CountSemCreate(&count_sem_id, "TimedWait", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Sem-take-timed-out - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_CountSemTake(count_sem_id); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Sem-take-timed-out - Count Sem Take failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_CountSemTimedWait(count_sem_id, 1000); + if ( res == OS_SEM_TIMEOUT ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + res = OS_CountSemDelete(count_sem_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + /* Setup */ + res = OS_CountSemCreate(&count_sem_id, "TimedWait", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#4 Nominal - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_CountSemTimedWait(count_sem_id, 1000); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_CountSemDelete(count_sem_id); + } + +UT_os_count_sem_timed_wait_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_CountSemTimedWait", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_CountSemGetIdByName +** Purpose: Returns the id of a given counting semaphore name +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_NOT_FOUND if the name passed in was not found in the counting +** semaphore table +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_count_sem_get_id_by_name_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 count_sem_id; + char long_sem_name[OS_MAX_API_NAME+5]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_CountSemGetIdByName(0, "InvalidName"); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_count_sem_get_id_by_name_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-pointer-arg-1"; + + res = OS_CountSemGetIdByName(NULL, "InvalidName"); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg-2"; + + res = OS_CountSemGetIdByName(&count_sem_id, NULL); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-too-long"; + + memset(long_sem_name, 'Y', sizeof(long_sem_name)); + long_sem_name[sizeof(long_sem_name)-1] = '\0'; + res = OS_CountSemGetIdByName(&count_sem_id, long_sem_name); + if ( res == OS_ERR_NAME_TOO_LONG ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-not-found"; + + res = OS_CountSemGetIdByName(&count_sem_id, "NameNotFound"); + if ( res == OS_ERR_NAME_NOT_FOUND ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + /* Setup */ + res = OS_CountSemCreate(&count_sem_id, "GetIDByName", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 Nominal - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_CountSemGetIdByName(&count_sem_id, "GetIDByName"); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_CountSemDelete(count_sem_id); + } + +UT_os_count_sem_get_id_by_name_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_CountSemGetIdByName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_CountSemGetInfo +** Purpose: Returns semaphore information about the given binary semaphore id +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore id +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_count_sem_get_info_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 count_sem_id; + OS_count_sem_prop_t count_sem_prop; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_CountSemGetInfo(0,&count_sem_prop); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_count_sem_get_info_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_CountSemGetInfo(99999, &count_sem_prop); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg"; + + /* Setup */ + res = OS_CountSemCreate(&count_sem_id, "GetInfo", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#2 Invalid-pointer-arg - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_CountSemGetInfo(count_sem_id, NULL); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_CountSemDelete(count_sem_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_CountSemCreate(&count_sem_id, "GetInfo", 1, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Count Sem Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_CountSemGetInfo(count_sem_id, &count_sem_prop); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_CountSemDelete(count_sem_id); + } + +UT_os_count_sem_get_info_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_CountSemGetInfo", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_oscore_countsem_test.c +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_countsem_test.h b/src/unit-tests/oscore-test/ut_oscore_countsem_test.h new file mode 100644 index 000000000..23671074c --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_countsem_test.h @@ -0,0 +1,50 @@ +/*================================================================================* +** File: ut_oscore_countsem_test.h +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSCORE_COUNTSEM_TEST_H_ +#define _UT_OSCORE_COUNTSEM_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_count_sem_create_test(void); +void UT_os_count_sem_delete_test(void); +void UT_os_count_sem_give_test(void); +void UT_os_count_sem_timed_wait_test(void); +void UT_os_count_sem_take_test(void); +void UT_os_count_sem_get_id_by_name_test(void); +void UT_os_count_sem_get_info_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSCORE_COUNTSEM_TEST_H_ */ + +/*================================================================================* +** End of File: ut_oscore_countsem_test.h +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_misc_test.c b/src/unit-tests/oscore-test/ut_oscore_misc_test.c new file mode 100644 index 000000000..c92abac21 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_misc_test.c @@ -0,0 +1,725 @@ +/*================================================================================* +** File: ut_oscore_misc_test.c +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_oscore_misc_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_API_Init(void) +** Purpose: Initializes the tables that the OS API uses to keep track of information +** about objects +** Parameters: None +** Returns: OS_ERROR on an unsuccessful inits +** OS_SUCCESS on a successful inits +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Init-not-call-first condition +** 1) Don't call this routine first +** 2) Call OS_QueueCreate, OS_BinSemCreate, OS_CountSemCreate, OS_MutSemCreate +** 3) Expect the returned value from those routines to be +** (a) __not__ OS_SUCCESS +*** ----------------------------------------------------- +** Test #2: Nominal condition +** 1) Call this routine +** 2) Expect the returned value to be +** (a) OS_SUCCESS (although results are not directly observable) +** 3) Call OS_QueueCreate, OS_BinSemCreate, OS_CountSemCreate, OS_MutSemCreate +** 4) Expect the returned value from those routines to be +** (a) OS_SUCCESS +*--------------------------------------------------------------------------------*/ +void UT_os_apiinit_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 qId = 0, qDepth = 10, qSize = 4, qFlags = 0; + uint32 semIds[3], semInitValue = 1, semOptions = 0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "#1 Init-not-call-first"; + + if ((OS_QueueCreate(&qId, "Queue A", qDepth, qSize, qFlags) != OS_SUCCESS) && + (OS_BinSemCreate(&semIds[0], "BinSem 1", semInitValue, semOptions) != OS_SUCCESS) && + (OS_CountSemCreate(&semIds[1], "CountSem 1", semInitValue, semOptions) != OS_SUCCESS) && + (OS_MutSemCreate(&semIds[2], "MutexSem 1", semOptions) != OS_SUCCESS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_QueueDelete(qId); + OS_BinSemDelete(semIds[0]); + OS_CountSemDelete(semIds[1]); + OS_MutSemDelete(semIds[2]); + + /*-----------------------------------------------------*/ + testDesc = "#2 Nominal"; + + res = OS_API_Init(); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + testDesc = "API not implemented"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_apiinit_test_exit_tag; + } + else if ((res == OS_SUCCESS) && + (OS_QueueCreate(&qId, "Queue A", qDepth, qSize, qFlags) == OS_SUCCESS) && + (OS_BinSemCreate(&semIds[0], "BinSem 1", semInitValue, semOptions) == OS_SUCCESS) && + (OS_CountSemCreate(&semIds[1], "CountSem 1", semInitValue, semOptions) == OS_SUCCESS) && + (OS_MutSemCreate(&semIds[2], "MutexSem 1", semOptions) == OS_SUCCESS)) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /* Reset test environment */ + OS_QueueDelete(qId); + OS_BinSemDelete(semIds[0]); + OS_CountSemDelete(semIds[1]); + OS_MutSemDelete(semIds[2]); + +UT_os_apiinit_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_API_Init", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: void OS_printf(const char String, ...) +** Purpose: Provides a printing utility similar to printf +** Parameters: String - text portion of the print +** ellipsis - the other parameters to print +** Returns: Nothing +** ----------------------------------------------------- +** Test #1: Nominal condition +** 1) Call OS_printf_enable +** 2) Call this routine to print a text string. +** 3) Visually observe that the text string in #2 did get print. +**--------------------------------------------------------------------------------*/ +void UT_os_printf_test() +{ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + OS_printf_enable(); + UT_OS_LOG_MACRO("OS_printf() - #1 Nominal [This is the expected output after API call]\n") + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, "#1 Nominal - Manual inspection required", UT_OS_MIR) + + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_printf", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: void OS_printf_enable(void) +** Purpose: Enables the UART or console output of OS_printf +** Parameters: None +** Returns: Nothing +** Test #1: Nominal condition +** 1) Call OS_printf_disable +** 2) Call OS_printf to print a text string. +** 3) Call this routine +** 4) Call OS_printf to print a text string that's different than #2 +** 5) Visually observe that text string in #2 did not print, but text string in #4 did. +**--------------------------------------------------------------------------------*/ +void UT_os_printfenable_test() +{ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + OS_printf_disable(); + + OS_printf_enable(); + UT_OS_LOG_MACRO("OS_printf_enable() - #1 Nominal [This is the expected output after API call]\n") + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, "#1 Nominal - Manual inspection required", UT_OS_MIR) + + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_printf_enable", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: void OS_printf_disable(void) +** Purpose: Disables the UART or console output of OS_printf +** Parameters: None +** Returns: Nothing +** Test #1: Nominal condition +** 1) Call OS_printf_enable +** 2) Call OS_printf() to print a text string. +** 3) Call this routine +** 4) Call OS_printf() to print a text string that's different than #2 +** 5) Visually observe that text string in #2 did get print, but text string in #4 did not. +**--------------------------------------------------------------------------------*/ +void UT_os_printfdisable_test() +{ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + OS_printf_enable(); + UT_OS_LOG_MACRO("OS_printf_disable() - #1 Nominal [This is the expected output before API call]\n") + + OS_printf_disable(); + UT_OS_LOG_MACRO("OS_printf_disable() - #1 Nominal [This is NOT the expected output after API call]\n") + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, "#1 Nominal - Manual inspection required", UT_OS_MIR) + + /* Reset test environment */ + OS_printf_enable(); + UT_OS_LOG_MACRO("OS_printf_disable() - #1 Nominal [This is the expected output after test reset]\n") + + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_printf_disable", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_Tick2Micros(void) +** Purpose: Returns the number of microseconds per OS tick +** Parameters: None +** Returns: Microseconds per OS tick +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Nominal condition +** 1) Call this routine +** 2) Expect the returned value to be +** (a) a value greater than or equal to 0 +**--------------------------------------------------------------------------------*/ +void UT_os_tick2micros_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_Tick2Micros(); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_tick2micros_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Nominal"; + + res = OS_Tick2Micros(); + if (res >= 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_tick2micros_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_Tick2Micros", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_Milli2Ticks(uint32 milli_seconds) +** Purpose: Returns the equivalent number of system clock ticks for the given period +** of time in milliseconds +** Parameters: milli_seconds - the number of milliseconds to convert to ticks +** Returns: Number of ticks in the given period of milliseconds +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Zero-value-argument condition +** 1) Call this routine with a zero argument +** 2) Expect the returned value to be +** (a) exactly 0 +** ----------------------------------------------------- +** Test #2: Nominal condition +** 1) Call this routine with a non-zero argument, T, in milli_seconds +** 2) Expect the returned value to be +** (a) a value greater than or equal to 0 +**--------------------------------------------------------------------------------*/ +void UT_os_milli2ticks_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + uint32 timeInMillisecs = 0; + const char* testDesc = NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_Milli2Ticks(timeInMillisecs); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_milli2ticks_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 zero-value-arg"; + + timeInMillisecs = 0; + res = OS_Milli2Ticks(timeInMillisecs); + if (res == 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Nominal"; + + timeInMillisecs = 100; + res = OS_Milli2Ticks(timeInMillisecs); + if (res >= 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_milli2ticks_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_Milli2Ticks", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_GetLocalTime(OS_time_t *time_struct) +** Purpose: Returns the local time of the machine it is on +** Parameters: *time_struct - a pointer to an OS_time_t structure that will hold +** the current time in seconds and milliseconds +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-argument condition +** 1) Call this routine with a null-pointer argument +** 2) Expect the returned value to be +** (a) OS_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: OS-call-failure condition +** 1) Setup test to cause the OS call to fail inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_ERROR +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call this routine with valid argument +** 2) Expect the returned value to be +** (a) OS_SUCCESS (although results are not directly observable) +**--------------------------------------------------------------------------------*/ +void UT_os_getlocaltime_test() +{ + OS_time_t time_struct; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + char text[UT_OS_LG_TEXT_LEN]; + int32 res = 0, idx = 0, i = 0, j = 0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_GetLocalTime(NULL); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_getlocaltime_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + res = OS_GetLocalTime(NULL); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + res = OS_GetLocalTime(&time_struct); + if (res == OS_SUCCESS) + { + UT_OS_LOG_MACRO("\n") + for (i=0; i < 5; i++) + { + UT_OS_LOG_MACRO("OS_GetLocalTime() - #3 Nominal ") + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "[Expecting output after API call to increase over time: %d.%d]\n", + time_struct.seconds, time_struct.microsecs); + UT_OS_LOG_MACRO(text) + + for (j=0; j < 10000; j++) { } + + OS_GetLocalTime(&time_struct); + } + + testDesc = "#3 Nominal - Manual inspection required"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_MIR) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + +UT_os_getlocaltime_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_GetLocalTime", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_SetLocalTime(OS_time_t *time_struct) +** Purpose: Allows user to set the local time of the machine it is on +** Parameters: *time_struct - a pointer to an OS_time_t structure that holds the +** target time in seconds and milliseconds +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-argument condition +** 1) Call this routine with a null-pointer argument +** 2) Expect the returned value to be +** (a) OS_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: OS-call-failure condition +** 1) Setup the test to cause the OS call to fail inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_ERROR +** ----------------------------------------------------- +** Test #3: Nominal condition +** - Call this routine with valid argument +** - Expect the returned value to be +** (a) OS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_setlocaltime_test() +{ + OS_time_t time_struct; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + char text[UT_OS_LG_TEXT_LEN]; + int32 res = 0, idx = 0, i = 0, j = 0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_SetLocalTime(NULL); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_setlocaltime_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + res = OS_GetLocalTime(NULL); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + res = OS_GetLocalTime(&time_struct); + if (res == OS_SUCCESS) + { + UT_os_printf("\n"); + for (i=0; i < 5; i++) + { + UT_OS_LOG_MACRO("OS_SetLocalTime() - #3 Nominal ") + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "[Expecting output before API call to increase over time: %d.%d]\n", + time_struct.seconds, time_struct.microsecs); + UT_OS_LOG_MACRO(text) + + for (j=0; j < 10000; j++) { } + + OS_GetLocalTime(&time_struct); + } + } + + memset(&time_struct, 0x00, sizeof(time_struct)); + time_struct.seconds = 20000; + time_struct.microsecs = 123; + + res = OS_SetLocalTime(&time_struct); + if (res == OS_SUCCESS) + { + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "OS_SetLocalTime() - #3 Nominal [New time set at %d.%d]\n", + time_struct.seconds, time_struct.microsecs); + UT_OS_LOG_MACRO(text) + + res = OS_GetLocalTime(&time_struct); + if (res == OS_SUCCESS) + { + UT_os_printf("\n"); + for (i=0; i < 5; i++) + { + UT_OS_LOG_MACRO("OS_SetLocalTime() - #3 Nominal ") + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "[Expecting output after API call to increase over time: %d.%d]\n", + time_struct.seconds, time_struct.microsecs); + UT_OS_LOG_MACRO(text) + + for (j=0; j < 10000; j++) { } + + OS_GetLocalTime(&time_struct); + } + } + + testDesc = "#3 Nominal - Manual inspection required"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_MIR) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + +UT_os_setlocaltime_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_SetLocalTime", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: void OS_GetErrorName(int32 error_num, os_err_name_t * err_name) +** Purpose: Returns the string name of the error value +** Parameters: error_num - an error value +** *err_name - pointer to hold the returned string name +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-argument condition +** 1) Call this routine with a null-pointer argument +** 2) Expect the returned value to be +** (a) OS_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Nominal condition +** - Call this routine with valid argument +** - Expect the returned value to be +** (a) OS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_geterrorname_test(void) +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + os_err_name_t errNames[4]; + const char* testDesc = NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_GetErrorName(OS_SUCCESS, &errNames[0]); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_geterrorname_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + res = OS_GetErrorName(OS_ERROR, NULL); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Nominal"; + + if ((OS_GetErrorName(OS_ERR_NAME_TOO_LONG, &errNames[0]) == OS_SUCCESS) && + (strcmp(errNames[0], "OS_ERR_NAME_TOO_LONG") == 0) && + (OS_GetErrorName(OS_ERR_NAME_TAKEN, &errNames[1]) == OS_SUCCESS) && + (strcmp(errNames[1], "OS_ERR_NAME_TAKEN") == 0) && + (OS_GetErrorName(OS_ERR_NO_FREE_IDS, &errNames[2]) == OS_SUCCESS) && + (strcmp(errNames[2], "OS_ERR_NO_FREE_IDS") == 0) && + (OS_GetErrorName(12345, &errNames[3]) == OS_ERROR) && + (strcmp(errNames[3], "ERROR_UNKNOWN") == 0)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_geterrorname_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_GetErrorName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_oscore_misc_test.c +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_misc_test.h b/src/unit-tests/oscore-test/ut_oscore_misc_test.h new file mode 100644 index 000000000..80f1bda7c --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_misc_test.h @@ -0,0 +1,56 @@ +/*================================================================================* +** File: ut_oscore_misc_test.h +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSCORE_MISC_TEST_H_ +#define _UT_OSCORE_MISC_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_apiinit_test(void); + +void UT_os_printf_test(void); +void UT_os_printfenable_test(void); +void UT_os_printfdisable_test(void); + +void UT_os_tick2micros_test(void); +void UT_os_milli2ticks_test(void); + +void UT_os_getlocaltime_test(void); +void UT_os_setlocaltime_test(void); + +void UT_os_geterrorname_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSCORE_MISC_TEST_H_ */ + +/*================================================================================* +** End of File: ut_oscore_misc_test.h +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_mutex_test.c b/src/unit-tests/oscore-test/ut_oscore_mutex_test.c new file mode 100644 index 000000000..303b1e815 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_mutex_test.c @@ -0,0 +1,656 @@ +/*================================================================================* +** File: ut_oscore_mutex_test.c +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_oscore_mutex_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: OS_MutSemCreate +** Purpose: Creates a mutex semaphore +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_TAKEN if the name passed in has already been used +** OS_ERR_NO_FREE_IDS if there are no more free mutex ids +** OS_SEM_FAILURE if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_mut_sem_create_test() +{ + int i; + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 mut_sem_id; + uint32 mut_sem_id2; + char sem_name[OS_MAX_API_NAME]; + char long_sem_name[OS_MAX_API_NAME+5]; + uint32 test_setup_invalid = 0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_MutSemCreate(&mut_sem_id, "Good", 0 ); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_mut_sem_create_test_exit_tag; + } + + /* Clean up */ + res = OS_MutSemDelete(mut_sem_id); + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg-1"; + + res = OS_MutSemCreate(NULL, "MutSem1", 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Null-pointer-arg-2"; + + res = OS_MutSemCreate(&mut_sem_id, NULL, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-too-long"; + + memset(long_sem_name, 'X', sizeof(long_sem_name)); + long_sem_name[sizeof(long_sem_name)-1] = '\0'; + res = OS_MutSemCreate(&mut_sem_id, long_sem_name, 0); + if (res == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 No-free-IDs"; + + /* Setup */ + for ( i = 0; i< OS_MAX_MUTEXES; i++ ) + { + memset(sem_name, '\0', sizeof(sem_name)); + UT_os_sprintf(sem_name, "MUTSEM%d",i); + res = OS_MutSemCreate(&mut_sem_id, sem_name, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#4 No-free-IDs - Mutex Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + test_setup_invalid = 1; + break; + } + } + + if ( test_setup_invalid == 0 ) + { + res = OS_MutSemCreate(&mut_sem_id, "OneTooMany", 0); + if (res == OS_ERR_NO_FREE_IDS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /* Reset test environment */ + for ( i = 0; i< OS_MAX_MUTEXES; i++ ) + { + res = OS_MutSemDelete(i); /* Ignore errors, does not matter here */ + } + + /*-----------------------------------------------------*/ + testDesc = "#5 Duplicate-name"; + + /* Setup */ + res = OS_MutSemCreate(&mut_sem_id2, "DUPLICATE", 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 Duplicate-name - Mutex Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_MutSemCreate(&mut_sem_id, "DUPLICATE", 0); + if (res == OS_ERR_NAME_TAKEN) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_MutSemDelete(mut_sem_id2); + } + + /*-----------------------------------------------------*/ + testDesc = "#6 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#7 Nominal"; + + res = OS_MutSemCreate(&mut_sem_id, "Good", 0); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_MutSemDelete(mut_sem_id); + +UT_os_mut_sem_create_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_MutSemCreate", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_MutSemDelete +** Purpose: Deletes a mutex semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid mutex id +** OS_ERR_SEM_NOT_FULL if the mutex is empty +** OS_SEM_FAILURE if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_mut_sem_delete_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 mut_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_MutSemDelete(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_mut_sem_delete_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_MutSemDelete(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_MutSemCreate(&mut_sem_id, "DeleteTest", 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Mutex Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_MutSemDelete(mut_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + +UT_os_mut_sem_delete_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_MutSemDelete", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_MutSemGive +** Purpose: Releases a mutex semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid mutex id +** OS_SEM_FAILURE if the mutex was not previously init'd or is not in the +** array of semaphores defined by the system +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_mut_sem_give_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 mut_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_MutSemGive(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_mut_sem_give_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_MutSemGive(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_MutSemCreate(&mut_sem_id, "GiveTest", 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Mutex Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_MutSemTake(mut_sem_id); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Mutex Take failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_MutSemGive(mut_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_MutSemDelete(mut_sem_id); + } + } + +UT_os_mut_sem_give_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_MutSemGive", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_MutSemTake +** Purpose: Allocates a mutex semaphore +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid mutex id +** OS_SEM_FAILURE if the mutex was not previously init'd or is not in the +** array of semaphores defined by the system +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_mut_sem_take_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 mut_sem_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_MutSemTake(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_mut_sem_take_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_MutSemTake(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_MutSemCreate(&mut_sem_id, "TakeTest", 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Mutex Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_MutSemTake(mut_sem_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_MutSemGive(mut_sem_id); + res = OS_MutSemDelete(mut_sem_id); + } + +UT_os_mut_sem_take_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_MutSemTake", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_MutSemGetIdByName +** Purpose: Returns the id of a given mutex semaphore name +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_NOT_FOUND if the name was not found in the mutex semaphore table +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_mut_sem_get_id_by_name_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 mut_sem_id; + char long_sem_name[OS_MAX_API_NAME+5]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_MutSemGetIdByName(0,"InvalidName"); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_mut_sem_get_id_by_name_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-pointer-arg-1"; + + res = OS_MutSemGetIdByName(NULL, "InvalidName"); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg-2"; + + res = OS_MutSemGetIdByName(&mut_sem_id, NULL); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-too-long"; + + memset(long_sem_name, 'Y', sizeof(long_sem_name)); + long_sem_name[sizeof(long_sem_name)-1] = '\0'; + res = OS_MutSemGetIdByName(&mut_sem_id, long_sem_name); + if ( res == OS_ERR_NAME_TOO_LONG ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-not-found"; + + res = OS_MutSemGetIdByName(&mut_sem_id, "NameNotFound"); + if ( res == OS_ERR_NAME_NOT_FOUND ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + /* Setup */ + res = OS_MutSemCreate(&mut_sem_id, "GetIDByName", 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 Nominal - Mutex Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_MutSemGetIdByName(&mut_sem_id, "GetIDByName"); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_MutSemDelete(mut_sem_id); + } + +UT_os_mut_sem_get_id_by_name_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_MutSemGetIdByName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_MutSemGetInfo +** Purpose: Returns mutex semaphore information about a given mutex id +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore id +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_mut_sem_get_info_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 mut_sem_id; + OS_mut_sem_prop_t mut_sem_prop; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_MutSemGetInfo(0, &mut_sem_prop); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_mut_sem_get_info_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_MutSemGetInfo(99999, &mut_sem_prop); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg"; + + res = OS_MutSemCreate(&mut_sem_id, "InvalidPtr", 0); + if (res != OS_SUCCESS) + { + testDesc = "#2 Invalid-pointer-arg - Mutex Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_MutSemGetInfo(mut_sem_id, NULL); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + OS_MutSemDelete(mut_sem_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_MutSemCreate(&mut_sem_id, "GetInfo", 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Mutex Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_MutSemGetInfo(mut_sem_id, &mut_sem_prop); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_MutSemDelete(mut_sem_id); + } + +UT_os_mut_sem_get_info_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_MutSemGetInfo", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_oscore_mutex_test.c +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_mutex_test.h b/src/unit-tests/oscore-test/ut_oscore_mutex_test.h new file mode 100644 index 000000000..f641ee7b4 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_mutex_test.h @@ -0,0 +1,49 @@ +/*================================================================================* +** File: ut_oscore_mutex_test.h +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSCORE_MUTEX_TEST_H_ +#define _UT_OSCORE_MUTEX_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_mut_sem_create_test(void); +void UT_os_mut_sem_delete_test(void); +void UT_os_mut_sem_give_test(void); +void UT_os_mut_sem_take_test(void); +void UT_os_mut_sem_get_id_by_name_test(void); +void UT_os_mut_sem_get_info_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSCORE_MUTEX_TEST_H_ */ + +/*================================================================================* +** End of File: ut_oscore_mutex_test.h +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_queue_test.c b/src/unit-tests/oscore-test/ut_oscore_queue_test.c new file mode 100644 index 000000000..8d8099c9d --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_queue_test.c @@ -0,0 +1,829 @@ +/*================================================================================* +** File: ut_oscore_queue_test.c +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_oscore_queue_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: OS_QueueCreate +** Purpose: Creates a queue in the OS +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_TAKEN if the name has already been used on a created queue +** OS_ERR_NO_FREE_IDS if there are no more free queue ids +** OS_ERROR if the OS create call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_queue_create_test() +{ + int i,j; + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 queue_id; + uint32 queue_id2; + char queue_name[OS_MAX_API_NAME]; + char long_queue_name[OS_MAX_API_NAME+5]; + uint32 test_setup_invalid = 0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_QueueCreate(&queue_id, "Good", 10, 4, 0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_queue_create_test_exit_tag; + } + /* Clean up */ + res = OS_QueueDelete(queue_id); + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg-1"; + + res = OS_QueueCreate(NULL, "Queue1", 10, 4, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Null-pointer-arg-2"; + + res = OS_QueueCreate(&queue_id, NULL, 10, 4, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-too-long"; + + memset(long_queue_name, 'X', sizeof(long_queue_name)); + long_queue_name[sizeof(long_queue_name)-1] = '\0'; + res = OS_QueueCreate(&queue_id, long_queue_name, 10, 4, 0); + if (res == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 No-free-IDs"; + + /* Setup */ + for ( i = 0; i< OS_MAX_QUEUES; i++ ) + { + memset(queue_name, '\0', sizeof(queue_name)); + UT_os_sprintf(queue_name, "QUEUE%d",i); + res = OS_QueueCreate(&queue_id, queue_name, 2, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#4 No-free-IDs - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + test_setup_invalid = 1; + break; + } + } + + if ( test_setup_invalid == 0 ) + { + res = OS_QueueCreate(&queue_id, "OneTooMany", 10, 4, 0); + if (res == OS_ERR_NO_FREE_IDS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /* Reset test environment */ + for ( i = 0; i< OS_MAX_QUEUES; i++ ) + { + res = OS_QueueDelete(i); /* Ignore errors, does not matter here */ + } + + /*-----------------------------------------------------*/ + testDesc = "#5 Duplicate-name"; + + /* Setup */ + res = OS_QueueCreate(&queue_id2, "DUPLICATE", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, "Queue Create failed", UT_OS_TSF) + } + else + { + res = OS_QueueCreate(&queue_id, "DUPLICATE", 10, 4, 0); + if (res == OS_ERR_NAME_TAKEN) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_QueueDelete(queue_id2); + } + + /*-----------------------------------------------------*/ + testDesc = "#6 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#7 Nominal"; + + res = OS_QueueCreate(&queue_id, "Good", 10, 4, 0); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_QueueDelete(queue_id); + +UT_os_queue_create_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_QueueCreate", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_QueueDelete +** Purpose: Deletes a queue in the OS +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in does not exist +** OS_ERROR if the OS call to delete the queue failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_queue_delete_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 queue_id; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_QueueDelete(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_queue_delete_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_QueueDelete(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "DeleteTest", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueDelete(queue_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + +UT_os_queue_delete_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_QueueDelete", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_QueueGet +** Purpose: Retrieves a data item from an existing queue +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_INVALID_ID if the id passed in does not exist +** OS_QUEUE_EMPTY if the queue has no message on it to be received +** OS_QUEUE_TIMEOUT if the timeout was OS_PEND and the time expired +** OS_QUEUE_INVALID_SIZE if the size copied from the queue is incorrect +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_queue_get_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 queue_id; + uint32 queue_data_out; + uint32 queue_data_in; + uint32 size_copied; + uint32 data_size; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_QueueGet(0, (void *)&queue_data_in, 4, &size_copied, OS_CHECK); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_queue_get_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_QueueGet(99999, (void *)&queue_data_in, 4, &size_copied, OS_CHECK); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg-1"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#2 Invalid-pointer-arg-1 - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueGet(queue_id, NULL, 4, &size_copied, OS_CHECK); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_QueueDelete(queue_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#3 Invalid-pointer-arg-2"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Invalid-pointer-arg-2 - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, NULL, OS_CHECK); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_QueueDelete(queue_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#4 Queue-empty"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "QueueEmpty", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#4 Queue-empty - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, &data_size, OS_CHECK); + if ( res == OS_QUEUE_EMPTY ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_QueueDelete(queue_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#5 Queue-timed-out"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "QueueTimeout", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 Queue-timed-out - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, &data_size, 2); + if ( res == OS_QUEUE_TIMEOUT ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_QueueDelete(queue_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#6 Invalid-queue-size"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "QueuePut", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#6 Invalid-queue-size - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + queue_data_out = 0x11223344; + res = OS_QueuePut(queue_id, (void *)&queue_data_out, 2, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#6 Invalid-queue-size - Queue Put failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueGet(queue_id, (void *)&queue_data_in, 3, &data_size, OS_CHECK); + if ( res == OS_QUEUE_INVALID_SIZE ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + res = OS_QueueDelete(queue_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#7 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#8 Nominal"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#8 Nominal - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + queue_data_out = 0x11223344; + res = OS_QueuePut(queue_id, (void *)&queue_data_out, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#8 Nominal - Queue Put failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueGet(queue_id, (void *)&queue_data_in, 4, &data_size, OS_PEND); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + res = OS_QueueDelete(queue_id); + } + +UT_os_queue_get_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_QueueGet", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_QueuePut +** Purpose: Sends data on an existing queue +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_INVALID_ID if the id passed in does not exist +** OS_QUEUE_FULL if the queue could not accept another message +** OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_queue_put_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 queue_id; + uint32 queue_data_out; + int i; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_QueuePut(0, (void *)&queue_data_out, 4, 0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_queue_put_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_QueuePut(99999, (void *)&queue_data_out, 4, 0); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "QueuePut", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#2 Invalid-pointer-arg - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueuePut(queue_id, NULL, 4, 0); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + res = OS_QueueDelete(queue_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Queue-full"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "QueuePut", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#4 Queue-full - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + queue_data_out = 0x11223344; + for ( i = 0; i < 100; i++ ) + { + res = OS_QueuePut(queue_id, (void *)&queue_data_out, 4, 0); + if ( res == OS_QUEUE_FULL ) + break; + } + + if ( res == OS_QUEUE_FULL ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_QueueDelete(queue_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "QueueGet", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 Nominal - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + queue_data_out = 0x11223344; + res = OS_QueuePut(queue_id, (void *)&queue_data_out, 4, 0); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + res = OS_QueueDelete(queue_id); + } + +UT_os_queue_put_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_QueuePut", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_QueueGetIdByName +** Purpose: Returns the queue id of a given queue name +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the name of id pointers are null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_NOT_FOUND if the name was not found in the queue table +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_queue_get_id_by_name_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 queue_id; + char long_queue_name[OS_MAX_API_NAME+5]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_QueueGetIdByName(0, "InvalidName"); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_queue_get_id_by_name_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-pointer-arg-1"; + + res = OS_QueueGetIdByName(NULL, "InvalidName"); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg-2"; + + res = OS_QueueGetIdByName(&queue_id, NULL); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-too-long"; + + memset(long_queue_name, 'Y', sizeof(long_queue_name)); + long_queue_name[sizeof(long_queue_name)-1] = '\0'; + res = OS_QueueGetIdByName(&queue_id, long_queue_name); + if ( res == OS_ERR_NAME_TOO_LONG ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-not-found"; + + res = OS_QueueGetIdByName(&queue_id, "NameNotFound"); + if ( res == OS_ERR_NAME_NOT_FOUND ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "GetIDByName", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 Nominal - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueGetIdByName(&queue_id, "GetIDByName"); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_QueueDelete(queue_id); + } + +UT_os_queue_get_id_by_name_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_QueueGetIdByName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_QueueGetInfo +** Purpose: Returns queue information about the given queue id +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_INVALID_ID if the id passed in does not exist +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_queue_get_info_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 queue_id; + OS_queue_prop_t queue_prop; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_QueueGetInfo(0,&queue_prop); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_queue_get_info_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_QueueGetInfo(99999, &queue_prop); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "GetInfo", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#2 Invalid-pointer-arg - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueGetInfo(queue_id, NULL); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_QueueDelete(queue_id); + } + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_QueueCreate(&queue_id, "GetInfo", 10, 4, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Queue Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_QueueGetInfo(queue_id, &queue_prop); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_QueueDelete(queue_id); + } + +UT_os_queue_get_info_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_QueueGetInfo", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_oscore_queue_test.c +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_queue_test.h b/src/unit-tests/oscore-test/ut_oscore_queue_test.h new file mode 100644 index 000000000..29de42389 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_queue_test.h @@ -0,0 +1,49 @@ +/*================================================================================* +** File: ut_oscore_queue_test.h +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSCORE_QUEUE_TEST_H_ +#define _UT_OSCORE_QUEUE_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_queue_create_test(void); +void UT_os_queue_delete_test(void); +void UT_os_queue_put_test(void); +void UT_os_queue_get_test(void); +void UT_os_queue_get_id_by_name_test(void); +void UT_os_queue_get_info_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSCORE_QUEUE_TEST_H_ */ + +/*================================================================================* +** End of File: ut_oscore_queue_test.h +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.c b/src/unit-tests/oscore-test/ut_oscore_task_test.c new file mode 100644 index 000000000..600de7593 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.c @@ -0,0 +1,1178 @@ +/*================================================================================* +** File: ut_oscore_task_test.c +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_oscore_task_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_TASK_STACK_SIZE 0x2000 +#define UT_TASK_PRIORITY 111 + +/* This is not global in the OSAL */ +#define MAX_PRIORITY 255 + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +extern int32 g_skipTestCase; +extern char* g_skipTestCaseResult; + +extern char* g_task_names[UT_OS_TASK_LIST_LEN]; +extern char g_long_task_name[OS_MAX_API_NAME+5]; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +uint32 g_task_result = 0; +uint32 g_task_sync_sem = 0; +uint32 g_task_ids[UT_OS_TASK_LIST_LEN]; +uint32 g_task_stacks[UT_OS_TASK_LIST_LEN][UT_TASK_STACK_SIZE]; + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "API not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------*/ + +void generic_test_task(void) +{ + int32 res=0, task_id=0; + OS_task_prop_t task_prop; + char text[UT_OS_MD_TEXT_LEN]; + + OS_TaskRegister(); + + task_id = OS_TaskGetId(); + res = OS_TaskGetInfo(task_id, &task_prop); + + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "Starting GenericTask: %s, id: %d\n", task_prop.name, task_id); + UT_OS_LOG_MACRO(text) + + while (1) + { + OS_TaskDelay(1000); + } +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskCreate +** Purpose: Creates a task +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_INVALID_PRIORITY if the priority passed in is bad +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_TAKEN if the name passed in has already been used +** OS_ERR_NO_FREE_IDS if there no more task can be created +** OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_task_create_test() +{ + UT_OsApiInfo_t apiInfo; + int32 i=0, res=0, idx=0; + const char* testDesc=NULL; + char task_name[UT_OS_SM_TEXT_LEN]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TaskCreate(&g_task_ids[0], g_task_names[0], generic_test_task, g_task_stacks[0], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_task_create_test_exit_tag; + } + + /* Delay to let child task run */ + OS_TaskDelay(200); + + /* Reset test environment */ + res = OS_TaskDelete(g_task_ids[0]); + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg-1"; + + res = OS_TaskCreate(NULL, g_task_names[1], generic_test_task, g_task_stacks[1], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Null-pointer-arg-2"; + + res = OS_TaskCreate(&g_task_ids[2], NULL, generic_test_task, g_task_stacks[2], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Null-pointer-arg-3"; + + res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], NULL, g_task_stacks[3], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-too-long"; + + res = OS_TaskCreate(&g_task_ids[4], g_long_task_name, generic_test_task, g_task_stacks[4], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 Invalid-priority"; + + res = OS_TaskCreate(&g_task_ids[5], g_task_names[5], generic_test_task, g_task_stacks[5], + UT_TASK_STACK_SIZE, MAX_PRIORITY+1, 0); + if (res == OS_ERR_INVALID_PRIORITY) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#6 No-free-IDs"; + + if (g_skipTestCase == 6) + { + testDesc = "#6 No-free-IDs - Test case not applicable on platform"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, g_skipTestCaseResult) + } + else + { + /* Setup */ + for (i=0; i <= OS_MAX_TASKS; i++) + { + memset(task_name, '\0', sizeof(task_name)); + UT_os_sprintf(task_name, "CREATE_TASK%d", (int)i); + res = OS_TaskCreate(&g_task_ids[i], task_name, generic_test_task, g_task_stacks[i], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + break; + } + } + + if ((res == OS_ERR_NO_FREE_IDS) && (i == OS_MAX_TASKS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Delay to let child tasks run */ + OS_TaskDelay(500); + + /* Reset test environment */ + for (i=0; i < OS_MAX_TASKS; i++) + { + res = OS_TaskDelete(g_task_ids[i]); /* Ignore errors, does not matter here */ + } + } + + /*-----------------------------------------------------*/ + testDesc = "#7 Duplicate-name"; + + /* Setup */ + res = OS_TaskCreate(&g_task_ids[7], g_task_names[7], generic_test_task, g_task_stacks[7], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#7 Duplicate-name - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_TaskCreate(&g_task_ids[8], g_task_names[7], generic_test_task, g_task_stacks[8], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res == OS_ERR_NAME_TAKEN) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Delay to let child task run */ + OS_TaskDelay(200); + + /* Reset test environment */ + res = OS_TaskDelete(g_task_ids[7]); + } + + /*-----------------------------------------------------*/ + testDesc = "#8 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#9 Nominal"; + + res = OS_TaskCreate(&g_task_ids[9], g_task_names[9], generic_test_task, g_task_stacks[9], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Delay to let child task run */ + OS_TaskDelay(200); + + /* Reset test environment */ + res = OS_TaskDelete(g_task_ids[9]); + +UT_os_task_create_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskCreate", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskDelete +** Purpose: Deletes a task +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid task id +** OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_task_delete_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TaskDelete(99999); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_task_delete_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_TaskDelete(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, g_task_stacks[3], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#3 Nominal - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + /* Delay to let child task run */ + OS_TaskDelay(200); + + res = OS_TaskDelete(g_task_ids[3]); + if (res == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + +UT_os_task_delete_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskDelete", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskInstallDeleteHandler +** Purpose: Installs a callback function that is called when the task is deleted +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid task id +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void delete_handler_callback(void) +{ + UT_OS_LOG_MACRO("Task delete callback...\n") +} + +/*--------------------------------------------------------------------------------*/ + +void delete_handler_test_task(void) +{ + int32 res=0, task_id=0; + OS_task_prop_t task_prop; + char text[UT_OS_MD_TEXT_LEN]; + + OS_TaskRegister(); + + task_id = OS_TaskGetId(); + res = OS_TaskGetInfo(task_id, &task_prop); + + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "Starting DeleteTest Task: %s, id: %d\n", task_prop.name, task_id); + UT_OS_LOG_MACRO(text) + + g_task_result = OS_TaskInstallDeleteHandler((void *)&delete_handler_callback); + + /* + ** Release the semaphore so the main function can record the results of the test + ** and clean up + */ + res = OS_BinSemGive(g_task_sync_sem); + + for (;;) + { + OS_TaskDelay(1000); + } +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_task_install_delete_handler_test(void) +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TaskInstallDeleteHandler((void *)&delete_handler_callback); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_task_install_delete_handler_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + if (g_skipTestCase == 1) + { + testDesc = "#1 Invalid-ID-arg - Test case not applicable on platform"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, g_skipTestCaseResult) + } + else + { + /* + ** This test works because it is being called from the main task + ** which should not be an official OSAL task + */ + res = OS_TaskInstallDeleteHandler((void *)&delete_handler_callback); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /*-----------------------------------------------------*/ + testDesc = "#2 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&g_task_sync_sem, "TaskSync", 1, 0); + if (res != OS_SUCCESS) + { + testDesc = "#2 Nominal - Bin-Sem-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemTake(g_task_sync_sem); + + res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], delete_handler_test_task, g_task_stacks[2], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#2 Nominal - Task-Create-failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + /* Wait for the task to finish the test */ + res = OS_BinSemTake(g_task_sync_sem); + /* Delay to let child task run */ + OS_TaskDelay(500); + + res = OS_TaskDelete(g_task_ids[2]); + + if (g_task_result == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + res = OS_BinSemDelete(g_task_sync_sem); + } + +UT_os_task_install_delete_handler_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskInstallDeleteHandler", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskExit +** Purpose: Allows a task to delete itself +** Parameters: To-be-filled-in +** Returns: Nothing +**--------------------------------------------------------------------------------*/ +void exit_test_task(void) +{ + int32 res=0, task_id=0; + OS_task_prop_t task_prop; + char text[UT_OS_MD_TEXT_LEN]; + + OS_TaskRegister(); + + task_id = OS_TaskGetId(); + res = OS_TaskGetInfo(task_id, &task_prop); + + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "Starting ExitTest Task: %s, id: %d\n", task_prop.name, task_id); + UT_OS_LOG_MACRO(text) + + /* + ** The parent task will check to see if this task is valid. + ** As long as it has not successfully called OS_TaskExit, it should + ** be valid. + */ + while (1) + { + res = OS_BinSemGive(g_task_sync_sem); + + OS_TaskExit(); + } +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_task_exit_test(void) +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + OS_task_prop_t task_prop; + const char* testDesc = NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "#1 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&g_task_sync_sem, "TaskSync", 1, 0); + if (res != OS_SUCCESS) + { + testDesc = "#1 Nominal - Bin-Sem-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemTake(g_task_sync_sem); + + res = OS_TaskCreate(&g_task_ids[1], g_task_names[1], exit_test_task, g_task_stacks[1], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#1 Nominal - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + /* Wait for the task to finish the test */ + res = OS_BinSemTake(g_task_sync_sem); + /* Delay to let the child task run */ + OS_TaskDelay(500); + + /* + ** The only real way to tell if TaskExit ran is to check to see if the + ** task ID is valid. It should not be valid + */ + res = OS_TaskGetInfo(g_task_ids[1], &task_prop); + if (res == OS_ERR_INVALID_ID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_TaskDelete(g_task_ids[1]); /* Won't hurt if its already deleted */ + } + + res = OS_BinSemDelete(g_task_sync_sem); + } + + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskExit", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskDelay +** Purpose: Suspends a given task for the given period of milliseconds +** Parameters: To-be-filled-in +** Returns: OS_ERROR if sleep failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_task_delay_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TaskDelay(100); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_task_delay_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#2 Nominal"; + + res = OS_TaskDelay(100); + if (res == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_task_delay_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskDelay", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskSetPriority +** Purpose: Sets task priority for the given task id +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid task id +** OS_ERR_INVALID_PRIORITY if the priority passed in is greater than the max allowed +** OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_task_set_priority_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TaskCreate(&g_task_ids[0], g_task_names[0], generic_test_task, g_task_stacks[0], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#0 API not implemented - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_task_set_priority_test_exit_tag; + } + else + { + res = OS_TaskSetPriority(g_task_ids[0], UT_TASK_PRIORITY); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_task_set_priority_test_exit_tag; + } + + /* Delay to let child task run */ + OS_TaskDelay(500); + + /* Clean up */ + res = OS_TaskDelete(g_task_ids[0]); + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_TaskSetPriority(99999, 100); + if (res == OS_ERR_INVALID_ID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-priority"; + + res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], generic_test_task, g_task_stacks[2], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#2 Invalid-priority - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_TaskSetPriority(g_task_ids[2], MAX_PRIORITY+1); + if (res == OS_ERR_INVALID_PRIORITY) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Delay to let child task run */ + OS_TaskDelay(500); + + /* Reset test environment */ + res = OS_TaskDelete(g_task_ids[2]); + } + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + res = OS_TaskCreate(&g_task_ids[4], g_task_names[4], generic_test_task, g_task_stacks[4], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#4 Nominal - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_TaskSetPriority(g_task_ids[4], UT_TASK_PRIORITY-10); + if (res == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Delay to let child task run */ + OS_TaskDelay(500); + + /* Reset test environment */ + res = OS_TaskSetPriority(g_task_ids[4], UT_TASK_PRIORITY); + res = OS_TaskDelete(g_task_ids[4]); + } + +UT_os_task_set_priority_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskSetPriority", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskRegister +** Purpose: Registers the task, performs application- and OS-specific inits +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid task id +** OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void register_test_task(void) +{ + int32 res=0, task_id=0; + OS_task_prop_t task_prop; + char text[UT_OS_MD_TEXT_LEN]; + + g_task_result = OS_TaskRegister(); + + task_id = OS_TaskGetId(); + res = OS_TaskGetInfo(task_id, &task_prop); + + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "Starting RegisterTest Task: %s\n", task_prop.name); + UT_OS_LOG_MACRO(text) + + /* + ** Release the semaphore so the main function can record the results of the test + ** and clean up + */ + res = OS_BinSemGive(g_task_sync_sem); + + for (;;) + { + OS_TaskDelay(1000); + } +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_task_register_test(void) +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TaskRegister(); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_task_register_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + if (g_skipTestCase == 1) + { + testDesc = "#1 Invalid-ID-arg - Test case not applicable on platform"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, g_skipTestCaseResult) + } + else + { + res = OS_TaskRegister(); + if (res == OS_ERR_INVALID_ID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_BinSemCreate(&g_task_sync_sem, "TaskSync", 1, 0); + if (res != OS_SUCCESS) + { + testDesc = "#3 Nominal - Bin-Sem-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_BinSemTake(g_task_sync_sem); + + res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], register_test_task, g_task_stacks[3], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + /* Wait for the task to finish the test */ + res = OS_BinSemTake(g_task_sync_sem); + /* Delay to let child task run */ + OS_TaskDelay(500); + + res = OS_TaskDelete(g_task_ids[3]); + res = OS_BinSemDelete(g_task_sync_sem); + + if (g_task_result == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + } + +UT_os_task_register_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskRegister", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------*/ + +void getid_test_task(void) +{ + int32 res=0, task_id=0; + OS_task_prop_t task_prop; + char text[UT_OS_LG_TEXT_LEN]; + + OS_TaskRegister(); + + task_id = OS_TaskGetId(); + res = OS_TaskGetInfo(task_id, &task_prop); + + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "OS_TaskGetId() - #1 Nominal [This is the returned task Id=%d]\n", + task_id); + UT_OS_LOG_MACRO(text) + + while (1) + { + OS_TaskDelay(1000); + } +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskGetId +** Purpose: Returns the task id for the task that calls this routine +** Parameters: To-be-filled-in +** Returns: Task id of the task that calls this routine +**--------------------------------------------------------------------------------*/ +void UT_os_task_get_id_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + char text[UT_OS_MD_TEXT_LEN]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TaskGetId(); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_task_get_id_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Nominal"; + + /* Setup */ + res = OS_TaskCreate(&g_task_ids[1], g_task_names[1], getid_test_task, g_task_stacks[1], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#1 Nominal - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + OS_TaskDelay(500); + + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "OS_TaskGetId() - #1 Nominal [This is the expected task Id=%d]\n", + g_task_ids[1]); + UT_OS_LOG_MACRO(text) + + res = OS_TaskDelete(g_task_ids[1]); /* Won't hurt if its already deleted */ + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, "#1 Nominal - Manual inspection required", UT_OS_MIR) + } + +UT_os_task_get_id_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskGetId", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskGetIdByName +** Purpose: Returns the task id of the given task name +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_NOT_FOUND if the name passed in is not in the task table +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_task_get_id_by_name_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TaskGetIdByName(0, "InvalidName"); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_task_get_id_by_name_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-pointer-arg-1"; + + res = OS_TaskGetIdByName(NULL, "InvalidName"); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg-2"; + + res = OS_TaskGetIdByName(&g_task_ids[2], NULL); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-too-long"; + + res = OS_TaskGetIdByName(&g_task_ids[3], g_long_task_name); + if (res == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-not-found"; + + res = OS_TaskGetIdByName(&g_task_ids[4], "NameNotFound"); + if ( res == OS_ERR_NAME_NOT_FOUND ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + /* Setup */ + res = OS_TaskCreate(&g_task_ids[5], g_task_names[5], generic_test_task, g_task_stacks[5], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#5 Nominal - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_TaskGetIdByName(&g_task_ids[6], g_task_names[5]); + if ((res == OS_SUCCESS) && (g_task_ids[5] == g_task_ids[6])) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + OS_TaskDelay(500); /* Delay to let task run */ + res = OS_TaskDelete(g_task_ids[5]); + } + +UT_os_task_get_id_by_name_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskGetIdByName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_TaskGetInfo +** Purpose: Returns task information about the given task id +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_INVALID_ID if the id passed in is not a valid task id +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_task_get_info_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + OS_task_prop_t task_prop; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TaskGetInfo(99999, &task_prop); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_task_get_info_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_TaskGetInfo(99999, &task_prop); + if (res == OS_ERR_INVALID_ID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg"; + + /* Setup */ + res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], generic_test_task, g_task_stacks[2], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#2 Invalid-pointer-arg - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_TaskGetInfo(g_task_ids[2], NULL); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Delay to let child task run */ + OS_TaskDelay(500); + + /* Reset test environment */ + res = OS_TaskDelete(g_task_ids[2]); + } + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, g_task_stacks[3], + UT_TASK_STACK_SIZE, UT_TASK_PRIORITY, 0); + if (res != OS_SUCCESS) + { + testDesc = "#3 Nominal - Task-Create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_TaskGetInfo(g_task_ids[3], &task_prop); + if (res == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Delay to let child task run */ + OS_TaskDelay(500); + + /* Reset test environment */ + res = OS_TaskDelete(g_task_ids[3]); + } + +UT_os_task_get_info_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TaskGetInfo", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_oscore_task_test.c +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.h b/src/unit-tests/oscore-test/ut_oscore_task_test.h new file mode 100644 index 000000000..34ba14dab --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.h @@ -0,0 +1,56 @@ +/*================================================================================* +** File: ut_oscore_task_test.h +** Owner: Alan Cudmore +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSCORE_TASK_TEST_H_ +#define _UT_OSCORE_TASK_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_TASK_LIST_LEN (OS_MAX_TASKS + 10) + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_task_create_test(void); +void UT_os_task_delete_test(void); +void UT_os_task_install_delete_handler_test(void); +void UT_os_task_exit_test(void); +void UT_os_task_set_priority_test(void); +void UT_os_task_register_test(void); +void UT_os_task_get_id(void); +void UT_os_task_get_id_by_name_test(void); +void UT_os_task_get_info_test(void); +void UT_os_task_delay_test(void); +void UT_os_task_get_id_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSCORE_TASK_TEST_H_ */ + +/*================================================================================* +** End of File: ut_oscore_task_test.h +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_test.c b/src/unit-tests/oscore-test/ut_oscore_test.c new file mode 100644 index 000000000..58447da05 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_test.c @@ -0,0 +1,275 @@ +/*================================================================================* +** File: ut_oscore_test.c +** Owner: Tam Ngo/Alan Cudmore +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_oscore_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +int32 g_skipTestCase = -1; +char* g_skipTestCaseResult = " "; + +char* g_task_names[UT_OS_TASK_LIST_LEN]; +char g_long_task_name[OS_MAX_API_NAME+5]; + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_init_task_misc(void); +void UT_os_init_task_create_test(void); +void UT_os_init_task_delete_test(void); +void UT_os_setup_install_delete_handler_test(void); +void UT_os_init_task_exit_test(void); +void UT_os_init_task_delay_test(void); +void UT_os_init_task_set_priority_test(void); +void UT_os_init_task_get_id_test(void); +void UT_os_init_task_get_id_by_name_test(void); +void UT_os_init_task_get_info_test(void); + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +void UT_os_init_task_misc() +{ + memset(g_long_task_name, 'X', sizeof(g_long_task_name)); + g_long_task_name[sizeof(g_long_task_name)-1] = '\0'; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_create_test() +{ + g_task_names[0] = "Create_NotImpl"; + g_task_names[1] = "Create_NullPtr1"; + g_task_names[2] = "Create_NullPtr2"; + g_task_names[3] = "Create_NullPtr3"; + g_task_names[4] = "Create_LongName"; + g_task_names[5] = "Create_InvPrior"; + g_task_names[6] = "Create_Full"; + g_task_names[7] = "Create_DuplName"; + g_task_names[8] = "Create_OsErr"; + g_task_names[9] = "Create_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_delete_test() +{ + g_task_names[0] = "Delete_NotImpl"; + g_task_names[1] = "Delete_InvArg"; + g_task_names[2] = "Delete_OsErr"; + g_task_names[3] = "Delete_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_install_delete_handler_test() +{ + g_task_names[0] = "DelHandler_NotImpl"; + g_task_names[1] = "DelHandler_InvArg"; + g_task_names[2] = "DelHandler_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_exit_test() +{ + g_task_names[0] = "Exit_NotImpl"; + g_task_names[1] = "Exit_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_delay_test() +{ + g_task_names[0] = "Delay_NotImpl"; + g_task_names[1] = "Delay_OsErr"; + g_task_names[2] = "Delay_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_set_priority_test() +{ + g_task_names[0] = "SetPrio_NotImpl"; + g_task_names[1] = "SetPrio_InvArg"; + g_task_names[2] = "SetPrio_InvPrio"; + g_task_names[3] = "SetPrio_OsErr"; + g_task_names[4] = "SetPrio_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_register_test() +{ + g_task_names[0] = "Register_NotImpl"; + g_task_names[1] = "Register_InvArg"; + g_task_names[2] = "Register_OsErr"; + g_task_names[3] = "Register_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_get_id_test() +{ + g_task_names[0] = "GetId_NotImpl"; + g_task_names[1] = "GetId_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_get_id_by_name_test() +{ + g_task_names[0] = "GetIdByName_NotImpl"; + g_task_names[1] = "GetIdByName_InvPtr1"; + g_task_names[2] = "GetIdByName_InvPtr2"; + g_task_names[3] = "GetIdByName_LongName"; + g_task_names[4] = "GetIdByName_NotFound"; + g_task_names[5] = "GetIdByName_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_get_info_test() +{ + g_task_names[0] = "GetInfo_NotImpl"; + g_task_names[1] = "GetInfo_InvId"; + g_task_names[2] = "GetInfo_InvPtr"; + g_task_names[3] = "GetInfo_Nominal"; +} + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ +#ifdef _OSAL_UNIT_TEST_ + void OS_Application_Startup(void) +#else + int main(int argc, char* argv[]) +#endif +{ + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for oscore APIs\n") + + UT_os_apiinit_test(); + + UT_OS_LOG_MACRO("\n============================================\n") + UT_os_printf_test(); + UT_os_printfenable_test(); + UT_os_printfdisable_test(); + UT_OS_LOG_MACRO("============================================\n") + + UT_os_bin_sem_create_test(); + UT_os_bin_sem_delete_test(); + UT_os_bin_sem_flush_test(); + UT_os_bin_sem_give_test(); + UT_os_bin_sem_take_test(); + UT_os_bin_sem_timed_wait_test(); + UT_os_bin_sem_get_id_by_name_test(); + UT_os_bin_sem_get_info_test(); + + UT_os_count_sem_create_test(); + UT_os_count_sem_delete_test(); + UT_os_count_sem_give_test(); + UT_os_count_sem_take_test(); + UT_os_count_sem_timed_wait_test(); + UT_os_count_sem_get_id_by_name_test(); + UT_os_count_sem_get_info_test(); + + UT_os_mut_sem_create_test(); + UT_os_mut_sem_delete_test(); + UT_os_mut_sem_give_test(); + UT_os_mut_sem_take_test(); + UT_os_mut_sem_get_id_by_name_test(); + UT_os_mut_sem_get_info_test(); + + UT_os_queue_create_test(); + UT_os_queue_delete_test(); + UT_os_queue_put_test(); + UT_os_queue_get_test(); + UT_os_queue_get_id_by_name_test(); + UT_os_queue_get_info_test(); + + UT_os_init_task_misc(); + + UT_os_init_task_create_test(); + UT_os_task_create_test(); + + UT_os_init_task_delete_test(); + UT_os_task_delete_test(); + + UT_os_setup_install_delete_handler_test(); + UT_os_task_install_delete_handler_test(); + + UT_os_init_task_exit_test(); + UT_os_task_exit_test(); + + UT_os_init_task_delay_test(); + UT_os_task_delay_test(); + + UT_os_init_task_set_priority_test(); + UT_os_task_set_priority_test(); + + UT_os_init_task_register_test(); + UT_os_task_register_test(); + + UT_os_init_task_get_id_test(); + UT_OS_LOG_MACRO("\n============================================\n") + UT_os_task_get_id_test(); + UT_OS_LOG_MACRO("============================================\n") + + UT_os_init_task_get_id_by_name_test(); + UT_os_task_get_id_by_name_test(); + + UT_os_init_task_get_info_test(); + UT_os_task_get_info_test(); + + UT_os_geterrorname_test(); + + UT_os_tick2micros_test(); + UT_os_milli2ticks_test(); + + UT_OS_LOG_MACRO("\n============================================") + UT_os_getlocaltime_test(); + UT_OS_LOG_MACRO("============================================\n") + UT_os_setlocaltime_test(); + + UT_os_teardown("ut_oscore"); + + return (0); +} + +/*================================================================================* +** End of File: ut_oscore_test.c +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_test.h b/src/unit-tests/oscore-test/ut_oscore_test.h new file mode 100644 index 000000000..ca810bde6 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_test.h @@ -0,0 +1,50 @@ +/*================================================================================* +** File: ut_oscore_test.h +** Owner: Tam Ngo/Alan Cudmore +** Date: May 2013 +**================================================================================*/ + +#ifndef _UT_OSCORE_TEST_H_ +#define _UT_OSCORE_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" +#include "ut_oscore_misc_test.h" +#include "ut_oscore_binsem_test.h" +#include "ut_oscore_countsem_test.h" +#include "ut_oscore_mutex_test.h" +#include "ut_oscore_queue_test.h" +#include "ut_oscore_task_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_LOG_FILENAME "ut_oscore_log.txt" + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSCORE_TEST_H_ */ + +/*================================================================================* +** End of File: ut_oscore_test_posix.h +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_test_arinc653.c b/src/unit-tests/oscore-test/ut_oscore_test_arinc653.c new file mode 100644 index 000000000..c5cd623f2 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_test_arinc653.c @@ -0,0 +1,300 @@ +/*================================================================================* +** File: ut_oscore_test_arinc653.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include + +#include "ut_oscore_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +int32 g_skipTestCase = -1; +char* g_skipTestCaseResult = " "; + +char* g_task_names[UT_OS_TASK_LIST_LEN]; +char g_long_task_name[OS_MAX_API_NAME+5]; + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_init_task_misc(void); +void UT_os_init_task_create_test(void); +void UT_os_init_task_delete_test(void); +void UT_os_setup_install_delete_handler_test(void); +void UT_os_init_task_exit_test(void); +void UT_os_init_task_set_priority_test(void); +void UT_os_init_task_get_id_test(void); +void UT_os_init_task_get_id_by_name_test(void); +void UT_os_init_task_get_info_test(void); + +void UT_os_core_tests(void); + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +void UT_os_init_task_misc() +{ + memset(g_long_task_name, 'X', sizeof(g_long_task_name)); + g_long_task_name[sizeof(g_long_task_name)-1] = '\0'; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_create_test() +{ + memset(g_long_task_name, 'X', sizeof(g_long_task_name)); + g_long_task_name[sizeof(g_long_task_name)-1] = '\0'; + + g_task_names[0] = "Task_A"; /* Create_NotImpl */ + g_task_names[1] = "Task_A"; /* Create_NullPtr1 */ + g_task_names[2] = "Task_A"; /* Create_NullPtr2 */ + g_task_names[3] = "Task_B"; /* Create_NullPtr3 */ + g_task_names[4] = "Task_A"; /* Create_LongName */ + g_task_names[5] = "Task_A"; /* Create_InvPrior */ + g_task_names[6] = "Task_A"; /* Create_Full */ + g_task_names[7] = "Task_A"; /* Create_DuplName */ + g_task_names[8] = "Task_B"; /* Create_OsErr */ + g_task_names[9] = "Task_A"; /* Create_Nominal */ + + g_skipTestCase = 6; + g_skipTestCaseResult = UT_OS_NA; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_delete_test() +{ + g_task_names[0] = "Task_B"; /* Delete_NotImpl */ + g_task_names[1] = "Task_B"; /* Delete_InvArg */ + g_task_names[2] = "Task_B"; /* Delete_OsErr */ + g_task_names[3] = "Task_B"; /* Delete_Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_install_delete_handler_test() +{ + g_task_names[0] = "Task_B"; /* DelHandler_NotImpl */ + g_task_names[1] = "Task_B"; /* DelHandler_InvArg */ + g_task_names[2] = "Task_B"; /* DelHandler_Nominal */ + + g_skipTestCase = 1; + g_skipTestCaseResult = UT_OS_NA; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_exit_test() +{ + g_task_names[0] = "Task_A"; /* Exit_NotImpl */ + g_task_names[1] = "Task_A"; /* Exit Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_delay_test() +{ + g_task_names[0] = "Task_A"; /* Delay_NotImpl */ + g_task_names[1] = "Task_A"; /* Delay_OsErr */ + g_task_names[2] = "Task_A"; /* Delay_Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_set_priority_test() +{ + g_task_names[0] = "Task_A"; /* SetPrio_NotImpl */ + g_task_names[1] = "Task_B"; /* SetPrio_InvArg */ + g_task_names[2] = "Task_A"; /* SetPrio_InvPrio */ + g_task_names[3] = "Task_B"; /* SetPrio_OsErr */ + g_task_names[4] = "Task_A"; /* SetPrio_Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_register_test() +{ + g_task_names[0] = "Task_A"; /* Register_NotImpl */ + g_task_names[1] = "Task_A"; /* Register_InvArg */ + g_task_names[2] = "Task_A"; /* Register_OsErr */ + g_task_names[3] = "Task_A"; /* Register_Nominal */ + + g_skipTestCase = 1; + g_skipTestCaseResult = UT_OS_NA; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_get_id_test() +{ + g_task_names[0] = "Task_B"; /* GetId_NotImpl */ + g_task_names[1] = "Task_B"; /* GetId_Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_get_id_by_name_test() +{ + g_task_names[0] = "Task_B"; /* GetIdByName_NotImpl */ + g_task_names[1] = "Task_B"; /* GetIdByName_InvPtr1 */ + g_task_names[2] = "Task_B"; /* GetIdByName_InvPtr2 */ + g_task_names[3] = "Task_B"; /* GetIdByName_LongName */ + g_task_names[4] = "Task_B"; /* GetIdByName_NotFound */ + g_task_names[5] = "Task_B"; /* GetIdByName_Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_task_get_info_test() +{ + g_task_names[0] = "Task_B"; /* GetInfo_NotImpl */ + g_task_names[1] = "Task_B"; /* GetInfo_InvId */ + g_task_names[2] = "Task_B"; /* GetInfo_InvPtr */ + g_task_names[3] = "Task_B"; /* GetInfo_Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_core_tests() +{ + UT_OS_LOG_MACRO("\n============================================\n") + UT_os_printf_test(); + UT_os_printfenable_test(); + UT_os_printfdisable_test(); + UT_OS_LOG_MACRO("============================================\n") + + UT_os_bin_sem_create_test(); + UT_os_bin_sem_delete_test(); + UT_os_bin_sem_flush_test(); + UT_os_bin_sem_give_test(); + UT_os_bin_sem_take_test(); + UT_os_bin_sem_timed_wait_test(); + UT_os_bin_sem_get_id_by_name_test(); + UT_os_bin_sem_get_info_test(); + + UT_os_count_sem_create_test(); + UT_os_count_sem_delete_test(); + UT_os_count_sem_give_test(); + UT_os_count_sem_take_test(); + UT_os_count_sem_timed_wait_test(); + UT_os_count_sem_get_id_by_name_test(); + UT_os_count_sem_get_info_test(); + + UT_os_mut_sem_create_test(); + UT_os_mut_sem_delete_test(); + UT_os_mut_sem_give_test(); + UT_os_mut_sem_take_test(); + UT_os_mut_sem_get_id_by_name_test(); + UT_os_mut_sem_get_info_test(); + + UT_os_queue_create_test(); + UT_os_queue_delete_test(); + UT_os_queue_put_test(); + UT_os_queue_get_test(); + UT_os_queue_get_id_by_name_test(); + UT_os_queue_get_info_test(); + + UT_os_init_task_misc(); + + UT_os_init_task_create_test(); + UT_os_task_create_test(); + + UT_os_init_task_delete_test(); + UT_os_task_delete_test(); + + UT_os_setup_install_delete_handler_test(); + UT_os_task_install_delete_handler_test(); + + UT_os_init_task_exit_test(); + UT_os_task_exit_test(); + + UT_os_init_task_delay_test(); + UT_os_task_delay_test(); + + UT_os_init_task_set_priority_test(); + UT_os_task_set_priority_test(); + + UT_os_init_task_register_test(); + UT_os_task_register_test(); + + UT_os_init_task_get_id_test(); + UT_OS_LOG_MACRO("\n============================================\n") + UT_os_task_get_id_test(); + UT_OS_LOG_MACRO("============================================\n") + + UT_os_init_task_get_id_by_name_test(); + UT_os_task_get_id_by_name_test(); + + UT_os_init_task_get_info_test(); + UT_os_task_get_info_test(); + + UT_os_geterrorname_test(); + + UT_os_tick2micros_test(); + UT_os_milli2ticks_test(); + + UT_OS_LOG_MACRO("\n============================================") + UT_os_getlocaltime_test(); + UT_OS_LOG_MACRO("============================================\n") + UT_os_setlocaltime_test(); + + UT_os_teardown("ut_oscore"); +} + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ + +void UT_main() +{ + int32 osalRet=0; + uint32 tId=0, stackPtr=0; + RETURN_CODE_TYPE arincRet=NO_ERROR; + + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for ARINC653-implementation of oscore APIs\n") + + UT_os_apiinit_test(); + + osalRet = OS_TaskCreate(&tId, "ut_oscore", + (osal_task_entry)&UT_os_core_tests, + &stackPtr, 0x2000, 110, 0); + + SET_PARTITION_MODE(NORMAL, &arincRet); +} + +/*================================================================================* +** End of File: ut_oscore_test_arinc653.c +**================================================================================*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_test_platforms.h b/src/unit-tests/oscore-test/ut_oscore_test_platforms.h new file mode 100644 index 000000000..f05cd6116 --- /dev/null +++ b/src/unit-tests/oscore-test/ut_oscore_test_platforms.h @@ -0,0 +1,66 @@ +/*================================================================================* +** File: ut_oscore_test_platforms.h +** Owner: Tam Ngo +** Date: September 2013 +**================================================================================*/ + +#ifndef _UT_OSCORE_TEST_PLATFORMS_H_ +#define _UT_OSCORE_TEST_PLATFORMS_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#ifdef _LINUX_OS_ +#include +#endif /* _LINUX_OS_ */ + +#ifdef OSP_ARINC653 +#include "apex_api.h" +#endif /* OSP_ARINC653 */ + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#ifdef OSP_ARINC653 +#define SEM_VALUE_MAX 255 +#endif /* OSP_ARINC653 */ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef _LINUX_OS_ +/*--------------------------------------------*/ +/*--------------------------------------------*/ +#endif /* _LINUX_OS_ */ +/*--------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef OSP_ARINC653 +/*--------------------------------------------*/ +/*--------------------------------------------*/ +#endif /* OSP_ARINC653 */ +/*--------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSCORE_TEST_PLATFORMS_H_ */ + +/*================================================================================* +** End of File: ut_oscore_test_platforms.h +**================================================================================*/ diff --git a/src/unit-tests/osfile-test/ut_osfile_dirio_test.c b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c new file mode 100644 index 000000000..412e5e5fe --- /dev/null +++ b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c @@ -0,0 +1,946 @@ +/*================================================================================* +** File: ut_osfile_dirio_test.c +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osfile_dirio_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_FILE_MAX_DIRS 5 + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +extern char* g_fsAddrPtr; + +extern int32 g_skipTestCase; +extern char* g_skipTestCaseResult; + +extern char g_longPathName[OS_MAX_PATH_LEN+5]; + +extern char* g_mntName; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +char g_dirName[UT_OS_SM_TEXT_LEN]; +char g_fileName[UT_OS_SM_TEXT_LEN]; + +char g_subdirNames[UT_OS_FILE_MAX_DIRS][UT_OS_SM_TEXT_LEN]; +char* g_tgtSubdirs[UT_OS_FILE_MAX_DIRS] = {"subdir1", "subdir2"}; + +char g_dirItems[UT_OS_FILE_MAX_DIRS][UT_OS_SM_TEXT_LEN]; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_read_n_sort_dirs(os_dirp_t); + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_mkdir(const char *path, uint32 access) +** Purpose: Creates a directory specified by path +** Parameters: *path - pointer to the absolute pathname of the directory to be created +** access - directory access mode (unused) +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_PATH_TOO_LONG if the path is too long +** OS_FS_ERR_PATH_INVALID if the path is invalid +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with a really long path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #3: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #4: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #5: Nominal condition +** 1) Call this routine to create a directory under /cf mount point +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call OS_creat to create and open a file inside the directory created in #1 +** 4) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +**--------------------------------------------------------------------------------*/ +void UT_os_makedir_test() +{ + UT_OsApiInfo_t apiInfo; + int32 idx=0, fileDesc=0; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_mkdir(NULL, 755) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_makedir_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_mkdir(NULL, 755) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if (OS_mkdir(g_longPathName, 755) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Invalid-path-arg"; + + if (OS_mkdir("tmpDir", 755) == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + memset(g_dirName, '\0', sizeof(g_dirName)); + UT_os_sprintf(g_dirName, "%s/mkdir_Nominal", g_mntName); + if (OS_mkdir(g_dirName, 755) != OS_FS_SUCCESS) + { + testDesc = "#5 Nominal - File-system-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_makedir_test_exit_tag; + } + + memset(g_fileName, '\0', sizeof(g_fileName)); + UT_os_sprintf(g_fileName, "%s/mkdir_File.txt", g_dirName); + fileDesc = OS_creat(g_fileName, OS_READ_WRITE); + if (fileDesc >= 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(fileDesc); + OS_remove(g_fileName); + OS_rmdir(g_dirName); + +UT_os_makedir_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_mkdir", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: os_dirp_t OS_opendir(const char *path) +** Purpose: Opens the specified directory for reading +** Parameters: *path - pointer to the absolute pathname of the directory to be opened +** Returns: NULL if path is NULL, path is too long, or OS call failed +** A pointer of type OS_dirp_t to the directory if succeeded +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) This test is not applicable to this routine. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) NULL +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with a really long path as argument +** 2) Expect the returned value to be +** (a) NULL +** ----------------------------------------------------- +** Test #3: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) NULL +** ----------------------------------------------------- +** Test #4: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) NULL +** ----------------------------------------------------- +** Test #5: Nominal condition +** 1) Call OS_mkdir to create a directory under /cf mount point +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call this routine with directory name used in #1 as argument +** 4) Expect the returned value to be +** (a) a directory descriptor pointer that is __not__ NULL +**--------------------------------------------------------------------------------*/ +void UT_os_opendir_test() +{ + int32 idx=0; + os_dirp_t dirHdl=NULL; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if ((int)OS_opendir(NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_opendir_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_opendir(NULL) == NULL) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if (OS_opendir(g_longPathName) == NULL) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Invalid-path-arg"; + + if (OS_opendir("/drive0/tmpDir") == NULL) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + memset(g_dirName, '\0', sizeof(g_dirName)); + UT_os_sprintf(g_dirName, "%s/opendir_Nominal", g_mntName); + if (OS_mkdir(g_dirName, 755) != OS_FS_SUCCESS) + { + testDesc = "#5 Nominal - Dir-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_opendir_test_exit_tag; + } + + dirHdl = OS_opendir(g_dirName); + if (dirHdl != NULL) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_closedir(dirHdl); + OS_rmdir(g_dirName); + +UT_os_opendir_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_opendir", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_closedir(os_dirp_t directory) +** Purpose: Closes the specified directory for reading +** Parameters: directory - a directory descriptor pointer that was returned from +** a call to OS_opendir() +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is NULL +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call OS_mkdir() to create a directory under /cf mount point +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call OS_opendir() with directory name used in #1 as argument +** 4) Expect the returned value to be +** (a) a directory descriptor pointer that is __not__ NULL +** 5) Call this routine with the directory descriptor pointer returned in #3 as argument +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 7) Call OS_readdir() with the directory descriptor pointer returned in #3 as argument +** 8) Expect the returned value to be +** (a) a NULL pointer to the next directory entry +**--------------------------------------------------------------------------------*/ +void UT_os_closedir_test() +{ + int32 idx=0; + os_dirp_t dirHdl=NULL; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_closedir(NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_closedir_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_closedir(NULL) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + memset(g_dirName, '\0', sizeof(g_dirName)); + UT_os_sprintf(g_dirName, "%s/closeDir3", g_mntName); + if (OS_mkdir(g_dirName, 755) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - Dir-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_closedir_test_exit_tag; + } + + dirHdl = OS_opendir(g_dirName); + if (dirHdl == NULL) + { + testDesc = "#3 Nominal - Dir-open failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_closedir_test_exit_tag; + } + + if (OS_closedir(dirHdl) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_closedir_test_exit_tag; + } + + if (OS_readdir(dirHdl) == NULL) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_rmdir(g_dirName); + +UT_os_closedir_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_closedir", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: os_dirent_t* OS_readdir(os_dirp_t directory) +** Purpose: Provides information about a directory +** Parameters: directory - a directory descriptor pointer that was returned from +** a call to OS_opendir() +** Returns: NULL if error or end of directory is reached +** A pointer to the next entry if succeeded +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) This test is not applicable to this routine. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) NULL +** ----------------------------------------------------- +** Test #2: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) NULL +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call OS_mkdir() to create a directory +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call OS_opendir() with directory name used in #1 as argument +** 4) Expect the returned value to be +** (a) a directory descriptor pointer +** 5) Call this routine with the directory descriptor pointer returned in #3 +** 6) Expect the returned value to be +** (a) a directory entry pointer __and__ +** (b) the directory name to be "." +** 7) Call this routine again with the directory descriptor pointer returned in #3 +** 8) Expect the returned value to be +** (a) a directory entry pointer __and__ +** (b) the directory name to be ".." +**--------------------------------------------------------------------------------*/ +void UT_os_readdir_test() +{ + int32 idx=0; + os_dirp_t dirHdl=NULL; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + strcpy(g_subdirNames[0], " "); + strcpy(g_subdirNames[1], " "); + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_readdir(NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_readdir_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_readdir(NULL) == NULL) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + memset(g_dirName, '\0', sizeof(g_dirName)); + UT_os_sprintf(g_dirName, "%s/readdir_Nominal", g_mntName); + if (OS_mkdir(g_dirName, 755) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - Dir-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_readdir_test_exit_tag; + } + + memset(g_subdirNames[0], '\0', sizeof(g_subdirNames[0])); + UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]); + if (OS_mkdir(g_subdirNames[0], 755) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - Dir-create(subdir1) failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + goto UT_os_readdir_test_exit_tag; + } + + memset(g_subdirNames[1], '\0', sizeof(g_subdirNames[1])); + UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]); + if (OS_mkdir(g_subdirNames[1], 755) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - Dir-create(subdir2) failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + goto UT_os_readdir_test_exit_tag; + } + + dirHdl = OS_opendir(g_dirName); + if (dirHdl == NULL) + { + testDesc = "#3 Nominal - Dir-open failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + goto UT_os_readdir_test_exit_tag; + } + + UT_os_read_n_sort_dirs(dirHdl); + + if ((strcmp(g_dirItems[2], g_tgtSubdirs[0]) == 0) && + (strcmp(g_dirItems[3], g_tgtSubdirs[1]) == 0)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_readdir_test_exit_tag: + /* Reset test environment */ + OS_closedir(dirHdl); + OS_rmdir(g_subdirNames[0]); + OS_rmdir(g_subdirNames[1]); + OS_rmdir(g_dirName); + + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_readdir", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: void OS_rewinddir(os_dirp_t directory) +** Purpose: Resets the directory pointer to the beginning +** Parameters: directory - a directory descriptor pointer that was returned from +** a call to OS_opendir() +** Returns: None +** Test #0: Not-implemented condition +** 1) This test is not applicable to this routine. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) NULL +** ----------------------------------------------------- +** Test #2: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) NULL +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call OS_mkdir() to create a directory +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call OS_opendir() with directory name used in #1 as argument +** 4) Expect the returned value to be +** (a) a directory descriptor pointer +** 5) Call OS_readdir() with the directory descriptor pointer returned in #3 +** 6) Expect the returned value to be +** (a) a directory entry pointer __and__ +** (b) the directory name to be "." +** 7) Call OS_readdir() again with the directory descriptor pointer returned in #3 +** 8) Expect the returned value to be +** (a) a directory entry pointer __and__ +** (b) the directory name to be ".." +** 9) Call this routine with the directory descriptor pointer returned in #3 +** 10) Call OS_readdir() the 3rd time with the directory descriptor pointer returned in #3 +** 11) Expect the returned value to be +** (a) a directory entry pointer __and__ +** (b) a the directory name to be "." +**--------------------------------------------------------------------------------*/ +void UT_os_rewinddir_test() +{ + int32 idx=0; + os_dirp_t dirHdl=NULL; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + strcpy(g_subdirNames[0], " "); + strcpy(g_subdirNames[1], " "); + + /*-----------------------------------------------------*/ + testDesc = "Not implemented"; + + /* Since this is a void function, we can't check if it's implemented. */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + OS_rewinddir(NULL); + + /* Passed if the test application did not crash at this point */ + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + if (g_skipTestCase == 3) + { + testDesc = "API not implemented"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, g_skipTestCaseResult) + } + else + { + memset(g_dirName, '\0', sizeof(g_dirName)); + UT_os_sprintf(g_dirName, "%s/rewinddir_Nominal", g_mntName); + if (OS_mkdir(g_dirName, 755) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - Dir-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + goto UT_os_rewinddir_test_exit_tag; + } + + memset(g_subdirNames[0], '\0', sizeof(g_subdirNames[0])); + UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]); + if (OS_mkdir(g_subdirNames[0], 755) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - Dir-create(subdir1) failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + goto UT_os_rewinddir_test_exit_tag; + } + + memset(g_subdirNames[1], '\0', sizeof(g_subdirNames[1])); + UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]); + if (OS_mkdir(g_subdirNames[1], 755) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - Dir-create(subdir2) failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + goto UT_os_rewinddir_test_exit_tag; + } + + dirHdl = OS_opendir(g_dirName); + if (dirHdl == NULL) + { + testDesc = "#3 Nominal - Dir-open failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + goto UT_os_rewinddir_test_exit_tag; + } + + UT_os_read_n_sort_dirs(dirHdl); + + if ((strcmp(g_dirItems[2], g_tgtSubdirs[0]) != 0) || + (strcmp(g_dirItems[3], g_tgtSubdirs[1]) != 0)) + { + testDesc = "#3 Nominal - Dir-read failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + goto UT_os_rewinddir_test_exit_tag; + } + + OS_rewinddir(dirHdl); + + UT_os_read_n_sort_dirs(dirHdl); + + if ((strcmp(g_dirItems[2], g_tgtSubdirs[0]) != 0) || + (strcmp(g_dirItems[3], g_tgtSubdirs[1]) != 0)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + } + +UT_os_rewinddir_test_exit_tag: + /* Reset test environment */ + OS_closedir(dirHdl); + OS_rmdir(g_subdirNames[0]); + OS_rmdir(g_subdirNames[1]); + OS_rmdir(g_dirName); + + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_rewinddir", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_rmdir(const char *path) +** Purpose: Removes the specified directory +** Parameters: *path - pointer to the absolute pathname of the directory to be removed +** Returns: OS_FS_ERR_INVALID_POINTER if pointer passed in is NULL +** OS_FS_ERR_PATH_TOO_LONG if path is too long +** OS_FS_ERR_PATH_INVALID if path is invalid +** OS_FS_ERROR if OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with a really long path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #3: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #4: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #5: Nominal condition +** 1) Call OS_mkdir to create a directory under /cf mount point +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call OS_creat() to create and open a file under the directory created in #1 +** 4) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 5) Call this routine with directory name used in #1 +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 7) Call OS_close() with the file descriptor returned in #3 as argument +** 8) Call OS_remove() with the file name used in #3 as argument +** 9) Call OS_creat() to create and open another file under the directory deleted in #5 +** 10) Expect the returned value to be +** (a) a file descriptor value less than 0 +**--------------------------------------------------------------------------------*/ +void UT_os_removedir_test() +{ + UT_OsApiInfo_t apiInfo; + int32 idx=0, fileDesc=0; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_rmdir(NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_removedir_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_rmdir(NULL) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if (OS_rmdir(g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Invalid-path-arg"; + + if (OS_rmdir("tmpDir") == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + memset(g_dirName, '\0', sizeof(g_dirName)); + UT_os_sprintf(g_dirName, "%s/rmdir_Nominal", g_mntName); + if (OS_mkdir(g_dirName, 755) != OS_FS_SUCCESS) + { + testDesc = "#5 Nominal - Dir-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_removedir_test_exit_tag; + } + + memset(g_fileName, '\0', sizeof(g_fileName)); + UT_os_sprintf(g_fileName, "%s/rmdir_File1.txt", g_dirName); + fileDesc = OS_creat(g_fileName, OS_READ_WRITE); + if (fileDesc < 0) + { + testDesc = "#5 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + + /* Must close and remove all files before the directory can be removed */ + OS_close(fileDesc); + OS_remove(g_fileName); + + if (OS_rmdir(g_dirName) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_removedir_test_exit_tag; + } + + memset(g_fileName, '\0', sizeof(g_fileName)); + UT_os_sprintf(g_fileName, "%s/rmdir_File2.txt", g_dirName); + fileDesc = OS_creat(g_fileName, OS_READ_WRITE); + if (fileDesc < 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_removedir_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_rmdir", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* + * Internal helper function +**--------------------------------------------------------------------------------*/ +void UT_os_read_n_sort_dirs(os_dirp_t dirHdl) +{ + int i=0; + os_dirent_t* dirEntry=NULL; + + for (i=0; i < UT_OS_FILE_MAX_DIRS; i++) + strcpy(g_dirItems[i], " "); + + dirEntry = OS_readdir(dirHdl); + while (dirEntry != NULL) + { + if (strcmp(dirEntry->d_name, ".") == 0) + strcpy(g_dirItems[0], "."); + else if (strcmp(dirEntry->d_name, "..") == 0) + strcpy(g_dirItems[1], ".."); + else if (strcmp(dirEntry->d_name, g_tgtSubdirs[0]) == 0) + strcpy(g_dirItems[2], g_tgtSubdirs[0]); + else if (strcmp(dirEntry->d_name, g_tgtSubdirs[1]) == 0) + strcpy(g_dirItems[3], g_tgtSubdirs[1]); + + dirEntry = OS_readdir(dirHdl); + } +} + +/*================================================================================* +** End of File: ut_osfile_dirio_test.c +**================================================================================*/ diff --git a/src/unit-tests/osfile-test/ut_osfile_dirio_test.h b/src/unit-tests/osfile-test/ut_osfile_dirio_test.h new file mode 100644 index 000000000..abc9270d1 --- /dev/null +++ b/src/unit-tests/osfile-test/ut_osfile_dirio_test.h @@ -0,0 +1,51 @@ +/*================================================================================* +** File: ut_osfile_dirio.h +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSFILE_DIRIO_H_ +#define _UT_OSFILE_DIRIO_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_FILE_LIST_LEN (NUM_TABLE_ENTRIES + 10) + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_makedir_test(void); +void UT_os_opendir_test(void); +void UT_os_closedir_test(void); +void UT_os_readdir_test(void); +void UT_os_rewinddir_test(void); +void UT_os_removedir_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSFILE_DIRIO_H_ */ + +/*================================================================================* +** End of File: ut_osfile_dirio.h +**================================================================================*/ diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c new file mode 100644 index 000000000..a6a8fc206 --- /dev/null +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c @@ -0,0 +1,2685 @@ +/*================================================================================* +** File: ut_osfile_fileio_test.c +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osfile_fileio_test.h" +#include "ut_osfile_test_platforms.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_FILE_LIST_LEN (OS_MAX_NUM_OPEN_FILES + 10) + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/* As defined in osfileapi.c */ +extern OS_FDTableEntry OS_FDTable[OS_MAX_NUM_OPEN_FILES]; + +extern char* g_fsAddrPtr; + +extern int32 g_skipTestCase; +extern char* g_skipTestCaseResult; + +extern char g_longPathName[OS_MAX_PATH_LEN+5]; +extern char g_longFileName[OS_MAX_PATH_LEN]; +extern char g_invalidPath[OS_MAX_PATH_LEN]; + +extern char* g_mntName; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +char g_fNames[UT_OS_FILE_LIST_LEN][UT_OS_SM_TEXT_LEN]; +int32 g_fDescs[UT_OS_FILE_LIST_LEN]; + +char g_readBuff[UT_OS_MD_TEXT_LEN]; +char g_writeBuff[UT_OS_MD_TEXT_LEN]; + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_FS_Init(void) +** Purpose: Initializes the tables that the OS file-system uses to keep track of information +** about objects +** Parameters: None +** Returns: OS_ERROR on an unsuccessful inits +** OS_SUCCESS on a successful inits +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Init-not-call-first condition +** 1) Don't call this routine first +** 2) Call TBD routine(s) +** 3) Expect the returned value from those routines to be +** (a) __not__ OS_SUCCESS +*** ----------------------------------------------------- +** Test #2: Nominal condition +** 1) Call this routine +** 2) Expect the returned value to be +** (a) OS_SUCCESS (although results are not directly observable) +** 3) Call TBD routine(s) +** 4) Expect the returned value from those routines to be +** (a) OS_SUCCESS +*--------------------------------------------------------------------------------*/ +void UT_os_initfs_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "#1 Init-not-call-first - Test case not applicable on platform"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + + /*-----------------------------------------------------*/ + testDesc = "#2 Nominal"; + + /* Call to OS_FS_Init() is inside OS_API_Init(); */ + res = OS_API_Init(); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + testDesc = "API not implemented"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + } + else if (res == OS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_FS_Init", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_creat(const char *path, int32 access) +** Purpose: Creates a file of a given name and access mode, if doesn't exist; +** then opens it +** Parameters: *path - pointer to the absolute path name of the file to be created +** access - access modes with which to open a file +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_PATH_INVALID is the path passed in is invalid +** OS_FS_ERR_PATH_TOO_LONG if the absolute path name passed in is too long +** OS_FS_ERR_NAME_TOO_LONG if the file name passed in is too long +** OS_FS_ERROR if the OS call failed or file access is invalid +** OS_FS_ERR_NO_FREE_IDS if there are no more free file descriptors left in +** the File Descriptor table +** A file descriptor value if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** NOTE: If OS_creat() is implemented, then OS_close() and OS_remove() should +** also be implemented. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #3: Path-too-long-arg condition +** 1) Call this routine with a path of length greater than OS_MAX_PATH_LEN as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #4: Name-too-long-arg condition +** 1) Call this routine with just a file name (no absolute path) as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_NAME_TOO_LONG +** ----------------------------------------------------- +** Test #5: Invalid-permission-arg condition +** 1) Call this routine with a value of neither OS_WRITE_ONLY or OS_READ_WRITE +** 2) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #6: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #7: File-descriptors-full condition +** 1) Call this routine OS_MAX_NUM_OPEN_FILES+1 times +** 2) Expect the returned value, of all but the last call, to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Expect the returned value, of the last call, to be +** (b) OS_FS_ERR_NO_FREE_FDS +** ----------------------------------------------------- +** Test #8: Nominal condition +** 1) Call this routine twice with different file names and access modes +** 2) Expect both returned values to be +** (a) A file descriptor value greater than or equal to 0 +** 3) Call OS_close() on both files opened in #1 +** 4) Expect both returned values to be +** (a) OS_FS_SUCCESS +** 5) Call OS_remove() on both files closed in #3 +** 6) Expect both returned values to be +** (a) OS_FS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_createfile_test() +{ + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + int32 res=0, idx=0, i=0, j=0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_creat(NULL, OS_READ_WRITE) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_createfile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_creat(NULL, OS_READ_WRITE) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-path-arg"; + + if (OS_creat(g_invalidPath, OS_READ_WRITE) == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Path-too-long-arg"; + + if (OS_creat(g_longPathName, OS_READ_WRITE) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-too-long-arg"; + + if (OS_creat(g_longFileName, OS_READ_WRITE) == OS_FS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 Invalid-permission-arg"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Create_InvPerm.txt", g_mntName); + res = OS_creat(g_fNames[0], 123); + if (res == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(res); + OS_remove(g_fNames[0]); + + /*-----------------------------------------------------*/ + testDesc = "#6 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#7 File-descriptors-full"; + + UT_os_print_fdtable("FD TABLE _BEFORE_ FILE-DESC-FULL TEST SETUP FOR OS_creat()"); + + for (i=0; i <= OS_MAX_NUM_OPEN_FILES; i++) + { + memset(g_fNames[i], '\0', sizeof(g_fNames[i])); + UT_os_sprintf(g_fNames[i], "%s/tmpFile%d.txt", g_mntName, (int)i); + g_fDescs[i] = OS_creat(g_fNames[i], OS_WRITE_ONLY); + if (g_fDescs[i] < 0) + break; + } + + UT_os_print_fdtable("FD TABLE _AFTER_ FILE-DESC-FULL TEST SETUP FOR OS_creat()"); + + if ((i == OS_MAX_NUM_OPEN_FILES) && (g_fDescs[i] == OS_FS_ERR_NO_FREE_FDS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + for (j=0; j < i; j++) + { + OS_close(g_fDescs[j]); + OS_remove(g_fNames[j]); + } + + UT_os_print_fdtable("FD TABLE _AFTER_ FILE-DESC-FULL TEST TEARDOWN FOR OS_creat()"); + + /*-----------------------------------------------------*/ + testDesc = "#8 Nominal"; + + g_fDescs[5] = OS_creat(g_fNames[5], OS_WRITE_ONLY); + g_fDescs[6] = OS_creat(g_fNames[6], OS_WRITE_ONLY); + + UT_os_print_fdtable("FD TABLE _AFTER_ 2 FILE CREATIONS IN NOMINAL TEST FOR OS_creat()"); + + if ((OS_close(g_fDescs[5]) != OS_FS_SUCCESS) || (OS_close(g_fDescs[6]) != OS_FS_SUCCESS) || + (OS_remove(g_fNames[5]) != OS_FS_SUCCESS) || (OS_remove(g_fNames[6]) != OS_FS_SUCCESS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + UT_os_print_fdtable("FD TABLE _AFTER_ NOMINAL TEST FOR OS_creat()"); + +UT_os_createfile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_creat", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_open(const char *path, int32 access, uint32 mode) +** Purpose: Opens a file of a given name and access mode; if it doesn't exist, +** creates it first +** Parameters: *path - pointer to the absolute path name of the file to be created +** access - access modes with which to open a file +** mode - file permission which is not currently used +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_PATH_INVALID is the path passed in is invalid +** OS_FS_ERR_PATH_TOO_LONG if the absolute path name passed in is too long +** OS_FS_ERR_NAME_TOO_LONG if the file name passed in is too long +** OS_FS_ERROR if the OS call failed or file access is invalid +** OS_FS_ERR_NO_FREE_IDS if there are no more free file descriptors left in +** the File Descriptor table +** A file descriptor value if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** NOTE: If OS_creat() is implemented, then OS_close() and OS_remove() should +** also be implemented. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #3: Path-too-long-arg condition +** 1) Call this routine with a path of length greater than OS_MAX_PATH_LEN as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #4: Name-too-long-arg condition +** 1) Call this routine with just a file name (no absolute path) as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_NAME_TOO_LONG +** ----------------------------------------------------- +** Test #5: Invalid-permission-arg condition +** 1) Call this routine with a value of neither OS_WRITE_ONLY or OS_READ_WRITE +** 2) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #6: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #7: File-descriptors-full condition +** 1) Call this routine OS_MAX_NUM_OPEN_FILES+1 times +** 2) Expect the returned value, of all but the last call, to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Expect the returned value, of the last call, to be +** (b) OS_FS_ERR_NO_FREE_FDS +** ----------------------------------------------------- +** Test #8: Nominal condition +** 1) Call this routine twice with different file names and access modes +** 2) Expect both returned values to be +** (a) A file descriptor value greater than or equal to 0 +** 3) Call OS_close() on both files opened in #1 +** 4) Expect both returned values to be +** (a) OS_FS_SUCCESS +** 5) Call OS_remove() on both files closed in #3 +** 6) Expect both returned values to be +** (a) OS_FS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_openfile_test() +{ + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + int32 res=0, idx=0, i=0, j=0, continueFlg=0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_open(NULL, OS_READ_WRITE, 644) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_openfile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_open(NULL, OS_READ_WRITE, 644) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-path-arg"; + + if (OS_open(g_invalidPath, OS_READ_WRITE, 644) == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Path-too-long-arg"; + + if (OS_open(g_longPathName, OS_READ_WRITE, 644) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-too-long-arg"; + + if (OS_open(g_longFileName, OS_READ_WRITE, 644) == OS_FS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 Invalid-permission-arg"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Open_InvPerm.txt", g_mntName); + res = OS_open(g_fNames[0], 123, 644); + if (res == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(res); + OS_remove(g_fNames[0]); + + /*-----------------------------------------------------*/ + testDesc = "#6 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#7 File-descriptors-full"; + + UT_os_print_fdtable("FD TABLE _BEFORE_ FILE-DESC-FULL TEST SETUP FOR OS_open()"); + + continueFlg = 1; + for (i=0; i < OS_MAX_NUM_OPEN_FILES; i++) + { + memset(g_fNames[i], '\0', sizeof(g_fNames[i])); + UT_os_sprintf(g_fNames[i], "%s/tmpFile%d.txt", g_mntName, (int)i); + g_fDescs[i] = OS_creat(g_fNames[i], OS_WRITE_ONLY); + if (g_fDescs[i] < OS_FS_SUCCESS) + { + testDesc = "#7 File-descriptors-full - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + continueFlg = 0; + break; + } + + if (continueFlg && (OS_close(g_fDescs[i]) != OS_FS_SUCCESS)) + { + testDesc = "#7 File-descriptors-full - File-close failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + continueFlg = 0; + break; + } + } + + if (continueFlg) + { + for (i=0; i <= OS_MAX_NUM_OPEN_FILES; i++) + { + g_fDescs[i] = OS_open(g_fNames[i], OS_WRITE_ONLY, 644); + if (g_fDescs[i] < 0) + break; + } + + UT_os_print_fdtable("FD TABLE _AFTER_ FILE-DESC-FULL TEST SETUP FOR OS_open()"); + + if ((i == OS_MAX_NUM_OPEN_FILES) && (g_fDescs[i] < OS_FS_SUCCESS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + for (j=0; j < i; j++) + { + OS_close(g_fDescs[j]); + OS_remove(g_fNames[j]); + } + + UT_os_print_fdtable("FD TABLE _AFTER_ FILE-DESC-FULL TEST TEARDOWN FOR OS_open()"); + } + + /*-----------------------------------------------------*/ + testDesc = "#8 Nominal"; + + g_fDescs[5] = OS_creat(g_fNames[5], OS_READ_WRITE); + g_fDescs[6] = OS_creat(g_fNames[6], OS_WRITE_ONLY); + if ((g_fDescs[5] < OS_FS_SUCCESS) || (g_fDescs[6] < OS_FS_SUCCESS)) + { + testDesc = "#8 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_openfile_test_exit_tag; + } + + if ((OS_close(g_fDescs[5]) != OS_FS_SUCCESS) || (OS_close(g_fDescs[6]) != OS_FS_SUCCESS)) + { + testDesc = "#8 Nominal - File-close failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_openfile_test_exit_tag; + } + + g_fDescs[5] = OS_open(g_fNames[5], OS_READ_WRITE, 644); + g_fDescs[6] = OS_open(g_fNames[6], OS_WRITE_ONLY, 644); + + UT_os_print_fdtable("FD TABLE _AFTER_ 2 FILE OPENINGS IN NOMINAL TEST FOR OS_open()"); + + if ((OS_close(g_fDescs[5]) != OS_FS_SUCCESS) || (OS_close(g_fDescs[6]) != OS_FS_SUCCESS) || + (OS_remove(g_fNames[5]) != OS_FS_SUCCESS) || (OS_remove(g_fNames[6]) != OS_FS_SUCCESS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + UT_os_print_fdtable("FD TABLE _AFTER_ NOMINAL TEST FOR OS_open()"); + +UT_os_openfile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_open", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_close(int32 filedes) +** Purpose: Closes a file of a given file descriptor +** Parameters: filedes - a file descriptor value +** Returns: OS_FS_ERR_INVALID_FD if the file descriptor passed in invalid +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** NOTE: If OS_close() is implemented, then OS_open() should also be implemented. +** ----------------------------------------------------- +** Test #1: Invalid-file-desc-arg condition +** 1) Call this routine 3 times with a file descriptors of 0, -1, and (OS_MAX_NUM_OPEN_FILES+5) +** respectively as argument +** 2) Expect all three returned values to be +** (a) OS_FS_ERR_INVALID_FD +** ----------------------------------------------------- +** Test #2: OS-call-failure condition +** 1) Setup the test to fail OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call OS_creat() to create and open a file +** 2) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call this routine with the file descriptor returned in #1 +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call OS_read() and OS_write() with the file descriptor returned in #1 +** 6) Expect both returned value to be +** (a) OS_FS_ERR_INVALID_FD +**--------------------------------------------------------------------------------*/ +void UT_os_closefile_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + char tmpBuff[UT_OS_XS_TEXT_LEN]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_close(99999) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_closefile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-file-desc-arg"; + + if (OS_close(99999) == OS_FS_ERR_INVALID_FD) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Close_Nominal.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#3 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_closefile_test_exit_tag; + } + + if ((OS_close(g_fDescs[0]) != OS_FS_SUCCESS) || + (OS_write(g_fDescs[0], tmpBuff, sizeof(tmpBuff)) != OS_FS_ERR_INVALID_FD) || + (OS_read(g_fDescs[0], tmpBuff, sizeof(tmpBuff)) != OS_FS_ERR_INVALID_FD)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + +UT_os_closefile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_close", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_read(int32 filedes, void *buffer, uint32 nbytes) +** Purpose: Reads nBytes from the file of a given file descriptors and write that +** nBytes to the given buffer +** Parameters: filedes - a file descriptor +** *buffer - pointer that will hold the data read from file +** nbytes - the number of bytes to be read from file +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_INVALID_FD if the file descriptor passed in is invalid +** OS_FS_ERROR if the OS call failed +** The number of bytes read if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-file-desc-arg condition +** 1) Call this routine 3 times with a file descriptors of 0, -1, and (OS_MAX_NUM_OPEN_FILES+5) +** respectively as argument +** 2) Expect all three returned values to be +** (a) OS_FS_ERR_INVALID_FD +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup the test to fail OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_creat() to create and open a file +** 2) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call OS_write() to write something to the file opened in #1 +** 4) Expect the returned value to be +** (a) number of bytes written that is equal to the number of bytes in the write buffer +** 5) Call OS_close() to flush and close the file opened in #1 +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 7) Call OS_open() with file name used in #1 as argument +** 8) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 9) Call this routine with the file descriptor returned in #7 +** 10) Expect the returned value to be +** (a) the number of bytes read that is equal to the number of bytes written in #3 __and__ +** (b) the read buffer content is the same as the write buffer content in #3 +**--------------------------------------------------------------------------------*/ +void UT_os_readfile_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + char text[UT_OS_LG_TEXT_LEN]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_read(99999, NULL, 0) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_readfile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Read_NullPtr.txt", g_mntName); + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#1 Null-pointer-arg - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + if (OS_read(g_fDescs[0], NULL, sizeof(g_readBuff)) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + } + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-file-desc-arg"; + + if (OS_read(99999, g_readBuff, sizeof(g_readBuff)) == OS_FS_ERR_INVALID_FD) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Read_Nominal.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#4 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_readfile_test_exit_tag; + } + + memset(g_writeBuff, '\0', sizeof(g_writeBuff)); + strcpy(g_writeBuff, "A HORSE! A HORSE! MY KINGDOM FOR A HORSE!"); + if (OS_write(g_fDescs[0], g_writeBuff, strlen(g_writeBuff)) != strlen(g_writeBuff)) + { + testDesc = "#4 Nominal - File-write failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + + goto UT_os_readfile_test_exit_tag; + } + + if (OS_close(g_fDescs[0]) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-close failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + + goto UT_os_readfile_test_exit_tag; + } + + g_fDescs[0] = OS_open(g_fNames[0], OS_READ_WRITE, 644); + if (g_fDescs[0] < 0) + { + testDesc = "#4 Nominal - File-open failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + + goto UT_os_readfile_test_exit_tag; + } + + memset(g_readBuff, '\0', sizeof(g_readBuff)); + if ((OS_read(g_fDescs[0], g_readBuff, strlen(g_writeBuff)) == strlen(g_writeBuff)) && + (strncmp(g_readBuff, g_writeBuff, strlen(g_writeBuff)) == 0)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "OS_read() success test -- Write to file:\n\t%s\n", g_writeBuff); + UT_OS_LOG_MACRO(text) + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "OS_read() success test -- Read from file:\n\t%s\n", g_readBuff); + UT_OS_LOG_MACRO(text) + +UT_os_readfile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_read", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_write(int32 filedes, void *buffer, uint32 nbytes) +** Purpose: Writes nBytes from the given buffer to the file of a given file descriptor +** Parameters: filedes - a file descriptor +** *buffer - pointer that holds the data to be written to file +** nbytes - the maximum number of bytes to copy to file +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_INVALID_FD if the file descriptor passed in is invalid +** OS_FS_ERROR if the OS call failed +** The number of bytes written if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-file-desc-arg condition +** 1) Call this routine 3 times with a file descriptors of 0, -1, and (OS_MAX_NUM_OPEN_FILES+5) +** respectively as argument +** 2) Expect all three returned values to be +** (a) OS_FS_ERR_INVALID_FD +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup the test to fail OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_creat() to create and open a file +** 2) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call this routine to write something to the file opened in #1 +** 4) Expect the returned value to be +** (a) number of bytes written that is equal to the number of bytes in the write buffer +** 5) Call OS_close() to flush and close the file opened in #1 +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 7) Call OS_open() with file name used in #1 as argument +** 8) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 9) Call OS_read() with the file descriptor returned in #7 +** 10) Expect the returned value to be +** (a) the number of bytes read that is equal to the number of bytes written in #3 __and__ +** (b) the read buffer content is the same as the write buffer content in #3 +**--------------------------------------------------------------------------------*/ +void UT_os_writefile_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + char text[UT_OS_LG_TEXT_LEN]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_write(99999, NULL, 0) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_writefile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Write_NullPtr.txt", g_mntName); + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#1 Null-pointer-arg - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + if (OS_write(g_fDescs[0], NULL, sizeof(g_writeBuff)) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + } + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-file-desc-arg"; + + if (OS_write(99999, g_writeBuff, sizeof(g_writeBuff)) == OS_FS_ERR_INVALID_FD) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Write_Nominal.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_writefile_test_exit_tag; + } + + memset(g_writeBuff, '\0', sizeof(g_writeBuff)); + strcpy(g_writeBuff, "TO BE OR NOT TO BE, THAT IS A QUESTION."); + if (OS_write(g_fDescs[0], g_writeBuff, strlen(g_writeBuff)) != strlen(g_writeBuff)) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + + goto UT_os_writefile_test_exit_tag; + } + + if (OS_close(g_fDescs[0]) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-close failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + + goto UT_os_writefile_test_exit_tag; + } + + g_fDescs[0] = OS_open(g_fNames[0], OS_READ_WRITE, 644); + if (g_fDescs[0] < 0) + { + testDesc = "#4 Nominal - File-open failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + + goto UT_os_writefile_test_exit_tag; + } + + memset(g_readBuff, '\0', sizeof(g_readBuff)); + if ((OS_read(g_fDescs[0], g_readBuff, strlen(g_writeBuff)) == strlen(g_writeBuff)) && + (strncmp(g_readBuff, g_writeBuff, strlen(g_writeBuff)) == 0)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "OS_write() success test -- Write to file:\n\t%s\n", g_writeBuff); + UT_OS_LOG_MACRO(text) + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "OS_write() success test -- Read from file:\n\t%s\n", g_readBuff); + UT_OS_LOG_MACRO(text) + +UT_os_writefile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_write", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_lseek(int32 filedes, int32 offset, uint32 whence) +** Purpose: Moves the read/write pointer of a given file descriptor to the given offset +** Parameters: filedes - file descriptor of the given file +** offset - number of bytes to offset the read/write pointer from its position +** dictated by whence +** whence - tells offset where to begin offsetting +** OS_SEEK_SET - starts at beginning of file +** OS_SEEK_CUR - starts at the current read/write pointer +** OS_SEEK_END - starts at the end of the file +** Returns: OS_FS_ERR_INVALID_FD is the file descriptor passed in is invalid +** OS_FS_ERROR if the OS call failed or the whence value is invalid +** The new offset from the beginning of the given file +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Invalid-file-desc-arg condition +** 1) Call this routine 3 times with a file descriptors of 0, -1, and (OS_MAX_NUM_OPEN_FILES+5) +** respectively as argument +** 2) Expect all three returned values to be +** (a) OS_FS_ERR_INVALID_FD +** ----------------------------------------------------- +** Test #2: Invalid-whence-arg condition +** 1) Call this routine with invalid "whence" value as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup the test to fail OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_creat() to create and open a file +** 2) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call OS_write() to write something to the file opened in #1 +** 4) Expect the returned value to be +** (a) the number of bytes that is equal to the number of bytes in the write buffer __and__ +** (b) the file position is now at the end of the file +** 5) Call this routine repeatedly with the file descriptor returned in #1, and different +** offset and whence value each time +** 6) Expect the returned value each time to be +** (a) the expected file position value given the arguments +**--------------------------------------------------------------------------------*/ +void UT_os_lseekfile_test() +{ + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + int32 idx=0, buffLen=0, pos1=0, pos2=0, pos3=0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_lseek(99999, 0, OS_SEEK_CUR) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_lseekfile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-file-desc-arg"; + + if (OS_lseek(99999, 0, OS_SEEK_SET) == OS_FS_ERR_INVALID_FD) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-whence-arg"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Seek_InvWhence.txt", g_mntName); + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#2 Invalid-whence-arg - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + if (OS_lseek(g_fDescs[0], 0, 123456) == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Seek_Nominal.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#4 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_lseekfile_test_exit_tag; + } + + memset(g_writeBuff, '\0', sizeof(g_writeBuff)); + strcpy(g_writeBuff, "THE BROWN FOX JUMPS OVER THE LAZY DOG."); + buffLen = (int32)strlen(g_writeBuff); + + if (OS_write(g_fDescs[0], g_writeBuff, buffLen) != buffLen) + { + testDesc = "#4 Nominal - File-write failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_lseekfile_test_exit_tag; + } + + pos1 = OS_lseek(g_fDescs[0], 10, OS_SEEK_SET); + pos2 = OS_lseek(g_fDescs[0], 7, OS_SEEK_CUR); + pos3 = OS_lseek(g_fDescs[0], -16, OS_SEEK_END); + if ((pos1 < 0) || (g_writeBuff[pos1] != 'F') || + (pos2 < 0) || (g_writeBuff[pos2] != 'P') || + (pos3 < 0) || (g_writeBuff[pos3] != 'E')) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + +UT_os_lseekfile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_lseek", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_chmod(const char *path, uint32 access) +** Purpose: Changes access mode of a given file name +** Parameters: *path - pointer to the path/name of the given file +** access - file access flags +** Returns: OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +**--------------------------------------------------------------------------------*/ +void UT_os_chmodfile_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_chmod(NULL, 644) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_chmodfile_test_exit_tag; + } + +UT_os_chmodfile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_chmod", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_stat(const char *path, os_fstat_t *filestats) +** Purpose: Returns file information about a given file name +** Parameters: *path - pointer to the file/name of a given file +** *filestats - pointer that will hold file information +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is null +** OS_FS_ERR_PATH_INVALID if the path is invalid +** OS_FS_ERR_PATH_TOO_LONG if the path name is too long +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #3: Path-too-long-arg condition +** 1) Call this routine with a path of length greater than OS_MAX_PATH_LEN as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #4: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #5: Nominal condition +** 1) Call OS_creat() to create and open a file +** 2) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call this routine with the file name used in #1 +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call OS_write() to cause a file modification to occur +** 6) Expect the returned value to be +** (a) number of bytes written to be equal to the length of write buffer +** 7) Call OS_close() to flush and close the file written to in #5 +** 8) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 9) Call this routine again with the file name used in #1 +** 10) Expect the returned value to be +** (a) OS_FS_SUCCESS __and__ +** (b) fstats1 returned in #3 and fstats2 returned in #9 to be not equal +**--------------------------------------------------------------------------------*/ +void UT_os_statfile_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + os_fstat_t fstats1, fstats2; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_stat(NULL, NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_statfile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if ((OS_stat(NULL, &fstats1) == OS_FS_ERR_INVALID_POINTER) && + (OS_stat(g_fNames[0], NULL) == OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-path-arg"; + + if (OS_stat(g_invalidPath, &fstats1) == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Path-too-long-arg"; + + if (OS_stat(g_longPathName, &fstats1) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Stat_Nominal.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#5 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_statfile_test_exit_tag; + } + + if (OS_stat(g_fNames[0], &fstats1) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_statfile_test_exit_tag; + } + + memset(g_writeBuff, '\0', sizeof(g_writeBuff)); + strcpy(g_writeBuff, "HOW NOW, BROWN COW?"); + if (OS_write(g_fDescs[0], g_writeBuff, strlen(g_writeBuff)) != strlen(g_writeBuff)) + { + testDesc = "#5 Nominal - File-write failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_statfile_test_exit_tag; + } + + if (OS_close(g_fDescs[0]) != OS_FS_SUCCESS) + { + testDesc = "#5 Nominal - File-close failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_statfile_test_exit_tag; + } + + if (OS_stat(g_fNames[0], &fstats2) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_statfile_test_exit_tag; + } + + if (memcmp(&fstats1, &fstats2, sizeof(fstats1)) != 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + +UT_os_statfile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_stat", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_remove(const char *path) +** Purpose: Removes the given file name +** Parameters: *path - pointer to the path/name of the file to be removed +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_PATH_INVALID if the path is invalid +** OS_FS_ERR_PATH_TOO_LONG if the path name is too long +** OS_FS_ERR_NAME_TOO_LONG if the name is too long +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #3: Path-too-long-arg condition +** 1) Call this routine with a path of length greater than OS_MAX_PATH_LEN as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #4: Name-too-long-arg condition +** 1) Call this routine with just a file name (no absolute path) as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_NAME_TOO_LONG +** ----------------------------------------------------- +** Test #5: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #6: Nominal condition +** 1) Call OS_creat() to create and open a file +** 2) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call this routine with path/file name used in #1 as argument +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call OS_stat() to get file status on the deleted file +** 6) Expect the returned values to be +** (a) OS_FS_ERROR +**--------------------------------------------------------------------------------*/ +void UT_os_removefile_test() +{ + int32 idx=0; + os_fstat_t fstats; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_remove(NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_removefile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_remove(NULL) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-path-arg"; + + if (OS_remove(g_invalidPath) == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Path-too-long-arg"; + + if (OS_remove(g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-too-long-arg"; + + if (OS_remove(g_longFileName) == OS_FS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#6 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Remove_Nominal.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + if (g_fDescs[0] < 0) + { + testDesc = "#6 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_removefile_test_exit_tag; + } + + UT_os_print_fdtable("FD TABLE _AFTER_ FILE CREATION FOR OS_remove()"); + + /* TODO: Check to see if OS_remove() can delete an opened file. + * If so, OS_FDTable should get clean up afterward. */ + OS_close(g_fDescs[0]); + + if (OS_remove(g_fNames[0]) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_removefile_test_exit_tag; + } + + UT_os_print_fdtable("FD TABLE _AFTER_ FILE REMOVAL FOR OS_remove()"); + + if (OS_stat(g_fNames[0], &fstats) == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_removefile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_remove", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_rename(const char *old, const char *new) +** Purpose: Renames the given file name to the new file name +** Parameters: *old - pointer to the path/name of the file to be renamed +** *new - pointer to the new path/name of the file +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is null +** OS_FS_ERR_PATH_TOO_LONG if the path name is too long +** OS_FS_ERR_NAME_TOO_LONG if the name is too long +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #3: Path-too-long-arg condition +** 1) Call this routine with a path of length greater than OS_MAX_PATH_LEN as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #4: Name-too-long-arg condition +** 1) Call this routine with just a file name (no absolute path) as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_NAME_TOO_LONG +** ----------------------------------------------------- +** Test #5: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #6: Nominal condition +** 1) Call OS_creat() to create and open a file +** 2) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call this routine with path/file name used in #1 as argument for old name +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call OS_stat() to get file status on the old name used in #3 +** 6) Expect the returned values to be +** (a) OS_FS_ERROR +**--------------------------------------------------------------------------------*/ +void UT_os_renamefile_test() +{ + int32 idx=0; + os_fstat_t fstats; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_rename(NULL, NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_renamefile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + memset(g_fNames[1], '\0', sizeof(g_fNames[1])); + UT_os_sprintf(g_fNames[0], "%s/oldName.txt", g_mntName); + UT_os_sprintf(g_fNames[1], "%s/newName.txt", g_mntName); + + if ((OS_rename(NULL, g_fNames[1]) == OS_FS_ERR_INVALID_POINTER) && + (OS_rename(g_fNames[0], NULL) == OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-path-arg"; + + if (OS_rename(g_invalidPath, g_invalidPath) == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Path-too-long-arg"; + + if (OS_rename(g_longPathName, g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-too-long-arg"; + + if (OS_rename(g_longFileName, g_longFileName) == OS_FS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#6 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + memset(g_fNames[0], '\0', sizeof(g_fNames[1])); + UT_os_sprintf(g_fNames[0], "%s/Rename_Nom_Old.txt", g_mntName); + UT_os_sprintf(g_fNames[1], "%s/Rename_Nom_New.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + if (g_fDescs[0] < 0) + { + testDesc = "#6 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_renamefile_test_exit_tag; + } + + if (OS_rename(g_fNames[0], g_fNames[1]) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_renamefile_test_exit_tag; + } + + if (OS_stat(g_fNames[0], &fstats) == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[1]); + +UT_os_renamefile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_rename", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_cp(const char *src, const char *dest) +** Purpose: Copies the given file to a new specified file +** Parameters: *src - pointer to the absolute path of the file to be copied +** *dest - pointer to the absolute path of the new file +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is null +** OS_FS_ERR_PATH_INVALID if the path is invalid +** OS_FS_ERR_PATH_TOO_LONG if the path name is too long +** OS_FS_ERR_NAME_TOO_LONG if the name is too long +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #3: Path-too-long-arg condition +** 1) Call this routine with a path of length greater than OS_MAX_PATH_LEN as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #4: Name-too-long-arg condition +** 1) Call this routine with just a file name (no absolute path) as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_NAME_TOO_LONG +** ----------------------------------------------------- +** Test #5: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #6: Nominal condition +** 1) Call OS_stat() with a non-existing file name as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERROR +** 3) Call OS_creat() to create and open a file +** 4) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 5) Call this routine with file name used in #3 as old file and file name used +** in #1 as new file +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 7) Call OS_stat() again as in #1 +** 8) Expect the returned value to be +** (a) OS_FS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_copyfile_test() +{ + int32 idx=0; + os_fstat_t fstats; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_cp(NULL, NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_copyfile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + memset(g_fNames[1], '\0', sizeof(g_fNames[1])); + UT_os_sprintf(g_fNames[0], "%s/oldName.txt", g_mntName); + UT_os_sprintf(g_fNames[1], "%s/newName.txt", g_mntName); + + if ((OS_cp(NULL, g_fNames[1]) == OS_FS_ERR_INVALID_POINTER) && + (OS_cp(g_fNames[0], NULL) == OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-path-arg"; + + if (OS_cp(g_invalidPath, g_invalidPath) == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Path-too-long-arg"; + + if (OS_cp(g_longPathName, g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-too-long-arg"; + + if (OS_cp(g_longFileName, g_longFileName) == OS_FS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#6 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + memset(g_fNames[1], '\0', sizeof(g_fNames[1])); + UT_os_sprintf(g_fNames[0], "%s/Cp_Nom_Old.txt", g_mntName); + UT_os_sprintf(g_fNames[1], "%s/Cp_Nom_New.txt", g_mntName); + + if (OS_stat(g_fNames[1], &fstats) != OS_FS_ERROR) + { + testDesc = "#6 Nominal - File-stat failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_copyfile_test_exit_tag; + } + + g_fDescs[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + if (g_fDescs[0] < 0) + { + testDesc = "#6 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_copyfile_test_exit_tag; + } + + if (OS_close(g_fDescs[0]) != OS_FS_SUCCESS) + { + testDesc = "#6 Nominal - File-close failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_copyfile_test_exit_tag; + } + + if (OS_cp(g_fNames[0], g_fNames[1]) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_copyfile_test_exit_tag; + } + + if (OS_stat(g_fNames[1], &fstats) == OS_FS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + OS_remove(g_fNames[1]); + +UT_os_copyfile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_cp", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_mv(const char *src, const char *dest) +** Purpose: Moves the given file to a new specified file +** Parameters: *src - pointer to the absolute path of the file to be moved +** *dest - pointer to the aboslute path of the new file +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is null +** OS_FS_ERR_INVALID_PATH if path is invalid +** OS_FS_ERR_PATH_TOO_LONG if the path name is too long +** OS_FS_ERR_NAME_TOO_LONG if the name is too long +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #3: Path-too-long-arg condition +** 1) Call this routine with a path of length greater than OS_MAX_PATH_LEN as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #4: Name-too-long-arg condition +** 1) Call this routine with just a file name (no absolute path) as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_NAME_TOO_LONG +** ----------------------------------------------------- +** Test #5: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #6: Nominal condition +** 1) Call OS_stat() with a non-existing file name as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERROR +** 3) Call OS_creat() to create and open a file +** 4) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 5) Call this routine with file name used in #3 as old file and file name used +** in #1 as new file +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 7) Call OS_stat() again as in #1 +** 8) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 9) Call OS_stat() on the file name used in #3 +** 10) Expect the returned value to be +** (a) not OS_FS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_movefile_test() +{ + int32 idx=0; + os_fstat_t fstats; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_mv(NULL, NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_movefile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + memset(g_fNames[1], '\0', sizeof(g_fNames[1])); + UT_os_sprintf(g_fNames[0], "%s/oldName.txt", g_mntName); + UT_os_sprintf(g_fNames[1], "%s/newName.txt", g_mntName); + + if ((OS_mv(NULL, g_fNames[1]) == OS_FS_ERR_INVALID_POINTER) && + (OS_mv(g_fNames[0], NULL) == OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-path-arg"; + + if (OS_mv(g_invalidPath, g_invalidPath) == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Path-too-long-arg"; + + if (OS_mv(g_longPathName, g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Name-too-long-arg"; + + if (OS_mv(g_longFileName, g_longFileName) == OS_FS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#5 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#6 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + memset(g_fNames[0], '\0', sizeof(g_fNames[1])); + UT_os_sprintf(g_fNames[0], "%s/Mv_Nom_Old.txt", g_mntName); + UT_os_sprintf(g_fNames[1], "%s/Mv_Nom_New.txt", g_mntName); + + if (OS_stat(g_fNames[1], &fstats) != OS_FS_ERROR) + { + testDesc = "#6 Nominal - File-stat failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_movefile_test_exit_tag; + } + + g_fDescs[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + if (g_fDescs[0] < 0) + { + testDesc = "#6 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_movefile_test_exit_tag; + } + + if (OS_mv(g_fNames[0], g_fNames[1]) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_movefile_test_exit_tag; + } + + if ((OS_stat(g_fNames[1], &fstats) == OS_FS_SUCCESS) && + (OS_stat(g_fNames[0], &fstats) != OS_FS_SUCCESS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[1]); + +UT_os_movefile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_mv", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_ShellOutputToFile(char *Cmd, int32 OS_fd) +** Purpose: Passes a command to the OS shell and directs the output from the command +** to the given file descriptor +** Parameters: *Cmd - pointer to the command to pass to the OS +** OS_fd - file descriptor to which the command output is written to +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_INVALID_FD if the file descriptor passed in is invalid +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-file-desc-arg condition +** 1) Call this routine 3 times with a file descriptors of 0, -1, and (OS_MAX_NUM_OPEN_FILES+5) +** respectively as argument +** 2) Expect all three returned values to be +** (a) OS_FS_ERR_INVALID_FD +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup the test to fail OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_creat() to create and open a file for writing +** 2) Expect the returned value to be +** (a) a file descriptor greater than or equal to 0 +** 3) Call this routine with file descriptor returned in #1 and +** command "echo $HOME" as arguments +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call OS_lseek() with file descriptor returned in #1 to rewind to the +** beginning of file to get ready for reading +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 7) Call OS_read() with file descriptor returned in #1 to read from beginning of file +** 8) Expect the returned value to be +** (a) number of bytes greater than 0 __and__ +** (b) the read string is the same as the string returned from getevn("HOME") call +**--------------------------------------------------------------------------------*/ +void UT_os_outputtofile_test() +{ + int32 idx=0; + char *envName=NULL; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (g_skipTestCase == 0) + { + testDesc = "API not applicable on platform"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, g_skipTestCaseResult) + goto UT_os_outputtofile_test_exit_tag; + } + + if (OS_ShellOutputToFile(NULL, 0) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_outputtofile_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_ShellOutputToFile(NULL, 0) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-file-desc-arg"; + + if (OS_ShellOutputToFile("ls", 99999) == OS_FS_ERR_INVALID_FD) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Output_Nominal.txt", g_mntName); + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#4 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_outputtofile_test_exit_tag; + } + + UT_OS_GET_HOME_ENV_FOR_NOMINAL_SHELLOUTPUTTOFILE_MACRO + + if (OS_ShellOutputToFile("echo $HOME", g_fDescs[0]) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_outputtofile_test_exit_tag; + } + + if (OS_lseek(g_fDescs[0], 0, OS_SEEK_SET) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-lseek failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_outputtofile_test_exit_tag; + } + + memset(g_readBuff, '\0', sizeof(g_readBuff)); + if (OS_read(g_fDescs[0], g_readBuff, sizeof(g_readBuff)) <= 0) + { + testDesc = "#4 Nominal - File-read failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_outputtofile_test_exit_tag; + } + + if (strncmp(g_readBuff, envName, strlen(envName)) == 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + +UT_os_outputtofile_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_ShellOutputToFile", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_FDGetInfo(int32 filedesc, OS_FDTableEntry *fd_prop) +** Purpose: Returns file descriptor information about a given file descriptor +** Parameters: filedesc - a file descriptor +** *fd_prop - pointer that will hold the file descriptor's data +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_INVALID_FD if the file descriptor passed in is invalid +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-file-desc-arg condition +** 1) Call this routine 3 times with a file descriptors of 0, -1, and (OS_MAX_NUM_OPEN_FILES+5) +** respectively as argument +** 2) Expect all three returned values to be +** (a) OS_FS_ERR_INVALID_FD +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup the test to fail OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_creat() to create and open a file +** 2) Expect the returned value to be +** (a) a file descriptor greater than or equal to 0 +** 3) Call this routine with the file descriptor returned in #1 as argument +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS __and__ +** (b) file descriptor property shows IsValid is TRUE __and__ +** (c) file path is the same as the file path used in #1 +** 5) Call OS_close() with file descriptor returned in #1 as argument +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 7) Call this routine with the file descriptor returned in #1 as argument +** 8) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_FD +**--------------------------------------------------------------------------------*/ +void UT_os_getfdinfo_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + OS_FDTableEntry fdProps; + const char* testDesc=NULL; + char* fileName="GetInfo_Nom.txt"; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_FDGetInfo(0, NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_getfdinfo_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/GetInfo_Null.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#1 Null-pointer-arg - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else if (OS_FDGetInfo(g_fDescs[0], NULL) != OS_FS_ERR_INVALID_POINTER) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + } + + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-file-desc-arg"; + + if (OS_FDGetInfo(99999, &fdProps) == OS_FS_ERR_INVALID_FD) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/%s", g_mntName, fileName); + g_fDescs[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + if (g_fDescs[0] < 0) + { + testDesc = "#4 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_getfdinfo_test_exit_tag; + } + + memset(&fdProps, 0x00, sizeof(fdProps)); + UT_OS_COMPARE_COND_FOR_NOMINAL_GETFDINFO_MACRO + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_getfdinfo_test_exit_tag; + } + + if (OS_close(g_fDescs[0]) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-close failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_getfdinfo_test_exit_tag; + } + + memset(&fdProps, 0x00, sizeof(fdProps)); + if (OS_FDGetInfo(g_fDescs[0], &fdProps) == OS_FS_ERR_INVALID_FD) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + +UT_os_getfdinfo_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_FDGetInfo", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_FileOpenCheck(char *Filename) +** Purpose: Determines if a given file is opened +** Parameters: *Filename - pointer to the name of the file to check +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERROR if the file is not opened +** OS_FS_SUCCESS if the file is opened +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: File-not-opened condition +** 1) Call this routine with some non-existing filename as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call OS_creat() to create and open some file +** 2) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call this routine with file name used in #1 +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_checkfileopen_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_FileOpenCheck(NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_checkfileopen_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_FileOpenCheck(NULL) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 File-not-opened"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/FChk_UnOpened.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#2 File-not-opened - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else if (OS_close(g_fDescs[0]) != OS_FS_SUCCESS) + { + testDesc = "#2 File-not-opened - File-close failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else if (OS_FileOpenCheck(g_fNames[0]) != OS_FS_ERROR) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + } + + /* Reset test environment */ + OS_remove(g_fNames[0]); + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/FileChk_Nominal.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#3 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_checkfileopen_test_exit_tag; + } + + if (OS_FileOpenCheck(g_fNames[0]) == OS_FS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_close(g_fDescs[0]); + OS_remove(g_fNames[0]); + +UT_os_checkfileopen_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_FileOpenCheck", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_CloseAllFiles(void) +** Purpose: Closes all opened files +** Parameters: None +** Returns: OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #2: Nominal condition +** 1) Call OS_creat() 3 times to create and open some files +** 2) Expect all returned values to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call this routine +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call OS_FileOpenCheck() on the file descriptors returned in #1 +** 6) Expect all returned values to be +** (a) OS_FS_ERROR +**--------------------------------------------------------------------------------*/ +void UT_os_closeallfiles_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_CloseAllFiles() == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_closeallfiles_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#2 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + memset(g_fNames[1], '\0', sizeof(g_fNames[1])); + memset(g_fNames[2], '\0', sizeof(g_fNames[2])); + UT_os_sprintf(g_fNames[0], "%s/CloseAll_Nom_1.txt", g_mntName); + UT_os_sprintf(g_fNames[1], "%s/CloseAll_Nom_2.txt", g_mntName); + UT_os_sprintf(g_fNames[2], "%s/CloseAll_Nom_3.txt", g_mntName); + + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fDescs[1] = OS_creat(g_fNames[1], OS_READ_WRITE); + g_fDescs[2] = OS_creat(g_fNames[2], OS_READ_WRITE); + if ((g_fDescs[0] < 0) || (g_fDescs[1] < 0) || (g_fDescs[1] < 0)) + { + testDesc = "#2 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_closeallfiles_test_exit_tag; + } + + if (OS_CloseAllFiles() != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_closeallfiles_test_exit_tag; + } + + if ((OS_FileOpenCheck(g_fNames[0]) == OS_FS_ERROR) && + (OS_FileOpenCheck(g_fNames[1]) == OS_FS_ERROR) && + (OS_FileOpenCheck(g_fNames[2]) == OS_FS_ERROR)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + OS_remove(g_fNames[1]); + OS_remove(g_fNames[2]); + +UT_os_closeallfiles_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_CloseAllFiles", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_CloseFileByName(char *Filename) +** Purpose: Closes a given file +** Parameters: *Filename - pointer to the name of the file to be closed +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_PATH_INVALID if the path is invalid +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_FS_UNIMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_FS_UNIMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-path-arg condition +** 1) Call this routine with a non-existing path as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup the test to fail the OS call inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_creat() to create and open a file +** 2) Expect the returned value to be +** (a) a file descriptor value greater than or equal to 0 +** 3) Call this routine with the file name used in #1 +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call OS_FileOpenCheck() with the file name used in #1 +** 6) Expect the returned value to be +** (a) OS_FS_ERROR +**--------------------------------------------------------------------------------*/ +void UT_os_closefilebyname_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_CloseFileByName(NULL) == OS_FS_UNIMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_closefilebyname_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_CloseFileByName(NULL) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-path-arg"; + + if (OS_CloseFileByName(g_invalidPath) == OS_FS_ERR_PATH_INVALID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + memset(g_fNames[0], '\0', sizeof(g_fNames[0])); + UT_os_sprintf(g_fNames[0], "%s/Close_Nominal.txt", g_mntName); + g_fDescs[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + if (g_fDescs[0] < 0) + { + testDesc = "#4 Nominal - File-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_closefilebyname_test_exit_tag; + } + + if (OS_CloseFileByName(g_fNames[0]) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_closefilebyname_test_exit_tag; + } + + if (OS_FileOpenCheck(g_fNames[0]) == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_remove(g_fNames[0]); + +UT_os_closefilebyname_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_CloseFileByName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_osfile_fileio_test.c +**================================================================================*/ diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.h b/src/unit-tests/osfile-test/ut_osfile_fileio_test.h new file mode 100644 index 000000000..112420388 --- /dev/null +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.h @@ -0,0 +1,67 @@ +/*================================================================================* +** File: ut_osfile_fileio.h +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSFILE_FILEIO_H_ +#define _UT_OSFILE_FILEIO_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_initfs_test(void); + +void UT_os_createfile_test(void); +void UT_os_openfile_test(void); +void UT_os_closefile_test(void); + +void UT_os_readfile_test(void); +void UT_os_writefile_test(void); +void UT_os_lseekfile_test(void); + +void UT_os_chmodfile_test(void); +void UT_os_statfile_test(void); + +void UT_os_removefile_test(void); +void UT_os_renamefile_test(void); +void UT_os_copyfile_test(void); +void UT_os_movefile_test(void); + +void UT_os_outputtofile_test(void); +void UT_os_getfdinfo_test(void); + +void UT_os_checkfileopen_test(void); +void UT_os_closeallfiles_test(void); +void UT_os_closefilebyname_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSFILE_FILEIO_H_ */ + +/*================================================================================* +** End of File: ut_osfile_fileio.h +**================================================================================*/ diff --git a/src/unit-tests/osfile-test/ut_osfile_test.c b/src/unit-tests/osfile-test/ut_osfile_test.c new file mode 100644 index 000000000..8ba25c03f --- /dev/null +++ b/src/unit-tests/osfile-test/ut_osfile_test.c @@ -0,0 +1,177 @@ +/*================================================================================* +** File: ut_osfile_test.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osfile_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +char* g_fsAddrPtr = NULL; + +int32 g_skipTestCase = -1; +char* g_skipTestCaseResult = " "; + +char g_longPathName[OS_MAX_PATH_LEN+5]; +char g_longFileName[OS_MAX_PATH_LEN]; +char g_invalidPath[OS_MAX_PATH_LEN]; + +char* g_devName = "/ramdev3"; +char* g_mntName = "/drive3"; + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +int32 UT_os_setup_fs(void); +int32 UT_os_teardown_fs(void); + +void UT_os_init_file_misc(void); + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +int32 UT_os_setup_fs() +{ + int32 res=OS_FS_SUCCESS; + char text[UT_OS_LG_TEXT_LEN]; + + res = OS_mkfs(g_fsAddrPtr, g_devName, " ", 512, 20); + if (res != OS_FS_SUCCESS) + goto UT_os_setup_fs_exit_tag; + + res = OS_mount(g_devName, g_mntName); + if (res != OS_FS_SUCCESS) + { + OS_rmfs(g_devName); + goto UT_os_setup_fs_exit_tag; + } + +UT_os_setup_fs_exit_tag: + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "\nUT_os_setup_fs() returns %d\n", (int)res); + UT_OS_LOG_MACRO(text); + + return (res); +} + +/*--------------------------------------------------------------------------------*/ + +int32 UT_os_teardown_fs() +{ + OS_unmount(g_mntName); + OS_rmfs(g_devName); + + return (OS_FS_SUCCESS); +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_file_misc() +{ + memset(g_longPathName, 'Y', sizeof(g_longPathName)); + g_longPathName[0] = '/'; + g_longPathName[sizeof(g_longPathName)-1] = '\0'; + + memset(g_longFileName, 'Z', sizeof(g_longFileName)); + g_longFileName[0] = '/'; + g_longFileName[4] = '/'; + g_longFileName[sizeof(g_longFileName)-1] = '\0'; + + memset(g_invalidPath, '\0', sizeof(g_invalidPath)); + strcpy(g_invalidPath, "/InvalidMnt/log1.txt"); +} + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ +#ifdef _OSAL_UNIT_TEST_ + void OS_Application_Startup(void) +#else + int main(int argc, char* argv[]) +#endif +{ + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for osfile APIs\n"); + + UT_os_initfs_test(); + + if (UT_os_setup_fs() == OS_FS_SUCCESS) + { + UT_os_init_file_misc(); + + /* Directory I/O APIs */ + UT_os_makedir_test(); + UT_os_opendir_test(); + UT_os_closedir_test(); + + UT_os_readdir_test(); + UT_os_rewinddir_test(); + UT_os_removedir_test(); + + /* File I/O APIs */ + UT_os_createfile_test(); + UT_os_openfile_test(); + UT_os_closefile_test(); + + UT_os_readfile_test(); + UT_os_writefile_test(); + UT_os_lseekfile_test(); + + UT_os_chmodfile_test(); + UT_os_statfile_test(); + + UT_os_removefile_test(); + UT_os_renamefile_test(); + UT_os_copyfile_test(); + UT_os_movefile_test(); + + UT_os_outputtofile_test(); + + UT_os_getfdinfo_test(); + UT_os_checkfileopen_test(); + + UT_os_closeallfiles_test(); + UT_os_closefilebyname_test(); + + UT_os_teardown_fs(); + } + + UT_os_teardown("ut_osfile"); + + return (0); +} + +/*================================================================================* +** End of File: ut_osfile_test.c +**================================================================================*/ diff --git a/src/unit-tests/osfile-test/ut_osfile_test.h b/src/unit-tests/osfile-test/ut_osfile_test.h new file mode 100644 index 000000000..9943a8f8a --- /dev/null +++ b/src/unit-tests/osfile-test/ut_osfile_test.h @@ -0,0 +1,50 @@ +/*================================================================================* +** File: ut_osfile_test.h +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +#ifndef _UT_OSFILE_TEST_H_ +#define _UT_OSFILE_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" +#include "ut_osfile_fileio_test.h" +#include "ut_osfile_dirio_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_LOG_FILENAME "ut_osfile_log.txt" + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +#ifdef _ARINC653_OS_ +void UT_main(void); +#endif /* _ARINC653_OS_ */ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSFILE_TEST_H_ */ + +/*================================================================================* +** End of File: ut_osfile_test.h +**================================================================================*/ diff --git a/src/unit-tests/osfile-test/ut_osfile_test_arinc653.c b/src/unit-tests/osfile-test/ut_osfile_test_arinc653.c new file mode 100644 index 000000000..8722ff4f9 --- /dev/null +++ b/src/unit-tests/osfile-test/ut_osfile_test_arinc653.c @@ -0,0 +1,200 @@ +/*================================================================================* +** File: ut_osfile_test_arinc653.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osfile_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_FS_BLOCK_SIZE 512 +#define UT_OS_FS_MAX_BLOCKS 20 + +#define UT_OS_FS_MEM_SPACE (2 * UT_OS_FS_BLOCK_SIZE * UT_OS_FS_MAX_BLOCKS) + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +char g_fsMemSpace[UT_OS_FS_MEM_SPACE]; /* This variable must not be moved. */ +char* g_fsAddrPtr = &g_fsMemSpace[9]; /* Offset to be 32-bit aligned, + which is important for the PIRD layer */ +int32 g_skipTestCase = -1; +char* g_skipTestCaseResult = " "; + +char g_longPathName[OS_MAX_PATH_LEN+5]; +char g_longFileName[OS_MAX_PATH_LEN]; +char g_invalidPath[OS_MAX_PATH_LEN]; + +char* g_devName = "/ramdev1"; +char* g_mntName = "/drive1"; + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +int32 UT_os_setup_fs(void); +int32 UT_os_teardown_fs(void); + +void UT_os_init_file_misc(void); +void UT_os_init_rewinddir_test(void); +void UT_os_init_outputtofile_test(void); + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +int32 UT_os_setup_fs() +{ + int32 res = OS_FS_SUCCESS; + char text[UT_OS_LG_TEXT_LEN]; + + res = OS_mkfs(g_fsAddrPtr, g_devName, " ", UT_OS_FS_BLOCK_SIZE, UT_OS_FS_MAX_BLOCKS); + if (res != OS_FS_SUCCESS) + goto UT_os_setup_fs_exit_tag; + + res = OS_mount(g_devName, g_mntName); + if (res != OS_FS_SUCCESS) + { + OS_rmfs(g_devName); + goto UT_os_setup_fs_exit_tag; + } + +UT_os_setup_fs_exit_tag: + memset(text, '\0', sizeof(text)); + OS_sprintf(text, "\nUT_os_setup_fs() returns %d\n", (int)res); + UT_OS_LOG_MACRO(text); + + return (res); +} + +/*--------------------------------------------------------------------------------*/ + +int32 UT_os_teardown_fs() +{ + OS_unmount(g_mntName); + OS_rmfs(g_devName); + + return (OS_FS_SUCCESS); +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_file_misc() +{ + memset(g_longPathName, 'Y', sizeof(g_longPathName)); + g_longPathName[0] = '/'; + g_longPathName[sizeof(g_longPathName)-1] = '\0'; + + memset(g_longFileName, 'Z', sizeof(g_longFileName)); + g_longFileName[0] = '/'; + g_longFileName[4] = '/'; + g_longFileName[sizeof(g_longFileName)-1] = '\0'; + + memset(g_invalidPath, '\0', sizeof(g_invalidPath)); + strcpy(g_invalidPath, "log1.txt"); +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_rewinddir_test() +{ + g_skipTestCase = 3; + g_skipTestCaseResult = UT_OS_NA; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_outputtofile_test() +{ + g_skipTestCase = 0; + g_skipTestCaseResult = UT_OS_NA; +} + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ +void UT_main() +{ + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for ARINC653-implementation of osfile APIs\n"); + + UT_os_initfs_test(); + + if (UT_os_setup_fs() == OS_FS_SUCCESS) + { + UT_os_init_file_misc(); + + /* Directory I/O APIs */ + UT_os_makedir_test(); + UT_os_opendir_test(); + UT_os_closedir_test(); + + UT_os_readdir_test(); + + UT_os_init_rewinddir_test(); + UT_os_rewinddir_test(); + + UT_os_removedir_test(); + + /* File I/O APIs */ + UT_os_createfile_test(); + + UT_os_openfile_test(); + UT_os_closefile_test(); + + UT_os_readfile_test(); + UT_os_writefile_test(); + UT_os_lseekfile_test(); + + UT_os_chmodfile_test(); + UT_os_statfile_test(); + + UT_os_removefile_test(); + UT_os_renamefile_test(); + UT_os_copyfile_test(); + UT_os_movefile_test(); + + UT_os_init_outputtofile_test(); + UT_os_outputtofile_test(); + + UT_os_getfdinfo_test(); + UT_os_checkfileopen_test(); + + UT_os_closeallfiles_test(); + UT_os_closefilebyname_test(); + + UT_os_teardown_fs(); + } + + UT_os_teardown("ut_osfile"); +} + +/*================================================================================* +** End of File: ut_osfile_test_arinc653.c +**================================================================================*/ diff --git a/src/unit-tests/osfile-test/ut_osfile_test_platforms.h b/src/unit-tests/osfile-test/ut_osfile_test_platforms.h new file mode 100644 index 000000000..50b0a740f --- /dev/null +++ b/src/unit-tests/osfile-test/ut_osfile_test_platforms.h @@ -0,0 +1,82 @@ +/*================================================================================* +** File: ut_osfile_test_platforms.h +** Owner: Tam Ngo +** Date: September 2013 +**================================================================================*/ + +#ifndef _UT_OSFILE_TEST_PLATFORMS_H_ +#define _UT_OSFILE_TEST_PLATFORMS_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#ifdef _LINUX_OS_ +#endif /* _LINUX_OS_ */ + +#ifdef OSP_ARINC653 +#include "apex_api.h" +#endif /* OSP_ARINC653 */ + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef _LINUX_OS_ +/*--------------------------------------------*/ + +#define UT_OS_GET_HOME_ENV_FOR_NOMINAL_SHELLOUTPUTTOFILE_MACRO \ + envName = getenv("HOME"); + +/*--------------------------------------------------------------------------------*/ + +#define UT_OS_COMPARE_COND_FOR_NOMINAL_GETFDINFO_MACRO \ +if ((OS_FDGetInfo(g_fDescs[0], &fdProps) != OS_FS_SUCCESS) || \ + (fdProps.IsValid != TRUE) || \ + (strncmp(fdProps.Path, g_fNames[0], strlen(g_fNames[0])) != 0)) + +/*--------------------------------------------*/ +#endif /* _LINUX_OS_ */ +/*--------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef OSP_ARINC653 +/*--------------------------------------------*/ + +#define UT_OS_GET_HOME_ENV_FOR_NOMINAL_SHELLOUTPUTTOFILE_MACRO + +/*--------------------------------------------------------------------------------*/ + +#define UT_OS_COMPARE_COND_FOR_NOMINAL_GETFDINFO_MACRO \ +if ((OS_FDGetInfo(g_fDescs[0], &fdProps) != OS_FS_SUCCESS) || \ + (fdProps.IsValid != TRUE) || \ + (strncmp(fdProps.Path, fileName, strlen(fileName)) != 0)) + +/*--------------------------------------------*/ +#endif /* OSP_ARINC653 */ +/*--------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSFILE_TEST_PLATFORMS_H_ */ + +/*================================================================================* +** End of File: ut_osfile_test_platforms.h +**================================================================================*/ diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c new file mode 100644 index 000000000..f82a8d5d2 --- /dev/null +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c @@ -0,0 +1,1324 @@ +/*================================================================================* +** File: ut_osfilesys_diskio_test.c +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osfilesys_diskio_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +extern char* g_fsAddrPtr; + +extern int32 g_blkSize; +extern int32 g_blkCnt; + +extern int32 g_skipTestCase; +extern char* g_skipTestCaseResult; + +extern char g_fsLongName[OS_MAX_PATH_LEN+5]; +extern char g_physDriveName[OS_MAX_PATH_LEN]; + +extern char g_volNames[UT_OS_FILESYS_LIST_LEN][UT_OS_XS_TEXT_LEN]; +extern char g_devNames[UT_OS_FILESYS_LIST_LEN][UT_OS_XS_TEXT_LEN]; +extern char g_mntNames[UT_OS_FILESYS_LIST_LEN][UT_OS_XS_TEXT_LEN]; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_initfs(char *address, char *devname, char *volname, uint32 blocksize, uint32 numblocks) +** Purpose: Initializes (without re-formatting) a drive on the target without +** erasing the existing file system +** Parameters: *address - a pointer to the address at which to start the new disk +** *devname - a pointer to the name of the "generic" device +** *volname - a pointer to the name of the volume (only used in vxWorks) +** blocksize - size of a single block on the drive +** numblocks - the number of blocks to be allocated for the drive +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is NULL +** OS_FS_ERR_PATH_TOO_LONG if the device name or volume name passed in is too long +** OS_FS_ERR_DEVICE_NOT_FREE if the Volume table is full +** OS_FS_ERR_DRIVE_NOT_CREATED if the volume is not FS-BASED +** OS_FS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as one of the arguments +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with some device name or volume name of length greater than +** Volume table's name +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup test to cause the OS call to fail inside this routine +** 2) Expect the returned value to be +** (a) OS_FS_ERR_DRIVE_NOT_CREATED +** ----------------------------------------------------- +** Test #4: Disk-full condition +** 1) Call this routine (NUM_TABLE_ENTRIES+1) of times +** 2) Expect the returned value to be (except the last call) +** (a) OS_FS_SUCCESS +** 3) Expect the returned value of the last call to be +** (a) OS_FS_ERR_DEVICE_NOT_FREE +** ----------------------------------------------------- +** Test #5: Nominal condition +** 1) Make sure no file system has been created previously +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 4) Call OS_rmfs with device name used in #1 as argument +** 5) Expect the returned value to be +** (a) OS_FS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_initfs_test() +{ + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + int32 res=0, idx=0, i=0, j=0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_initfs(NULL, NULL, NULL, g_blkSize, g_blkCnt); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_initfs_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if ((OS_initfs(g_fsAddrPtr, NULL, g_volNames[1], 0, 0) == + OS_FS_ERR_INVALID_POINTER) && + (OS_initfs(g_fsAddrPtr, g_devNames[1], NULL, 0, 0) == + OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if ((OS_initfs(g_fsAddrPtr, g_fsLongName, g_volNames[2], g_blkSize, g_blkCnt) == + OS_FS_ERR_PATH_TOO_LONG) && + (OS_initfs(g_fsAddrPtr, g_devNames[2], g_fsLongName, g_blkSize, g_blkCnt) == + OS_FS_ERR_PATH_TOO_LONG)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Disk-full"; + + UT_os_print_volumetable("VOLUME TABLE _BEFORE_ DISK-FULL TEST SETUP FOR OS_initfs()"); + + for (i=0; i <= NUM_TABLE_ENTRIES; i++) + { + memset(g_devNames[i], '\0', sizeof(g_devNames[i])); + UT_os_sprintf(g_devNames[i], "/ramdev%d", (int)i); + memset(g_volNames[i], '\0', sizeof(g_volNames[i])); + UT_os_sprintf(g_volNames[i], "RAM%d", (int)i); + res = OS_initfs(g_fsAddrPtr, g_devNames[i], g_volNames[i], g_blkSize, g_blkCnt); + if (res != OS_FS_SUCCESS) + break; + } + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ DISK-FULL TEST SETUP FOR OS_initfs()"); + + /* Only need to check the last call to OS_initfs() */ + if (res == OS_FS_ERR_DEVICE_NOT_FREE) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + for (j=0; j < i; j++) + OS_rmfs(g_devNames[j]); + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ DISK-FULL TEST TEARDOWN FOR OS_initfs()"); + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + UT_os_print_volumetable("VOLUME TABLE _BEFORE_ NOMINAL TEST SETUP FOR OS_initfs()"); + + if (OS_initfs(g_fsAddrPtr, g_devNames[5], g_volNames[5], g_blkSize, g_blkCnt) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_initfs_test_exit_tag; + } + + if (OS_rmfs(g_devNames[5]) == OS_FS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ NOMINAL TEST FOR OS_initfs()"); + +UT_os_initfs_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_initfs", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_mkfs(char *address, char *devname, char *volname, uint32 blocksize, uint32 numblocks) +** Purpose: Formats a volume with a file system +** Parameters: *address - a pointer to the address at which to start the new disk +** *devname - a pointer to the name of the "generic" device +** *volname - a pointer to the name of the volume (only used in vxWorks) +** blocksize - the size of a single block on the drive +** numblocks - the number of blocks to be allocated for the drive +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is NULL +** OS_FS_ERR_PATH_TOO_LONG if the name passed in is too long +** OS_FS_ERR_DRIVE_NOT_CREATED if the OS call failed +** OS_FS_ERR_DEVICE_NOT_FREE if the Volume table is full +** OS_FS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** NOTE: If OS_mkfs() is implemented, then OS_rmfs() should also be implemented. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as one of the arguments +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with some device name or volume name of length greater than +** Volume table's name +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup test to cause the OS call to fail inside this routine +** 2) Expect the returned value to be +** (a) OS_FS_ERR_DRIVE_NOT_CREATED +** ----------------------------------------------------- +** Test #4: Disk-full condition +** 1) Call this routine (NUM_TABLE_ENTRIES+1) of times +** 2) Expect the returned value to be (except the last call) +** (a) OS_FS_SUCCESS +** 3) Expect the returned value of the last call to be +** (a) OS_FS_ERR_DEVICE_NOT_FREE +** ----------------------------------------------------- +** Test #5: Nominal condition +** 1) Make sure no file system has been created previously +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 4) Call OS_rmfs with device name used in #1 as argument +** 5) Expect the returned value to be +** (a) OS_FS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_makefs_test() +{ + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + int32 res=0, idx=0, i=0, j=0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_mkfs(g_fsAddrPtr, NULL, NULL, g_blkSize, g_blkCnt); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_makefs_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if ((OS_mkfs(g_fsAddrPtr, NULL, g_volNames[1], 0, 0) == OS_FS_ERR_INVALID_POINTER) && + (OS_mkfs(g_fsAddrPtr, g_devNames[1], NULL, 0, 0) == OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if ((OS_mkfs(g_fsAddrPtr, g_fsLongName, g_volNames[2], g_blkSize, g_blkCnt) == + OS_FS_ERR_PATH_TOO_LONG) && + (OS_mkfs(g_fsAddrPtr, g_devNames[2], g_fsLongName, g_blkSize, g_blkCnt) == + OS_FS_ERR_PATH_TOO_LONG)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Disk-full"; + UT_os_print_volumetable("VOLUME TABLE _BEFORE_ DISK-FULL TEST SETUP FOR OS_mkfs()"); + + for (i=0; i <= NUM_TABLE_ENTRIES; i++) + { + memset(g_devNames[i], '\0', sizeof(g_devNames[i])); + UT_os_sprintf(g_devNames[i], "/ramdev%d", (int)i); + memset(g_volNames[i], '\0', sizeof(g_volNames[i])); + UT_os_sprintf(g_volNames[i], "RAM%d", (int)i); + res = OS_mkfs(g_fsAddrPtr, g_devNames[i], g_volNames[i], g_blkSize, g_blkCnt); + if (res != OS_FS_SUCCESS) + break; + } + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ DISK-FULL TEST SETUP FOR OS_mkfs()"); + + /* Only need to check the last call to OS_mkfs() */ + if (res == OS_FS_ERR_DEVICE_NOT_FREE) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + for (j=0; j < i; j++) + OS_rmfs(g_devNames[j]); + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ DISK-FULL TEST TEARDOWN FOR OS_mkfs()"); + + /*-----------------------------------------------------*/ + testDesc = "#5 Nominal"; + + UT_os_print_volumetable("VOLUME TABLE _BEFORE_ NOMINAL TEST SETUP FOR OS_mkfs()"); + + if (OS_mkfs(g_fsAddrPtr, g_devNames[5], g_volNames[5], g_blkSize, g_blkCnt) != OS_FS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + goto UT_os_makefs_test_exit_tag; + } + + if (OS_rmfs(g_devNames[5]) == OS_FS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ NOMINAL TEST FOR OS_mkfs()"); + +UT_os_makefs_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_mkfs", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_rmfs(char *devname) +** Purpose: Removes or un-maps the target file system +** Parameters: *devname - a pointer to the name of the "generic" drive +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is NULL +** OS_FS_ERROR if the given device is not found in the Volume table +** OS_FS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** NOTE: If OS_rmfs() is implemented, then OS_mkfs() should also be implemented. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-device-arg condition +** 1) Make sure no file system has been created previously +** 2) Call this routine with some device name as argument +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call OS_mkfs to create a file system +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call this routine with the device name used in #1 as argument +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call OS_mkfs to create a file system again exactly as in #1 +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_removefs_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_rmfs(NULL); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_removefs_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_rmfs(NULL) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-device-arg"; + + if (OS_rmfs(g_devNames[2]) == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + if (OS_mkfs(g_fsAddrPtr, g_devNames[3], g_volNames[3], g_blkSize, g_blkCnt) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - File-system-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_removefs_test_exit_tag; + } + + if ((OS_rmfs(g_devNames[3]) == OS_FS_SUCCESS) && + (OS_mkfs(g_fsAddrPtr, g_devNames[3], g_volNames[3], g_blkSize, g_blkCnt) == OS_FS_SUCCESS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_rmfs(g_devNames[3]); + +UT_os_removefs_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_rmfs", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_mount(const char *devname, char *mountpoint) +** Purpose: Mounts a disk volume to the file system tree +** Parameters: *devname - a pointer to the name of the drive to mount +** *mountpoint - a pointer to the name to call this disk from now on +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is NULL +** OS_FS_ERROR if the given device is not found in the Volume table +** OS_FS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** NOTE: If OS_mount() is implemented, then +** OS_mkfs(), OS_rmfs and OS_unmount should also be implemented. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-device-arg condition +** 1) Make sure no file system has been created previously +** 2) Call this routine with some device name as argument +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call OS_mkfs to create a file system +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call this routine with the device name used in #1 as argument +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call this routine again exactly as in #3 +** 6) Expect the returned value to be +** (a) OS_FS_ERROR +** 7) Call OS_unmount with the mount-point used in #3 as argument +** 8) Expect the returned value to be +** (a) OS_FS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_mount_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_mount(NULL, NULL); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_mount_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if ((OS_mount(NULL, g_mntNames[1]) == OS_FS_ERR_INVALID_POINTER) && + (OS_mount(g_devNames[1], NULL) == OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-device-arg"; + + if (OS_mount("ramdev0", g_mntNames[2]) == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + UT_os_print_volumetable("VOLUME TABLE _BEFORE_ NOMINAL TEST SETUP FOR OS_mount()"); + + if (OS_mkfs(g_fsAddrPtr, g_devNames[3], g_volNames[3], g_blkSize, g_blkCnt) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - File-system-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_mount_test_exit_tag; + } + + if ((OS_mount(g_devNames[3], g_mntNames[3]) == OS_FS_SUCCESS) && + (OS_mount(g_devNames[3], g_mntNames[3]) == OS_FS_ERROR)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ NOMINAL TEST FOR OS_mount()"); + + /* Reset test environment */ + OS_unmount(g_mntNames[3]); + OS_rmfs(g_devNames[3]); + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ NOMINAL TEST TEARDOWN FOR OS_mount()"); + +UT_os_mount_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_mount", idx) + UT_OS_LOG_API_MACRO(apiInfo)} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_unmount(const char *mountpoint) +** Purpose: Un-mounts a drive from the file system and makes all open file descriptors +** obsolete +** Parameters: *mountpoint - a pointer to the name of the drive to unmount +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is NULL +** OS_FS_ERR_PATH_TOO_LONG if the absolute path passed in is too long +** OS_FS_ERROR if the mount-point passed in is not found in the Volume table +** OS_FS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** NOTE: If OS_unmount() is implemented, then +** OS_mkfs(), OS_rmfs() and OS_mount() should also be implemented. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with some mount-point name of length greater than +** Volume table's name +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #3: Invalid-mount-point-arg condition +** 1) Make sure no file system has been created previously +** 2) Call this routine with some mount-point name as argument +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_mkfs to create a file system +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call OS_mount to mount the device to a mount-point +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call this routine with the mount-point used in #3 as argument +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 7) Call this routine again exactly as in #5 +** 8) Expect the returned value to be +** (a) OS_FS_ERROR +**--------------------------------------------------------------------------------*/ +void UT_os_unmount_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_unmount(NULL); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_unmount_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_unmount(NULL) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if (OS_unmount(g_fsLongName) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Invalid-mount-point-arg"; + + if (OS_unmount(g_mntNames[3]) == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_FS_SUCCESS) + { + testDesc = "#3 Nominal - File-system-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_unmount_test_exit_tag; + } + + if ((OS_mount(g_devNames[4], g_mntNames[4]) == OS_FS_SUCCESS) && + (OS_unmount(g_mntNames[4]) == OS_FS_SUCCESS) && + (OS_unmount(g_mntNames[4]) == OS_FS_ERROR)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_rmfs(g_devNames[4]); + +UT_os_unmount_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_unmount", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_FS_GetPhysDriveName(char *PhysDriveName, char *MountPoint) +** Purpose: Returns the name of the physical drive of a given mount-point +** Parameters: *PhysDriveName - a pointer that will hold the name of the physical drive +** *MountPoint - a pointer to the name of the mount-point +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is NULL +** OS_FS_ERR_PATH_TOO_LONG if the mount-point passed in is too long +** OS_FS_ERROR if the mount-point passed in is not found in the Volume table +** OS_FS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** NOTE: If OS_unmount() is implemented, then +** OS_mkfs(), OS_rmfs() and OS_mount() should also be implemented. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with some mount-point name of length greater than +** Volume table's name +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #3: Invalid-mount-point-arg condition +** 1) Call OS_mkfs +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call this routine +** 4) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_mkfs +** 2) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 3) Call OS_mount with device name used in #1 as argument +** 4) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 5) Call this routine with the device name used in #1 as argument +** 6) Expect the returned value to be +** (a) OS_FS_SUCCESS +** --------------------------------------------------------------------------------*/ +void UT_os_getphysdrivename_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + char physDevName[UT_OS_LG_TEXT_LEN]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_FS_GetPhysDriveName(NULL, NULL); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_getphysicaldrivename_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if ((OS_FS_GetPhysDriveName(NULL, g_mntNames[1]) == OS_FS_ERR_INVALID_POINTER) && + (OS_FS_GetPhysDriveName(physDevName, NULL) == OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if (OS_FS_GetPhysDriveName(physDevName, g_fsLongName) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Invalid-mount-point-arg"; + + if (OS_FS_GetPhysDriveName(physDevName, g_mntNames[3]) == OS_FS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-system-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_getphysicaldrivename_test_exit_tag; + } + + if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-system-mount failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_getphysicaldrivename_test_exit_tag; + } + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ NOMINAL TEST SETUP for OS_FS_GetPhysDriveName()"); + + memset(physDevName, '\0', sizeof(physDevName)); + if ((OS_FS_GetPhysDriveName(physDevName, g_mntNames[4]) == OS_FS_SUCCESS) && + (strncmp(physDevName, g_physDriveName, strlen(g_physDriveName)) == 0)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_unmount(g_mntNames[4]); + OS_rmfs(g_devNames[4]); + +UT_os_getphysicaldrivename_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_FS_GetPhysDriveName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) +** Purpose: Translates the given virtual path to the real path +** Parameters: *VirtualPath - pointer to the name of the virtual path or mount point +** *LocalPath - pointer that will hold the name of the local path or +** physical device name +** Returns: OS_FS_ERR_INVALID_POINTER if any of the pointers passed in is NULL +** OS_FS_ERR_PATH_TOO_LONG if the device name or volume name passed in is too long +** OS_FS_ERR_PATH_INVALID if the virtual path passed in is not in correct format, or +** virtual path name not found in the Volume table +** OS_FS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as one of the arguments +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with some device name or volume name of length greater than +** Volume table's name +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #3: Invalid-virtual-path-arg condition +** 1) Call this routine with a incorrectly formatted virtual path name as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_INVALID +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Make sure no file system has been created previously +** 2) Call OS_mkfs +** 3) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 4) Call OS_mount with device name used in #2 as argument +** 5) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 6) Call this routine with the mount-point used in #4 as argument +** 7) Expect the returned value to be +** (a) OS_FS_SUCCESS __and__ +** (b) the returned local path to be ? +** --------------------------------------------------------------------------------*/ +void UT_os_translatepath_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + char localPath[UT_OS_LG_TEXT_LEN]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TranslatePath(NULL, NULL); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_translatepath_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if ((OS_TranslatePath(NULL, localPath) == OS_FS_ERR_INVALID_POINTER) && + (OS_TranslatePath(g_mntNames[1], NULL) == OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if (OS_TranslatePath(g_fsLongName, localPath) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Invalid-virtual-path-arg"; + + if ((OS_TranslatePath("cf", localPath) == OS_FS_ERR_PATH_INVALID) && + (OS_TranslatePath("/foobar", localPath) == OS_FS_ERR_PATH_INVALID)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != + OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-system-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_translatepath_test_exit_tag; + } + + if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-system-mount failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + + /* Reset test environment */ + OS_rmfs(g_devNames[4]); + + goto UT_os_translatepath_test_exit_tag; + } + + if ((OS_TranslatePath(g_mntNames[4], localPath) == OS_FS_SUCCESS) && + (strncmp(localPath, g_physDriveName, strlen(g_physDriveName)) == 0)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_unmount(g_mntNames[4]); + OS_rmfs(g_devNames[4]); + +UT_os_translatepath_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TranslatePath (internal)", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: os_fshealth_t OS_chkfs(const char *name, boolean repair) +** Purpose: Checks the integrity of the file system, and may or may not repair it, +** depending on repair +** Parameters: *name - the name of the drive to check +** repair - boolean flag to repair or not to repair +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is NULL +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as one of the arguments +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: OS-call-failure condition +** 1) Setup the test to cause the OS call to fail inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test#3: Nominal condition +** 1) TBD - posix implementation is not yet implemented +** --------------------------------------------------------------------------------*/ +void UT_os_checkfs_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_chkfs(NULL, 0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_checkfs_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_chkfs(NULL, 0) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + if (g_skipTestCase == 3) + { + testDesc = "#3 Nominal - Not implemented in API"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, g_skipTestCaseResult) + } + else + { + /* TBD */ + } + +UT_os_checkfs_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_chkfs", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_fsBlocksFree(const char *name) +** Purpose: Returns the number of blocks free in a the file system +** Parameters: *name - a pointer to the name of the drive to check for free blocks +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is NULL +** OS_FS_ERR_PATH_TOO_LONG if the path passed in is too long +** OS_FS_ERROR if the OS call failed +** Number of blocks free in a volume if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as one of the arguments +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with a path name of length greater than Volume table's +** name as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup the test to cause the OS call to fail inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test#4: Nominal condition +** 1) Make sure no file system has been previously created +** 2) Call OS_mkfs +** 3) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 4) Call OS_mount with device name used in #2 +** 5) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 6) Call this routine with mount-point used in #4 +** 7) Expect the returned value to be +** (a) greater than or equal to 0 +** --------------------------------------------------------------------------------*/ +void UT_os_fsblocksfree_test() +{ + int32 idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_fsBlocksFree(NULL) == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_fsblocksfree_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if (OS_fsBlocksFree(NULL) == OS_FS_ERR_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if (OS_fsBlocksFree(g_fsLongName) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-system-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_fsblocksfree_test_exit_tag; + } + + if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-system-mount failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_fsblocksfree_test_exit_tag; + } + + if (OS_fsBlocksFree(g_mntNames[4]) >= 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_unmount(g_mntNames[4]); + OS_rmfs(g_devNames[4]); + +UT_os_fsblocksfree_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_fsBlocksFree", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) +** Purpose: Returns the number of bytes free in a the file system +** Parameters: *name - a pointer to the name of the drive to check for free bytes +** *bytes_free - a pointer that will hold the number of bytes free +** Returns: OS_FS_ERR_INVALID_POINTER if the pointer passed in is NULL +** OS_FS_ERROR if the OS call failed +** OS_FS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue. +** ----------------------------------------------------- +** Test #1: Null-pointer-arg condition +** 1) Call this routine with a null pointer as one of the arguments +** 2) Expect the returned value to be +** (a) OS_FS_ERR_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Path-too-long-arg condition +** 1) Call this routine with a path name of length greater than Volume table's +** name as argument +** 2) Expect the returned value to be +** (a) OS_FS_ERR_PATH_TOO_LONG +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** 1) Setup the test to cause the OS call to fail inside this routine +** 2) Call this routine +** 3) Expect the returned value to be +** (a) OS_FS_ERROR +** ----------------------------------------------------- +** Test#4: Nominal condition +** 1) Make sure no file system has been previously created +** 2) Call OS_mkfs +** 3) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 4) Call OS_mount with device name used in #2 +** 5) Expect the returned value to be +** (a) OS_FS_SUCCESS +** 6) Call this routine with mount-point used in #4 +** 7) Expect the returned value to be +** (a) greater than or equal to 0 +** --------------------------------------------------------------------------------*/ +void UT_os_fsbytesfree_test() +{ + int32 idx=0; + uint64 retBytes=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_fsBytesFree(NULL, NULL) == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_fsbytesfree_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if ((OS_fsBytesFree(NULL, &retBytes) == OS_FS_ERR_INVALID_POINTER) && + (OS_fsBytesFree(g_mntNames[1], NULL) == OS_FS_ERR_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Path-too-long-arg"; + + if (OS_fsBytesFree(g_fsLongName, &retBytes) == OS_FS_ERR_PATH_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-system-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_fsbytesfree_test_exit_tag; + } + + if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_FS_SUCCESS) + { + testDesc = "#4 Nominal - File-system-mount failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_fsbytesfree_test_exit_tag; + } + + if (OS_fsBytesFree(g_mntNames[4], &retBytes) == OS_FS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_unmount(g_mntNames[4]); + OS_rmfs(g_devNames[4]); + +UT_os_fsbytesfree_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_fsBytesFree", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_osfilesys_diskio_test.c +**================================================================================*/ diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h new file mode 100644 index 000000000..7d828dedd --- /dev/null +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h @@ -0,0 +1,60 @@ +/*================================================================================* +** File: ut_osfilesys_diskio_test.h +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSFILESYS_DISKIO_TEST_H_ +#define _UT_OSFILESYS_DISKIO_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_FILESYS_LIST_LEN (NUM_TABLE_ENTRIES + 10) + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_initfs_test(void); + +void UT_os_makefs_test(void); +void UT_os_removefs_test(void); + +void UT_os_mount_test(void); +void UT_os_unmount_test(void); + +void UT_os_getphysdrivename_test(void); +void UT_os_translatepath_test(void); + +void UT_os_checkfs_test(void); + +void UT_os_fsblocksfree_test(void); +void UT_os_fsbytesfree_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSFILESYS_DISKIO_TEST_H_ */ + +/*================================================================================* +** End of File: ut_osfilesys_diskio_test.h +**================================================================================*/ diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c new file mode 100644 index 000000000..d79d9f5fe --- /dev/null +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c @@ -0,0 +1,152 @@ +/*================================================================================* +** File: ut_osfilesys_test.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osfilesys_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_FS_BLOCK_SIZE 512 +#define UT_OS_FS_MAX_BLOCKS 20 + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +char* g_fsAddrPtr = NULL; + +int32 g_blkSize = UT_OS_FS_BLOCK_SIZE; +int32 g_blkCnt = UT_OS_FS_MAX_BLOCKS; + +int32 g_skipTestCase = -1; +char* g_skipTestCaseResult = " "; + +char g_fsLongName[OS_MAX_PATH_LEN+5]; +char g_physDriveName[OS_MAX_PATH_LEN]; + +char g_volNames[UT_OS_FILESYS_LIST_LEN][UT_OS_XS_TEXT_LEN]; +char g_devNames[UT_OS_FILESYS_LIST_LEN][UT_OS_XS_TEXT_LEN]; +char g_mntNames[UT_OS_FILESYS_LIST_LEN][UT_OS_XS_TEXT_LEN]; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_init_fs_misc(void); +void UT_os_init_checkfs_test(void); + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +void UT_os_init_fs_misc() +{ + memset(g_fsLongName, 'X', sizeof(g_fsLongName)); + g_fsLongName[0] = '/'; + g_fsLongName[sizeof(g_fsLongName)-1] = '\0'; + + strcpy(g_devNames[0], "/ramdev0"); + strcpy(g_volNames[0], " "); + strcpy(g_mntNames[0], "/drive0"); + + strcpy(g_devNames[1], "/ramdev1"); + strcpy(g_volNames[1], " "); + strcpy(g_mntNames[1], "/drive1"); + + strcpy(g_devNames[2], "/ramdev2"); + strcpy(g_volNames[2], " "); + strcpy(g_mntNames[2], "/drive2"); + + strcpy(g_devNames[3], "/ramdev3"); + strcpy(g_volNames[3], " "); + strcpy(g_mntNames[3], "/drive3"); + + strcpy(g_devNames[4], "/ramdev4"); + strcpy(g_volNames[4], " "); + strcpy(g_mntNames[4], "/drive4"); + + strcpy(g_devNames[5], "/ramdev5"); + strcpy(g_volNames[5], " "); + strcpy(g_mntNames[5], "/drive5"); + + strcpy(g_devNames[6], "/ramdev6"); + strcpy(g_volNames[6], " "); + strcpy(g_mntNames[6], "/drive6"); + + strcpy(g_devNames[7], "/ramdev7"); + strcpy(g_volNames[7], " "); + strcpy(g_mntNames[7], "/drive7"); +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_checkfs_test() +{ + g_skipTestCase = 3; + g_skipTestCaseResult = UT_OS_NA; +} + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ +#ifdef _OSAL_UNIT_TEST_ + void OS_Application_Startup(void) +#else + int main(int argc, char* argv[]) +#endif +{ + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for osfilesys APIs\n") + + OS_API_Init(); + + UT_os_print_volumetable("VOLUME TABLE _AFTER_ OS_API_Init() call"); + + UT_os_init_fs_misc(); + + UT_os_makefs_test(); + UT_os_initfs_test(); + UT_os_removefs_test(); + + UT_os_mount_test(); + UT_os_unmount_test(); + + UT_os_getphysdrivename_test(); + UT_os_translatepath_test(); + + UT_os_init_checkfs_test(); + UT_os_checkfs_test(); + + UT_os_fsblocksfree_test(); + UT_os_fsbytesfree_test(); + + UT_os_teardown("ut_osfilesys"); + + return (0); +} + +/*================================================================================* +** End of File: ut_osfilesys_test.c +**================================================================================*/ diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test.h b/src/unit-tests/osfilesys-test/ut_osfilesys_test.h new file mode 100644 index 000000000..32e1c3e45 --- /dev/null +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test.h @@ -0,0 +1,45 @@ +/*================================================================================* +** File: ut_osfilesys_test.h +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +#ifndef _UT_OSFILESYS_TEST_H_ +#define _UT_OSFILESYS_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" +#include "ut_osfilesys_diskio_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_LOG_FILENAME "ut_osfilesys_log.txt" + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSFILESYS_TEST_H_ */ + +/*================================================================================* +** End of File: ut_osfilesys_test.h +**================================================================================*/ diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test_arinc653.c b/src/unit-tests/osfilesys-test/ut_osfilesys_test_arinc653.c new file mode 100644 index 000000000..ec1323775 --- /dev/null +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test_arinc653.c @@ -0,0 +1,149 @@ +/*================================================================================* +** File: ut_osfilesys_test.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osfilesys_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_FS_BLOCK_SIZE 512 +#define UT_OS_FS_MAX_BLOCKS 20 + +#define UT_OS_FS_MEM_SPACE (2 * UT_OS_FS_BLOCK_SIZE * UT_OS_FS_MAX_BLOCKS) + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +char g_fsMemSpace[UT_OS_FS_MEM_SPACE]; /* This variable must not be moved. */ +char* g_fsAddrPtr = &g_fsMemSpace[3]; /* Offset to be 32-bit aligned, + which is important for the PIRD layer */ + +int32 g_blkSize = UT_OS_FS_BLOCK_SIZE; +int32 g_blkCnt = UT_OS_FS_MAX_BLOCKS; + +int32 g_skipTestCase = -1; +char* g_skipTestCaseResult = " "; + +char g_fsLongName[OS_MAX_PATH_LEN+5]; +char g_physDriveName[OS_MAX_PATH_LEN]; + +char g_volNames[UT_OS_FILESYS_LIST_LEN][UT_OS_XS_TEXT_LEN]; +char g_devNames[UT_OS_FILESYS_LIST_LEN][UT_OS_XS_TEXT_LEN]; +char g_mntNames[UT_OS_FILESYS_LIST_LEN][UT_OS_XS_TEXT_LEN]; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_init_fs_misc(void); +void UT_os_init_checkfs_test(void); + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +void UT_os_init_fs_misc() +{ + memset(g_fsLongName, 'X', sizeof(g_fsLongName)); + g_fsLongName[0] = '/'; + g_fsLongName[sizeof(g_fsLongName)-1] = '\0'; + + strcpy(g_devNames[0], "/ramdev0"); + strcpy(g_volNames[0], " "); + strcpy(g_mntNames[0], "/drive0"); + + strcpy(g_devNames[1], "/ramdev1"); + strcpy(g_volNames[1], " "); + strcpy(g_mntNames[1], "/drive1"); + + strcpy(g_devNames[2], "/ramdev2"); + strcpy(g_volNames[2], " "); + strcpy(g_mntNames[2], "/drive2"); + + strcpy(g_devNames[3], "/ramdev3"); + strcpy(g_volNames[3], " "); + strcpy(g_mntNames[3], "/drive3"); + + strcpy(g_devNames[4], "/ramdev4"); + strcpy(g_volNames[4], " "); + strcpy(g_mntNames[4], "/drive4"); + + strcpy(g_devNames[5], "/ramdev5"); + strcpy(g_volNames[5], " "); + strcpy(g_mntNames[5], "/drive5"); + + strcpy(g_devNames[6], "/ramdev6"); + strcpy(g_volNames[6], " "); + strcpy(g_mntNames[6], "/drive6"); + + strcpy(g_devNames[7], "/ramdev7"); + strcpy(g_volNames[7], " "); + strcpy(g_mntNames[7], "/drive7"); +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_checkfs_test() +{ + g_skipTestCase = 3; + g_skipTestCaseResult = UT_OS_NA; +} + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ + +void UT_main() +{ + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for ARINC653-implementation of osfilesys APIs\n") + + OS_API_Init(); + + UT_os_init_fs_misc(); + + UT_os_makefs_test(); + UT_os_initfs_test(); + UT_os_removefs_test(); + + UT_os_mount_test(); + UT_os_unmount_test(); + + UT_os_getphysdrivename_test(); + UT_os_translatepath_test(); + + UT_os_init_checkfs_test(); + UT_os_checkfs_test(); + + UT_os_fsblocksfree_test(); + UT_os_fsbytesfree_test(); + + UT_os_teardown("ut_osfilesys"); +} + +/*================================================================================* +** End of File: ut_osfilesys_test.c +**================================================================================*/ diff --git a/src/unit-tests/osloader-test/ut_module.c b/src/unit-tests/osloader-test/ut_module.c new file mode 100644 index 000000000..cb4e048fc --- /dev/null +++ b/src/unit-tests/osloader-test/ut_module.c @@ -0,0 +1,8 @@ +void MODULE_NAME(void) +{ + volatile int i; + i = 1; + return; +} + + diff --git a/src/unit-tests/osloader-test/ut_osloader_module_test.c b/src/unit-tests/osloader-test/ut_osloader_module_test.c new file mode 100644 index 000000000..94bb172e4 --- /dev/null +++ b/src/unit-tests/osloader-test/ut_osloader_module_test.c @@ -0,0 +1,454 @@ +/*================================================================================* +** File: ut_osloader_module_test.c +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osloader_module_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#ifndef OS_INCLUDE_MODULE_LOADER +#define OS_MAX_MODULES 10 +#endif /* !OS_INCLUDE_MODULE_LOADER */ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: OS_ModuleTableInit +** Purpose: Initialize the tables that the OS API uses to keep track of information +** about objects +** Parameters: To-be-filled-in +** Returns: OS_ERROR on an unsuccessful inits +** OS_SUCCESS on a successful inits +**--------------------------------------------------------------------------------*/ +void UT_os_module_table_init_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "#1 Init-not-call-first - Manual inspection required"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_MIR) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + res = OS_ModuleTableInit(); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + testDesc = "API Not implemented"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + } + else if (res == OS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_ModuleTableInit", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_ModuleLoad +** Purpose: Loads the new ELF object module into the RTOS +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NO_FREE_IDS if the module table is full +** OS_ERR_NAME_TAKEN if the module name has already been used +** OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_module_load_test() +{ + int i; + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 test_setup_invalid = 0; + uint32 module_id; + uint32 module_id2; + char module_name[OS_MAX_API_NAME]; + char module_file_name[OS_MAX_API_NAME]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + res = OS_ModuleLoad(0, "TestModule","/cf/module.so"); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_module_load_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg-1"; + + res = OS_ModuleLoad(0, "TestModule", "/cf/module.so"); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Null-pointer-arg-2"; + + res = OS_ModuleLoad(&module_id, 0, "/cf/module.so"); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Null-pointer-arg-3"; + + res = OS_ModuleLoad(&module_id, "TestModule", 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 No-free-IDs"; + + /* Setup */ + for ( i = 0; i< OS_MAX_MODULES; i++ ) + { + memset(module_name, '\0', sizeof(module_name)); + UT_os_sprintf(module_name, "MODULE%d",i); + memset(module_file_name, '\0', sizeof(module_file_name)); + UT_os_sprintf(module_file_name, "/cf/MODULE%d.so",i); + res = OS_ModuleLoad(&module_id, module_name, module_file_name); + if ( res != OS_SUCCESS ) + { + testDesc = "#4 No-free-IDs - Module Load failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + test_setup_invalid = 1; + break; + } + } + + if ( test_setup_invalid == 0 ) + { + res = OS_ModuleLoad(&module_id, "OneTooMany", "/cf/MODULE1.so"); + if (res == OS_ERR_NO_FREE_IDS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + } + /* Reset test environment */ + for ( i = 0; i< OS_MAX_MODULES; i++ ) + { + res = OS_ModuleUnload(i); /* Ignore errors, does not matter here */ + } + + /*-----------------------------------------------------*/ + testDesc = "#5 Duplicate-name"; + + /* Setup */ + res = OS_ModuleLoad(&module_id2, "DUPLICATE", "/cf/MODULE1.so"); + if ( res != OS_SUCCESS ) + { + testDesc = "#5 Duplicate-name - Module Load failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_ModuleLoad(&module_id, "DUPLICATE", "/cf/MODULE1.so"); + if (res == OS_ERR_NAME_TAKEN) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_ModuleUnload(module_id2); + } + + /*-----------------------------------------------------*/ + testDesc = "#6 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#7 Nominal"; + + res = OS_ModuleLoad(&module_id, "Good", "/cf/MODULE1.so"); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_ModuleUnload(module_id); + +UT_os_module_load_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_ModuleLoad", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_ModuleUnload +** Purpose: Unloads the module from the running RTOS +** Parameters: To-be-filled-in +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid module id +** OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_module_unload_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 module_id = 0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + res = OS_ModuleUnload(0); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_module_unload_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-ID-arg"; + + res = OS_ModuleUnload(99999); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_ModuleLoad(&module_id, "Good", "/cf/MODULE1.so"); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Module Load failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_ModuleUnload(module_id); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + +UT_os_module_unload_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_ModuleUnload", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_ModuleInfo +** Purpose: Returns module information about a given module id +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_INVALID_ID if the id passed in is not a valid module id +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_module_info_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 module_id; + OS_module_record_t module_info; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + res = OS_ModuleInfo(0, &module_info); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_module_info_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-pointer-arg"; + + res = OS_ModuleInfo(0, NULL); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-ID-arg"; + + res = OS_ModuleInfo(99999, &module_info); + if ( res == OS_ERR_INVALID_ID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* Setup */ + res = OS_ModuleLoad(&module_id, "Good", "/cf/MODULE1.so"); + if ( res != OS_SUCCESS ) + { + testDesc = "#3 Nominal - Module Load failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + res = OS_ModuleInfo(module_id, &module_info); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + res = OS_ModuleUnload(module_id); + } + +UT_os_module_info_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_ModuleInfo", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_osloader_module_test.c +**================================================================================*/ diff --git a/src/unit-tests/osloader-test/ut_osloader_module_test.h b/src/unit-tests/osloader-test/ut_osloader_module_test.h new file mode 100644 index 000000000..e33fe9570 --- /dev/null +++ b/src/unit-tests/osloader-test/ut_osloader_module_test.h @@ -0,0 +1,47 @@ +/*================================================================================* +** File: ut_osloader_module_test.h +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSLOADER_MODULE_TEST_H_ +#define _UT_OSLOADER_MODULE_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_module_table_init_test(void); +void UT_os_module_load_test(void); +void UT_os_module_unload_test(void); +void UT_os_module_info_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSLOADER_MODULE_TEST_H_ */ + +/*================================================================================* +** End of File: ut_osloader_module_test.h +**================================================================================*/ diff --git a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c new file mode 100644 index 000000000..5db714204 --- /dev/null +++ b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c @@ -0,0 +1,273 @@ +/*================================================================================* +** File: ut_osloader_symtable_test.c +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osloader_symtable_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: OS_SymbolLookup +** Purpose: Returns the memory address of a symbol +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERROR if the symbol name is not found +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ + +void UT_os_symbol_lookup_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 symbol_addr; + uint32 module_id = 0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + res = OS_SymbolLookup(&symbol_addr, "main"); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_symbol_lookup_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-pointer-arg-1"; + + res = OS_SymbolLookup(0, "main"); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-pointer-arg-2"; + + res = OS_SymbolLookup(&symbol_addr, 0); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Symbol-not-found"; + + res = OS_SymbolLookup(&symbol_addr, "ThisSymbolIsNotFound"); + if ( res == OS_ERROR ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + /* Setup */ + res = OS_ModuleLoad(&module_id, "Mod0", "/cf/MODULE0.so"); + if ( res != OS_SUCCESS ) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, "#4 Nominal - Module Load failed", UT_OS_TSF) + } + else + { + res = OS_SymbolLookup(&symbol_addr, "module0"); + if (res == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + res = OS_ModuleUnload(module_id); + } + +UT_os_symbol_lookup_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_SymbolLookup", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: OS_SymbolTableDump +** Purpose: Dumps the system symbol table to the given filename +** Parameters: To-be-filled-in +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_FS_ERR_PATH_INVALID if the filename is invalid +** OS_ERROR if there was any problem writing the symbol table to the file +** OS_SUCCESS if succeeded +**--------------------------------------------------------------------------------*/ +void UT_os_symbol_table_dump_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + uint32 size_limit; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + res = OS_SymbolTableDump("/cf/SymbolFile.dat", 32000); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_symbol_table_dump_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-pointer-arg"; + + res = OS_SymbolTableDump(0,10000); + if ( res == OS_INVALID_POINTER ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-path"; + + res = OS_SymbolTableDump("/this/path/is/invalid.dat", 10000); + if ( res == OS_FS_ERR_PATH_INVALID ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + /* Setup */ + res = OS_SymbolTableDump("/cf/SymbolFile.dat", 32000); + if ( res == OS_SUCCESS ) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_symbol_table_dump_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_SymbolTableDump", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_osloader_symtable_test.c +**================================================================================*/ diff --git a/src/unit-tests/osloader-test/ut_osloader_symtable_test.h b/src/unit-tests/osloader-test/ut_osloader_symtable_test.h new file mode 100644 index 000000000..653a31380 --- /dev/null +++ b/src/unit-tests/osloader-test/ut_osloader_symtable_test.h @@ -0,0 +1,45 @@ +/*================================================================================* +** File: ut_osloader_symtable_test.h +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSLOADER_SYMTABLE_TEST_H_ +#define _UT_OSLOADER_SYMTABLE_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_symbol_lookup_test(void); +void UT_os_symbol_table_dump_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSLOADER_SYMTABLE_TEST_H_ */ + +/*================================================================================* +** End of File: ut_osloader_symtable_test.h +**================================================================================*/ diff --git a/src/unit-tests/osloader-test/ut_osloader_test.c b/src/unit-tests/osloader-test/ut_osloader_test.c new file mode 100644 index 000000000..2f4f45513 --- /dev/null +++ b/src/unit-tests/osloader-test/ut_osloader_test.c @@ -0,0 +1,72 @@ +/*================================================================================* +** File: ut_osloader_test.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osloader_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ +#ifdef _OSAL_UNIT_TEST_ + void OS_Application_Startup(void) +#else + int main(int argc, char* argv[]) +#endif +{ + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for osloader APIs\n"); + + OS_API_Init(); + + UT_os_module_table_init_test(); + UT_os_module_load_test(); + UT_os_module_unload_test(); + UT_os_module_info_test(); + + UT_os_symbol_lookup_test(); + UT_os_symbol_table_dump_test(); + + UT_os_teardown("ut_osloader"); + + return (0); +} + +/*================================================================================* +** End of File: ut_osloader_test.c +**================================================================================*/ diff --git a/src/unit-tests/osloader-test/ut_osloader_test.h b/src/unit-tests/osloader-test/ut_osloader_test.h new file mode 100644 index 000000000..4d134b25b --- /dev/null +++ b/src/unit-tests/osloader-test/ut_osloader_test.h @@ -0,0 +1,50 @@ +/*================================================================================* +** File: ut_osloader_test.h +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +#ifndef _UT_OSLOADER_TEST_H_ +#define _UT_OSLOADER_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" +#include "ut_osloader_symtable_test.h" +#include "ut_osloader_module_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_LOG_FILENAME "ut_osloader_log.txt" + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +#ifdef _ARINC653_OS_ +void UT_main(void); +#endif /* _ARINC653_OS_ */ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSLOADER_TEST_H_ */ + +/*================================================================================* +** End of File: ut_osloader_test.h +**================================================================================*/ diff --git a/src/unit-tests/osloader-test/ut_osloader_test_arinc653.c b/src/unit-tests/osloader-test/ut_osloader_test_arinc653.c new file mode 100644 index 000000000..bf4155c97 --- /dev/null +++ b/src/unit-tests/osloader-test/ut_osloader_test_arinc653.c @@ -0,0 +1,7 @@ +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ + +void UT_main() +{ +} diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c new file mode 100644 index 000000000..16b1af0a3 --- /dev/null +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c @@ -0,0 +1,278 @@ +/*================================================================================* +** File: ut_osnetwork_misc_test.c +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osnetwork_misc_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_NetworkGetID(void) +** Purpose: Returns network ID of the machine it is on +** Parameters: None +** Returns: OS_ERROR if the OS call failed +** OS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: OS-call-failure condition +** 1) Cause the OS call to fail +** 2) Expect the returned value to be +** (a) OS_ERROR +** ----------------------------------------------------- +** Test #2: Nominal condition +** 1) Call this routine +** 2) Expect the returned value to be +** (a) OS_ERR_NOT_IMPLEMENTED __or__ +** (b) host id of value greater than 0 +**--------------------------------------------------------------------------------*/ +void UT_os_networkgetid_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + res = OS_NetworkGetID(); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_networkgetid_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#2 Nominal"; + + res = OS_NetworkGetID(); + if (res > 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_networkgetid_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_NetworkGetID", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_NetworkGetHostName(char *host_name, uint32 name_len) +** Purpose: Returns the network name of the machine it is on +** Parameters: *host_name - pointer that will hold the network name of the machine it is on +** name_len - the maximum length of the memory address host_name points to +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERROR if the OS call failed or name length passed in is 0 +** OS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Null-pointer-argument condition +** - Call this routine with a null pointer as one of the arguments +** - Expect the returned value to be +** (a) OS_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Zero-name-length-arg condition +** - Call this routine with 0 as the argument for name length +** - Expect the returned value to be +** (a) OS_ERROR +** ----------------------------------------------------- +** Test #3: OS-call-failure condition +** - Cause the OS call to fail +** - Expect the returned value to be +** (a) OS_ERROR +** ----------------------------------------------------- +** Test #4: Nominal condition +** - Call this routine with all valid arguments +** - Expect the returned value to be +** (a) OS_SUCCESS, _and_ +** (b) the returned buffer to be non-empty +**--------------------------------------------------------------------------------*/ +void UT_os_networkgethostname_test() +{ + UT_OsApiInfo_t apiInfo; + int32 res = 0, idx = 0; + const char* testDesc = NULL; + char buffer[UT_OS_XS_TEXT_LEN]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API Not implemented"; + + res = OS_NetworkGetHostName(buffer, sizeof(buffer)); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_networkgethostname_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + res = OS_NetworkGetHostName(NULL, 0); + if (res == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Zero-name-length-arg"; + + res = OS_NetworkGetHostName(buffer, 0); + if (res == OS_ERROR) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 OS-call-failure"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + res = OS_NetworkGetHostName(buffer, sizeof(buffer)); + if (res == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + +UT_os_networkgethostname_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_NetworkGetHostName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_osnetwork_misc_test.c +**================================================================================*/ diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.h b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.h new file mode 100644 index 000000000..014b0ce47 --- /dev/null +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.h @@ -0,0 +1,45 @@ +/*================================================================================* +** File: ut_osnetwork_misc_test.h +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSNETWORK_MISC_TEST_H_ +#define _UT_OSNETWORK_MISC_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_networkgetid_test(void); +void UT_os_networkgethostname_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSNETWORK_MISC_TEST_H_ */ + +/*================================================================================* +** End of File: ut_osnetwork_misc_test.h +**================================================================================*/ diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_test.c b/src/unit-tests/osnetwork-test/ut_osnetwork_test.c new file mode 100644 index 000000000..9cb3d4439 --- /dev/null +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_test.c @@ -0,0 +1,67 @@ +/*================================================================================* +** File: ut_osnetwork_test.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_osnetwork_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ +#ifdef _OSAL_UNIT_TEST_ + void OS_Application_Startup(void) +#else + int main(int argc, char* argv[]) +#endif +{ + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for osnetwork APIs\n"); + + OS_API_Init(); + + UT_os_networkgetid_test(); + UT_os_networkgethostname_test(); + + UT_os_teardown("ut_osnetwork"); + + return (0); +} + +/*================================================================================* +** End of File: ut_osnetwork_test.c +**================================================================================*/ diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_test.h b/src/unit-tests/osnetwork-test/ut_osnetwork_test.h new file mode 100644 index 000000000..15018ee0f --- /dev/null +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_test.h @@ -0,0 +1,49 @@ +/*================================================================================* +** File: ut_osnetwork_test.h +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +#ifndef _UT_OSNETWORK_TEST_H_ +#define _UT_OSNETWORK_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" +#include "ut_osnetwork_misc_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_LOG_FILENAME "ut_osnetwork_log.txt" + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +#ifdef _ARINC653_OS_ +void UT_main(void); +#endif /* _ARINC653_OS_ */ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSNETWORK_TEST_H_ */ + +/*================================================================================* +** End of File: ut_osnetwork_test.h +**================================================================================*/ diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_test_arinc653.c b/src/unit-tests/osnetwork-test/ut_osnetwork_test_arinc653.c new file mode 100644 index 000000000..45e198785 --- /dev/null +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_test_arinc653.c @@ -0,0 +1,3 @@ +void UT_main(void) +{ +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf.c b/src/unit-tests/osprintf-test/ut_osprintf.c new file mode 100644 index 000000000..7a89f3286 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf.c @@ -0,0 +1,279 @@ +/* + * ut_osprintf.c + * + * Created on: May 20, 2013 + * Author: Kevin McCluney + */ + +/* +** Includes +*/ +#include "ut_osprintf.h" +#ifdef UT_DO_OFFSET +#include "ut_osprintf_offset.h" +#endif + +#ifndef OSP_ARINC653 +#include + +FILE *UT_logfile; +#endif + +/* +** Global variables +*/ +unsigned OS_printf_enabled = 1; +int ut_passed; +int ut_failed; +char cMsg[UT_MAX_MESSAGE_LENGTH]; +char cNum[UT_MAX_MESSAGE_LENGTH]; +char strg_buf[BUF_LEN]; +char trunc_buf[BUF_LEN]; +char fill_strg[BUF_LEN]; + +/* +** Functions +*/ +#ifdef OSP_ARINC653 +int os_printf_main() +#else +int main() +#endif +{ + int i; + +#ifndef OSP_ARINC653 + UT_logfile = fopen("ut_osal_osprintf_log.txt", "w"); +#endif + +#ifdef OS_USE_EMBEDDED_PRINTF + UT_Text("Using replacement printf functions\n\n"); +#else + UT_Text("Using standard printf functions\n\n"); +#endif + + for (i = 0; i < BUF_LEN; i++) + { + fill_strg[i] = '*'; + } + + ut_passed = 0; + ut_failed = 0; + + /* Test sprintf and snprintf for each format */ + UT_osprintf_d(); + UT_osprintf_i(); + UT_osprintf_u(); + UT_osprintf_x(); + UT_osprintf_X(); + UT_osprintf_p(); + UT_osprintf_c(); + UT_osprintf_s(); + UT_osprintf_ld(); + UT_osprintf_li(); + UT_osprintf_lu(); + UT_osprintf_lx(); + UT_osprintf_lX(); + +#ifdef UT_DO_FLOAT + UT_osprintf_f(); + UT_osprintf_lf(); + UT_osprintf_misc(); +#endif + +#ifdef OS_USE_EMBEDDED_PRINTF + UT_osprintf_printf(); +#endif + + UT_ReportFailures(); + +#ifdef UT_DO_OFFSET + /* Calculate argument offsets for cFE variadic functions */ + UT_osprintf_CalcOffsets(); +#endif + + return 0; +} + +/* +** Initialize string buffer to all asterisks +*/ +void init_test(void) +{ + memcpy(strg_buf, fill_strg, BUF_LEN); +} + +/* +** Compare expected string output to actual string output; return +** pass/fail result +*/ +int check_test(char *expected, char *actual) +{ + int result = UT_PASS; + + if (memcmp(expected, actual, strlen(expected) + 1)) + { + strcpy(cMsg, " Mismatch: exp = ["); + strcat(cMsg, expected); + strcat(cMsg, "], act = ["); + strcat(cMsg, actual); + strcat(cMsg, "]\n"); + UT_Text(cMsg); + result = UT_FAIL; + } + + return result; +} + +/* +** Output text +*/ +void UT_Text(char *out_text) +{ +#ifdef OSP_ARINC653 + TUTF_print(out_text); +#else + fprintf(UT_logfile, "%s", out_text); + fflush(UT_logfile); +#endif +} + +/* +** Output result of a test +*/ +void UT_Report(int test, char *fun_name, char *info, + char *test_num, char *test_seq) +{ + if (test == UT_PASS) + { +#ifdef UT_SHOW_PASS + strcpy(cMsg, "PASSED ["); + strcat(cMsg, fun_name); + strcat(cMsg, "."); + strcat(cMsg, test_num); + strcat(cMsg, "."); + strcat(cMsg, test_seq); + strcat(cMsg, "] "); + strcat(cMsg, info); + strcat(cMsg, "\n-----\n"); + UT_Text(cMsg); +#endif + ut_passed++; + } + else + { + strcpy(cMsg, "FAILED ["); + strcat(cMsg, fun_name); + strcat(cMsg, "."); + strcat(cMsg, test_num); + strcat(cMsg, "."); + strcat(cMsg, test_seq); + strcat(cMsg, "] "); + strcat(cMsg, info); + strcat(cMsg, "\n-----\n"); + UT_Text(cMsg); + ut_failed++; + } +} + +/* +** Convert an integer to its character representation +*/ +void UT_itoa(int value, char *string, int radix, int out_len) +{ + char revertedStr[50]; + int revertedLength = 0; + unsigned int length = 0; + unsigned int neg = 0; + unsigned int digit_value = 0; + unsigned int uvalue; + + if ((radix == 10) && (value < 0)) + { + neg = 1; + uvalue = -value; + } + else + { + uvalue = (unsigned int) value; + } + + revertedLength = 0; + + while (uvalue >= radix) + { + digit_value = uvalue % radix; + + if (digit_value >= 10) + { + revertedStr[revertedLength] = digit_value - 10 + 'a'; + } + else + { + revertedStr[revertedLength] = digit_value + '0'; + } + + uvalue /= radix; + revertedLength++; + } + + if (uvalue >= 10) + { + revertedStr[revertedLength] = uvalue - 10 + 'a'; + } + else + { + revertedStr[revertedLength] = uvalue + '0'; + } + + if (neg == 1) + { + string[length] = '-'; + length++; + } + + if (revertedLength < out_len - 1) + { + while (revertedLength < out_len - 1) + { + revertedLength++; + revertedStr[revertedLength] = '0'; + } + } + + while (revertedLength >= 0) + { + string[length] = revertedStr[revertedLength]; + revertedLength--; + length++; + } + + string[length] = '\0'; +} + +/* +** Output summary of test results (# of passed & failed tests) +*/ +void UT_ReportFailures(void) +{ + char cNum[10]; + + strcpy(cMsg, "\nosprintf PASSED "); + UT_itoa(ut_passed, cNum, 10, 0); + strcat(cMsg, cNum); + strcat(cMsg, " tests.\n"); + strcat(cMsg, "osprintf FAILED "); + UT_itoa(ut_failed, cNum, 10, 0); + strcat(cMsg, cNum); + strcat(cMsg, " tests.\n"); + UT_Text(cMsg); + +#ifndef OSP_ARINC653 + printf("\nosprintf PASSED %d tests.\nosprintf FAILED %d tests.\n\n", + ut_passed, ut_failed); + + /* Ensure everything gets written */ + fflush(stdout); + fclose(UT_logfile); +#endif +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf.h b/src/unit-tests/osprintf-test/ut_osprintf.h new file mode 100644 index 000000000..52a7db4c8 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf.h @@ -0,0 +1,87 @@ +/* + * ut_osprintf.h + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#ifndef UT_OSPRINTF_H_ +#define UT_OSPRINTF_H_ + +/* +** Includes +*/ +#include +#include +#include "osprintf.h" + +/* printf Replacement Unit Test Compiler Flags + - Define UT_SHOW_PASS in order to display passing tests; if undefined then + only the failed tests are displayed. In either case the total number of + tests passes and failed are displayed + - Define UT_DO_FLOAT to test floating point printf's + - Define UT_DO_OFFSET when compiling on the GHS target to perform tests to + determine variable parameter offset values for the cFE variadic functions + - Define OSP_GHS to compile on the GHS platform + osprintf Compiler Flags + - Define OS_USE_EMBEDDED_PRINTF to test the replacement printf functions; + undefine it to test the standard printf functions + - Define OSP_ARINC653 if using embedded (replacement) printf functions + and compiling on the GHS target using cFE modified for ARINC653 +*/ + +#ifdef OS_USE_EMBEDDED_PRINTF +#ifndef OSP_GHS +int putchar(int); +#endif +#else +#include +#endif + +/* +** Macro Definitions +*/ +#define BUF_LEN 200 +#define UT_MAX_MESSAGE_LENGTH 300 +#define UT_TRUE 1 +#define UT_FALSE 0 +#define UT_PASS 0 +#define UT_FAIL 1 + +/* +** Function prototypes +*/ +void init_test(void); +int check_test(char *expected, char *actual); + +void UT_osprintf_d(void); +void UT_osprintf_i(void); +void UT_osprintf_u(void); +void UT_osprintf_x(void); +void UT_osprintf_X(void); +void UT_osprintf_p(void); +void UT_osprintf_c(void); +void UT_osprintf_s(void); +void UT_osprintf_ld(void); +void UT_osprintf_li(void); +void UT_osprintf_lu(void); +void UT_osprintf_lx(void); +void UT_osprintf_lX(void); + +#ifdef UT_DO_FLOAT +void UT_osprintf_f(void); +void UT_osprintf_lf(void); +void UT_osprintf_misc(void); +#endif + +#ifdef OS_USE_EMBEDDED_PRINTF +void UT_osprintf_printf(void); +#endif + +void UT_Text(char *out_text); +void UT_Report(int test, char *fun_name, char *info, + char *test_num, char *test_seq); +void UT_itoa(int value, char *string, int radix, int out_len); +void UT_ReportFailures(void); + +#endif /* UT_OSPRINTF_H_ */ diff --git a/src/unit-tests/osprintf-test/ut_osprintf_c.c b/src/unit-tests/osprintf-test/ut_osprintf_c.c new file mode 100644 index 000000000..f7cc90f1d --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_c.c @@ -0,0 +1,70 @@ +/* + * UT_osprintf_c.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %c format + *****************************************************************************/ +void UT_osprintf_c(void) +{ + char *test_fmt = "c"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + char test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 'k', 1, "%c", "k", "%c"}, + {"02", 'w', 5, "$$$%c$$$", "$$$w$$$", "%c embedded"}, + {"03", '?', 19, "%20c", " ?", "%c with minimum field size"}, + {"04", 'Q', 2, "%.10c", "Q", "%c with maximum field size"}, + {"05", '>', 5, "%7.9c", " >", "%c with minimum and maximum field size"}, + {"06", '#', 17, "%-20c", "# ", "%c with left-justify"}, + {"07", 'H', 2, "%+c", "H", "%c with sign"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_d.c b/src/unit-tests/osprintf-test/ut_osprintf_d.c new file mode 100644 index 000000000..0b4479f40 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_d.c @@ -0,0 +1,128 @@ +/* + * UT_osprintf_d.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %d format + *****************************************************************************/ +void UT_osprintf_d(void) +{ + char *test_fmt = "d"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 98765, 5, "%d", "98765", "%d only"}, + {"02", 46372, 8, "$$$%d$$$", "$$$46372$$$", "%d embedded, positive value"}, + {"03", 98765, 5, "% d", " 98765", "%d with space for sign, positive value"}, + {"04", 91827, 6, "%8d", " 91827", "%d with minimum field size > number of digits, positive value"}, + {"05", 91827, 4, "%4d", "91827", "%d with minimum field size < number of digits, positive value"}, + {"06", 33225, 8, "%.10d", "0000033225", "%d with precision field size > number of digits, positive value"}, + {"07", 33225, 5, "%.3d", "33225", "%d with precision field size < number of digits, positive value"}, + {"08", 12345, 8, "%9.7d", " 0012345", "%d with minimum field size > precision field size > number of digits, positive value"}, + {"09", 12345, 6, "%9.3d", " 12345", "%d with minimum field size > number of digits > precision field size, positive value"}, + {"10", 12345, 3, "%4.2d", "12345", "%d with number of digits > minimum field size > precision field size, positive value"}, + {"11", 12345, 7, "%7.9d", "000012345", "%d with precision field size > minimum field size > number of digits, positive value"}, + {"12", 12345, 8, "%3.9d", "000012345", "%d with precision field size > number of digits > minimum field size, positive value"}, + {"13", 12345, 4, "%2.4d", "12345", "%d with number of digits > precision field size > minimum field size, positive value"}, + {"14", 98765, 17, "%-.20d", "00000000000000098765", "%d with left-justify and precision field size > number of digits, positive value"}, + {"15", 98765, 5, "%-.3d", "98765", "%d with left-justify and precision field size < number of digits, positive value"}, + {"16", 98765, 4, "%+d", "+98765", "%d with sign, positive value"}, + {"17", 46372, 9, "$$$%+d$$$", "$$$+46372$$$", "%d sign and embedded, positive value"}, + {"18", 91827, 8, "%+8d", " +91827", "%d with sign and minimum field size > number of digits, positive value"}, + {"19", 91827, 5, "%+4d", "+91827", "%d with sign and minimum field size < number of digits, positive value"}, + {"20", 33225, 10, "%+.10d", "+0000033225", "%d with sign and precision field size > number of digits, positive value"}, + {"21", 33225, 4, "%+.3d", "+33225", "%d with sign and precision field size < number of digits, positive value"}, + {"22", 12345, 6, "%+9.7d", " +0012345", "%d with sign and minimum field size > precision field size > number of digits, positive value"}, + {"23", 12345, 7, "%+9.3d", " +12345", "%d with sign and minimum field size > number of digits > precision field size, positive value"}, + {"24", 12345, 2, "%+4.2d", "+12345", "%d with sign and number of digits > minimum field size > precision field size, positive value"}, + {"25", 12345, 6, "%+7.9d", "+000012345", "%d with sign and precision field size > minimum field size > number of digits, positive value"}, + {"26", 12345, 8, "%+3.9d", "+000012345", "%d with sign and precision field size > number of digits > minimum field size, positive value"}, + {"27", 12345, 5, "%+2.4d", "+12345", "%d with sign and number of digits > precision field size > minimum field size, positive value"}, + {"28", 98765, 16, "%+-.20d", "+00000000000000098765", "%d with sign and left-justify and precision field size > number of digits, positive value"}, + {"29", 98765, 5, "%+-.3d", "+98765", "%d with sign and left-justify and precision field size < number of digits, positive value"}, + {"30", 98765, 3, "%+d", "+98765", "%d with sign, positive value"}, + {"31", -98765, 2, "%d", "-98765", "%d, negative value"}, + {"32", -46372, 8, "$$$%d$$$", "$$$-46372$$$", "%d embedded, negative value"}, + {"33", -98765, 5, "% d", "-98765", "%d with space for sign, negative value"}, + {"34", -91827, 9, "%10d", " -91827", "%d with minimum field size > number of digits, negative value"}, + {"35", -91827, 5, "%4d", "-91827", "%d with minimum field size < number of digits, negative value"}, + {"36", -33225, 7, "%.10d", "-0000033225", "%d with precision field size > number of digits, negative value"}, + {"37", -33225, 4, "%.3d", "-33225", "%d with precision field size < number of digits, negative value"}, + {"38", -12345, 8, "%9.7d", " -0012345", "%d with minimum field size > precision field size > number of digits, negative value"}, + {"39", -12345, 9, "%9.3d", " -12345", "%d with minimum field size > number of digits > precision field size, negative value"}, + {"40", -12345, 5, "%4.2d", "-12345", "%d with number of digits > minimum field size > precision field size, negative value"}, + {"41", -12345, 7, "%7.9d", "-000012345", "%d with precision field size > minimum field size > number of digits, negative value"}, + {"42", -12345, 8, "%3.9d", "-000012345", "%d with precision field size > number of digits > minimum field size, negative value"}, + {"43", -12345, 5, "%2.4d", "-12345", "%d with number of digits > precision field size > minimum field size, negative value"}, + {"44", -98765, 20, "%-.20d", "-00000000000000098765", "%d with left-justify and precision field size > number of digits, negative value"}, + {"45", -98765, 5, "%-.3d", "-98765", "%d with left-justify and precision field size < number of digits, negative value"}, + {"46", -98765, 6, "%+d", "-98765", "%d with sign, negative value"}, + {"47", -46372, 8, "$$$%+d$$$", "$$$-46372$$$", "%d sign and embedded, negative value"}, + {"48", -91827, 7, "%+8d", " -91827", "%d with sign and minimum field size > number of digits, negative value"}, + {"49", -91827, 5, "%+4d", "-91827", "%d with sign and minimum field size < number of digits, negative value"}, + {"50", -33225, 9, "%+.10d", "-0000033225", "%d with sign and precision field size > number of digits, negative value"}, + {"51", -33225, 5, "%+.3d", "-33225", "%d with sign and precision field size < number of digits, negative value"}, + {"52", -12345, 6, "%+9.7d", " -0012345", "%d with sign and minimum field size > precision field size > number of digits, negative value"}, + {"53", -12345, 7, "%+9.3d", " -12345", "%d with sign and minimum field size > number of digits > precision field size, negative value"}, + {"54", -12345, 5, "%+4.2d", "-12345", "%d with sign and number of digits > minimum field size > precision field size, negative value"}, + {"55", -12345, 8, "%+7.9d", "-000012345", "%d with sign and precision field size > minimum field size > number of digits, negative value"}, + {"56", -12345, 7, "%+3.9d", "-000012345", "%d with sign and precision field size > number of digits > minimum field size, negative value"}, + {"57", -12345, 6, "%+2.4d", "-12345", "%d with sign and number of digits > precision field size > minimum field size, negative value"}, + {"58", -98765, 13, "%+-.20d", "-00000000000000098765", "%d with sign and left-justify and precision field size > number of digits, negative value"}, + {"59", -98765, 4, "%+-.3d", "-98765", "%d with sign and left-justify and precision field size < number of digits, negative value"}, + {"60", -98765, 5, "%+d", "-98765", "%d with sign, negative value"}, + {"61", 0, 6, "%d", "0", "%d, zero value"}, + {"62", 162534, 5, "%08d", "00162534", "%d with zero padding, positive value"}, + {"63", -162534, 6, "%08d", "-0162534", "%d with zero padding, negative value"}, + {"64", 0, 6, "%04d", "0000", "%d, with zero padding, zero value"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, + strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_f.c b/src/unit-tests/osprintf-test/ut_osprintf_f.c new file mode 100644 index 000000000..06162d90b --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_f.c @@ -0,0 +1,84 @@ +/* + * UT_osprintf_f.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %f format + *****************************************************************************/ +void UT_osprintf_f(void) +{ + char *test_fmt = "f"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + float test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 5.230, 6, "%f", "5.230000", "%f, positive value"}, + {"02", 2.1056, 9, "$$$%f$$$", "$$$2.105600$$$", "%f embedded, positive value"}, + {"03", 91827.3, 4, "%3f", "91827.296875", "%f with maximum field size, positive value"}, + {"04", 5.82345, 5, "%.3f", "5.823", "%f with minimum field size, positive value"}, + {"05", 12.6789, 8, "%9.5f", " 12.67890", "%f with minimum and maximum field size, positive value"}, + {"06", 65.5678, 13, "%-20.5f", "65.56780 ", "%f with left-justify, positive value"}, + {"07", 2.7944, 8, "%+f", "+2.794400", "%f with sign, positive value"}, + {"08", -0.6712237, 7, "%f", "-0.671224", "%f, negative value"}, + {"09", -7.1109, 8, "$$$%f$$$", "$$$-7.110900$$$", "%f embedded, negative value"}, + {"10", -918.987, 6, "%3f", "-918.987000", "%f with maximum field size, negative value"}, + {"11", -3.1415, 3, "%.2f", "-3.14", "%f with precision, negative value"}, + {"12", -1.23456, 6, "%9.7f", "-1.2345600", "%f with precision and maximum field size, negative value"}, + {"13", -65.65, 5, "%-8.3f", "-65.650 ", "%f with left-justify, negative value"}, + {"14", 0.0, 4, "%f", "0.000000", "%f, zero value"}, + {"15", 4.0, 6, "%7.0f", " 4", "%f, no fraction, positive value"}, + {"16", -56.0, 6, "%6.0f", " -56", "%f, no fraction, negative value"}, + {"17", 4887.12, 5, "%010.3f", "004887.120", "%f with zero padding, positive value"}, + {"18", -4887.12, 5, "%010.3f", "-04887.120", "%f with zero padding, negative value"}, + {"19", 0.0, 6, "%06.2f", "000.00", "%f, with zero padding, zero value"}, + {"20", 4.0, 6, "%07.0f", "0000004", "%f, zero padding, no fraction, positive value"}, + {"21", -56.0, 6, "%06.0f", "-00056", "%f, zero padding, no fraction, negative value"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_i.c b/src/unit-tests/osprintf-test/ut_osprintf_i.c new file mode 100644 index 000000000..96df57f66 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_i.c @@ -0,0 +1,128 @@ +/* + * UT_osprintf_i.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %i format + *****************************************************************************/ +void UT_osprintf_i(void) +{ + char *test_fmt = "i"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 98765, 5, "%i", "98765", "%i, positive value"}, + {"02", 46372, 9, "$$$%i$$$", "$$$46372$$$", "%i embedded, positive value"}, + {"03", 98765, 5, "% i", " 98765", "%i with space for sign, positive value"}, + {"04", 91827, 7, "%8i", " 91827", "%i with minimum field size > number of digits, positive value"}, + {"05", 91827, 2, "%4i", "91827", "%i with minimum field size < number of digits, positive value"}, + {"06", 33225, 7, "%.10i", "0000033225", "%i with precision field size > number of digits, positive value"}, + {"07", 33225, 3, "%.3i", "33225", "%i with precision field size < number of digits, positive value"}, + {"08", 12345, 5, "%9.7i", " 0012345", "%i with minimum field size > precision field size > number of digits, positive value"}, + {"09", 12345, 5, "%9.3i", " 12345", "%i with minimum field size > number of digits > precision field size, positive value"}, + {"10", 12345, 5, "%4.2i", "12345", "%i with number of digits > minimum field size > precision field size, positive value"}, + {"11", 12345, 8, "%7.9i", "000012345", "%i with precision field size > minimum field size > number of digits, positive value"}, + {"12", 12345, 7, "%3.9i", "000012345", "%i with precision field size > number of digits > minimum field size, positive value"}, + {"13", 12345, 4, "%2.4i", "12345", "%i with number of digits > precision field size > minimum field size, positive value"}, + {"14", 98765, 5, "%-.20i", "00000000000000098765", "%i with left-justify and precision field size > number of digits, positive value"}, + {"15", 98765, 5, "%-.3i", "98765", "%i with left-justify and precision field size < number of digits, positive value"}, + {"16", 98765, 5, "%+i", "+98765", "%i with sign, positive value"}, + {"17", 46372, 5, "$$$%+d$$$", "$$$+46372$$$", "%i sign and embedded, positive value"}, + {"18", 91827, 6, "%+8i", " +91827", "%i with sign and minimum field size > number of digits, positive value"}, + {"19", 91827, 4, "%+4i", "+91827", "%i with sign and minimum field size < number of digits, positive value"}, + {"20", 33225, 8, "%+.10i", "+0000033225", "%i with sign and precision field size > number of digits, positive value"}, + {"21", 33225, 5, "%+.3i", "+33225", "%i with sign and precision field size < number of digits, positive value"}, + {"22", 12345, 5, "%+9.7i", " +0012345", "%i with sign and minimum field size > precision field size > number of digits, positive value"}, + {"23", 12345, 5, "%+9.3i", " +12345", "%i with sign and minimum field size > number of digits > precision field size, positive value"}, + {"24", 12345, 5, "%+4.2i", "+12345", "%i with sign and number of digits > minimum field size > precision field size, positive value"}, + {"25", 12345, 8, "%+7.9i", "+000012345", "%i with sign and precision field size > minimum field size > number of digits, positive value"}, + {"26", 12345, 7, "%+3.9i", "+000012345", "%i with sign and precision field size > number of digits > minimum field size, positive value"}, + {"27", 12345, 5, "%+2.4i", "+12345", "%i with sign and number of digits > precision field size > minimum field size, positive value"}, + {"28", 98765, 16, "%+-.20i", "+00000000000000098765", "%i with sign and left-justify and precision field size > number of digits, positive value"}, + {"29", 98765, 5, "%+-.3i", "+98765", "%i with sign and left-justify and precision field size < number of digits, positive value"}, + {"30", 98765, 4, "%+i", "+98765", "%i with sign, positive value"}, + {"31", -98765, 6, "%i", "-98765", "%i, negative value"}, + {"32", -46372, 6, "$$$%i$$$", "$$$-46372$$$", "%i embedded, negative value"}, + {"33", -98765, 5, "% i", "-98765", "%i with space for sign, negative value"}, + {"34", -91827, 9, "%10i", " -91827", "%i with minimum field size > number of digits, negative value"}, + {"35", -91827, 6, "%4i", "-91827", "%i with minimum field size < number of digits, negative value"}, + {"36", -33225, 9, "%.10i", "-0000033225", "%i with precision field size > number of digits, negative value"}, + {"37", -33225, 5, "%.3i", "-33225", "%i with precision field size < number of digits, negative value"}, + {"38", -12345, 8, "%9.7i", " -0012345", "%i with minimum field size > precision field size > number of digits, negative value"}, + {"39", -12345, 7, "%9.3i", " -12345", "%i with minimum field size > number of digits > precision field size, negative value"}, + {"40", -12345, 6, "%4.2i", "-12345", "%i with number of digits > minimum field size > precision field size, negative value"}, + {"41", -12345, 7, "%7.9i", "-000012345", "%i with precision field size > minimum field size > number of digits, negative value"}, + {"42", -12345, 8, "%3.9i", "-000012345", "%i with precision field size > number of digits > minimum field size, negative value"}, + {"43", -12345, 5, "%2.4i", "-12345", "%i with number of digits > precision field size > minimum field size, negative value"}, + {"44", -98765, 18, "%-.20i", "-00000000000000098765", "%i with left-justify and precision field size > number of digits, negative value"}, + {"45", -98765, 5, "%-.3i", "-98765", "%i with left-justify and precision field size < number of digits, negative value"}, + {"46", -98765, 6, "%+i", "-98765", "%i with sign, negative value"}, + {"47", -46372, 7, "$$$%+d$$$", "$$$-46372$$$", "%i sign and embedded, negative value"}, + {"48", -91827, 5, "%+8i", " -91827", "%i with sign and minimum field size > number of digits, negative value"}, + {"49", -91827, 5, "%+4i", "-91827", "%i with sign and minimum field size < number of digits, negative value"}, + {"50", -33225, 7, "%+.10i", "-0000033225", "%i with sign and precision field size > number of digits, negative value"}, + {"51", -33225, 5, "%+.3i", "-33225", "%i with sign and precision field size < number of digits, negative value"}, + {"52", -12345, 7, "%+9.7i", " -0012345", "%i with sign and minimum field size > precision field size > number of digits, negative value"}, + {"53", -12345, 8, "%+9.3i", " -12345", "%i with sign and minimum field size > number of digits > precision field size, negative value"}, + {"54", -12345, 4, "%+4.2i", "-12345", "%i with sign and number of digits > minimum field size > precision field size, negative value"}, + {"55", -12345, 8, "%+7.9i", "-000012345", "%i with sign and precision field size > minimum field size > number of digits, negative value"}, + {"56", -12345, 7, "%+3.9i", "-000012345", "%i with sign and precision field size > number of digits > minimum field size, negative value"}, + {"57", -12345, 5, "%+2.4i", "-12345", "%i with sign and number of digits > precision field size > minimum field size, negative value"}, + {"58", -98765, 19, "%+-.20i", "-00000000000000098765", "%i with sign and left-justify and precision field size > number of digits, negative value"}, + {"59", -98765, 6, "%+-.3i", "-98765", "%i with sign and left-justify and precision field size < number of digits, negative value"}, + {"60", -98765, 5, "%+i", "-98765", "%i with sign, negative value"}, + {"61", 0, 6, "%i", "0", "%i, zero value"}, + {"62", 162534, 5, "%08i", "00162534", "%i with zero padding, positive value"}, + {"63", -162534, 6, "%08i", "-0162534", "%i with zero padding, negative value"}, + {"64", 0, 6, "%04i", "0000", "%i, with zero padding, zero value"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} + diff --git a/src/unit-tests/osprintf-test/ut_osprintf_ld.c b/src/unit-tests/osprintf-test/ut_osprintf_ld.c new file mode 100644 index 000000000..6a5f78079 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_ld.c @@ -0,0 +1,127 @@ +/* + * UT_osprintf_ld.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %ld format + *****************************************************************************/ +void UT_osprintf_ld(void) +{ + char *test_fmt = "ld"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + long int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 12798765, 5, "%ld", "12798765", "%ld, positive value"}, + {"02", 43246372, 9, "$$$%ld$$$", "$$$43246372$$$", "%ld embedded, positive value"}, + {"03", 63198765, 9, "% ld", " 63198765", "%ld with space for sign, positive value"}, + {"04", 77691827, 8, "%11ld", " 77691827", "%ld with minimum field size > number of digits, positive value"}, + {"05", 54691827, 5, "%4ld", "54691827", "%ld with minimum field size < number of digits, positive value"}, + {"06", 77833225, 7, "%.10ld", "0077833225", "%ld with precision field size > number of digits, positive value"}, + {"07", 99933225, 6, "%.3ld", "99933225", "%ld with precision field size < number of digits, positive value"}, + {"08", 12345789, 8, "%12.10ld", " 0012345789", "%ld with minimum field size > precision field size > number of digits, positive value"}, + {"09", 12345987, 7, "%12.3ld", " 12345987", "%ld with minimum field size > number of digits > precision field size, positive value"}, + {"10", 12345444, 8, "%4.2ld", "12345444", "%ld with number of digits > minimum field size > precision field size, positive value"}, + {"11", 12345321, 10, "%10.12ld", "000012345321", "%ld with precision field size > minimum field size > number of digits, positive value"}, + {"12", 12333345, 9, "%6.12ld", "000012333345", "%ld with precision field size > number of digits > minimum field size, positive value"}, + {"13", 12345777, 8, "%2.4ld", "12345777", "%ld with number of digits > precision field size > minimum field size, positive value"}, + {"14", 98765321, 15, "%-.20ld", "00000000000098765321", "%ld with left-justify and precision field size > number of digits, positive value"}, + {"15", 98765111, 8, "%-.3ld", "98765111", "%ld with left-justify and precision field size < number of digits, positive value"}, + {"16", 98765222, 8, "%+ld", "+98765222", "%ld with sign, positive value"}, + {"17", 46372333, 7, "$$$%+ld$$$", "$$$+46372333$$$", "%ld sign and embedded, positive value"}, + {"18", 91827444, 6, "%+11ld", " +91827444", "%ld with sign and minimum field size > number of digits, positive value"}, + {"19", 91827555, 5, "%+4ld", "+91827555", "%ld with sign and minimum field size < number of digits, positive value"}, + {"20", 33225666, 7, "%+.13ld", "+0000033225666", "%ld with sign and precision field size > number of digits, positive value"}, + {"21", 33225777, 8, "%+.3ld", "+33225777", "%ld with sign and precision field size < number of digits, positive value"}, + {"22", 12345888, 9, "%+12.10ld", " +0012345888", "%ld with sign and minimum field size > precision field size > number of digits, positive value"}, + {"23", 12345999, 10, "%+12.3ld", " +12345999", "%ld with sign and minimum field size > number of digits > precision field size, positive value"}, + {"24", 12345000, 8, "%+4.2ld", "+12345000", "%ld with sign and number of digits > minimum field size > precision field size, positive value"}, + {"25", 12345121, 9, "%+10.12ld", "+000012345121", "%ld with sign and precision field size > minimum field size > number of digits, positive value"}, + {"26", 12345232, 8, "%+6.12ld", "+000012345232", "%ld with sign and precision field size > number of digits > minimum field size, positive value"}, + {"27", 12345343, 6, "%+2.4ld", "+12345343", "%ld with sign and number of digits > precision field size > minimum field size, positive value"}, + {"28", 98765454, 19, "%+-.20ld", "+00000000000098765454", "%ld with sign and left-justify and precision field size > number of digits, positive value"}, + {"29", 98765565, 7, "%+-.3ld", "+98765565", "%ld with sign and left-justify and precision field size < number of digits, positive value"}, + {"30", 98765676, 8, "%+ld", "+98765676", "%ld with sign, positive value"}, + {"31", -98765787, 9, "%ld", "-98765787", "%ld, negative value"}, + {"32", -46372898, 10, "$$$%ld$$$", "$$$-46372898$$$", "%ld embedded, negative value"}, + {"33", -98765909, 9, "% ld", "-98765909", "%ld with space for sign, negative value"}, + {"34", -91827121, 8, "%13ld", " -91827121", "%ld with minimum field size > number of digits, negative value"}, + {"35", -91827232, 5, "%4ld", "-91827232", "%ld with minimum field size < number of digits, negative value"}, + {"36", -33225343, 8, "%.13ld", "-0000033225343", "%ld with precision field size > number of digits, negative value"}, + {"37", -33225454, 6, "%.3ld", "-33225454", "%ld with precision field size < number of digits, negative value"}, + {"38", -12345565, 7, "%12.10ld", " -0012345565", "%ld with minimum field size > precision field size > number of digits, negative value"}, + {"39", -12345676, 8, "%12.4ld", " -12345676", "%ld with minimum field size > number of digits > precision field size, negative value"}, + {"40", -12345787, 9, "%4.2ld", "-12345787", "%ld with number of digits > minimum field size > precision field size, negative value"}, + {"41", -12345898, 11, "%7.12ld", "-000012345898", "%ld with precision field size > minimum field size > number of digits, negative value"}, + {"42", -12345909, 10, "%3.12ld", "-000012345909", "%ld with precision field size > number of digits > minimum field size, negative value"}, + {"43", -12345101, 9, "%2.4ld", "-12345101", "%ld with number of digits > precision field size > minimum field size, negative value"}, + {"44", -98765292, 10, "%-.20ld", "-00000000000098765292", "%ld with left-justify and precision field size > number of digits, negative value"}, + {"45", -98765383, 8, "%-.3ld", "-98765383", "%ld with left-justify and precision field size < number of digits, negative value"}, + {"46", -98765474, 9, "%+ld", "-98765474", "%ld with sign, negative value"}, + {"47", -46372565, 8, "$$$%+ld$$$", "$$$-46372565$$$", "%ld sign and embedded, negative value"}, + {"48", -91827112, 7, "%+11ld", " -91827112", "%ld with sign and minimum field size > number of digits, negative value"}, + {"49", -91827223, 6, "%+4ld", "-91827223", "%ld with sign and minimum field size < number of digits, negative value"}, + {"50", -33225334, 11, "%+.13ld", "-0000033225334", "%ld with sign and precision field size > number of digits, negative value"}, + {"51", -33225445, 9, "%+.3ld", "-33225445", "%ld with sign and precision field size < number of digits, negative value"}, + {"52", -12345556, 11, "%+12.10ld", " -0012345556", "%ld with sign and minimum field size > precision field size > number of digits, negative value"}, + {"53", -12345667, 10, "%+12.3ld", " -12345667", "%ld with sign and minimum field size > number of digits > precision field size, negative value"}, + {"54", -12345778, 9, "%+4.2ld", "-12345778", "%ld with sign and number of digits > minimum field size > precision field size, negative value"}, + {"55", -12345889, 10, "%+7.12ld", "-000012345889", "%ld with sign and precision field size > minimum field size > number of digits, negative value"}, + {"56", -12345990, 9, "%+3.12ld", "-000012345990", "%ld with sign and precision field size > number of digits > minimum field size, negative value"}, + {"57", -12345221, 8, "%+2.4ld", "-12345221", "%ld with sign and number of digits > precision field size > minimum field size, negative value"}, + {"58", -98765332, 7, "%+-.20ld", "-00000000000098765332", "%ld with sign and left-justify and precision field size > number of digits, negative value"}, + {"59", -98765443, 6, "%+-.3ld", "-98765443", "%ld with sign and left-justify and precision field size < number of digits, negative value"}, + {"60", -98765554, 5, "%+ld", "-98765554", "%ld with sign, negative value"}, + {"61", 0, 6, "%ld", "0", "%ld, zero value"}, + {"62", 16253409, 5, "%010ld", "0016253409", "%ld with zero padding, positive value"}, + {"63", -16253409, 6, "%010ld", "-016253409", "%ld with zero padding, negative value"}, + {"64", 0, 6, "%012ld", "000000000000", "%ld, with zero padding, zero value"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lf.c b/src/unit-tests/osprintf-test/ut_osprintf_lf.c new file mode 100644 index 000000000..30f663237 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_lf.c @@ -0,0 +1,84 @@ +/* + * UT_osprintf_lf.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %lf format + *****************************************************************************/ +void UT_osprintf_lf(void) +{ + char *test_fmt = "lf"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + double test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 9876543.125, 14, "%lf", "9876543.125000", "%lf, positive value"}, + {"02", 4637210.36, 12, "$$$%lf$$$", "$$$4637210.360000$$$", "%lf embedded, positive value"}, + {"03", 9182755.2756, 9, "%3lf", "9182755.275600", "%lf with maximum field size, positive value"}, + {"04", 12554.08, 5, "%.7lf", "12554.0800000", "%lf with precision, positive value"}, + {"05", 123456.2311, 11, "%9.7lf", "123456.2311000", "%lf with precision and maximum field size, positive value"}, + {"06", 9876543.6765, 15, "%-20lf", "9876543.676500 ", "%lf with left-justify, positive value"}, + {"07", 9876543.001, 13, "%+lf", "+9876543.001000", "%lf with sign, positive value"}, + {"08", -9876543.1987, 12, "%lf", "-9876543.198700", "%lf, negative value"}, + {"09", -4637210.871, 14, "$$$%lf$$$", "$$$-4637210.871000$$$", "%lf embedded, negative value"}, + {"10", -9182755.22222, 15, "%3lf", "-9182755.222220", "%lf with maximum field size, negative value"}, + {"11", -3355.6109, 11, "%.5lf", "-3355.61090", "%lf with precision, negative value"}, + {"12", -123456.7, 14, "%15.4lf", " -123456.7000", "%lf with precision and maximum field size, negative value"}, + {"13", -9876543.64388, 17, "%-20lf", "-9876543.643880 ", "%lf with left-justify, negative value"}, + {"14", 0.0, 4, "%lf", "0.000000", "%lf, zero value"}, + {"15", 123456789.0, 6, "%10.0lf", " 123456789", "%lf, no fraction, positive value"}, + {"16", -987654321.0, 6, "%12.0lf", " -987654321", "%lf, no fraction, negative value"}, + {"17", 34887.1255667, 5, "%020.4lf", "000000000034887.1256", "%lf with zero padding, positive value"}, + {"18", -34887.1255667, 5, "%020.4lf", "-00000000034887.1256", "%lf with zero padding, negative value"}, + {"19", 0.0, 6, "%09.4lf", "0000.0000", "%lf, with zero padding, zero value"}, + {"20", 467812.3, 6, "%9.0lf", " 467812", "%lf, no fraction, positive value"}, + {"21", -544446.0, 6, "%8.0lf", " -544446", "%lf, no fraction, negative value"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_li.c b/src/unit-tests/osprintf-test/ut_osprintf_li.c new file mode 100644 index 000000000..b8098edab --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_li.c @@ -0,0 +1,127 @@ +/* + * UT_osprintf_li.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %li format + *****************************************************************************/ +void UT_osprintf_li(void) +{ + char *test_fmt = "li"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + long int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 12798765, 7, "%li", "12798765", "%li, positive value"}, + {"02", 43246372, 9, "$$$%li$$$", "$$$43246372$$$", "%li embedded, positive value"}, + {"03", 63198765, 8, "% li", " 63198765", "%li with space for sign, positive value"}, + {"04", 77691827, 7, "%11li", " 77691827", "%li with minimum field size > number of digits, positive value"}, + {"05", 54691827, 5, "%4li", "54691827", "%li with minimum field size < number of digits, positive value"}, + {"06", 77833225, 8, "%.10li", "0077833225", "%li with precision field size > number of digits, positive value"}, + {"07", 99933225, 5, "%.3li", "99933225", "%li with precision field size < number of digits, positive value"}, + {"08", 12345789, 10, "%12.10li", " 0012345789", "%li with minimum field size > precision field size > number of digits, positive value"}, + {"09", 12345987, 12, "%12.3li", " 12345987", "%li with minimum field size > number of digits > precision field size, positive value"}, + {"10", 12345444, 8, "%4.2li", "12345444", "%li with number of digits > minimum field size > precision field size, positive value"}, + {"11", 12345321, 11, "%10.12li", "000012345321", "%li with precision field size > minimum field size > number of digits, positive value"}, + {"12", 12333345, 7, "%6.12li", "000012333345", "%li with precision field size > number of digits > minimum field size, positive value"}, + {"13", 12345777, 5, "%2.4li", "12345777", "%li with number of digits > precision field size > minimum field size, positive value"}, + {"14", 98765321, 19, "%-.20li", "00000000000098765321", "%li with left-justify and precision field size > number of digits, positive value"}, + {"15", 98765111, 7, "%-.3li", "98765111", "%li with left-justify and precision field size < number of digits, positive value"}, + {"16", 98765222, 10, "%+li", "+98765222", "%li with sign, positive value"}, + {"17", 46372333, 9, "$$$%+li$$$", "$$$+46372333$$$", "%li sign and embedded, positive value"}, + {"18", 91827444, 8, "%+11li", " +91827444", "%li with sign and minimum field size > number of digits, positive value"}, + {"19", 91827555, 7, "%+4li", "+91827555", "%li with sign and minimum field size < number of digits, positive value"}, + {"20", 33225666, 2, "%+.13li", "+0000033225666", "%li with sign and precision field size > number of digits, positive value"}, + {"21", 33225777, 5, "%+.3li", "+33225777", "%li with sign and precision field size < number of digits, positive value"}, + {"22", 12345888, 9, "%+12.10li", " +0012345888", "%li with sign and minimum field size > precision field size > number of digits, positive value"}, + {"23", 12345999, 8, "%+12.3li", " +12345999", "%li with sign and minimum field size > number of digits > precision field size, positive value"}, + {"24", 12345000, 9, "%+4.2li", "+12345000", "%li with sign and number of digits > minimum field size > precision field size, positive value"}, + {"25", 12345121, 11, "%+10.12li", "+000012345121", "%li with sign and precision field size > minimum field size > number of digits, positive value"}, + {"26", 12345232, 10, "%+6.12li", "+000012345232", "%li with sign and precision field size > number of digits > minimum field size, positive value"}, + {"27", 12345343, 7, "%+2.4li", "+12345343", "%li with sign and number of digits > precision field size > minimum field size, positive value"}, + {"28", 98765454, 15, "%+-.20li", "+00000000000098765454", "%li with sign and left-justify and precision field size > number of digits, positive value"}, + {"29", 98765565, 8, "%+-.3li", "+98765565", "%li with sign and left-justify and precision field size < number of digits, positive value"}, + {"30", 98765676, 7, "%+li", "+98765676", "%li with sign, positive value"}, + {"31", -98765787, 6, "%li", "-98765787", "%li, negative value"}, + {"32", -46372898, 15, "$$$%li$$$", "$$$-46372898$$$", "%li embedded, negative value"}, + {"33", -98765909, 9, "% li", "-98765909", "%li with space for sign, negative value"}, + {"34", -91827121, 11, "%13li", " -91827121", "%li with minimum field size > number of digits, negative value"}, + {"35", -91827232, 5, "%4li", "-91827232", "%li with minimum field size < number of digits, negative value"}, + {"36", -33225343, 8, "%.13li", "-0000033225343", "%li with precision field size > number of digits, negative value"}, + {"37", -33225454, 7, "%.3li", "-33225454", "%li with precision field size < number of digits, negative value"}, + {"38", -12345565, 9, "%12.10li", " -0012345565", "%li with minimum field size > precision field size > number of digits, negative value"}, + {"39", -12345676, 8, "%12.4li", " -12345676", "%li with minimum field size > number of digits > precision field size, negative value"}, + {"40", -12345787, 4, "%4.2li", "-12345787", "%li with number of digits > minimum field size > precision field size, negative value"}, + {"41", -12345898, 10, "%7.12li", "-000012345898", "%li with precision field size > minimum field size > number of digits, negative value"}, + {"42", -12345909, 9, "%3.12li", "-000012345909", "%li with precision field size > number of digits > minimum field size, negative value"}, + {"43", -12345101, 7, "%2.4li", "-12345101", "%li with number of digits > precision field size > minimum field size, negative value"}, + {"44", -98765292, 18, "%-.20li", "-00000000000098765292", "%li with left-justify and precision field size > number of digits, negative value"}, + {"45", -98765383, 7, "%-.3li", "-98765383", "%li with left-justify and precision field size < number of digits, negative value"}, + {"46", -98765474, 8, "%+li", "-98765474", "%li with sign, negative value"}, + {"47", -46372565, 10, "$$$%+li$$$", "$$$-46372565$$$", "%li sign and embedded, negative value"}, + {"48", -91827112, 9, "%+11li", " -91827112", "%li with sign and minimum field size > number of digits, negative value"}, + {"49", -91827223, 5, "%+4li", "-91827223", "%li with sign and minimum field size < number of digits, negative value"}, + {"50", -33225334, 11, "%+.13li", "-0000033225334", "%li with sign and precision field size > number of digits, negative value"}, + {"51", -33225445, 8, "%+.3li", "-33225445", "%li with sign and precision field size < number of digits, negative value"}, + {"52", -12345556, 12, "%+12.10li", " -0012345556", "%li with sign and minimum field size > precision field size > number of digits, negative value"}, + {"53", -12345667, 10, "%+12.3li", " -12345667", "%li with sign and minimum field size > number of digits > precision field size, negative value"}, + {"54", -12345778, 6, "%+4.2li", "-12345778", "%li with sign and number of digits > minimum field size > precision field size, negative value"}, + {"55", -12345889, 9, "%+7.12li", "-000012345889", "%li with sign and precision field size > minimum field size > number of digits, negative value"}, + {"56", -12345990, 11, "%+3.12li", "-000012345990", "%li with sign and precision field size > number of digits > minimum field size, negative value"}, + {"57", -12345221, 7, "%+2.4li", "-12345221", "%li with sign and number of digits > precision field size > minimum field size, negative value"}, + {"58", -98765332, 15, "%+-.20li", "-00000000000098765332", "%li with sign and left-justify and precision field size > number of digits, negative value"}, + {"59", -98765443, 7, "%+-.3li", "-98765443", "%li with sign and left-justify and precision field size < number of digits, negative value"}, + {"60", -98765554, 5, "%+li", "-98765554", "%li with sign, negative value"}, + {"61", 0, 6, "%li", "0", "%li, zero value"}, + {"62", 16253409, 5, "%010li", "0016253409", "%li with zero padding, positive value"}, + {"63", -16253409, 6, "%010li", "-016253409", "%li with zero padding, negative value"}, + {"64", 0, 6, "%012li", "000000000000", "%li, with zero padding, zero value"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lu.c b/src/unit-tests/osprintf-test/ut_osprintf_lu.c new file mode 100644 index 000000000..6f9156ff9 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_lu.c @@ -0,0 +1,73 @@ +/* + * UT_osprintf_lu.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %lu format + *****************************************************************************/ +void UT_osprintf_lu(void) +{ + char *test_fmt = "lu"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + unsigned long int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 9876543, 6, "%lu", "9876543", "%lu, negative value"}, + {"02", 4637210, 12, "$$$%lu$$$", "$$$4637210$$$", "%lu embedded"}, + {"03", 9182755, 6, "%3lu", "9182755", "%lu with maximum field size"}, + {"04", 3322554, 10, "%.10lu", "0003322554", "%lu with minimum field size"}, + {"05", 123456, 8, "%9.7lu", " 0123456", "%lu with minimum and maximum field size"}, + {"06", 9876543, 16, "%-.20lu", "00000000000009876543", "%lu with left-justify"}, + {"07", 9876543, 5, "%+lu", "9876543", "%lu with sign"}, + {"08", -9876543, 8, "%lu", "4285090753", "%lu, negative value"}, + {"09", 0, 6, "%lu", "0", "%lu, zero value"}, + {"10", 162534098, 5, "%011lu", "00162534098", "%lu with zero padding"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lx.c b/src/unit-tests/osprintf-test/ut_osprintf_lx.c new file mode 100644 index 000000000..16cd00b6e --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_lx.c @@ -0,0 +1,72 @@ +/* + * UT_osprintf_lx.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %x format + *****************************************************************************/ +void UT_osprintf_lx(void) +{ + char *test_fmt = "lx"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + unsigned long int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 0x9a8b7c6d, 5, "%lx", "9a8b7c6d", "%lx"}, + {"02", 0xdd46ee21, 12, "$$$%lx$$$", "$$$dd46ee21$$$", "%lx embedded"}, + {"03", 0x9ccc8275, 7, "%3lx", "9ccc8275", "%lx with minimum field size < number of digits"}, + {"04", 0xbee33225, 10, "%.10lx", "00bee33225", "%lx with precision field size"}, + {"05", 0x123fdb, 7, "%9.7lx", " 0123fdb", "%lx with minimum and precision field size"}, + {"06", 0xabc6543f, 19, "%-.20lx", "000000000000abc6543f", "%lx with left-justify"}, + {"07", -9876543, 7, "%lx", "ff694bc1", "%lx, negative value"}, + {"08", 0x12b45, 5, "%8lx", " 12b45", "%lx with minimum field size > number of digits"}, + {"09", 0x12b45, 6, "%08lx", "00012b45", "%lx with minimum field size > number of digits and leading zeroes"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c b/src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c new file mode 100644 index 000000000..d06e70ed2 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c @@ -0,0 +1,72 @@ +/* + * UT_osprintf_lX.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %lX format + *****************************************************************************/ +void UT_osprintf_lX(void) +{ + char *test_fmt = "lx"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + unsigned long int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 0x9a8b7c6d, 8, "%lX", "9A8B7C6D", "%lX"}, + {"02", 0xdd46ee21, 8, "$$$%lX$$$", "$$$DD46EE21$$$", "%lX embedded"}, + {"03", 0x9ccc8275, 7, "%3lX", "9CCC8275", "%lX with minimum field size < number of digits"}, + {"04", 0xbee33225, 10, "%.10lX", "00BEE33225", "%lX with precision field size"}, + {"05", 0x123fdb, 7, "%9.7lX", " 0123FDB", "%lX with minimum and precision field size"}, + {"06", 0xabc6543f, 16, "%-.20lX", "000000000000ABC6543F", "%lX with left-justify"}, + {"07", -9876543, 5, "%lX", "FF694BC1", "%lX, negative value"}, + {"08", 0x12b45, 3, "%8lX", " 12B45", "%lX with minimum field size > number of digits"}, + {"09", 0x12b45, 2, "%08lX", "00012B45", "%lX with minimum field size > number of digits and leading zeroes"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_misc.c b/src/unit-tests/osprintf-test/ut_osprintf_misc.c new file mode 100644 index 000000000..6da39dd40 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_misc.c @@ -0,0 +1,152 @@ +/* + * UT_osprintf_misc.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; + +/***************************************************************************** + * Test miscellaneous formats & combinations + *****************************************************************************/ +void UT_osprintf_misc(void) +{ + int test_int; + long test_long; + unsigned test_unsigned; + unsigned test_hex; + float test_float; + double test_double; + char test_char; + char *test_num = "misc"; + + /* Test representing percent character using %% */ + init_test(); + SPRINTF(strg_buf, "Show percent character .%%."); + UT_Report(check_test("Show percent character .%.", strg_buf), "SPRINTF", + "Represent percent character using %%", + test_num, "01"); + + /* Test representing percent character using %%, truncated */ + init_test(); + SNPRINTF(strg_buf, 11, "Show percent character .%%."); + UT_Report(check_test("Show perce", strg_buf), "SNPRINTF", + "Represent percent character using %%, truncated", + test_num, "01"); + + /* Test combination of types */ + init_test(); + test_int = -123; + test_long = 9876543; + test_unsigned = 4321; + test_hex = 0xa1b2; + test_float = -2.3456; + test_double = 6543.123456; + test_char = '$'; + SPRINTF(strg_buf, + "int = %d long = %ld uns = %u hex = 0x%x flt = %f " + "dbl = %lf chr = %c", + test_int, test_long, test_unsigned, test_hex, + test_float, test_double, test_char); + UT_Report(check_test("int = -123 long = 9876543 uns = 4321 hex = " + "0xa1b2 flt = -2.345600 dbl = 6543.123456 " + "chr = $", strg_buf), "SPRINTF", + "Combination of types", + test_num, "02"); + + /* Test combination of types, truncated */ + init_test(); + test_int = -123; + test_long = 9876543; + test_unsigned = 4321; + test_hex = 0xa1b2; + test_float = -2.3456; + test_double = 6543.123456; + test_char = '$'; + SNPRINTF(strg_buf, 16, + "int = %d long = %ld uns = %u hex = 0x%x flt = %f " + "dbl = %lf chr = %c", + test_int, test_long, test_unsigned, test_hex, + test_float, test_double, test_char); + UT_Report(check_test("int = -123 lon", strg_buf), "SNPRINTF", + "Combination of types, truncated", + test_num, "02"); + + /* Test combination of types 2 */ + init_test(); + test_int = -123; + test_long = 9876543; + test_unsigned = 4321; + test_hex = 0xa1b2; + test_float = -2.3456; + test_double = 6543.123456; + test_char = '$'; + SPRINTF(strg_buf, + "flt = %f dbl = %lf flt = %f", + test_float, test_double, test_float); + UT_Report(check_test("flt = -2.345600 dbl = 6543.123456 flt = -2.345600", + strg_buf), "SPRINTF", + "Combination of types 2", + test_num, "03"); + + /* Test combination of types 2, truncated */ + init_test(); + test_int = -123; + test_long = 9876543; + test_unsigned = 4321; + test_hex = 0xa1b2; + test_float = -2.3456; + test_double = 6543.123456; + test_char = '$'; + SNPRINTF(strg_buf, 10, + "flt = %f dbl = %lf flt = %f", + test_float, test_double, test_float); + UT_Report(check_test("flt = -2.", strg_buf), "SNPRINTF", + "Combination of types 2", + test_num, "03"); + + /* Test format string ending with percent character */ + init_test(); + SPRINTF(strg_buf, "End with percent character %"); + UT_Report(check_test("End with percent character ", strg_buf), "SPRINTF", + "End with percent character", + test_num, "04"); + + /* Test representing percent character using %%, truncated */ + init_test(); + SNPRINTF(strg_buf, 11, "End with percent character %"); + UT_Report(check_test("End with p", strg_buf), "SNPRINTF", + "End with percent character, truncated", + test_num, "04"); + + /* Test null format string */ + init_test(); + SPRINTF(strg_buf, ""); + UT_Report(check_test("", strg_buf), "SPRINTF", + "Null format string", + test_num, "05"); + + /* Test representing percent character using %%, truncated */ + init_test(); + SNPRINTF(strg_buf, 5, ""); + UT_Report(check_test("", strg_buf), "SNPRINTF", + "Null format string", + test_num, "05"); + + /* Test too many decimals in format width/precision modifier */ + init_test(); + SPRINTF(strg_buf, "Too many decimals %13.5.2f"); + UT_Report(check_test("Too many decimals %13.5.2f", strg_buf), "SPRINTF", + "Invalid format string", + test_num, "06"); + + /* Test too many decimals in format width/precision modifier, truncated */ + init_test(); + SNPRINTF(strg_buf, 23, "Too many decimals %13.5.2f"); + UT_Report(check_test("Too many decimals %13.", strg_buf), "SNPRINTF", + "Invalid format string", + test_num, "06"); +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_offset.c b/src/unit-tests/osprintf-test/ut_osprintf_offset.c new file mode 100644 index 000000000..7614fd38a --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_offset.c @@ -0,0 +1,210 @@ +#ifdef UT_DO_OFFSET + +#include "ut_osprintf.h" +#include "ut_osprintf_offset.h" + +extern char cMsg[]; +extern char cNum[]; + +unsigned long testPattern = 0x12ab34cd; + +void UT_osprintf_CalcOffsets(void) +{ + CFE_TIME_SysTime_t Time = {0, 0}; + + /* Determine variadic offsets */ + CalcOffset_CFE_ES_WriteToSysLog("CFE_ES_WriteToSysLog test %ld", + testPattern); + CalcOffset_EVS_SendEvent(111, 222, + "EVS_SendEvent test %ld", + testPattern); + CalcOffset_CFE_EVS_SendEvent(333, 444, + "CFE_EVS_SendEvent test %ld", + testPattern); + CalcOffset_CFE_EVS_SendEventWithAppID(555, 666, 5, + "CFE_EVS_SendEventWithAppID test %ld", + testPattern); + CalcOffset_CFE_EVS_SendTimedEvent(Time, 777, 888, + "CFE_EVS_SendTimedEvent test %ld", + testPattern); +} + +void UT_ShowHex(unsigned char *ptr, int numBytes) +{ + int i; + unsigned char *bytePtr = (unsigned char *) ptr; + + strcpy(cMsg, "args = "); + + for (i = 0; i < numBytes; i++) + { + OS_sprintf(cNum, "%02x ", *bytePtr); + strcat(cMsg, cNum); + bytePtr++; + } + + UT_Text(cMsg); +} + +void UT_CheckArgumentOffset(VA_LIST ptr) +{ + int i = 0; + int offset = -1; + int max_allowed_offset = 20; + unsigned char *bytePtr = (unsigned char *) ptr; + unsigned char *testPtr = (void *) &testPattern; + + while (offset < max_allowed_offset && i < sizeof(unsigned long)) + { + offset++; + + for (i = 0; i < sizeof(unsigned long); i++) + { + if (*(bytePtr + (offset * sizeof(VA_LIST)) + i) != *(testPtr + i)) + { + break; + } + } + } + + if (offset == max_allowed_offset) + { + offset = -1; + } + + OS_sprintf(cMsg, " Offset = %d\n", offset); + UT_Text(cMsg); +} + +/* Mimic CFE_ES_WriteToSysLog() */ +long int CalcOffset_CFE_ES_WriteToSysLog(const char *SpecStringPtr, ...) +{ + char TmpString[CFE_ES_MAX_SYSLOG_MSG_SIZE]; + char MsgWithoutTime[CFE_EVS_MAX_MESSAGE_LENGTH]; + CFE_TIME_SysTime_t time = {0, 0}; + VA_LIST ArgPtr; + + VA_START(ArgPtr, SpecStringPtr, 0); + UT_Text("\nCFE_ES_WriteToSysLog Argument Offset Calculation:\n"); + UT_CheckArgumentOffset(ArgPtr); + + /* These function calls from the original function are needed in + * order for the correct offset to be calculated */ + OS_vsnprintfDummy(MsgWithoutTime, 0, SpecStringPtr, ArgPtr); + CFE_TIME_PrintDummy(TmpString, time); + strcatDummy(TmpString, " "); + strncatDummy(TmpString, MsgWithoutTime, 0); + OS_printfDummy("%s", TmpString); + strlenDummy(TmpString); + strncpyDummy(TmpString, TmpString, 0); + strncpyDummy(TmpString, "\0", 1); + OS_printfDummy("Warning: Last System Log Message Truncated.\n"); + strlenDummy(TmpString); + strncpyDummy(TmpString, TmpString, 0); + return 0; +} + +/* Mimic EVS_SendEvent() */ +long int CalcOffset_EVS_SendEvent(unsigned short int EventID, + unsigned short int EventType, + const char *Spec, + ...) +{ + CFE_EVS_Packet_t EVS_Packet; + CFE_TIME_SysTime_t Time = {0, 0}; + VA_LIST Ptr; + + VA_START(Ptr, Spec, 0); + UT_Text("\nEVS_SendEvent Argument Offset Calculation:\n"); + UT_CheckArgumentOffset(Ptr); + + /* These function calls from the original function are needed in + * order for the correct offset to be calculated */ + EVS_IsFilteredDummy(0, EventID, EventType); + CFE_SB_InitMsgDummy(&EVS_Packet, 0, sizeof(CFE_EVS_Packet_t), 0); + OS_vsnprintfDummy(EVS_Packet.Message, 0, Spec, Ptr); + CFE_TIME_GetTimeDummy(); + EVS_SendPacketDummy(0, Time, &EVS_Packet); + return 0; +} + +/* Mimic CFE_EVS_SendEvent() */ +long int CalcOffset_CFE_EVS_SendEvent(unsigned short int EventID, + unsigned short int EventType, + const char *Spec, + ...) +{ + CFE_EVS_Packet_t EVS_Packet; + unsigned long int AppID = 0; + CFE_TIME_SysTime_t Time = {0, 0}; + VA_LIST Ptr; + + VA_START(Ptr, Spec, 0); + UT_Text("\nCFE_EVS_SendEvent Argument Offset Calculation:\n"); + UT_CheckArgumentOffset(Ptr); + + /* These function calls from the original function are needed in + * order for the correct offset to be calculated */ + EVS_GetAppIDDummy(&AppID); + EVS_NotRegisteredDummy(AppID); + EVS_IsFilteredDummy(AppID, EventID, EventType); + CFE_SB_InitMsgDummy(&EVS_Packet, 0, sizeof(CFE_EVS_Packet_t), 0); + OS_vsnprintfDummy(EVS_Packet.Message, 0, Spec, Ptr); + CFE_TIME_GetTimeDummy(); + EVS_SendPacketDummy(AppID, Time, &EVS_Packet); + return 0; +} + +/* Mimic CFE_EVS_SendEventWithAppID() */ +long int CalcOffset_CFE_EVS_SendEventWithAppID(unsigned short int EventID, + unsigned short int EventType, + unsigned long int AppID, + const char *Spec, + ...) +{ + CFE_EVS_Packet_t EVS_Packet; + CFE_TIME_SysTime_t Time = {0, 0}; + VA_LIST Ptr; + + VA_START(Ptr, Spec, 0); + UT_Text("\nCFE_EVS_SendEventWithAppID Argument Offset Calculation:\n"); + UT_CheckArgumentOffset(Ptr); + + /* These function calls from the original function are needed in + * order for the correct offset to be calculated */ + EVS_NotRegisteredDummy(AppID); + EVS_IsFilteredDummy(AppID, EventID, EventType); + CFE_SB_InitMsgDummy(&EVS_Packet, 0, sizeof(CFE_EVS_Packet_t), 0); + OS_vsnprintfDummy(EVS_Packet.Message, 0, Spec, Ptr); + CFE_TIME_GetTimeDummy(); + EVS_SendPacketDummy(AppID, Time, &EVS_Packet); + return 0; +} + +/* Mimic CFE_EVS_SendTimedEvent() */ +long int CalcOffset_CFE_EVS_SendTimedEvent(CFE_TIME_SysTime_t Time, + unsigned short int EventID, + unsigned short int EventType, + const char *Spec, + ...) +{ + CFE_EVS_Packet_t EVS_Packet; + unsigned long int AppID = 0; + VA_LIST Ptr; + + VA_START(Ptr, Spec, 0); + UT_Text("\nCFE_EVS_SendTimedEvent Argument Offset Calculation:\n"); + UT_CheckArgumentOffset(Ptr); + + /* These function calls from the original function are needed in + * order for the correct offset to be calculated */ + EVS_GetAppIDDummy(&AppID); + EVS_NotRegisteredDummy(AppID); + EVS_IsFilteredDummy(AppID, EventID, EventType); + CFE_SB_InitMsgDummy(&EVS_Packet, 0, sizeof(CFE_EVS_Packet_t), 0); + OS_vsnprintfDummy(EVS_Packet.Message, 0, Spec, Ptr); + EVS_SendPacketDummy(AppID, Time, &EVS_Packet); + return 0; +} + +#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_offset.h b/src/unit-tests/osprintf-test/ut_osprintf_offset.h new file mode 100644 index 000000000..73bd9245b --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_offset.h @@ -0,0 +1,61 @@ +/* + * ut_osprintf_offset.h + * + * Variadic argument offset calculation + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ +#ifdef UT_DO_OFFSET + +#ifndef UT_OSPRINTF_OFFSET_H_ +#define UT_OSPRINTF_OFFSET_H_ + +#include "cfe_sb.h" +#include "cfe_evs_task.h" +#include "cfe_time.h" +#include "osprintf.h" + +#define OS_MAX_API_NAME 20 + +void UT_ShowHex(unsigned char *, int); +void UT_CheckArgumentOffset(VA_LIST); +void UT_osprintf_CalcOffsets(void); +long int CalcOffset_CFE_ES_WriteToSysLog(const char *, ...); +long int CalcOffset_EVS_SendEvent(unsigned short int, + unsigned short int, + const char *, + ...); +long int CalcOffset_CFE_EVS_SendEvent(unsigned short int, + unsigned short int, + const char *, + ...); +long int CalcOffset_CFE_EVS_SendEventWithAppID(unsigned short int, + unsigned short int, + unsigned long int, + const char *, + ...); +long int CalcOffset_CFE_EVS_SendTimedEvent(CFE_TIME_SysTime_t, + unsigned short int, + unsigned short int, + const char *, + ...); +void CFE_TIME_PrintDummy(char *, CFE_TIME_SysTime_t); +unsigned char EVS_IsFilteredDummy(unsigned long int, unsigned int, + unsigned int); +void CFE_SB_InitMsgDummy(void *, unsigned int, unsigned int, unsigned char); +CFE_TIME_SysTime_t CFE_TIME_GetTimeDummy(void); +void EVS_SendPacketDummy(unsigned long int, CFE_TIME_SysTime_t, + CFE_EVS_Packet_t *); +long int EVS_GetAppIDDummy(unsigned long int *); +long int EVS_NotRegisteredDummy(unsigned long int); +int OS_vsnprintfDummy(char *, int, const char *, VA_LIST); +void OS_printfDummy(const char *, ...); +char *strcatDummy(char *, const char *); +char *strncatDummy(char *, const char *, int); +char *strncpyDummy(char *, const char *, int); +int strlenDummy(const char *); + +#endif /* UT_OSPRINTF_OFFSET_H_ */ + +#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c b/src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c new file mode 100644 index 000000000..8a4fcf14c --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c @@ -0,0 +1,75 @@ +#ifdef UT_DO_OFFSET + +#include "ut_osprintf.h" +#include "ut_osprintf_offset.h" + +void CFE_TIME_PrintDummy(char *PrintBuffer, CFE_TIME_SysTime_t TimeToPrint) +{ +} + +unsigned char EVS_IsFilteredDummy(unsigned long int AppID, + unsigned int EventID, unsigned int EventType) +{ + return 0; +} + +void CFE_SB_InitMsgDummy(void *MsgPtr, + unsigned int MsgId, + unsigned int Length, + unsigned char Clear) +{ +} + +CFE_TIME_SysTime_t CFE_TIME_GetTimeDummy(void) +{ + CFE_TIME_SysTime_t Time = {0, 0}; + + return Time; +} + +void EVS_SendPacketDummy(unsigned long int AppID, CFE_TIME_SysTime_t Time, + CFE_EVS_Packet_t *EVS_PktPtr) +{ +} + +long int EVS_GetAppIDDummy(unsigned long int *AppIdPtr) +{ + return 0; +} + +long int EVS_NotRegisteredDummy(unsigned long int AppID) +{ + return 0; +} + +int OS_vsnprintfDummy(char *out_buffer, int max_len, + const char *format, VA_LIST varg) +{ + return 0; +} + +void OS_printfDummy(const char *format, ...) +{ +} + +char *strcatDummy(char *out, const char *in) +{ + return out; +} + +char *strncatDummy(char *out, const char *in, int len) +{ + return out; +} + +char *strncpyDummy(char *out, const char *in, int len) +{ + return out; +} + +int strlenDummy(const char *in) +{ + return 0; +} + +#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_p.c b/src/unit-tests/osprintf-test/ut_osprintf_p.c new file mode 100644 index 000000000..8daf3a5cf --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_p.c @@ -0,0 +1,72 @@ +/* + * UT_osprintf_p.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %p format + *****************************************************************************/ +void UT_osprintf_p(void) +{ + char *test_fmt = "p"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + long int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 98765, 5, "%p", "0x181cd", "%p"}, + {"02", 46372, 10, "$$$%p$$$", "$$$0xb524$$$", "%p embedded"}, + {"03", 91827, 5, "%3p", "0x166b3", "%p with minimum field size"}, + {"04", 33225, 11, "%.10p", "0x00000081c9", "%p with precision field size"}, + {"05", 12345, 9, "%9.7p", "0x0003039", "%p with minimum and precision field size"}, + {"06", 98765, 19, "%-.20p", "0x000000000000000181cd", "%p with left-justify"}, + {"07", -98765, 8, "%p", "0xfffe7e33", "%p, negative value"}, + {"08", 4108, 4, "%8p", " 0x100c", "%p with minimum field size > number of digits"}, + {"09", 55220, 6, "%010p", "0x0000d7b4", "%p with minimum field size > number of digits and leading zeroes"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, (void *) osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, (void *) osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_printf.c b/src/unit-tests/osprintf-test/ut_osprintf_printf.c new file mode 100644 index 000000000..bef23516d --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_printf.c @@ -0,0 +1,37 @@ +/* + * UT_osprintf_printf.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#ifdef OS_USE_EMBEDDED_PRINTF + +#include "ut_osprintf.h" + +extern unsigned OS_printf_enabled; + +/***************************************************************************** + * Tests of embedded printf to get complete osprintf.c code coverage + *****************************************************************************/ +void UT_osprintf_printf(void) +{ + /* Perform printf enabled test */ + PRINTF("%s", "printf_test_string\n"); + UT_Report(UT_PASS, + "PRINTF", + "Output to console", + "%s", + "01"); + + /* Perform printf disabled test */ + OS_printf_enabled = 0; + PRINTF("%s", "printf_test_string_disabled\n"); + UT_Report(UT_PASS, + "PRINTF", + "Output to console disabled", + "%s", + "02"); + OS_printf_enabled = 1; +} +#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_s.c b/src/unit-tests/osprintf-test/ut_osprintf_s.c new file mode 100644 index 000000000..0c68d204f --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_s.c @@ -0,0 +1,72 @@ +/* + * UT_osprintf_s.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %s format + *****************************************************************************/ +void UT_osprintf_s(void) +{ + char *test_fmt = "s"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + char test_val[30]; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", "123456789abcd", 7, "%s", "123456789abcd", "%s"}, + {"02", "123456789abcd", 7, "$$$%s$$$", "$$$123456789abcd$$$", "%s embedded"}, + {"03", "123456789abcd", 11, "%20s", " 123456789abcd", "%s with minimum field size"}, + {"04", "123456789abcd", 8, "%.10s", "123456789a", "%s with maximum field size"}, + {"05", "123456789abcd", 7, "%5.7s", "1234567", "%s with minimum and maximum field size"}, + {"06", "123456789abcd", 10, "%-20s", "123456789abcd ", "%s with left-justify"}, + {"07", "3456789abcd", 7, "%+s", "3456789abcd", "%s with sign"}, + {"08", "", 3, "%s", "", "%s with null string"}, + {"09", "123456789abcd", 11, "%020s", " 123456789abcd", "%s with minimum field size, ignore zero padding"}, + {"", "", 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_u.c b/src/unit-tests/osprintf-test/ut_osprintf_u.c new file mode 100644 index 000000000..50a48bc38 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_u.c @@ -0,0 +1,73 @@ +/* + * UT_osprintf_u.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %u format + *****************************************************************************/ +void UT_osprintf_u(void) +{ + char *test_fmt = "u"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 98765, 5, "%u", "98765", "%u"}, + {"02", 46372, 10, "$$$%u$$$", "$$$46372$$$", "%u embedded"}, + {"03", 91827, 5, "%3u", "91827", "%u with maximum field size"}, + {"04", 33225, 8, "%.10u", "0000033225", "%u with minimum field size"}, + {"05", 12345, 7, "%9.7u", " 0012345", "%u with minimum and maximum field size"}, + {"06", 98765, 18, "%-.20u", "00000000000000098765", "%u with left-justify"}, + {"07", 98765, 5, "%+u", "98765", "%u with sign"}, + {"08", -98765, 8, "%u", "4294868531", "%u, negative value"}, + {"09", 0, 6, "%u", "0", "%u, zero value"}, + {"10", 162534, 5, "%08u", "00162534", "%u with zero padding"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_x.c b/src/unit-tests/osprintf-test/ut_osprintf_x.c new file mode 100644 index 000000000..d03f9b77e --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_x.c @@ -0,0 +1,72 @@ +/* + * UT_osprintf_x.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %x format + *****************************************************************************/ +void UT_osprintf_x(void) +{ + char *test_fmt = "x"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + unsigned int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 0xa8b7, 3, "%x", "a8b7", "%x"}, + {"02", 0xff123, 10, "$$$%x$$$", "$$$ff123$$$", "%x embedded"}, + {"03", 0xd1827, 5, "%3x", "d1827", "%x with minimum field size < number of digits"}, + {"04", 0x3c225, 9, "%.10x", "000003c225", "%x with precision field size"}, + {"05", 0x12b45, 9, "%9.7x", " 0012b45", "%x with minimum and precision field size"}, + {"06", 0xe8a60, 19, "%-.20x", "000000000000000e8a60", "%x with left-justify"}, + {"07", -16, 7, "%x", "fffffff0", "%x, negative value"}, + {"08", 0x12b45, 3, "%8x", " 12b45", "%x with minimum field size > number of digits"}, + {"09", 0x12b45, 5, "%08x", "00012b45", "%x with minimum field size > number of digits and leading zeroes"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_x_uc.c b/src/unit-tests/osprintf-test/ut_osprintf_x_uc.c new file mode 100644 index 000000000..6e2aff3e0 --- /dev/null +++ b/src/unit-tests/osprintf-test/ut_osprintf_x_uc.c @@ -0,0 +1,72 @@ +/* + * UT_osprintf_X.c + * + * Created on: May 22, 2013 + * Author: Kevin McCluney + */ + +#include "ut_osprintf.h" + +extern char strg_buf[]; +extern char trunc_buf[]; + +/***************************************************************************** + * Test %X format + *****************************************************************************/ +void UT_osprintf_X(void) +{ + char *test_fmt = "x"; /* Test format character(s) */ + int i; + + struct + { + char *test_num; /* Test identifier; sequential numbers */ + unsigned int test_val; /* Test value */ + int max_len; /* Maximum output string length */ + char *format; /* Format string */ + char *expected; /* Expected result */ + char *description; /* Test description */ + } osp_tests[] = + { + {"01", 0xa8b7, 3, "%X", "A8B7", "%X"}, + {"02", 0xff123, 10, "$$$%X$$$", "$$$FF123$$$", "%X embedded"}, + {"03", 0xd1827, 5, "%3X", "D1827", "%X with minimum field size < number of digits"}, + {"04", 0x3c225, 9, "%.10X", "000003C225", "%X with precision field size"}, + {"05", 0x12b45, 7, "%9.7X", " 0012B45", "%X with minimum and precision field size"}, + {"06", 0xe8a60, 19, "%-.20X", "000000000000000E8A60", "%X with left-justify"}, + {"07", -16, 7, "%X", "FFFFFFF0", "%X, negative value"}, + {"08", 0x12b45, 4, "%8X", " 12B45", "%X with minimum field size > number of digits"}, + {"09", 0x12b45, 5, "%08X", "00012B45", "%X with minimum field size > number of digits and leading zeroes"}, + {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ + }; + + for (i = 0; osp_tests[i].format[0] != '\0'; i++) + { + /* Perform sprintf test */ + init_test(); + SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(osp_tests[i].expected, strg_buf), + "SPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + + /* Truncate expected string in preparation for snprintf test */ + strcpy(trunc_buf, osp_tests[i].expected); + + if (strlen(trunc_buf) >= osp_tests[i].max_len) + { + trunc_buf[osp_tests[i].max_len - 1] = '\0'; + } + + /* Perform snprintf test */ + init_test(); + SNPRINTF(strg_buf, osp_tests[i].max_len, + osp_tests[i].format, osp_tests[i].test_val); + UT_Report(check_test(trunc_buf, strg_buf), + "SNPRINTF", + osp_tests[i].description, + test_fmt, + osp_tests[i].test_num); + } +} diff --git a/src/unit-tests/ostimer-test/ut_ostimer_test.c b/src/unit-tests/ostimer-test/ut_ostimer_test.c new file mode 100644 index 000000000..6efe9a7cf --- /dev/null +++ b/src/unit-tests/ostimer-test/ut_ostimer_test.c @@ -0,0 +1,238 @@ +/*================================================================================* +** File: ut_ostimer_test.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_ostimer_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +int32 g_skipTestCase = -1; +char* g_skipTestCaseResult = " "; + +char* g_timerNames[UT_OS_TIMER_LIST_LEN]; +char g_longTimerName[OS_MAX_API_NAME+5]; + +uint32 g_cbLoopCntMax = 5; +uint32 g_toleranceVal = 0; +uint32 g_timerFirst = 0; +int32 g_status = 0; +uint32 g_timerId = 0; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_timercallback(uint32 timerId); + +void UT_os_init_timer_misc(void); +void UT_os_setup_timercreate_test(void); +void UT_os_setup_timerdelete_test(void); +void UT_os_setup_timergetidbyname_test(void); +void UT_os_setup_timergetinfo_test(void); +void UT_os_setup_timerset_test(void); + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +void UT_os_timercallback(uint32 timerId) +{ + int deltaTime = 0; + char text[UT_OS_LG_TEXT_LEN]; + static int32 loopCnt = 0, res = 0; + static uint32 prevIntervalTime = 0; + static uint32 currIntervalTime = 0; + static OS_time_t currTime = {0,0}, endTime = {0,0}; + + if (timerId == g_timerId) + { + if (g_timerFirst) + { + g_timerFirst = 0; + g_status = 0; + prevIntervalTime = 0; + res = 0; + loopCnt = 0; + OS_GetLocalTime(&currTime); + } + + OS_GetLocalTime(&endTime); + + if (endTime.seconds == currTime.seconds) + currIntervalTime = endTime.microsecs - currTime.microsecs; + else + currIntervalTime = endTime.microsecs + (1000000 - currTime.microsecs); + + if (currIntervalTime >= prevIntervalTime) + deltaTime = currIntervalTime - prevIntervalTime; + else + deltaTime = prevIntervalTime - currIntervalTime; + + if (g_logInfo.verboseLevel == UT_OS_LOG_EVERYTHING) + { + UT_OS_LOG_MACRO("\n"); + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "OS_TimerSet() - #4 Nominal [Output from timer callback func: "); + UT_OS_LOG_MACRO(text) + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "current_time=%d.%d, delta_time=%d, tolVal=%d, loopCnt=%d]\n", + (int)currTime.seconds, (int)currTime.microsecs, + (int)deltaTime, (int)g_toleranceVal, (int)loopCnt); + UT_OS_LOG_MACRO(text) + } + + if ((deltaTime > g_toleranceVal) && (loopCnt > 1)) + res = -1; + + loopCnt++; + + if (loopCnt < g_cbLoopCntMax) + { + currTime = endTime; + prevIntervalTime = currIntervalTime; + } + else + { + g_status = (res == 0) ? 1 : -1; + /* slow the timer down so the main test thread can continue */ + res = OS_TimerSet(g_timerId, 1000, 500000); + } + } +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_timer_misc() +{ + memset(g_longTimerName, 'Y', sizeof(g_longTimerName)); + g_longTimerName[sizeof(g_longTimerName)-1] = '\0'; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timercreate_test() +{ + memset(g_longTimerName, 'Y', sizeof(g_longTimerName)); + g_longTimerName[sizeof(g_longTimerName)-1] = '\0'; + + g_timerNames[0] = "Create_NotImpl"; + g_timerNames[1] = "Create_NullPtr"; + g_timerNames[2] = "Create_LongName"; + g_timerNames[3] = "Create_DuplName"; + g_timerNames[4] = "Create_Full"; + g_timerNames[5] = "Create_InvArg"; + g_timerNames[6] = "Create_UnAvail"; + g_timerNames[7] = "Create_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timerdelete_test() +{ + g_timerNames[0] = "Delete_NotImpl"; + g_timerNames[1] = "Delete_InvArg"; + g_timerNames[2] = "Delete_IntErr"; + g_timerNames[3] = "Delete_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timergetidbyname_test() +{ + g_timerNames[0] = "GetId_NotImpl"; + g_timerNames[1] = "GetId_NullPtr"; + g_timerNames[2] = "GetId_LongName"; + g_timerNames[3] = "GetId_NotFound"; + g_timerNames[4] = "GetId_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timergetinfo_test() +{ + g_timerNames[0] = "GetInfo_NotImpl"; + g_timerNames[1] = "GetInfo_NullPtr"; + g_timerNames[2] = "GetInfo_InvArg"; + g_timerNames[3] = "GetInfo_Nominal"; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timerset_test() +{ + g_timerNames[0] = "Set_NotImpl"; + g_timerNames[1] = "Set_InvArg"; + g_timerNames[2] = "Set_IntErr"; + g_timerNames[3] = "Set_ShortIntv"; + g_timerNames[4] = "Set_Nominal"; +} + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ +#ifdef _OSAL_UNIT_TEST_ + void OS_Application_Startup(void) +#else + int main(int argc, char* argv[]) +#endif +{ + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for ostimer APIs\n"); + + UT_os_timerinit_test(); + + OS_API_Init(); + + UT_os_init_timer_misc(); + + UT_os_setup_timercreate_test(); + UT_os_timercreate_test(); + + UT_os_setup_timerdelete_test(); + UT_os_timerdelete_test(); + + UT_os_setup_timergetidbyname_test(); + UT_os_timergetidbyname_test(); + + UT_os_setup_timergetinfo_test(); + UT_os_timergetinfo_test(); + + UT_os_setup_timerset_test(); + UT_OS_LOG_MACRO("\n============================================\n") + UT_os_timerset_test(); + UT_OS_LOG_MACRO("============================================\n") + + UT_os_teardown("ut_ostimer"); + + return (0); +} + +/*================================================================================* +** End of File: ut_ostimer_test.c +**================================================================================*/ diff --git a/src/unit-tests/ostimer-test/ut_ostimer_test.h b/src/unit-tests/ostimer-test/ut_ostimer_test.h new file mode 100644 index 000000000..7b52cbe6f --- /dev/null +++ b/src/unit-tests/ostimer-test/ut_ostimer_test.h @@ -0,0 +1,45 @@ +/*================================================================================* +** File: ut_ostimer_test.h +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +#ifndef _UT_OSTIMER_TEST_H_ +#define _UT_OSTIMER_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" +#include "ut_ostimer_timerio_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_LOG_FILENAME "ut_ostimer_log.txt" + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSTIMER_TEST_H_ */ + +/*================================================================================* +** End of File: ut_ostimer_test.h +**================================================================================*/ diff --git a/src/unit-tests/ostimer-test/ut_ostimer_test_arinc653.c b/src/unit-tests/ostimer-test/ut_ostimer_test_arinc653.c new file mode 100644 index 000000000..35882ddcd --- /dev/null +++ b/src/unit-tests/ostimer-test/ut_ostimer_test_arinc653.c @@ -0,0 +1,219 @@ +/*================================================================================* +** File: ut_ostimer_test_arinc653.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include + +#include "ut_ostimer_test.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +int32 g_skipTestCase = -1; +char* g_skipTestCaseResult = " "; + +char* g_timerNames[UT_OS_TIMER_LIST_LEN]; +char g_longTimerName[OS_MAX_API_NAME+5]; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_timercallback(uint32 timerId); + +void UT_os_init_timer_misc(void); +void UT_os_setup_timercreate_test(void); +void UT_os_setup_timerdelete_test(void); +void UT_os_setup_timergetidbyname_test(void); +void UT_os_setup_timergetinfo_test(void); +void UT_os_setup_timerset_test(void); + +void UT_os_timer_tests(void); + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +void UT_os_timercallback(uint32 timerId) +{ + int deltaTime = 0; + char text[UT_OS_LG_TEXT_LEN]; + RETURN_CODE_TYPE arincRes = 0; + static int32 loopCnt = 0, res = 0; + static uint32 prevIntervalTime = 0; + static uint32 currIntervalTime = 0; + static OS_time_t beginTime = {0,0}, currTime = {0,0}; + + OS_GetLocalTime(&currTime); + + if (currTime.seconds == beginTime.seconds) + currIntervalTime = currTime.microsecs - beginTime.microsecs; + else + currIntervalTime = currTime.microsecs + (1000000 - beginTime.microsecs); + + if (currIntervalTime >= prevIntervalTime) + deltaTime = currIntervalTime - prevIntervalTime; + else + deltaTime = prevIntervalTime - currIntervalTime; + + if (g_logInfo.verboseLevel == UT_OS_LOG_EVERYTHING) + { + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "OS_TimerSet() - #4 Nominal [Output from timer callback func: "); + UT_OS_LOG_MACRO(text) + memset(text, '\0', sizeof(text)); + UT_os_sprintf(text, "current_time=%d.%d, delta_time=%d, loopCnt=%d]\n", + (int)currTime.seconds, (int)currTime.microsecs, + (int)deltaTime, (int)loopCnt); + UT_OS_LOG_MACRO(text) + } + + loopCnt++; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_init_timer_misc() +{ + memset(g_longTimerName, 'Y', sizeof(g_longTimerName)); + g_longTimerName[sizeof(g_longTimerName)-1] = '\0'; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timercreate_test() +{ + g_timerNames[0] = "Timer #1"; /* Create_NotImpl */ + g_timerNames[1] = "Timer #1"; /* Create_NullPtr */ + g_timerNames[2] = "Timer #1"; /* Create_LongName */ + g_timerNames[3] = "Timer #1"; /* Create_DuplName */ + g_timerNames[4] = "Timer #1"; /* Create_Full */ + g_timerNames[5] = "Timer #1"; /* Create_InvArg */ + g_timerNames[6] = "Timer #1"; /* Create_UnAvail */ + g_timerNames[7] = "Timer #1"; /* Create_Nominal */ + + g_skipTestCase = 4; + g_skipTestCaseResult = UT_OS_NA; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timerdelete_test() +{ + g_timerNames[0] = "Timer #1"; /* Delete_NotImpl */ + g_timerNames[1] = "Timer #1"; /* Delete_InvArg */ + g_timerNames[2] = "Timer #1"; /* Delete_IntErr */ + g_timerNames[3] = "Timer #1"; /* Delete_Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timergetidbyname_test() +{ + g_timerNames[0] = "Timer #0"; /* GetId_NotImpl */ + g_timerNames[1] = "Timer #0"; /* GetId_NullPtr */ + g_timerNames[2] = "Timer #0"; /* GetId_LongName */ + g_timerNames[3] = "Timer #0"; /* GetId_NotFound */ + g_timerNames[4] = "Timer #0"; /* GetId_Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timergetinfo_test() +{ + g_timerNames[0] = "Timer #1"; /* GetInfo_NotImpl */ + g_timerNames[1] = "Timer #1"; /* GetInfo_NullPtr */ + g_timerNames[2] = "Timer #1"; /* GetInfo_InvArg */ + g_timerNames[3] = "Timer #1"; /* GetInfo_Nominal */ +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_setup_timerset_test() +{ + g_timerNames[0] = "Timer #0"; /* Set_NotImpl */ + g_timerNames[1] = "Timer #0"; /* Set_InvArg */ + g_timerNames[2] = "Timer #0"; /* Set_IntErr */ + g_timerNames[3] = "Timer #0"; /* Set_ShortIntv */ + g_timerNames[4] = "Timer #0"; /* Set_Nominal */ + + g_skipTestCase = 3; + g_skipTestCaseResult = UT_OS_NA; +} + +/*--------------------------------------------------------------------------------*/ + +void UT_os_timer_tests() +{ + UT_os_init_timer_misc(); + + UT_os_setup_timercreate_test(); + UT_os_timercreate_test(); + + UT_os_setup_timerdelete_test(); + UT_os_timerdelete_test(); + + UT_os_setup_timergetidbyname_test(); + UT_os_timergetidbyname_test(); + + UT_os_setup_timergetinfo_test(); + UT_os_timergetinfo_test(); + + UT_os_setup_timerset_test(); + UT_OS_LOG_MACRO("\n============================================\n") + UT_os_timerset_test(); + UT_OS_LOG_MACRO("============================================\n") + + UT_os_teardown("ut_ostimer"); +} + +/*--------------------------------------------------------------------------------* +** Main +**--------------------------------------------------------------------------------*/ + +void UT_main() +{ + int32 osalRet=0; + uint32 tId1=0, tId2=0, stackPtr=0; + RETURN_CODE_TYPE arincRet=NO_ERROR; + + UT_os_setup(UT_OS_LOG_FILENAME); + + /* UT_OS_LOG_OFF, UT_OS_LOG_MINIMAL, UT_OS_LOG_MODERATE, UT_OS_LOG_EVERYTHING */ + UT_os_set_log_verbose(UT_OS_LOG_EVERYTHING); + + UT_OS_LOG_MACRO("OSAL Unit Test Output File for ARINC653-implementation of ostimer APIs\n"); + + UT_os_timerinit_test(); + + osalRet = OS_TaskCreate(&tId1, "ut_ostimer", + (osal_task_entry)&UT_os_timer_tests, + &stackPtr, 0x2000, 110, 0); + + SET_PARTITION_MODE(NORMAL, &arincRet); +} + +/*================================================================================* +** End of File: ut_ostimer_test_arinc653.c +**================================================================================*/ diff --git a/src/unit-tests/ostimer-test/ut_ostimer_test_platforms.h b/src/unit-tests/ostimer-test/ut_ostimer_test_platforms.h new file mode 100644 index 000000000..96844aa80 --- /dev/null +++ b/src/unit-tests/ostimer-test/ut_ostimer_test_platforms.h @@ -0,0 +1,176 @@ +/*================================================================================* +** File: ut_ostimer_test_platforms.h +** Owner: Tam Ngo +** Date: September 2013 +**================================================================================*/ + +#ifndef _UT_OSTIMER_TEST_PLATFORMS_H_ +#define _UT_OSTIMER_TEST_PLATFORMS_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#ifdef _LINUX_OS_ +#endif /* _LINUX_OS_ */ + +#ifdef OSP_ARINC653 +#include "apex_api.h" +#endif /* OSP_ARINC653 */ + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef _LINUX_OS_ +/*--------------------------------------------*/ + +#define UT_OS_TIMER_SET_SHORT_INTERVAL_ELSE_MACRO \ +{ \ + g_status = 0; \ + g_timerId = g_timerIds[3]; \ + g_timerFirst = 1; \ + g_cbLoopCntMax = 10; \ + startTime = 1000; \ + intervalTime = 5; \ + g_toleranceVal = 0; \ + memset(text, '\0', sizeof(text)); \ + UT_os_sprintf(text, "\nOS_TimerSet() - #3 Interval-too-short (clk_accuracy=%d)\n", \ + (int)g_clkAccuracy); \ + UT_OS_LOG_MACRO(text) \ + res = OS_TimerSet(g_timerIds[3], startTime, intervalTime); \ + if (res == OS_SUCCESS) \ + { \ + while (!g_status) \ + OS_TaskDelay(1); \ + if (g_status < 0) \ + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) \ + else \ + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) \ + } \ + else \ + { \ + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) \ + } \ + /* Reset test environment */ \ + OS_TimerDelete(g_timerIds[3]); \ +} + +/*--------------------------------------------------------------------------------*/ + +#define UT_OS_TIMER_SET_NOMINAL_ELSE_MACRO \ +{ \ + g_status = 0; \ + g_timerId = g_timerIds[4]; \ + g_timerFirst = 1; \ + g_cbLoopCntMax = 10; \ + startTime = 1000; \ + intervalTime = 500000; \ + g_toleranceVal = intervalTime / 20; /* 5% */ \ + memset(text, '\0', sizeof(text)); \ + UT_os_sprintf(text, "\nOS_TimerSet() - #1 Nominal condition (clk_accuracy=%d)\n", \ + (int)g_clkAccuracy); \ + UT_OS_LOG_MACRO(text) \ + res = OS_TimerSet(g_timerIds[4], startTime, intervalTime); \ + if (res == OS_SUCCESS) \ + { \ + while (!g_status) \ + OS_TaskDelay(1); \ + if (g_status > 0) \ + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) \ + else \ + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) \ + } \ + else \ + { \ + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) \ + } \ + /* Reset test environment */ \ + OS_TimerDelete(g_timerIds[4]); \ +} + +/*--------------------------------------------*/ +#endif /* _LINUX_OS_ */ +/*--------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef OSP_ARINC653 +/*--------------------------------------------*/ + +#define UT_OS_TIMER_SET_SHORT_INTERVAL_ELSE_MACRO \ +{ \ + /* Do nothing for now */ \ +} + +/*--------------------------------------------------------------------------------*/ + +#define UT_OS_TIMER_SET_NOMINAL_ELSE_MACRO \ +{ \ + RETURN_CODE_TYPE arincRes=0; \ + startTime = 1000; \ + intervalTime = 500000; \ + res = OS_TimerSet(g_timerIds[4], startTime, intervalTime); \ + if (res == OS_SUCCESS) \ + { \ + testDesc = "#4 Nominal - Manual inspection required"; \ + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_MIR) \ + } \ + else \ + { \ + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) \ + } \ + /* Reset test environment */ \ + PERIODIC_WAIT(&arincRes); \ + OS_TaskDelay(intervalTime * 500); \ + OS_TimerDelete(g_timerIds[4]); \ +} + +/*--------------------------------------------*/ +#endif /* OSP_ARINC653 */ +/*--------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef _LINUX_OS_ +/*--------------------------------------------*/ + +extern uint32 g_cbLoopCntMax; +extern uint32 g_toleranceVal; +extern uint32 g_timerFirst; +extern int32 g_status; +extern uint32 g_timerId; + +/*--------------------------------------------*/ +#endif /* _LINUX_OS_ */ +/*--------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef OSP_ARINC653 +/*--------------------------------------------*/ +/*--------------------------------------------*/ +#endif /* OSP_ARINC653 */ +/*--------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSTIMER_TEST_PLATFORMS_H_ */ + +/*================================================================================* +** End of File: ut_ostimer_test_platforms.h +**================================================================================*/ diff --git a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c new file mode 100644 index 000000000..a2b5d30c6 --- /dev/null +++ b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c @@ -0,0 +1,885 @@ +/*================================================================================* +** File: ut_ostimer_timerio_test.c +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_ostimer_timerio_test.h" +#include "ut_ostimer_test_platforms.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +extern UT_OsLogInfo_t g_logInfo; + +extern char* g_timerNames[UT_OS_TIMER_LIST_LEN]; +extern char g_longTimerName[OS_MAX_API_NAME+5]; + +extern int32 g_skipTestCase; +extern char* g_skipTestCaseResult; + +/*--------------------------------------------------------------------------------* +** External function prototypes +**--------------------------------------------------------------------------------*/ + +extern void UT_os_timercallback(uint32 timerId); + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +uint32 g_clkAccuracy = 0; +uint32 g_timerIds[UT_OS_TIMER_LIST_LEN]; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Local function definitions +**--------------------------------------------------------------------------------*/ + +/* Test code template for testing a single OSAL API with multiple test cases */ + +#if 0 +void UT_os_sample_test() +{ + /* Must declare these variables for each function. They can be renamed. + * They're referenced in the macros used to track test cases and their results. */ + int32 idx = 0; + UT_OsApiInfo_t apiInfo; + const char* testDesc = NULL; + + /* Call this once at the beginning of the function to initialize the test variables. */ + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------* + * For each test case, + * 1. Assign testDesc a brief description of the test + * 2. Setup the test environment, if necessary + * 3. Run the test + * 4. Log result by calling UT_OS_SET_TEST_RESULT_MACRO + * 4. Reset the test environment, if neccessary + * + * NOTE: "Not implemented" is always checked first but not + * being included as a test case. + * "Nominal" test case is always the last test case. + *-----------------------------------------------------*/ + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + /* TODO: Setup the test environment, if necessary */ + + if (OS_xxx() == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_sample_test_exit_tag; + } + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(NULL,...) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(aVeryLoooooongName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* TODO: Reset the test environment here, if necessary */ + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + /* TODO: Setup the test environment here, if necessary */ + + if (OS_xxx(...) != OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + + /* TODO: Reset the test environment here, if necessary */ + +UT_os_sample_test_exit_tag: + /* Call these macros at the very end of the function to close out the test variables + * and get it added to the global list being tracked. */ + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_xxx", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} +#endif + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_TimerAPIInit(void) +** Purpose: Initializes the tables that the OS timer uses to keep track of information +** about objects +** Parameters: None +** Returns: OS_ERROR on an unsuccessful inits +** OS_SUCCESS on a successful inits +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** ----------------------------------------------------- +** Test #1: Init-not-call-first condition +** 1) Don't call this routine first +** 2) Call TBD routine(s) +** 3) Expect the returned value from those routines to be +** (a) __not__ OS_SUCCESS +*** ----------------------------------------------------- +** Test #2: Nominal condition +** 1) Call this routine +** 2) Expect the returned value to be +** (a) OS_SUCCESS (although results are not directly observable) +** 3) Call TBD routine(s) +** 4) Expect the returned value from those routines to be +** (a) OS_SUCCESS +*--------------------------------------------------------------------------------*/ +void UT_os_timerinit_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "#1 Init-not-call-first"; + + res = OS_TimerCreate(&g_timerIds[0], "Timer #0", &g_clkAccuracy, &UT_os_timercallback); + if (res != OS_SUCCESS) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + } + else + { + /* Reset test environment */ + OS_TimerDelete(g_timerIds[0]); + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /*-----------------------------------------------------*/ + testDesc = "#2 Nominal"; + + res = OS_API_Init(); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + testDesc = "API not implemented"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + } + else if (res == OS_SUCCESS) + { + res = OS_TimerCreate(&g_timerIds[0], "Timer #0", &g_clkAccuracy, &UT_os_timercallback); + if (res == OS_SUCCESS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_TimerDelete(g_timerIds[0]); + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TimerAPIInit", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_TimerCreate(uint32 *timer_id, const char *timer_name, uint32 *clock_accuracy, OS_TimerCallback_t callback_ptr) +** Purpose: Creates a new timer and associates it with a callback routine +** Parameters: *timer_id - a pointer that will hold the timer id +** *timer_name - a pointer that holds the name of the timer to be created +** *clock_accuracy - a pointer that will hold the clock accuracy in microseconds +** callback_ptr - a function pointer to the timer's callback +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_TAKEN if the name passed in has already been used +** OS_ERR_NO_FREE_IDS if all of the timers has already been allocated +** OS_TIMER_ERR_INVALID_ARGS if the callback pointer is null +** OS_TIMER_ERR_UNAVAILABLE if the timer cannot be created +** OS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** NOTE: If OS_TimerCreate() is implemented, then +** OS_TimerDelete() and OS_TimerGetIdByName() should be implemented +** ----------------------------------------------------- +** Test #1: Null-pointer-argument condition +** 1) Call this routine with a null pointer as one of the arguments (exclude callback ptr) +** 2) Expect the returned value to be +** (a) OS_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Name-too-long-argument condition +** 1) Call this routine with a timer name of length greater than OS_MAX_API_NAME as argument +** 2) Expect the returned value to be +** (a) OS_ERR_NAME_TOO_LONG +** ----------------------------------------------------- +** Test #3: Name-taken-argument condition +** 1) Call this routine with a valid timer name as argument +** 2) Expect the returned value to be +** (a) OS_SUCCESS +** 3) Call this routine the second time with the timer name used in #1 as argument +** 4) Expect the returned value to be +** (a) OS_ERR_NAME_TAKEN +** ----------------------------------------------------- +** Test #4: No-free-ids condition +** 1) Call this routine N number of times, where N = OS_MAX_TIMERS+1 +** 2) Expect the returned value of the last call to be +** (a) OS_ERR_NO_FREE_IDS +** ----------------------------------------------------- +** Test #5: Invalid-argument condition +** 1) Call this routine with a null pointer for callback as argument +** 2) Expect the returned value to be +** (a) OS_TIMER_ERR_INVALID_ARGS +** ----------------------------------------------------- +** Test #6: Timer-unavailable condition +** 1) Set up test to cause the OS call inside this routine to fail +** 2) Call this routine with valid arguments +** 3) Expect the returned value to be +** (a) OS_TIMER_ERR_UNAVAILABLE +** ----------------------------------------------------- +** Test #7: Nominal condition +** 1) Call this routine +** 2) Expect the returned value to be +** (a) OS_SUCCESS +** 3) Call OS_TimerGetIdByName with the timer name used in #1 as argument +** 4) Expect the returned value to be +** (a) OS_SUCCESS __and__ +** (b) the returned timer id is the same as the timer id returned in #1 +** 5) Call OS_TimerDelete with the timer id returned in #1 as argument +** 6) Expect the returned value to be +** (a) OS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_timercreate_test() +{ + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + int32 res=0, idx=0, i=0, j=0; + char tmpStr[UT_OS_XS_TEXT_LEN]; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TimerCreate(&g_timerIds[0], g_timerNames[0], &g_clkAccuracy, &UT_os_timercallback); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_timercreate_test_exit_tag; + } + + /* Reset test environment */ + OS_TimerDelete(g_timerIds[0]); + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if ((OS_TimerCreate(NULL, g_timerNames[1], &g_clkAccuracy, &UT_os_timercallback) == + OS_INVALID_POINTER) && + (OS_TimerCreate(&g_timerIds[1], NULL, &g_clkAccuracy, &UT_os_timercallback) == + OS_INVALID_POINTER) && + (OS_TimerCreate(&g_timerIds[1], g_timerNames[1], NULL, &UT_os_timercallback) == + OS_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long"; + + if (OS_TimerCreate(&g_timerIds[2], g_longTimerName, &g_clkAccuracy, &UT_os_timercallback) == + OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-taken"; + + if ((OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback) == + OS_SUCCESS) && + (OS_TimerCreate(&g_timerIds[4], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback) == + OS_ERR_NAME_TAKEN)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_TimerDelete(g_timerIds[3]); + + /*-----------------------------------------------------*/ + testDesc = "#4 No-free-IDs"; + + if (g_skipTestCase == 4) + { + testDesc = "#4 No-free-IDs - Test case not applicable on platform"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, g_skipTestCaseResult) + } + else + { + for (i=0; i <= OS_MAX_TIMERS; i++) + { + memset(tmpStr, '\0', sizeof(tmpStr)); + UT_os_sprintf(tmpStr, "Timer #%d", (int)i); + res = OS_TimerCreate(&g_timerIds[i], tmpStr, &g_clkAccuracy, &UT_os_timercallback); + if (res != OS_SUCCESS) + break; + } + + if (i < OS_MAX_TIMERS) + { + testDesc = "#4 No-free-IDs - Timer-created failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else if (i == OS_MAX_TIMERS) + { + if (res == OS_ERR_NO_FREE_IDS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /* Reset test environment */ + for (j=0; j < i; j++) + OS_TimerDelete(g_timerIds[j]); + } + + /*-----------------------------------------------------*/ + testDesc = "#5 Invalid-arg"; + + if (OS_TimerCreate(&g_timerIds[5], g_timerNames[5], &g_clkAccuracy, NULL) == + OS_TIMER_ERR_INVALID_ARGS) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#6 Timer-unavailable"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#7 Nominal"; + + res = OS_TimerCreate(&g_timerIds[7], g_timerNames[7], &g_clkAccuracy, &UT_os_timercallback); + if (res == OS_SUCCESS) + { + if ((OS_TimerGetIdByName(&g_timerIds[8], g_timerNames[7]) == OS_SUCCESS) && + (g_timerIds[7] == g_timerIds[8]) && + (OS_TimerDelete(g_timerIds[7]) == OS_SUCCESS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + +UT_os_timercreate_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TimerCreate", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_TimerDelete(uint32 timer_id) +** Purpose: Deletes a timer of a given timer id +** Parameters: timer_id - the id of the timer to be deleted +** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid timer id +** OS_TIMER_ERR_INTERNAL if the OS call failed +** OS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** Note: If OS_TimerDelete() is implemented, then +** OS_TimerCreate() and OS_TimerGetIdByName() should be implemented. +** ----------------------------------------------------- +** Test #1: Invalid-id-argument condition +** 1) Make sure there's no timer created previously +** 2) Call this routine with some value for timer id as argument +** 3) Expect the returned value to be +** (a) OS_ERR_INVALID_ID +** ----------------------------------------------------- +** Test #2: Internal-error condition +** 1) Set up test to cause the OS call inside this routine to fail +** 2) Call this routine with valid arguments +** 3) Expect the returned value to be +** (a) OS_TIMER_ERR_INTERNAL +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call OS_TimerCreate +** 2) Expect the returned value to be +** (a) OS_SUCCESS +** 3) Call this routine with the timer id returned in #1 as argument +** 4) Expect the returned value to be +** (a) OS_SUCCESS +** 5) Call OS_TimerGetIdByName with the timer name used in #1 as argument +** 6) Expect the returned value to be +** (a) OS_ERR_NAME_NOT_FOUND +** 7) Call OS_TimerCreate exactly as in #1 +** 8) Expect the returned value to be +** (a) OS_SUCCESS +**--------------------------------------------------------------------------------*/ +void UT_os_timerdelete_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TimerDelete(99999); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_timerdelete_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-id-arg"; + + if (OS_TimerDelete(99999) == OS_ERR_INVALID_ID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Internal-error"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + res = OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback); + if (res != OS_SUCCESS) + { + testDesc = "#3 Nominal - Timer-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_timerdelete_test_exit_tag; + } + + if (OS_TimerDelete(g_timerIds[3]) == OS_SUCCESS) + { + if ((OS_TimerGetIdByName(&g_timerIds[4], g_timerNames[3]) == OS_ERR_NAME_NOT_FOUND) && + (OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback) == + OS_SUCCESS)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /* Reset test environment */ + OS_TimerDelete(g_timerIds[3]); + +UT_os_timerdelete_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TimerDelete", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_TimerSet(uint32 timer_id, uint32 start_msec, uint32 interval_msec) +** Purpose: Programs a given timer with a start time of microseconds and an +** interval time of microseconds +** Parameters: timer_id - id of the timer to be programmed +** start_msec - start time in microseconds of when to first call the +** timer's callback function +** interval_msec - interval in microseconds of what the periodic timer +** will be programmed for +** Returns: OS_ERR_INVALID_ID if the timer id passed in is not a valid timer id +** OS_TIMER_ERR_INTERNAL if the OS call failed +** OS_SUCCESS if succeeded +** OS_ERR_NOT_IMPLEMENTED if not implemented +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** Note: If OS_TimerSet() is implemented, then +** OS_TimerCreate(), OS_TimerDelete() and OS_TimerGetIdByName() should be implemented. +** ----------------------------------------------------- +** Test #1: Invalid-id condition +** 1) Make sure there's no timer created previously +** 2) Call this routine with some value for timer id as argument +** 3) Expect the returned value to be +** (a) OS_ERR_INVALID_ID +** ----------------------------------------------------- +** Test #2: Internal-error condition +** 1) Setup test to cause the OS call inside this routine to fail +** 2) Call this routine with valid arguments +** 3) Expect the returned value to be +** (a) OS_TIMER_ERR_INTERNAL +** ----------------------------------------------------- +** Test #3: Interval-too-short condition +** 1) Call OS_TimerCreate +** 2) Expect the returned value to be +** (a) OS_SUCCESS +** 3) Call this routine with a start time of 1,000 and an interval time of 5 microsecs +** 4) When the timer callback registered in #1 gets call, determine if the duration +** is the set interval time +** 5) Exit test when the timer callback registered in #1 gets call 10 times +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_TimerCreate +** 2) Expect the returned value to be +** (a) OS_SUCCESS +** 3) Call this routine with a start time of 1,000 and an interval time of 500,000 microsecs +** 4) When the timer callback registered in #1 gets call, determine if the duration +** is within +/- 5% of the set interval time +** 5) Exit test when the timer callback registered in #1 gets call 10 times +**--------------------------------------------------------------------------------*/ +void UT_os_timerset_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + char text[UT_OS_LG_TEXT_LEN]; + uint32 startTime=0, intervalTime=0; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TimerSet(99999, startTime, intervalTime); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_timerset_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Invalid-id-arg"; + + res = OS_TimerSet(99999, startTime, intervalTime); + if (res == OS_ERR_INVALID_ID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Internal-error"; + + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_UOF) + + /*-----------------------------------------------------*/ + testDesc = "#3 Interval-too-short"; + + if (g_skipTestCase == 3) + { + testDesc = "#3 Interval-too-short - Test case not applicable on platform"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, g_skipTestCaseResult) + } + else + { + res = OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback); + if (res != OS_SUCCESS) + { + testDesc = "#3 Interval-too-short - Timer-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + UT_OS_TIMER_SET_SHORT_INTERVAL_ELSE_MACRO + } + } + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + res = OS_TimerCreate(&g_timerIds[4], g_timerNames[4], &g_clkAccuracy, &UT_os_timercallback); + if (res != OS_SUCCESS) + { + testDesc = "#4 Nominal - Timer-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_timerset_test_exit_tag; + } + else + { + UT_OS_TIMER_SET_NOMINAL_ELSE_MACRO + } + +UT_os_timerset_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TimerSet", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_TimerGetIdByName(uint32 *timer_id, const char *timer_name) +** Purpose: Returns the timer id of a given timer name +** Parameters: *timer_id - a pointer that will hold the timer id +** *timer_name - a pointer that holds the timer name +** Returns: OS_INVALID_POINTER if any of the pointers passed in is null +** OS_ERR_NAME_TOO_LONG if the name passed in is too long +** OS_ERR_NAME_NOT_FOUND if the name passed in is not found in the timer table +** OS_SUCCESS if succeeded +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** Note: If OS_TimerGetIdByName() is implemented, then +** OS_TimerCreate() and OS_TimerDelete() should be implemented. +** ----------------------------------------------------- +** Test #1: Null-pointer-argument condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Name-too-long condition +** 1) Call this routine with a timer name of length greater than OS_MAX_API_NAME as argument +** 2) Expect the returned value to be +** (a) OS_ERR_NAME_TOO_LONG +** ----------------------------------------------------- +** Test #3: Name-not-found condition +** 1) Make sure there's no timer created previously +** 2) Call this routine with a valid timer name +** 3) Expect the returned value to be +** (a) OS_ERR_NAME_NOT_FOUND +** ----------------------------------------------------- +** Test #4: Nominal condition +** 1) Call OS_TimerCreate +** 2) Expected the returned value to be +** (a) OS_SUCCESS +** 3) Call this routine with the timer name used in #1 as argument +** 4) Expect the returned value to be +** (a) OS_SUCCESS __and__ +** (b) the returned timer id is the same as the timer id returned in #1 +**--------------------------------------------------------------------------------*/ +void UT_os_timergetidbyname_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TimerGetIdByName(&g_timerIds[0], g_timerNames[0]); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_timergetidbyname_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + if ((OS_TimerGetIdByName(NULL, g_timerNames[1]) == OS_INVALID_POINTER) && + (OS_TimerGetIdByName(&g_timerIds[1], NULL) == OS_INVALID_POINTER)) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#2 Name-too-long"; + + if (OS_TimerGetIdByName(&g_timerIds[2], g_longTimerName) == OS_ERR_NAME_TOO_LONG) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#3 Name-not-found"; + + if (OS_TimerGetIdByName(&g_timerIds[3], g_timerNames[3]) == OS_ERR_NAME_NOT_FOUND) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /*-----------------------------------------------------*/ + testDesc = "#4 Nominal"; + + res = OS_TimerCreate(&g_timerIds[4], g_timerNames[4], &g_clkAccuracy, &UT_os_timercallback); + if (res != OS_SUCCESS) + { + testDesc = "#4 Nominal - Timer-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + goto UT_os_timergetidbyname_test_exit_tag; + } + + res = OS_TimerGetIdByName(&g_timerIds[5], g_timerNames[4]); + if ((res == OS_SUCCESS) && (g_timerIds[4] == g_timerIds[5])) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_TimerDelete(g_timerIds[4]); + +UT_os_timergetidbyname_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TimerGetIdByName", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_TimerGetInfo(uint32 timer_id, OS_timer_prop_t *timer_prop) +** Purpose: Returns timer information about a given timer +** Parameters: timer_id - the timer id to look up +** *timer_prop - a pointer to an OS_timer_prop_t structure that will +** hold a timer's information +** Returns: OS_INVALID_POINTER if the pointer passed in is null +** OS_ERR_INVALID_ID if the id passed in is not a valid timer id +** OS_SUCCESS if succeeded +** ----------------------------------------------------- +** Test #0: Not-implemented condition +** 1) Call this routine +** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test +** 3) Otherwise, continue +** Note: If OS_TimerGetInfo() is implemented, then +** OS_TimerCreate() and OS_TimerDelete() should be implemented. +** ----------------------------------------------------- +** Test #1: Null-pointer-argument condition +** 1) Call this routine with a null pointer as argument +** 2) Expect the returned value to be +** (a) OS_INVALID_POINTER +** ----------------------------------------------------- +** Test #2: Invalid-id-argument condition +** 1) Make sure there's no timer created previously +** 2) Call this routine with some value for timer id as argument +** 3) Expect the returned value to be +** (a) OS_ERR_INVALID_ID +** ----------------------------------------------------- +** Test #3: Nominal condition +** 1) Call OS_TimerCreate +** 2) Expect the returned value to be +** (a) OS_SUCCESS +** 3) Call this routine with the timer id returned in #1 +** 4) Expect the returned value to be +** (a) OS_SUCCESS __and__ +** (b) timer name returned for timer properties is the same as timer name used in #1 +**--------------------------------------------------------------------------------*/ +void UT_os_timergetinfo_test() +{ + int32 res=0, idx=0; + UT_OsApiInfo_t apiInfo; + const char* testDesc=NULL; + OS_timer_prop_t timerProps; + + UT_OS_CLEAR_API_INFO_MACRO(apiInfo, idx) + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + res = OS_TimerGetInfo(99999, &timerProps); + if (res == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_NA) + goto UT_os_timergetinfo_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1 Null-pointer-arg"; + + res = OS_TimerCreate(&g_timerIds[1], g_timerNames[1], &g_clkAccuracy, &UT_os_timercallback); + if (res != OS_SUCCESS) + { + testDesc = "#1 Null-pointer-arg - Timer-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + if (OS_TimerGetInfo(g_timerIds[1], NULL) == OS_INVALID_POINTER) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + /* Reset test environment */ + OS_TimerDelete(g_timerIds[1]); + } + + /*-----------------------------------------------------*/ + testDesc = "#2 Invalid-id-arg"; + + if (OS_TimerGetInfo(99999, &timerProps) == OS_ERR_INVALID_ID) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + + + /*-----------------------------------------------------*/ + testDesc = "#3 Nominal"; + + res = OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback); + if (res != OS_SUCCESS) + { + testDesc = "#3 Nominal - Timer-create failed"; + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_TSF) + } + else + { + memset(&timerProps, 0x00, sizeof(timerProps)); + res = OS_TimerGetInfo(g_timerIds[3], &timerProps); + if (res == OS_SUCCESS) + { + if (strcmp(timerProps.name, g_timerNames[3]) == 0) + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_PASSED) + else + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + else + { + UT_OS_SET_TEST_RESULT_MACRO(apiInfo, idx, testDesc, UT_OS_FAILED) + } + + /* Reset test environment */ + OS_TimerDelete(g_timerIds[3]); + } + +UT_os_timergetinfo_test_exit_tag: + UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(apiInfo, "OS_TimerGetInfo", idx) + UT_OS_LOG_API_MACRO(apiInfo) +} + +/*================================================================================* +** End of File: ut_ostimer_timerio_test.c +**================================================================================*/ diff --git a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.h b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.h new file mode 100644 index 000000000..9776ddb3f --- /dev/null +++ b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.h @@ -0,0 +1,51 @@ +/*================================================================================* +** File: ut_ostimer_timerio_test.h +** Owner: Tam Ngo +** Date: April 2013 +**================================================================================*/ + +#ifndef _UT_OSTIMER_TIMERIO_TEST_H_ +#define _UT_OSTIMER_TIMERIO_TEST_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +#define UT_OS_TIMER_LIST_LEN (OS_MAX_TIMERS + 10) + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_timerinit_test(void); +void UT_os_timercreate_test(void); +void UT_os_timerdelete_test(void); +void UT_os_timerset_test(void); +void UT_os_timergetidbyname_test(void); +void UT_os_timergetinfo_test(void); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OSTIMER_TIMERIO_TEST_H_ */ + +/*================================================================================* +** End of File: ut_ostimer_timerio_test.h +**================================================================================*/ diff --git a/src/unit-tests/shared/shared.mak b/src/unit-tests/shared/shared.mak new file mode 100644 index 000000000..958ebd9a1 --- /dev/null +++ b/src/unit-tests/shared/shared.mak @@ -0,0 +1,25 @@ +############################################################################### +# File: osal.mak +# +# Purpose: +# Compile the OS Abstraction layer library. +# +# History: +# 2004/04/12 A. Cudmore : Initial revision for SDO. +# 2004/05/24 P. Kutt : Modified for new directory structure; rewrote comments. +# +############################################################################### + +# Subsystem produced by this makefile. +TARGET = shared.o + +#============================================================================== +# Object files required to build subsystem. + +# OBJS=ut_oscore_stubs.o ut_osfile_stubs.o ut_osfilesys_stubs.o ut_osloader_stubs.o ut_osnetwork_stubs.o ut_os_stubs.o ut_ostimer_stubs.o +OBJS=ut_os_stubs.o +#============================================================================== +# Source files required to build subsystem; used to generate dependencies. + +SOURCES = $(OBJS:.o=.c) + diff --git a/src/unit-tests/shared/ut_os_stub_platforms.h b/src/unit-tests/shared/ut_os_stub_platforms.h new file mode 100644 index 000000000..9e97b90f7 --- /dev/null +++ b/src/unit-tests/shared/ut_os_stub_platforms.h @@ -0,0 +1,118 @@ +/*================================================================================* +** File: ut_os_stub_platforms.h +** Owner: Tam Ngo +** Date: September 2013 +**================================================================================*/ + +#ifndef _UT_OS_STUB_PLATFORMS_H_ +#define _UT_OS_STUB_PLATFORMS_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#ifndef ORIONSCP_BUILD +#include +#include +#include +#include +#endif /* !ORIONSCP_BUILD */ + +#ifdef _LINUX_OS_ +#endif /* _LINUX_OS_ */ + +#ifdef OSP_ARINC653 +#include "apex_api.h" + +#include "osfilesys.h" +#endif /* OSP_ARINC653 */ + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef _LINUX_OS_ +/*--------------------------------------------*/ + +#define UT_OS_PRINT_FDTABLE_CONTENT_MACRO \ + UT_os_sprintf(sVal, "[%d]", (int)j); \ + memcpy(&aLine[col0], sVal, strlen(sVal)); \ + UT_os_sprintf(sVal, "%d", (int)OS_FDTable[j].OSfd); \ + memcpy(&aLine[col1], sVal, strlen(sVal)); \ + memcpy(&aLine[col2], OS_FDTable[j].Path, strlen(OS_FDTable[j].Path)); \ + UT_os_sprintf(sVal, "%d", (int)OS_FDTable[j].User); \ + memcpy(&aLine[col3], sVal, strlen(sVal)); \ + UT_os_sprintf(sVal, "%d", (int)OS_FDTable[j].IsValid); \ + memcpy(&aLine[col4], sVal, strlen(sVal)); + +/*--------------------------------------------*/ +#endif /* _LINUX_OS_ */ +/*--------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef OSP_ARINC653 +/*--------------------------------------------*/ + +#define UT_OS_PRINT_FDTABLE_CONTENT_MACRO \ + UT_os_sprintf(sVal, "[%d]", (int)j); \ + memcpy(&aLine[col0], sVal, strlen(sVal)); \ + UT_os_sprintf(sVal, "%d", (int)OS_FDTable[j].fd_entry.OSfd); \ + memcpy(&aLine[col1], sVal, strlen(sVal)); \ + memcpy(&aLine[col2], OS_FDTable[j].fd_entry.Path, \ + strlen(OS_FDTable[j].fd_entry.Path)); \ + UT_os_sprintf(sVal, "%d", (int)OS_FDTable[j].fd_entry.User); \ + memcpy(&aLine[col3], sVal, strlen(sVal)); \ + UT_os_sprintf(sVal, "%d", (int)OS_FDTable[j].fd_entry.IsValid); \ + memcpy(&aLine[col4], sVal, strlen(sVal)); + +/*--------------------------------------------*/ +#endif /* OSP_ARINC653 */ +/*--------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef _LINUX_OS_ +/*--------------------------------------------*/ + +/* As defined in osfileapi.c */ +extern OS_FDTableEntry OS_FDTable[OS_MAX_NUM_OPEN_FILES]; + + +/*--------------------------------------------*/ +#endif /* _LINUX_OS_ */ +/*--------------------------------------------*/ + +/*--------------------------------------------*/ +#ifdef OSP_ARINC653 +/*--------------------------------------------*/ + +/* As defined in osfileapi.c */ +extern OS_FDTableEntry_Wrapper OS_FDTable[OS_MAX_NUM_OPEN_FILES]; + +/*--------------------------------------------*/ +#endif /* OSP_ARINC653 */ +/*--------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OS_STUB_PLATFORMS_H_ */ + +/*================================================================================* +** End of File: ut_os_stub_platforms.h +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_os_stubs.c b/src/unit-tests/shared/ut_os_stubs.c new file mode 100644 index 000000000..edba28483 --- /dev/null +++ b/src/unit-tests/shared/ut_os_stubs.c @@ -0,0 +1,433 @@ +/*================================================================================* +** File: ut_os_stubs.c +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +#include "ut_os_stubs.h" + +#include "ut_os_stub_platforms.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/* As defined in osfilesys.c */ +extern OS_VolumeInfo_t OS_VolumeTable[NUM_TABLE_ENTRIES]; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +UT_OsLogInfo_t g_logInfo; + +/*--------------------------------------------------------------------------------* +** Sets up test environment +**--------------------------------------------------------------------------------*/ +void UT_os_setup(const char* logFileName) +{ + g_logInfo.nPassed = 0; + g_logInfo.nFailed = 0; + g_logInfo.nMir = 0; + g_logInfo.nNa = 0; + g_logInfo.nUof = 0; + g_logInfo.nTsf = 0; + + g_logInfo.totalTstCnt = 0; + + g_logInfo.apiCnt = 0; + memset(g_logInfo.apis, 0x00, sizeof(g_logInfo.apis)); + + g_logInfo.verboseLevel = 0; + +#ifndef OS_USE_EMBEDDED_PRINTF + g_logInfo.logFD = NULL; + if (logFileName != NULL) + { + g_logInfo.logFD = fopen(logFileName, "w"); + if (g_logInfo.logFD == NULL) + fprintf(stderr, "Error: Can't open file %s\n", logFileName); + } +#endif /* !OS_USE_EMBEDDED_PRINTF */ +} + +/*--------------------------------------------------------------------------------* +** Tears down test setup +**--------------------------------------------------------------------------------*/ +void UT_os_teardown(const char* testSuiteName) +{ + UT_os_log_test_summaries(testSuiteName); + UT_os_log_test_results(testSuiteName); + +#ifndef OS_USE_EMBEDDED_PRINTF + if (g_logInfo.logFD != NULL) + { + fflush(g_logInfo.logFD); + fclose(g_logInfo.logFD); + g_logInfo.logFD = NULL; + } +#endif /* !OS_USE_EMBEDDED_PRINTF */ +} + +/*--------------------------------------------------------------------------------* +** Logs an API test descriptions +**--------------------------------------------------------------------------------*/ +void UT_os_log_api(UT_OsApiInfo_t* apiPtr) +{ + if (apiPtr != NULL) + { + int32 i = 0; + UT_OsApiInfo_t* apiInfo = NULL; + UT_OsTestDesc_t* testInfo = NULL; + UT_OsTestDesc_t* testPtr = NULL; + + apiInfo = &(g_logInfo.apis[g_logInfo.apiCnt]); + memset(apiInfo, 0x00, sizeof(UT_OsApiInfo_t)); + + strncpy(apiInfo->name, apiPtr->name, strlen(apiPtr->name)); + + apiInfo->tstCnt = apiPtr->tstCnt; + g_logInfo.totalTstCnt += apiInfo->tstCnt; + + for (i=0; i < apiInfo->tstCnt; i++) + { + testPtr = &(apiPtr->tests[i]); + testInfo = &(apiInfo->tests[i]); + + memset(testInfo, 0x00, sizeof(UT_OsTestDesc_t)); + + strncpy(testInfo->name, testPtr->name, strlen(testPtr->name)); + strncpy(testInfo->result, testPtr->result, strlen(testPtr->result)); + + if (strcmp(testInfo->result, UT_OS_PASSED) == 0) + g_logInfo.nPassed++; + else if (strcmp(testInfo->result, UT_OS_FAILED) == 0) + g_logInfo.nFailed++; + else if (strcmp(testInfo->result, UT_OS_MIR) == 0) + g_logInfo.nMir++; + else if (strcmp(testInfo->result, UT_OS_NA) == 0) + g_logInfo.nNa++; + else if (strcmp(testInfo->result, UT_OS_UOF) == 0) + g_logInfo.nUof++; + else if (strcmp(testInfo->result, UT_OS_TSF) == 0) + g_logInfo.nTsf++; + } + + g_logInfo.apiCnt++; + } +} + +/*--------------------------------------------------------------------------------* +** Set verbose level for logging +**--------------------------------------------------------------------------------*/ +void UT_os_set_log_verbose(uint32 vLevel) +{ + switch (vLevel) + { + case UT_OS_LOG_OFF: + case UT_OS_LOG_MINIMAL: + case UT_OS_LOG_MODERATE: + case UT_OS_LOG_EVERYTHING: + g_logInfo.verboseLevel = vLevel; + break; + + default: + g_logInfo.verboseLevel = UT_OS_LOG_EVERYTHING; + break; + } +} + +/*--------------------------------------------------------------------------------* +** Set return code +**--------------------------------------------------------------------------------*/ +void UT_os_set_return_code(UT_OsReturnCode_t* ret, int32 count, int32 value) +{ + if (ret != NULL) + { + ret->count = count; + ret->value = value; + } +} + +/*--------------------------------------------------------------------------------* +** Log test summaries +**--------------------------------------------------------------------------------*/ +void UT_os_log_test_summaries(const char* testSuiteName) +{ + char* txtPtr = NULL; + char txtStr[UT_OS_LG_TEXT_LEN]; + const char* tstName = testSuiteName; + + if (tstName == NULL) + tstName = " "; + + txtPtr = "\n========================================================\n"; + UT_OS_LOG_MACRO(txtPtr) + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "%s TOTAL APIs: %d\n", tstName, (int)g_logInfo.apiCnt); + UT_OS_LOG_MACRO(txtStr) + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "%s TOTAL TEST CASES: %d\n\n", tstName, (int)g_logInfo.totalTstCnt); + UT_OS_LOG_MACRO(txtStr) + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "%s PASSED %3d tests.\n", tstName, (int)g_logInfo.nPassed); + UT_OS_LOG_MACRO(txtStr) + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "%s FAILED %3d tests.\n", tstName, (int)g_logInfo.nFailed); + UT_OS_LOG_MACRO(txtStr) + + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "\n%s contains %2d tests that are untested OS-call-failure.\n", + tstName, (int)g_logInfo.nUof); + UT_OS_LOG_MACRO(txtStr) + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "%s contains %2d tests that are manual-inspection-required.\n", + tstName, (int)g_logInfo.nMir); + UT_OS_LOG_MACRO(txtStr) + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "\n%s contains %2d tests that are not-applicable.\n", + tstName, (int)g_logInfo.nNa); + UT_OS_LOG_MACRO(txtStr) + + if (g_logInfo.nTsf > 0) + { + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "\n%s contains %2d tests that are test-setup-failure.\n", + tstName, (int)g_logInfo.nTsf); + UT_OS_LOG_MACRO(txtStr) + } + + txtPtr = "========================================================\n"; + UT_OS_LOG_MACRO(txtPtr) +} + +/*--------------------------------------------------------------------------------* +** Print log info +**--------------------------------------------------------------------------------*/ +void UT_os_log_test_results(const char* testSuiteName) +{ + int32 i = 0, j = 0; + char* txtPtr = NULL; + UT_OsApiInfo_t* apiPtr = NULL; + char txtStr[UT_OS_LG_TEXT_LEN]; + const char* tstName = testSuiteName; + + if (tstName == NULL) + tstName = " "; + + if (g_logInfo.verboseLevel >= UT_OS_LOG_MODERATE) + { + txtPtr = "\n--------------------------------------------------------\n"; + UT_OS_LOG_MACRO(txtPtr) + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "%s TOTAL APIs: %d\n", tstName, (int)g_logInfo.apiCnt); + UT_OS_LOG_MACRO(txtStr) + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "%s TOTAL TEST CASES: %d\n", tstName, (int)g_logInfo.totalTstCnt); + UT_OS_LOG_MACRO(txtStr) + txtPtr = "--------------------------------------------------------"; + UT_OS_LOG_MACRO(txtPtr) + + for (i=0; i < g_logInfo.apiCnt; i++) + { + apiPtr = &(g_logInfo.apis[i]); + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, "\n %s: %d\n", apiPtr->name, (int)apiPtr->tstCnt); + UT_OS_LOG_MACRO(txtStr) + for (j=0; j < apiPtr->tstCnt; j++) + { + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, " %s [%s]\n", apiPtr->tests[j].name, + apiPtr->tests[j].result); + UT_OS_LOG_MACRO(txtStr) + } + } + } + + UT_os_log_test_result_category("PASSED", UT_OS_PASSED, g_logInfo.nPassed); + UT_os_log_test_result_category("FAILED", UT_OS_FAILED, g_logInfo.nFailed); + UT_os_log_test_result_category("MANUAL-INSPECTION-REQUIRED", UT_OS_MIR, g_logInfo.nMir); + UT_os_log_test_result_category("NOT-APPLICABLE", UT_OS_NA, g_logInfo.nNa); + UT_os_log_test_result_category("UNTESTED-OS-CALL-FAILURE", UT_OS_UOF, g_logInfo.nUof); + + if (g_logInfo.nTsf > 0) + { + UT_os_log_test_result_category("TEST-SETUP-FAILURE", UT_OS_TSF, g_logInfo.nTsf); + } + + if (g_logInfo.verboseLevel != UT_OS_LOG_OFF) + { + txtPtr = "\n\n"; + UT_OS_LOG_MACRO(txtPtr); + } +} + +/*--------------------------------------------------------------------------------* +** Print a test-result category +**--------------------------------------------------------------------------------*/ +void UT_os_log_test_result_category(const char* catName, const char* catKey, uint32 nCases) +{ + int32 i = 0, j = 0; + char* txtPtr = NULL; + UT_OsApiInfo_t* apiPtr = NULL; + const char* inCatKey = catKey; + char txtStr[UT_OS_LG_TEXT_LEN]; + const char* inCatName = catName; + + if (inCatKey == NULL) + inCatKey = " "; + + if (inCatName == NULL) + inCatName = " "; + + if (g_logInfo.verboseLevel >= UT_OS_LOG_MODERATE) + { + txtPtr = "\n--------------------------------------------------------\n"; + UT_OS_LOG_MACRO(txtPtr) + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, " TOTAL TEST CASES %s -> %d\n", inCatName, (int)nCases); + UT_OS_LOG_MACRO(txtStr) + txtPtr = "--------------------------------------------------------\n"; + UT_OS_LOG_MACRO(txtPtr) + + for (i=0; i < g_logInfo.apiCnt; i++) + { + apiPtr = &(g_logInfo.apis[i]); + for (j=0; j < apiPtr->tstCnt; j++) + { + if (strcmp(apiPtr->tests[j].result, inCatKey) == 0) + { + memset(txtStr, '\0', sizeof(txtStr)); + UT_os_sprintf(txtStr, " %s [ ] %s - %s \n", + inCatKey, apiPtr->name, apiPtr->tests[j].name); + UT_OS_LOG_MACRO(txtStr) + } + } + } + } +} + +/*--------------------------------------------------------------------------------* +** Print OS_FDTable[] +**--------------------------------------------------------------------------------*/ +void UT_os_print_fdtable(const char* outputDesc) +{ +#ifdef UT_VERBOSE + char* txtPtr = NULL; + char aLine[UT_OS_LG_TEXT_LEN], sVal[UT_OS_XS_TEXT_LEN]; + uint32 j = 0, col0 = 1, col1 = 8, col2 = 14, col3 = 44, col4 = 52; + + if (outputDesc) + UT_OS_LOG_MACRO(outputDesc) + + memset(aLine, ' ', sizeof(aLine)); + memcpy(&aLine[col1], "FD", strlen("FD")); + memcpy(&aLine[col2], "PATH", strlen("PATH")); + memcpy(&aLine[col3-2], "USERID", strlen("USERID")); + memcpy(&aLine[col4-2], "VALID?", strlen("VALID?")); + aLine[col4+strlen("VALID?")] = '\0'; + + txtPtr = "\n----------------------------------------------------------\n"; + UT_OS_LOG_MACRO(txtPtr) + UT_OS_LOG_MACRO(aLine) + txtPtr = "\n----------------------------------------------------------\n"; + UT_OS_LOG_MACRO(txtPtr) + + txtPtr = "\n"; + for (j=0; j < OS_MAX_NUM_OPEN_FILES; j++) + { + memset(aLine, ' ', sizeof(aLine)); + + UT_OS_PRINT_FDTABLE_CONTENT_MACRO + + aLine[col4+strlen(sVal)] = '\0'; + + UT_OS_LOG_MACRO(aLine) + UT_OS_LOG_MACRO(txtPtr) + } + + UT_OS_LOG_MACRO(txtPtr) +#endif /* UT_VERBOSE */ +} + +/*--------------------------------------------------------------------------------* +** Print OS_VolumeTable[] +**--------------------------------------------------------------------------------*/ +void UT_os_print_volumetable(const char* outputDesc) +{ +#ifdef UT_VERBOSE + char* txtPtr = NULL; + char aLine[UT_OS_LG_TEXT_LEN], sVal[UT_OS_XS_TEXT_LEN]; + uint32 j = 0, col0 = 1, col1 = 8, col2 = 24, col3 = 56; + uint32 col4 = 70, col5 = 88, col6 = 96, col7 = 104, col8 = 114; + + if (outputDesc) + UT_OS_LOG_MACRO(outputDesc) + + memset(aLine, ' ', sizeof(aLine)); + memcpy(&aLine[col1], "DEVNAME", strlen("DEVNAME")); + memcpy(&aLine[col2], "PHYSDEV", strlen("PHYSDEV")); + memcpy(&aLine[col3], "VOLNAME", strlen("VOLNAME")); + memcpy(&aLine[col4], "MOUNTPNT", strlen("MOUNTPNT")); + memcpy(&aLine[col5-5], "VOLATILE?", strlen("VOLATILE?")); + memcpy(&aLine[col6-2], "FREE?", strlen("FREE?")); + memcpy(&aLine[col7-3], "MOUNTED?", strlen("MOUNTED?")); + memcpy(&aLine[col8-3], "BLOCKSIZE", strlen("BLOCKSIZE")); + aLine[col8+strlen("BLOCKSIZE")] = '\0'; + + txtPtr = "\n--------------------------------------------------------------"; + UT_OS_LOG_MACRO(txtPtr) + txtPtr = "-------------------------------------------------------------\n"; + UT_OS_LOG_MACRO(txtPtr) + UT_OS_LOG_MACRO(aLine) + txtPtr = "\n--------------------------------------------------------------"; + UT_OS_LOG_MACRO(txtPtr) + txtPtr = "-------------------------------------------------------------\n"; + UT_OS_LOG_MACRO(txtPtr) + + txtPtr = "\n"; + for (j=0; j < NUM_TABLE_ENTRIES; j++) + { + memset(aLine, ' ', sizeof(aLine)); + + memset(sVal, '\0', sizeof(sVal)); + UT_os_sprintf(sVal, "[%d]", (int)j); + memcpy(&aLine[col0], sVal, strlen(sVal)); + memcpy(&aLine[col1], OS_VolumeTable[j].DeviceName, strlen(OS_VolumeTable[j].DeviceName)); + memcpy(&aLine[col2], OS_VolumeTable[j].PhysDevName, strlen(OS_VolumeTable[j].PhysDevName)); + memcpy(&aLine[col3], OS_VolumeTable[j].VolumeName, strlen(OS_VolumeTable[j].VolumeName)); + memcpy(&aLine[col4], OS_VolumeTable[j].MountPoint, strlen(OS_VolumeTable[j].MountPoint)); + memset(sVal, '\0', sizeof(sVal)); + UT_os_sprintf(sVal, "%d", (int)OS_VolumeTable[j].VolatileFlag); + memcpy(&aLine[col5], sVal, strlen(sVal)); + memset(sVal, '\0', sizeof(sVal)); + UT_os_sprintf(sVal, "%d", (int)OS_VolumeTable[j].FreeFlag); + memcpy(&aLine[col6], sVal, strlen(sVal)); + memset(sVal, '\0', sizeof(sVal)); + UT_os_sprintf(sVal, "%d", (int)OS_VolumeTable[j].IsMounted); + memcpy(&aLine[col7], sVal, strlen(sVal)); + memset(sVal, '\0', sizeof(sVal)); + UT_os_sprintf(sVal, "%d", (int)OS_VolumeTable[j].BlockSize); + memcpy(&aLine[col8], sVal, strlen(sVal)); + + aLine[col8+strlen(sVal)] = '\0'; + + UT_OS_LOG_MACRO(aLine) + UT_OS_LOG_MACRO(txtPtr) + } + + UT_OS_LOG_MACRO(txtPtr) +#endif /* UT_VERBOSE */ +} + +/*================================================================================* +** End of File: ut_os_stubs.c +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_os_stubs.h b/src/unit-tests/shared/ut_os_stubs.h new file mode 100644 index 000000000..f0dcec330 --- /dev/null +++ b/src/unit-tests/shared/ut_os_stubs.h @@ -0,0 +1,182 @@ +/*================================================================================* +** File: ut_os_stubs.h +** Owner: Tam Ngo +** Date: May 2013 +**================================================================================*/ + +#ifndef _UT_OS_STUBS_H_ +#define _UT_OS_STUBS_H_ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include + +#include +#include + +#include "common_types.h" +#include "osapi.h" +#include "osconfig.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/* Only use by developers for debugging; comment out when not debugging */ +/*#define OS_LOG_TO_STDOUT_TOO*/ + +#define UT_OS_LOG_OFF 0 +#define UT_OS_LOG_MINIMAL 1 +#define UT_OS_LOG_MODERATE 2 +#define UT_OS_LOG_EVERYTHING 3 + +#define UT_OS_PASSED "PASSED" +#define UT_OS_FAILED "FAILED" +#define UT_OS_MIR "_MIR_ " /* Manual Inspection Required */ +#define UT_OS_NA "__NA__" /* Not Applicable */ +#define UT_OS_UOF "_UOF_ " /* Untested OS-call Failure */ +#define UT_OS_TSF "_TSF_ " /* Test Setup Failure */ + +#define UT_OS_XS_LIST_LEN 25 +#define UT_OS_SM_LIST_LEN 50 +#define UT_OS_MD_LIST_LEN 100 +#define UT_OS_LG_LIST_LEN 200 + +#define UT_OS_XS_TEXT_LEN 25 +#define UT_OS_SM_TEXT_LEN 75 +#define UT_OS_MD_TEXT_LEN 125 +#define UT_OS_LG_TEXT_LEN 250 + +/*--------------------------------------------------------------------------------*/ + +#define UT_OS_CLEAR_API_INFO_MACRO(VAR1, TSTIDX) \ + memset(&(VAR1), 0x00, sizeof(UT_OsApiInfo_t)); \ + TSTIDX = 0; + +/*--------------------------------------------------------------------------------*/ + +#define UT_OS_SET_API_NAME_AND_TEST_COUNT_MACRO(VAR1, APINAME, TSTCNT) \ +{ \ + memset(VAR1.name, '\0', sizeof(VAR1.name)); \ + strncpy(VAR1.name, APINAME, strlen(APINAME)); \ + VAR1.tstCnt = TSTCNT; \ +} + +/*--------------------------------------------------------------------------------*/ + +#define UT_OS_SET_TEST_RESULT_MACRO(VAR1, TSTIDX, TSTNAME, TSTRESULT) \ +{ \ + memset(&(VAR1.tests[TSTIDX]), 0x00, sizeof(UT_OsTestDesc_t)); \ + strncpy(VAR1.tests[TSTIDX].name, TSTNAME, strlen(TSTNAME)); \ + strncpy(VAR1.tests[TSTIDX].result, TSTRESULT, strlen(TSTRESULT)); \ + (TSTIDX)++; \ +} + +/*--------------------------------------------------------------------------------*/ + +#define UT_OS_LOG_API_MACRO(VAR1) \ + UT_os_log_api(&VAR1); + +/*--------------------------------------------------------------------------------*/ + +#ifdef OS_USE_EMBEDDED_PRINTF +#define UT_os_printf OS_printf +#define UT_os_sprintf OS_sprintf +#else +#define UT_os_printf printf +#define UT_os_sprintf sprintf +#endif /* OS_USE_EMBEDDED_PRINTF */ + +/*--------------------------------------------------------------------------------*/ + +#ifdef OS_USE_EMBEDDED_PRINTF +#define UT_OS_LOG_MACRO(aVAR) UT_os_printf(aVAR); +#else +#ifdef OS_LOG_TO_STDOUT_TOO +#define UT_OS_LOG_MACRO(aVAR) \ + UT_os_printf(aVAR); \ + if (g_logInfo.logFD != NULL) \ + fprintf(g_logInfo.logFD, aVAR); +#else +#define UT_OS_LOG_MACRO(aVAR) \ + if (g_logInfo.logFD != NULL) \ + fprintf(g_logInfo.logFD, aVAR); +#endif /* OS_LOG_TO_STDOUT_TOO */ +#endif /* OS_USE_EMBEDDED_PRINTF */ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +typedef struct +{ + char name[UT_OS_SM_TEXT_LEN]; + char result[UT_OS_SM_TEXT_LEN]; +} UT_OsTestDesc_t; + +typedef struct +{ + char name[UT_OS_SM_TEXT_LEN]; + uint32 tstCnt; + UT_OsTestDesc_t tests[UT_OS_XS_LIST_LEN]; +} UT_OsApiInfo_t; + +typedef struct +{ +#ifndef OS_USE_EMBEDDED_PRINTF + FILE* logFD; +#endif /* !OS_USE_EMBEDDED_PRINTF */ + uint32 verboseLevel; + uint32 apiCnt; + UT_OsApiInfo_t apis[UT_OS_LG_LIST_LEN]; + uint32 totalTstCnt; + uint32 nPassed; + uint32 nFailed; + uint32 nMir; + uint32 nNa; + uint32 nUof; + uint32 nTsf; +} UT_OsLogInfo_t; + +typedef struct +{ + int32 count; + int32 value; +} UT_OsReturnCode_t; + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function prototypes +**--------------------------------------------------------------------------------*/ + +void UT_os_setup(const char* logFileName); +void UT_os_teardown(const char* testSuiteName); + +void UT_os_log_api(UT_OsApiInfo_t* apiPtr); + +void UT_os_set_log_verbose(uint32 verboseLevel); +void UT_os_set_return_code(UT_OsReturnCode_t* ret, int32 count, int32 value); + +void UT_os_log_test_summaries(const char* testSuiteName); +void UT_os_log_test_results(const char* testSuiteName); +void UT_os_log_test_result_category(const char* catName, const char* catKey, uint32 nCases); + +void UT_os_print_fdtable(const char* outputDesc); +void UT_os_print_volumetable(const char* outputDesc); + +/*--------------------------------------------------------------------------------*/ + +#endif /* _UT_OS_STUBS_H_ */ + +/*================================================================================* +** End of File: ut_os_stubs.h +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_oscore_stubs.c b/src/unit-tests/shared/ut_oscore_stubs.c new file mode 100644 index 000000000..d0b780b98 --- /dev/null +++ b/src/unit-tests/shared/ut_oscore_stubs.c @@ -0,0 +1,48 @@ +/*================================================================================* +** File: ut_oscore_stubs.c +** Owner: Tam Ngo +** Date: March 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +UT_OsReturnCode_t g_apiInit = {0,0}; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function definitions +**--------------------------------------------------------------------------------*/ + +int32 OS_API_Init() +{ + return (g_apiInit.value); +} + +/*--------------------------------------------------------------------------------*/ + +/*================================================================================* +** End of File: ut_oscore_stubs.c +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_osfile_stubs.c b/src/unit-tests/shared/ut_osfile_stubs.c new file mode 100644 index 000000000..538d2d6b3 --- /dev/null +++ b/src/unit-tests/shared/ut_osfile_stubs.c @@ -0,0 +1,237 @@ +/*================================================================================* +** File: ut_osfile_stubs.c +** Owner: Tam Ngo +** Date: March 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +UT_OsReturnCode_t g_osFsInit = {0,0}; +UT_OsReturnCode_t g_fileCreate = {0,0}; +UT_OsReturnCode_t g_fileOpen = {0,0}; +UT_OsReturnCode_t g_fileClose = {0,0}; +UT_OsReturnCode_t g_fileRead = {0,0}; +UT_OsReturnCode_t g_fileWrite = {0,0}; +UT_OsReturnCode_t g_fileChmod = {0,0}; +UT_OsReturnCode_t g_fileStat = {0,0}; +UT_OsReturnCode_t g_fileSeek = {0,0}; +UT_OsReturnCode_t g_fileRemove = {0,0}; +UT_OsReturnCode_t g_fileRename = {0,0}; +UT_OsReturnCode_t g_fileCopy = {0,0}; +UT_OsReturnCode_t g_fileMove = {0,0}; +UT_OsReturnCode_t g_fileOpenCheck = {0,0}; + +UT_OsReturnCode_t g_shellOutputToFile = {0,0}; +UT_OsReturnCode_t g_getFdInfo = {0,0}; +UT_OsReturnCode_t g_closeAllFiles = {0,0}; +UT_OsReturnCode_t g_closeFileByName = {0,0}; + +UT_OsReturnCode_t g_dirMake = {0,0}; +UT_OsReturnCode_t g_dirOpen = {0,0}; +UT_OsReturnCode_t g_dirClose = {0,0}; +UT_OsReturnCode_t g_dirRead = {0,0}; +UT_OsReturnCode_t g_dirRewind = {0,0}; +UT_OsReturnCode_t g_dirRemove = {0,0}; + +/* As defined in osfileapi.c */ +OS_FDTableEntry OS_FDTable[OS_MAX_NUM_OPEN_FILES]; + +#ifdef _LINUX_OS_ +pthread_mutex_t OS_FDTableMutex; +#endif + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function definitions +**--------------------------------------------------------------------------------*/ + +int32 OS_FS_Init(void) +{ + return (g_osFsInit.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_creat(const char* path, int32 access) +{ + return (g_fileCreate.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_open(const char* path, int32 access, uint32 mode) +{ + return (g_fileOpen.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_close(int32 filedes) +{ + return (g_fileClose.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_read(int32 filedes, void* buffer, uint32 nbytes) +{ + return (g_fileRead.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_write(int32 filedes, void* buffer, uint32 nbytes) +{ + return (g_fileWrite.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_chmod(const char* path, uint32 access) +{ + return (g_fileChmod.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_stat(const char* path, os_fstat_t* filestats) +{ + return (g_fileStat.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_lseek(int32 filedes, int32 offset, uint32 whence) +{ + return (g_fileSeek.value); +} +/*--------------------------------------------------------------------------------*/ + +int32 OS_remove(const char *path) +{ + return (g_fileRemove.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_rename(const char* old, const char* new) +{ + return (g_fileRename.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_cp(const char* src, const char* dest) +{ + return (g_fileCopy.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_mv(const char* src, const char* dest) +{ + return (g_fileMove.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_ShellOutputToFile(char* Cmd, int32 OS_fd) +{ + return (g_shellOutputToFile.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_FDGetInfo(int32 filedes, OS_FDTableEntry* fd_prop) +{ + return (g_getFdInfo.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_FileOpenCheck(char* filename) +{ + return (g_fileOpenCheck.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_CloseFileByName(char* filename) +{ + return (g_closeFileByName.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_CloseAllFiles(void) +{ + return (g_closeAllFiles.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_mkdir(const char* path, uint32 access) +{ + return (g_dirMake.value); +} + +/*--------------------------------------------------------------------------------*/ + +os_dirp_t OS_opendir(const char* path) +{ + return ((os_dirp_t)g_dirOpen.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_closedir(os_dirp_t directory) +{ + return (g_dirClose.value); +} + +/*--------------------------------------------------------------------------------*/ + +os_dirent_t* OS_readdir(os_dirp_t directory) +{ + return ((os_dirent_t*)g_dirRead.value); +} + +/*--------------------------------------------------------------------------------*/ + +void OS_rewinddir(os_dirp_t directory ) +{ +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_rmdir(const char* path) +{ + return (g_dirRemove.value); +} + +/*================================================================================* +** End of File: ut_osfile_stubs.c +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_osfilesys_stubs.c b/src/unit-tests/shared/ut_osfilesys_stubs.c new file mode 100644 index 000000000..52eff002b --- /dev/null +++ b/src/unit-tests/shared/ut_osfilesys_stubs.c @@ -0,0 +1,113 @@ +/*================================================================================* +** File: ut_osfilesys_stubs.c +** Owner: Tam Ngo +** Date: March 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/* As defined in osfilesys.c */ +extern OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES]; + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +UT_OsReturnCode_t g_fsMake = {0,0}; +UT_OsReturnCode_t g_fsRemove = {0,0}; +UT_OsReturnCode_t g_fsInit = {0,0}; +UT_OsReturnCode_t g_fsMount = {0,0}; +UT_OsReturnCode_t g_fsUnmount = {0,0}; +UT_OsReturnCode_t g_fsBlocksFree = {0,0}; +UT_OsReturnCode_t g_fsBytesFree = {0,0}; +UT_OsReturnCode_t g_fsGetPhysDriveName = {0,0}; +UT_OsReturnCode_t g_fsTranslatePath = {0,0}; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function definitions +**--------------------------------------------------------------------------------*/ + +int32 OS_mkfs(char* address, char* devname,char* volname, uint32 blocksize, uint32 numblocks) +{ + return (g_fsMake.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_rmfs(char* devname) +{ + return (g_fsRemove.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_initfs(char* address,char* devname, char* volname, uint32 blocksize, uint32 numblocks) +{ + return (g_fsInit.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_mount(const char* devname, char* mountpoint) +{ + return (g_fsMount.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_unmount(const char* mountpoint) +{ + return (g_fsUnmount.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_fsBlocksFree(const char* name) +{ + return (g_fsBlocksFree.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_fsBytesFree(const char* name, uint64* bytes_free) +{ + return (g_fsBytesFree.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_FS_GetPhysDriveName(char* PhysDriveName, char* MountPoint) +{ + return (g_fsGetPhysDriveName.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_TranslatePath(const char* VirtualPath, char* LocalPath) +{ + return (g_fsTranslatePath.value); +} + +/*================================================================================* +** End of File: ut_osfilesys_stubs.c +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_osloader_stubs.c b/src/unit-tests/shared/ut_osloader_stubs.c new file mode 100644 index 000000000..7a30589e8 --- /dev/null +++ b/src/unit-tests/shared/ut_osloader_stubs.c @@ -0,0 +1,96 @@ +/*================================================================================* +** File: ut_osloader_stubs.c +** Owner: Tam Ngo +** Date: March 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +UT_OsReturnCode_t g_moduleTblInit = {0,0}; +UT_OsReturnCode_t g_moduleLoad = {0,0}; +UT_OsReturnCode_t g_moduleUnload = {0,0}; +UT_OsReturnCode_t g_moduleInfo = {0,0}; + +UT_OsReturnCode_t g_symbolTblLookup = {0,0}; +UT_OsReturnCode_t g_symbolTblDump = {0,0}; + +#ifdef OS_INCLUDE_MODULE_LOADER +/* As defined in osloader.c */ +OS_module_record_t OS_module_table[OS_MAX_MODULES]; + +#ifdef _LINUX_OS_ +pthread_mutex_t OS_module_table_mut; +#endif +#endif /* OS_INCLUDE_MODULE_LOADER */ + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function definitions +**--------------------------------------------------------------------------------*/ + +int32 OS_ModuleTableInit() +{ + return (g_moduleTblInit.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_ModuleLoad(uint32* module_id, char* module_name, char* filename) +{ + return (g_moduleLoad.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_ModuleUnload(uint32 module_id) +{ + return (g_moduleUnload.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_ModuleInfo(uint32 module_id, OS_module_record_t* module_info) +{ + return (g_moduleInfo.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_SymbolLookup(uint32* SymbolAddress, char* SymbolName) +{ + return (g_symbolTblLookup.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_SymbolTableDump(char* filename, uint32 SizeLimit) +{ + return (g_symbolTblDump.value); +} + +/*================================================================================* +** End of File: ut_osloader_stubs.c +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_osnetwork_stubs.c b/src/unit-tests/shared/ut_osnetwork_stubs.c new file mode 100644 index 000000000..eba8d27cd --- /dev/null +++ b/src/unit-tests/shared/ut_osnetwork_stubs.c @@ -0,0 +1,54 @@ +/*================================================================================* +** File: ut_osnetwork_stubs.c +** Owner: Tam Ngo +** Date: March 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +UT_OsReturnCode_t g_networkGetId = {0,0}; +UT_OsReturnCode_t g_networkGetName = {0,0}; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function definitions +**--------------------------------------------------------------------------------*/ + +int32 OS_NetworkGetID() +{ + return (g_networkGetId.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_NetworkGetHostName(char* host_name, uint32 name_len) +{ + return (g_networkGetName.value); +} + +/*================================================================================* +** End of File: ut_osnetwork_stubs.c +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_ostimer_stubs.c b/src/unit-tests/shared/ut_ostimer_stubs.c new file mode 100644 index 000000000..026cf6070 --- /dev/null +++ b/src/unit-tests/shared/ut_ostimer_stubs.c @@ -0,0 +1,108 @@ +/*================================================================================* +** File: ut_ostimer_stubs.c +** Owner: Tam Ngo +** Date: March 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/* As defined in ostimer.c */ +typedef struct +{ + uint32 free; + char name[OS_MAX_API_NAME]; + uint32 creator; + uint32 start_time; + uint32 interval_time; + uint32 accuracy; + OS_TimerCallback_t callback_ptr; + uint32 host_timerid; +} OS_timer_record_t; + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +UT_OsReturnCode_t g_timerInit = {0,0}; +UT_OsReturnCode_t g_timerCreate = {0,0}; +UT_OsReturnCode_t g_timerDelete = {0,0}; +UT_OsReturnCode_t g_timerSet = {0,0}; +UT_OsReturnCode_t g_timerGetId = {0,0}; +UT_OsReturnCode_t g_timerGetInfo = {0,0}; + +/* As defined in ostimer.c */ +OS_timer_record_t OS_timer_table[OS_MAX_TIMERS]; +uint32 os_clock_accuracy; + +#ifdef _LINUX_OS_ +pthread_mutex_t OS_timer_table_mut; +#endif + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function definitions +**--------------------------------------------------------------------------------*/ + +int32 OS_TimerAPIInit(void) +{ + return (g_timerInit.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_TimerCreate(uint32* timer_id, const char* timer_name, + uint32* clock_accuracy, OS_TimerCallback_t callback_ptr) +{ + return (g_timerCreate.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_TimerDelete(uint32 timer_id) +{ + return (g_timerDelete.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_TimerSet(uint32 timer_id, uint32 start_msec, uint32 interval_msec) +{ + return (g_timerSet.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_TimerGetIdByName(uint32* timer_id, const char* timer_name) +{ + return (g_timerGetId.value); +} + +/*--------------------------------------------------------------------------------*/ + +int32 OS_TimerGetInfo(uint32 timer_id, OS_timer_prop_t* timer_prop) +{ + return (g_timerGetInfo.value); +} + +/*================================================================================* +** End of File: ut_ostimer_stubs.c +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_psp_voltab_stubs.c b/src/unit-tests/shared/ut_psp_voltab_stubs.c new file mode 100644 index 000000000..a44986cba --- /dev/null +++ b/src/unit-tests/shared/ut_psp_voltab_stubs.c @@ -0,0 +1,69 @@ +/*================================================================================* +** File: ut_psp_voltab_stubs.c +** Owner: Tam Ngo +** Date: March 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/* +** OSAL volume table. This is the only file in the PSP that still has the +** OS_ naming convention, since it belongs to the OSAL. +*/ +OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = +{ +/* DevName PhysDev VolType Volatile? Free? IsMounted? VolName MountPnt 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 }, + +/* +** The following entry is a "pre-mounted" path to a non-volatile device +*/ +/* DevName PhysDev VolType Volatile? Free? IsMounted? VolName MountPnt BlockSz */ +{"/eedev0", "./eeprom1", FS_BASED, FALSE, FALSE, TRUE, "CF", "/cf", 512 }, + +/* DevName PhysDev VolType Volatile? Free? IsMounted? VolName MountPnt BlockSz */ +{"/ramdev5", "./ram5", FS_BASED, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev6", "./ram6", FS_BASED, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev7", "./ram7", FS_BASED, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev8", "./ram8", FS_BASED, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev9", "./ram9", FS_BASED, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev10", "./ram10", FS_BASED, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev11", "./ram11", FS_BASED, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev12", "./ram12", FS_BASED, TRUE, TRUE, FALSE, " ", " ", 0 } +}; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function definitions +**--------------------------------------------------------------------------------*/ + +/*================================================================================* +** End of File: ut_psp_voltab_stubs.c +**================================================================================*/ diff --git a/src/unit-tests/shared/ut_psp_voltab_stubs_arinc653.c b/src/unit-tests/shared/ut_psp_voltab_stubs_arinc653.c new file mode 100644 index 000000000..8446e5fe0 --- /dev/null +++ b/src/unit-tests/shared/ut_psp_voltab_stubs_arinc653.c @@ -0,0 +1,62 @@ +/*================================================================================* +** File: ut_psp_voltab_stubs.c +** Owner: Tam Ngo +** Date: March 2013 +**================================================================================*/ + +/*--------------------------------------------------------------------------------* +** Includes +**--------------------------------------------------------------------------------*/ + +#include "ut_os_stubs.h" + +/*--------------------------------------------------------------------------------* +** Macros +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Data types +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** External global variables +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Global variables +**--------------------------------------------------------------------------------*/ + +/* +** OSAL volume table. This is the only file in the PSP that still has the +** OS_ naming convention, since it belongs to the OSAL. +*/ +OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = +{ +/* DevName PhysDev VolType Volatile? Free? IsMounted? VolName MountPnt BlockSz */ +{"/ramdev0", "/ram0", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev1", "/ram1", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev2", "/ram2", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev3", "/ram3", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev4", "/ram4", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev5", "/ram5", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev6", "/ram6", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev7", "/ram7", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev8", "/ram8", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev9", "/ram9", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev10", "/ram10", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev11", "/ram11", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev12", "/ram12", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 }, +{"/ramdev13", "/ram13", RAM_DISK, TRUE, TRUE, FALSE, " ", " ", 0 } +}; + +/*--------------------------------------------------------------------------------* +** Local function prototypes +**--------------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------------* +** Function definitions +**--------------------------------------------------------------------------------*/ + +/*================================================================================* +** End of File: ut_psp_voltab_stubs.c +**================================================================================*/