From 89fec290db06172267736c525d464792bef2ec46 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 18 Oct 2019 09:49:54 -0400 Subject: [PATCH 1/8] Fix #266: Rename "vxworks-ng" and "posix-ng" coverage tests Rename to "vxworks" and "posix", respectively, to match the actual implementation names. The build scripts rely on the name being the same and will fail if different. This also updates the default build to be vxworks rather than vxworks6, if not specified on the command line. --- src/unit-test-coverage/CMakeLists.txt | 2 +- .../{posix-ng => posix}/CMakeLists.txt | 0 .../modules/CMakeLists.txt | 0 .../{posix-ng => posix}/modules/Makefile | 0 .../{posix-ng => posix}/modules/README.txt | 0 .../modules/src/stub-map-to-real.h | 0 .../modules/src/ut-osapi.c | 0 .../src/coveragetest-osapi.c | 0 .../ut-stubs/CMakeLists.txt | 0 .../ut-stubs/src/osapi-impl-posix-stubs.c | 0 .../{vxworks-ng => vxworks}/CMakeLists.txt | 0 .../modules/CMakeLists.txt | 0 .../{vxworks-ng => vxworks}/modules/Makefile | 0 .../modules/README.txt | 0 .../modules/inc/ut-osapi.h | 0 .../modules/inc/ut-osfileapi.h | 0 .../modules/inc/ut-osfilesys.h | 0 .../modules/inc/ut-osloader.h | 0 .../modules/inc/ut-ostimer.h | 0 .../modules/src/stub-map-to-real.h | 0 .../modules/src/ut-osapi.c | 0 .../modules/src/ut-osfileapi.c | 0 .../modules/src/ut-osfilesys.c | 0 .../modules/src/ut-osloader.c | 0 .../modules/src/ut-ostimer.c | 0 .../src/coveragetest-osapi.c | 0 .../src/coveragetest-osfileapi.c | 0 .../src/coveragetest-osfilesys.c | 0 .../src/coveragetest-osloader.c | 0 .../src/coveragetest-ostimer.c | 0 .../src/coveragetest-posixfile.c | 0 .../src/coveragetest-posixgettime.c | 0 .../src/coveragetest-posixio.c | 0 .../src/coveragetest-printf.c | 0 .../src/os-vxworks-coveragetest.h | 0 .../ut-stubs/CMakeLists.txt | 0 .../ut-stubs/src/osapi-impl-vxworks-stubs.c | 0 .../vxworks6/CMakeLists.txt | 19 - src/unit-test-coverage/vxworks6/Makefile | 52 - .../vxworks6/osapi-test/CMakeLists.txt | 6 - .../vxworks6/osapi-test/Makefile | 87 - .../vxworks6/osapi-test/osapi_stubs.c | 737 ---- .../vxworks6/osapi-test/osapi_stubs.h | 117 - .../vxworks6/osapi-test/osapi_testcase.c | 96 - .../vxworks6/osapi-test/osapi_testcase.h | 52 - .../osapi-test/osapi_testcase_binsem.c | 1019 ----- .../osapi-test/osapi_testcase_cntsem.c | 920 ---- .../osapi-test/osapi_testcase_mutsem.c | 739 ---- .../osapi-test/osapi_testcase_queues.c | 972 ----- .../osapi-test/osapi_testcase_tasks.c | 1398 ------- .../osapi-test/osapi_testcase_time_int.c | 1429 ------- .../vxworks6/osfileapi-test/CMakeLists.txt | 6 - .../vxworks6/osfileapi-test/Makefile | 81 - .../vxworks6/osfileapi-test/osfileapi_stubs.c | 381 -- .../vxworks6/osfileapi-test/osfileapi_stubs.h | 103 - .../osfileapi-test/osfileapi_testcase.c | 3726 ----------------- .../vxworks6/osfilesys-test/CMakeLists.txt | 5 - .../vxworks6/osfilesys-test/Makefile | 82 - .../vxworks6/osfilesys-test/osfilesys_stubs.c | 266 -- .../vxworks6/osfilesys-test/osfilesys_stubs.h | 69 - .../osfilesys-test/osfilesys_testcase.c | 2483 ----------- .../vxworks6/osloader-test/CMakeLists.txt | 5 - .../vxworks6/osloader-test/Makefile | 89 - .../vxworks6/osloader-test/osloader_stubs.c | 276 -- .../vxworks6/osloader-test/osloader_stubs.h | 72 - .../osloader-test/osloader_testcase.c | 1188 ------ .../vxworks6/osnetwork-test/CMakeLists.txt | 5 - .../vxworks6/osnetwork-test/Makefile | 83 - .../vxworks6/osnetwork-test/osnetwork_stubs.c | 87 - .../vxworks6/osnetwork-test/osnetwork_stubs.h | 55 - .../osnetwork-test/osnetwork_testcase.c | 220 - .../vxworks6/ostimer-test/CMakeLists.txt | 5 - .../vxworks6/ostimer-test/Makefile | 82 - .../vxworks6/ostimer-test/ostimer_accessor.h | 59 - .../ostimer-test/ostimer_copiedstatictypes.h | 51 - .../vxworks6/ostimer-test/ostimer_stubs.c | 204 - .../vxworks6/ostimer-test/ostimer_stubs.h | 85 - .../vxworks6/ostimer-test/ostimer_testcase.c | 1596 ------- .../vxworks6/ut-osal/CMakeLists.txt | 11 - .../vxworks6/ut-osal/Makefile | 70 - .../vxworks6/ut-osal/README.txt | 38 - .../vxworks6/ut-osal/inc/cbioLib.h | 1 - .../vxworks6/ut-osal/inc/dirent.h | 1 - .../vxworks6/ut-osal/inc/dosFsLib.h | 1 - .../vxworks6/ut-osal/inc/drv/hdisk/ataDrv.h | 1 - .../vxworks6/ut-osal/inc/errnoLib.h | 1 - .../vxworks6/ut-osal/inc/fcntl.h | 1 - .../vxworks6/ut-osal/inc/hostLib.h | 1 - .../vxworks6/ut-osal/inc/intLib.h | 1 - .../vxworks6/ut-osal/inc/ioLib.h | 1 - .../vxworks6/ut-osal/inc/iv.h | 0 .../vxworks6/ut-osal/inc/loadLib.h | 1 - .../vxworks6/ut-osal/inc/logLib.h | 1 - .../vxworks6/ut-osal/inc/memPartLib.h | 1 - .../vxworks6/ut-osal/inc/msgQLib.h | 1 - .../vxworks6/ut-osal/inc/objLib.h | 1 - .../vxworks6/ut-osal/inc/ramDiskCbio.h | 1 - .../vxworks6/ut-osal/inc/ramDrv.h | 1 - .../vxworks6/ut-osal/inc/semLib.h | 1 - .../vxworks6/ut-osal/inc/shellLib.h | 1 - .../vxworks6/ut-osal/inc/stat.h | 1 - .../vxworks6/ut-osal/inc/stdio.h | 1 - .../vxworks6/ut-osal/inc/stdlib.h | 1 - .../vxworks6/ut-osal/inc/string.h | 1 - .../vxworks6/ut-osal/inc/strings.h | 1 - .../vxworks6/ut-osal/inc/symLib.h | 1 - .../vxworks6/ut-osal/inc/sys/stat.h | 1 - .../vxworks6/ut-osal/inc/sys/types.h | 1 - .../vxworks6/ut-osal/inc/sysLib.h | 1 - .../vxworks6/ut-osal/inc/taskLib.h | 1 - .../vxworks6/ut-osal/inc/taskVarLib.h | 1 - .../vxworks6/ut-osal/inc/time.h | 1 - .../vxworks6/ut-osal/inc/timers.h | 1 - .../vxworks6/ut-osal/inc/unistd.h | 1 - .../vxworks6/ut-osal/inc/unldLib.h | 1 - .../vxworks6/ut-osal/inc/usrLib.h | 1 - .../vxworks6/ut-osal/inc/version.h | 1 - .../vxworks6/ut-osal/inc/vxWorks.h | 1 - .../vxworks6/ut-osal/inc/xbdBlkDev.h | 1 - .../vxworks6/ut-osal/inc/xbdRamDisk.h | 1 - .../vxworks6/ut-osal/src/osapi.c | 231 - .../vxworks6/ut-osal/src/osfileapi.c | 11 - .../vxworks6/ut-osal/src/osfilesys.c | 11 - .../vxworks6/ut-osal/src/osloader.c | 11 - .../vxworks6/ut-osal/src/osnetwork.c | 11 - .../vxworks6/ut-osal/src/ostimer.c | 52 - .../vxworks6/ut-osal/src/stub-map-to-real.h | 222 - .../vxworks6/ut-stubs/inc/osapi_adaptor.h | 112 - .../vxworks6/ut-stubs/inc/osapi_stubs.h | 116 - .../vxworks6/ut-stubs/inc/ostimer_accessor.h | 58 - .../ut-stubs/inc/vxworks6-coverage-stubs.h | 429 -- 131 files changed, 1 insertion(+), 20429 deletions(-) rename src/unit-test-coverage/{posix-ng => posix}/CMakeLists.txt (100%) rename src/unit-test-coverage/{posix-ng => posix}/modules/CMakeLists.txt (100%) rename src/unit-test-coverage/{posix-ng => posix}/modules/Makefile (100%) rename src/unit-test-coverage/{posix-ng => posix}/modules/README.txt (100%) rename src/unit-test-coverage/{posix-ng => posix}/modules/src/stub-map-to-real.h (100%) rename src/unit-test-coverage/{posix-ng => posix}/modules/src/ut-osapi.c (100%) rename src/unit-test-coverage/{posix-ng => posix}/src/coveragetest-osapi.c (100%) rename src/unit-test-coverage/{posix-ng => posix}/ut-stubs/CMakeLists.txt (100%) rename src/unit-test-coverage/{posix-ng => posix}/ut-stubs/src/osapi-impl-posix-stubs.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/CMakeLists.txt (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/CMakeLists.txt (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/Makefile (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/README.txt (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/inc/ut-osapi.h (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/inc/ut-osfileapi.h (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/inc/ut-osfilesys.h (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/inc/ut-osloader.h (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/inc/ut-ostimer.h (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/src/stub-map-to-real.h (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/src/ut-osapi.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/src/ut-osfileapi.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/src/ut-osfilesys.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/src/ut-osloader.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/modules/src/ut-ostimer.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/coveragetest-osapi.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/coveragetest-osfileapi.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/coveragetest-osfilesys.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/coveragetest-osloader.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/coveragetest-ostimer.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/coveragetest-posixfile.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/coveragetest-posixgettime.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/coveragetest-posixio.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/coveragetest-printf.c (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/src/os-vxworks-coveragetest.h (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/ut-stubs/CMakeLists.txt (100%) rename src/unit-test-coverage/{vxworks-ng => vxworks}/ut-stubs/src/osapi-impl-vxworks-stubs.c (100%) delete mode 100644 src/unit-test-coverage/vxworks6/CMakeLists.txt delete mode 100644 src/unit-test-coverage/vxworks6/Makefile delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/CMakeLists.txt delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/Makefile delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_stubs.c delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_stubs.h delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase.c delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase.h delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_binsem.c delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_cntsem.c delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_mutsem.c delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_queues.c delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_tasks.c delete mode 100644 src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_time_int.c delete mode 100644 src/unit-test-coverage/vxworks6/osfileapi-test/CMakeLists.txt delete mode 100644 src/unit-test-coverage/vxworks6/osfileapi-test/Makefile delete mode 100644 src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_stubs.c delete mode 100644 src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_stubs.h delete mode 100644 src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_testcase.c delete mode 100644 src/unit-test-coverage/vxworks6/osfilesys-test/CMakeLists.txt delete mode 100644 src/unit-test-coverage/vxworks6/osfilesys-test/Makefile delete mode 100644 src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_stubs.c delete mode 100644 src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_stubs.h delete mode 100644 src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_testcase.c delete mode 100644 src/unit-test-coverage/vxworks6/osloader-test/CMakeLists.txt delete mode 100644 src/unit-test-coverage/vxworks6/osloader-test/Makefile delete mode 100644 src/unit-test-coverage/vxworks6/osloader-test/osloader_stubs.c delete mode 100644 src/unit-test-coverage/vxworks6/osloader-test/osloader_stubs.h delete mode 100644 src/unit-test-coverage/vxworks6/osloader-test/osloader_testcase.c delete mode 100644 src/unit-test-coverage/vxworks6/osnetwork-test/CMakeLists.txt delete mode 100644 src/unit-test-coverage/vxworks6/osnetwork-test/Makefile delete mode 100644 src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_stubs.c delete mode 100644 src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_stubs.h delete mode 100644 src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_testcase.c delete mode 100644 src/unit-test-coverage/vxworks6/ostimer-test/CMakeLists.txt delete mode 100644 src/unit-test-coverage/vxworks6/ostimer-test/Makefile delete mode 100644 src/unit-test-coverage/vxworks6/ostimer-test/ostimer_accessor.h delete mode 100644 src/unit-test-coverage/vxworks6/ostimer-test/ostimer_copiedstatictypes.h delete mode 100644 src/unit-test-coverage/vxworks6/ostimer-test/ostimer_stubs.c delete mode 100644 src/unit-test-coverage/vxworks6/ostimer-test/ostimer_stubs.h delete mode 100644 src/unit-test-coverage/vxworks6/ostimer-test/ostimer_testcase.c delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/CMakeLists.txt delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/Makefile delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/README.txt delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/cbioLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/dirent.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/dosFsLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/drv/hdisk/ataDrv.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/errnoLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/fcntl.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/hostLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/intLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/ioLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/iv.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/loadLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/logLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/memPartLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/msgQLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/objLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/ramDiskCbio.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/ramDrv.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/semLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/shellLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/stat.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/stdio.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/stdlib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/string.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/strings.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/symLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/sys/stat.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/sys/types.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/sysLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/taskLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/taskVarLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/time.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/timers.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/unistd.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/unldLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/usrLib.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/version.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/vxWorks.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/xbdBlkDev.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/inc/xbdRamDisk.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/src/osapi.c delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/src/osfileapi.c delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/src/osfilesys.c delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/src/osloader.c delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/src/osnetwork.c delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/src/ostimer.c delete mode 100644 src/unit-test-coverage/vxworks6/ut-osal/src/stub-map-to-real.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-stubs/inc/osapi_adaptor.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-stubs/inc/osapi_stubs.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-stubs/inc/ostimer_accessor.h delete mode 100644 src/unit-test-coverage/vxworks6/ut-stubs/inc/vxworks6-coverage-stubs.h diff --git a/src/unit-test-coverage/CMakeLists.txt b/src/unit-test-coverage/CMakeLists.txt index 864a3ade9..eacca29e7 100644 --- a/src/unit-test-coverage/CMakeLists.txt +++ b/src/unit-test-coverage/CMakeLists.txt @@ -43,7 +43,7 @@ set(OSALCOVERAGE_USER_C_FLAGS "$ENV{OSALCOVERAGE_USER_C_FLAGS}" CACHE STRING "Us # The currently supported setup is to use the "pc-linux" BSP to execute the "vxworks6" # code coverage analysis. Because the actual underlying OS calls are stubbed out, there # is no dependency on the actual underlying OS. -set(OSALCOVERAGE_TARGET_OSTYPE "vxworks6" CACHE STRING "OSAL target(s) to build coverage tests for") +set(OSALCOVERAGE_TARGET_OSTYPE "vxworks;shared" CACHE STRING "OSAL target(s) to build coverage tests for") set(OSALCOVERAGE_HOST_BSPTYPE "pc-linux" CACHE STRING "OSAL unit test BSP to execute coverage tests") # OSALCOVERAGE_SYSTEM_OSTYPE indicates which of the BSP packages to include diff --git a/src/unit-test-coverage/posix-ng/CMakeLists.txt b/src/unit-test-coverage/posix/CMakeLists.txt similarity index 100% rename from src/unit-test-coverage/posix-ng/CMakeLists.txt rename to src/unit-test-coverage/posix/CMakeLists.txt diff --git a/src/unit-test-coverage/posix-ng/modules/CMakeLists.txt b/src/unit-test-coverage/posix/modules/CMakeLists.txt similarity index 100% rename from src/unit-test-coverage/posix-ng/modules/CMakeLists.txt rename to src/unit-test-coverage/posix/modules/CMakeLists.txt diff --git a/src/unit-test-coverage/posix-ng/modules/Makefile b/src/unit-test-coverage/posix/modules/Makefile similarity index 100% rename from src/unit-test-coverage/posix-ng/modules/Makefile rename to src/unit-test-coverage/posix/modules/Makefile diff --git a/src/unit-test-coverage/posix-ng/modules/README.txt b/src/unit-test-coverage/posix/modules/README.txt similarity index 100% rename from src/unit-test-coverage/posix-ng/modules/README.txt rename to src/unit-test-coverage/posix/modules/README.txt diff --git a/src/unit-test-coverage/posix-ng/modules/src/stub-map-to-real.h b/src/unit-test-coverage/posix/modules/src/stub-map-to-real.h similarity index 100% rename from src/unit-test-coverage/posix-ng/modules/src/stub-map-to-real.h rename to src/unit-test-coverage/posix/modules/src/stub-map-to-real.h diff --git a/src/unit-test-coverage/posix-ng/modules/src/ut-osapi.c b/src/unit-test-coverage/posix/modules/src/ut-osapi.c similarity index 100% rename from src/unit-test-coverage/posix-ng/modules/src/ut-osapi.c rename to src/unit-test-coverage/posix/modules/src/ut-osapi.c diff --git a/src/unit-test-coverage/posix-ng/src/coveragetest-osapi.c b/src/unit-test-coverage/posix/src/coveragetest-osapi.c similarity index 100% rename from src/unit-test-coverage/posix-ng/src/coveragetest-osapi.c rename to src/unit-test-coverage/posix/src/coveragetest-osapi.c diff --git a/src/unit-test-coverage/posix-ng/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/posix/ut-stubs/CMakeLists.txt similarity index 100% rename from src/unit-test-coverage/posix-ng/ut-stubs/CMakeLists.txt rename to src/unit-test-coverage/posix/ut-stubs/CMakeLists.txt diff --git a/src/unit-test-coverage/posix-ng/ut-stubs/src/osapi-impl-posix-stubs.c b/src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c similarity index 100% rename from src/unit-test-coverage/posix-ng/ut-stubs/src/osapi-impl-posix-stubs.c rename to src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c diff --git a/src/unit-test-coverage/vxworks-ng/CMakeLists.txt b/src/unit-test-coverage/vxworks/CMakeLists.txt similarity index 100% rename from src/unit-test-coverage/vxworks-ng/CMakeLists.txt rename to src/unit-test-coverage/vxworks/CMakeLists.txt diff --git a/src/unit-test-coverage/vxworks-ng/modules/CMakeLists.txt b/src/unit-test-coverage/vxworks/modules/CMakeLists.txt similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/CMakeLists.txt rename to src/unit-test-coverage/vxworks/modules/CMakeLists.txt diff --git a/src/unit-test-coverage/vxworks-ng/modules/Makefile b/src/unit-test-coverage/vxworks/modules/Makefile similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/Makefile rename to src/unit-test-coverage/vxworks/modules/Makefile diff --git a/src/unit-test-coverage/vxworks-ng/modules/README.txt b/src/unit-test-coverage/vxworks/modules/README.txt similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/README.txt rename to src/unit-test-coverage/vxworks/modules/README.txt diff --git a/src/unit-test-coverage/vxworks-ng/modules/inc/ut-osapi.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osapi.h similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/inc/ut-osapi.h rename to src/unit-test-coverage/vxworks/modules/inc/ut-osapi.h diff --git a/src/unit-test-coverage/vxworks-ng/modules/inc/ut-osfileapi.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osfileapi.h similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/inc/ut-osfileapi.h rename to src/unit-test-coverage/vxworks/modules/inc/ut-osfileapi.h diff --git a/src/unit-test-coverage/vxworks-ng/modules/inc/ut-osfilesys.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osfilesys.h similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/inc/ut-osfilesys.h rename to src/unit-test-coverage/vxworks/modules/inc/ut-osfilesys.h diff --git a/src/unit-test-coverage/vxworks-ng/modules/inc/ut-osloader.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osloader.h similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/inc/ut-osloader.h rename to src/unit-test-coverage/vxworks/modules/inc/ut-osloader.h diff --git a/src/unit-test-coverage/vxworks-ng/modules/inc/ut-ostimer.h b/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/inc/ut-ostimer.h rename to src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h diff --git a/src/unit-test-coverage/vxworks-ng/modules/src/stub-map-to-real.h b/src/unit-test-coverage/vxworks/modules/src/stub-map-to-real.h similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/src/stub-map-to-real.h rename to src/unit-test-coverage/vxworks/modules/src/stub-map-to-real.h diff --git a/src/unit-test-coverage/vxworks-ng/modules/src/ut-osapi.c b/src/unit-test-coverage/vxworks/modules/src/ut-osapi.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/src/ut-osapi.c rename to src/unit-test-coverage/vxworks/modules/src/ut-osapi.c diff --git a/src/unit-test-coverage/vxworks-ng/modules/src/ut-osfileapi.c b/src/unit-test-coverage/vxworks/modules/src/ut-osfileapi.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/src/ut-osfileapi.c rename to src/unit-test-coverage/vxworks/modules/src/ut-osfileapi.c diff --git a/src/unit-test-coverage/vxworks-ng/modules/src/ut-osfilesys.c b/src/unit-test-coverage/vxworks/modules/src/ut-osfilesys.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/src/ut-osfilesys.c rename to src/unit-test-coverage/vxworks/modules/src/ut-osfilesys.c diff --git a/src/unit-test-coverage/vxworks-ng/modules/src/ut-osloader.c b/src/unit-test-coverage/vxworks/modules/src/ut-osloader.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/src/ut-osloader.c rename to src/unit-test-coverage/vxworks/modules/src/ut-osloader.c diff --git a/src/unit-test-coverage/vxworks-ng/modules/src/ut-ostimer.c b/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/modules/src/ut-ostimer.c rename to src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c diff --git a/src/unit-test-coverage/vxworks-ng/src/coveragetest-osapi.c b/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/coveragetest-osapi.c rename to src/unit-test-coverage/vxworks/src/coveragetest-osapi.c diff --git a/src/unit-test-coverage/vxworks-ng/src/coveragetest-osfileapi.c b/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/coveragetest-osfileapi.c rename to src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c diff --git a/src/unit-test-coverage/vxworks-ng/src/coveragetest-osfilesys.c b/src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/coveragetest-osfilesys.c rename to src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c diff --git a/src/unit-test-coverage/vxworks-ng/src/coveragetest-osloader.c b/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/coveragetest-osloader.c rename to src/unit-test-coverage/vxworks/src/coveragetest-osloader.c diff --git a/src/unit-test-coverage/vxworks-ng/src/coveragetest-ostimer.c b/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/coveragetest-ostimer.c rename to src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c diff --git a/src/unit-test-coverage/vxworks-ng/src/coveragetest-posixfile.c b/src/unit-test-coverage/vxworks/src/coveragetest-posixfile.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/coveragetest-posixfile.c rename to src/unit-test-coverage/vxworks/src/coveragetest-posixfile.c diff --git a/src/unit-test-coverage/vxworks-ng/src/coveragetest-posixgettime.c b/src/unit-test-coverage/vxworks/src/coveragetest-posixgettime.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/coveragetest-posixgettime.c rename to src/unit-test-coverage/vxworks/src/coveragetest-posixgettime.c diff --git a/src/unit-test-coverage/vxworks-ng/src/coveragetest-posixio.c b/src/unit-test-coverage/vxworks/src/coveragetest-posixio.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/coveragetest-posixio.c rename to src/unit-test-coverage/vxworks/src/coveragetest-posixio.c diff --git a/src/unit-test-coverage/vxworks-ng/src/coveragetest-printf.c b/src/unit-test-coverage/vxworks/src/coveragetest-printf.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/coveragetest-printf.c rename to src/unit-test-coverage/vxworks/src/coveragetest-printf.c diff --git a/src/unit-test-coverage/vxworks-ng/src/os-vxworks-coveragetest.h b/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h similarity index 100% rename from src/unit-test-coverage/vxworks-ng/src/os-vxworks-coveragetest.h rename to src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h diff --git a/src/unit-test-coverage/vxworks-ng/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt similarity index 100% rename from src/unit-test-coverage/vxworks-ng/ut-stubs/CMakeLists.txt rename to src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt diff --git a/src/unit-test-coverage/vxworks-ng/ut-stubs/src/osapi-impl-vxworks-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/osapi-impl-vxworks-stubs.c similarity index 100% rename from src/unit-test-coverage/vxworks-ng/ut-stubs/src/osapi-impl-vxworks-stubs.c rename to src/unit-test-coverage/vxworks/ut-stubs/src/osapi-impl-vxworks-stubs.c diff --git a/src/unit-test-coverage/vxworks6/CMakeLists.txt b/src/unit-test-coverage/vxworks6/CMakeLists.txt deleted file mode 100644 index 6fd80334e..000000000 --- a/src/unit-test-coverage/vxworks6/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# CMake snippet for building the vxworks6 OSAL coverage tests - -include_directories(ut-stubs/inc) - -add_subdirectory(ut-osal) - -# Build contents of all the *-test directories into an executable for each one -file(GLOB COVERAGE_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/*-test) -foreach(TEST ${COVERAGE_TESTS}) - get_filename_component(DIRNAME ${TEST} NAME_WE) - string(REPLACE -test "" TESTNAME ${DIRNAME}) - set(TESTCASE_FILES) - aux_source_directory(${TEST} TESTCASE_FILES) - add_executable(${TESTNAME}-testrunner ${TESTCASE_FILES}) - set_target_properties(${TESTNAME}-testrunner PROPERTIES LINK_FLAGS "${UT_C_FLAGS}") - target_link_libraries(${TESTNAME}-testrunner ut_osal_${TESTNAME} ${OSALCOVERAGE_LINK_LIBRARIES}) - add_test(${TESTNAME} ${TESTNAME}-testrunner) -endforeach() - diff --git a/src/unit-test-coverage/vxworks6/Makefile b/src/unit-test-coverage/vxworks6/Makefile deleted file mode 100644 index d4b3ce28f..000000000 --- a/src/unit-test-coverage/vxworks6/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -# -# Master $(MAKE)file for unit tests -# - -all: testrunner.o - $(MAKE) -C ut-osal - $(MAKE) -C osapi-test - $(MAKE) -C osfileapi-test - $(MAKE) -C osfilesys-test - $(MAKE) -C osloader-test - $(MAKE) -C osnetwork-test - $(MAKE) -C ostimer-test - -clean: - rm -f ./*.o - $(MAKE) -C ut-osal clean - $(MAKE) -C osapi-test clean - $(MAKE) -C osfileapi-test clean - $(MAKE) -C osfilesys-test clean - $(MAKE) -C osloader-test clean - $(MAKE) -C osnetwork-test clean - $(MAKE) -C ostimer-test clean - -run: -# note the leading "-" makes it always run and ignore errors - -$(MAKE) -C osapi-test run - -$(MAKE) -C osfileapi-test run - -$(MAKE) -C osfilesys-test run - -$(MAKE) -C osloader-test run - -$(MAKE) -C osnetwork-test run - -$(MAKE) -C ostimer-test run - -gcov: - $(MAKE) -C ut-osal gcov - - -# Build the "testrunner" library here since it can be shared by all tests -VPATH = $(OSAL)/ut_assert/src -VPATH += $(OSAL)/src/bsp/pc-linux/ut-src -INCLUDES = -I$(OSAL)/src/os/inc -I$(OSAL)/ut_assert/inc -I$(OSAL)/build/inc -DEFINES = -D_UNIT_TEST_ - -%.o: %.c - gcc $(OSAL_M32) -c -o $@ $(INCLUDES) $(DEFINES) $^ - -ifeq ($(OSAL_M32),-m32) -OSAL_LD32 ?= -melf_i386 -endif - -testrunner.o: utassert.o utlist.o utstubs.o uttest.o uttools.o bsp_ut.o bsp_ut_voltab.o - ld $(OSAL_LD32) -o $@ -r $^ - diff --git a/src/unit-test-coverage/vxworks6/osapi-test/CMakeLists.txt b/src/unit-test-coverage/vxworks6/osapi-test/CMakeLists.txt deleted file mode 100644 index cd85df048..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} TESTCASE_FILES) -add_executable(osapi-test ${TESTCASE_FILES}) -set_target_properties(osapi-test PROPERTIES LINK_FLAGS "${UT_C_FLAGS}") -target_link_libraries(osapi-test ut_osal_osapi ${OSALCOVERAGE_LINK_LIBRARIES}) -add_test(osapi-test osapi-test) diff --git a/src/unit-test-coverage/vxworks6/osapi-test/Makefile b/src/unit-test-coverage/vxworks6/osapi-test/Makefile deleted file mode 100644 index 5dda2f8ed..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/Makefile +++ /dev/null @@ -1,87 +0,0 @@ -############################################################################## -## GNU Makefile for building UT unit tests in a Linux environment for easy -## debug and code coverage - -# -# Supported MAKEFILE targets: -# clean - deletes object files, executables, output files, and gcov files -# all - makes utf_test_runner.exe -# run - runs utf_test_runner.exe -# gcov - prints a GCOV coverage report (make all, make run, make gcov) -# -# GCOV is disabled by default. If you are using the source level debugger you will want to -# disable GCOV. To enable GCOV you can override the ENABLE_GCOV variable on the command line -# by setting it to TRUE. For example "make ENABLE_GCOV=TRUE". -# - - -APP=osapi - -OSAL ?= $(CFS_HOME)/osal - -# -# INCLUDES specifies the search paths for include files outside of the current directory. -# Note that the -I is required. -# -INCLUDES += -I../ut-stubs/inc -INCLUDES += -I$(OSAL)/ut_assert/inc -INCLUDES += -I$(OSAL)/src/os/inc -INCLUDES += -I$(OSAL)/build/inc - - -# -# UT_OBJS specifies unit test object files. -# -UT_OBJS := $(APP)_testcase.o -UT_OBJS += $(APP)_stubs.o -UT_OBJS += $(APP)_testcase_tasks.o -UT_OBJS += $(APP)_testcase_queues.o -UT_OBJS += $(APP)_testcase_binsem.o -UT_OBJS += $(APP)_testcase_cntsem.o -UT_OBJS += $(APP)_testcase_mutsem.o -UT_OBJS += $(APP)_testcase_time_int.o - -############################################################################### - -COMPILER=gcc -LINKER=gcc - -# -# Compiler and Linker Options -# -ENABLE_GCOV = TRUE -ifeq ($(ENABLE_GCOV), TRUE) -GCOV_COPT = --coverage -GCOV_LOPT = --coverage -endif - -#WARNINGS = -Wall -W -ansi -Werror -Wstrict-prototypes -Wundef -WARNINGS = -Wall -Wstrict-prototypes -DEBUGGER = -g - -#COPT = $(WARNINGS) $(DEBUGGER) $(GCOV_COPT) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D__x86_64__ -D_LINUX_OS_ -COPT = $(WARNINGS) $(DEBUGGER) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D_ix86_ $(OSAL_M32) - -LOPT = $(OSAL_M32) - -############################################################################### -## "C" COMPILER RULE -## -%.o: %.c - $(COMPILER) -c $(COPT) $(INCLUDES) $< - -############################################################################## -## - -all:$(APP)_testrunner.exe - -$(APP)_testrunner.exe: $(UT_OBJS) - $(LINKER) $(GCOV_LOPT) $(LOPT) -o $@ $^ ../ut-osal/osapi.o ../testrunner.o - -clean :: - rm -f *.o *.exe *.gcda *.gcno *.gcov gmon.out $(APP)_log.txt - -run :: - ./$(APP)_testrunner.exe | tee ./$(APP)_log.txt - -# end of file diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_stubs.c b/src/unit-test-coverage/vxworks6/osapi-test/osapi_stubs.c deleted file mode 100644 index ec1ee8dae..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_stubs.c +++ /dev/null @@ -1,737 +0,0 @@ -/* - * File: osapi_stubs.c - * - * Purpose: - * Stub out various functions not stubbed out by the UT-Assert code - * - * Modification History: - * 06/25/2015 Alan Asp, Odyssey Space Research, LLC - * * Created - * - */ - -#include - -#include "osapi_stubs.h" -#include "osapi_adaptor.h" - -extern VCS_SEM_ID OS_task_table_sem; -extern VCS_SEM_ID OS_queue_table_sem; -extern VCS_SEM_ID OS_bin_sem_table_sem; -extern VCS_SEM_ID OS_count_sem_table_sem; -extern VCS_SEM_ID OS_mut_sem_table_sem; - -VCS_PART_ID VCS_memSysPartId; -int VCS_errno; - -OsApi_HookTable_t OsApi_HookTable; -OsApi_ReturnCodeTable_t OsApi_ReturnCodeTable[OSAPI_MAX_INDEX]; - - -int32 nSemTake[OS_MAX_SEM] = {0}; -int32 nSemGive[OS_MAX_SEM] = {0}; -int32 nTaskDeleteForce = 0; -int taskSpawnFlags = 0; -boolean exitCalled = FALSE; -int taskDelayTicks = 0; -int msgQReceiveTimeout = -2; -uint32 semBInitialValue = 99; -VCS_SEM_ID semIdCalled = 0; -int32 semTakeTicks = 0; -uint32 time_sec = 0; -uint32 time_nsec = 0; -unsigned long heap_freeBytes = 0; -unsigned long heap_freeBlocks = 0; -unsigned long heap_maxFreeBlock = 0; -uint32 fpuMask = 0; -uint32 nVsnprinf_calls = 0; -uint32 nLogMsg_calls = 0; - - -void OsApi_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt) -{ - if (Index < OSAPI_MAX_INDEX) { - OsApi_ReturnCodeTable[Index].Value = RtnVal; - OsApi_ReturnCodeTable[Index].Count = CallCnt; - } - else { - printf("Unsupported Index In SetReturnCode Call %u\n", (unsigned int)Index); - } -} - - -boolean OsApi_UseReturnCode(uint32 Index) -{ - if (OsApi_ReturnCodeTable[Index].Count > 0) { - OsApi_ReturnCodeTable[Index].Count--; - if (OsApi_ReturnCodeTable[Index].Count == 0) - return(TRUE); - } - - return(FALSE); -} - - -void OsApi_SetFunctionHook(uint32 Index, void *FunPtr) -{ - if (Index == OSAPI_STRLEN_INDEX) { OsApi_HookTable.strlen = FunPtr; } - else if (Index == OSAPI_STRCMP_INDEX) { OsApi_HookTable.strcmp = FunPtr; } - else if (Index == OSAPI_SEMMCREATE_INDEX) { OsApi_HookTable.semMCreate = FunPtr; } - else if (Index == OSAPI_SEMTAKE_INDEX) { OsApi_HookTable.semTake = FunPtr; } - else if (Index == OSAPI_SEMGIVE_INDEX) { OsApi_HookTable.semGive = FunPtr; } - else - { - printf("Unsupported OsApi Index In SetFunctionHook Call %u\n", (unsigned int)Index); - } -} - - -void OsApi_Reset(void) -{ - uint32 ii = 0; - - memset(&OsApi_HookTable, 0, sizeof(OsApi_HookTable)); - memset(&OsApi_ReturnCodeTable, 0, sizeof(OsApi_ReturnCodeTable)); - - for (ii = 0; ii < OS_MAX_SEM; ++ii) - { - nSemTake[ii] = 0; - nSemGive[ii] = 0; - } - nTaskDeleteForce = 0; - taskSpawnFlags = -1; - exitCalled = FALSE; - taskDelayTicks = 0; - msgQReceiveTimeout = -2; - semBInitialValue = 99; - semIdCalled = 0; - semTakeTicks = -1; - time_sec = 0; - time_nsec = 0; - heap_freeBytes = 0; - heap_freeBlocks = 0; - heap_maxFreeBlock = 0; - fpuMask = 0; - nVsnprinf_calls = 0; - nLogMsg_calls = 0; -} - - -int32 getNSemTake(uint32 id) -{ - if (id < OS_MAX_SEM) - { - return nSemTake[id]; - } - - return 0; -} - -int32 getSemTakeTicks() -{ - return semTakeTicks; -} - - -int32 getNSemGive(uint32 id) -{ - if (id < OS_MAX_SEM) - { - return nSemGive[id]; - } - - return 0; -} - -VCS_SEM_ID getSemGiveArg() -{ - return semIdCalled; -} - - -int32 getNTaskDeleteForce() -{ - return nTaskDeleteForce; -} - - -int getTaskSpawnFlags() -{ - return taskSpawnFlags; -} - -boolean getTaskExitCalled() -{ - return exitCalled; -} - -int getTaskDelayTicks() -{ - return taskDelayTicks; -} - -int getMsgQReceiveTimeout() -{ - return msgQReceiveTimeout; -} - -uint32 getSemBInitialValue() -{ - return semBInitialValue; -} - -uint32 getSeconds() -{ - return time_sec; -} - -uint32 getNSeconds() -{ - return time_nsec; -} - -void setTime(uint32 sec, uint32 nsec) -{ - time_sec = sec; - time_nsec = nsec; -} - -void setHeapInfo(unsigned long freeBytes, unsigned long freeBlocks, unsigned long maxFreeBlock) -{ - heap_freeBytes = freeBytes; - heap_freeBlocks = freeBlocks; - heap_maxFreeBlock = maxFreeBlock; -} - -uint32 getFpuMask() -{ - return fpuMask; -} - -uint32 getNVsnprintf_calls() -{ - return nVsnprinf_calls; -} - -uint32 getNLogMsg_calls() -{ - return nLogMsg_calls; -} - - - -/* Standard C library functions */ -void VCS_exit(int code) -{ - if (OsApi_UseReturnCode(OSAPI_EXIT_INDEX)) - { - exitCalled = TRUE; - } - -} - -size_t VCS_strlen(const char *str) -{ - if (OsApi_UseReturnCode(OSAPI_STRLEN_INDEX)) - return (size_t)OsApi_ReturnCodeTable[OSAPI_STRLEN_INDEX].Value; - - return strlen(str); -} - -int VCS_strcmp(const char *str1, const char *str2) -{ - if (OsApi_UseReturnCode(OSAPI_STRCMP_INDEX)) - return (size_t)OsApi_ReturnCodeTable[OSAPI_STRCMP_INDEX].Value; - - return strcmp(str1, str2); -} - -char *VCS_strcpy(char *str1, const char *str2) -{ - if (OsApi_UseReturnCode(OSAPI_STRCPY_INDEX)) - return (char *)OsApi_ReturnCodeTable[OSAPI_STRCPY_INDEX].Value; - - return strcpy(str1, str2); -} - -int VCS_vsnprintf(char *str, size_t size, const char *format, va_list ap) -{ - nVsnprinf_calls++; - - return vsnprintf(str, size, format, ap); -} - - -/* VxWorks functions */ -int VCS_clock_gettime(VCS_clockid_t clock_id, struct VCS_timespec *tp) -{ - tp->tv_sec = time_sec; - tp->tv_nsec = time_nsec; - - if (OsApi_UseReturnCode(OSAPI_CLOCKGETTIME_INDEX)) - { - return (int)OsApi_ReturnCodeTable[OSAPI_CLOCKGETTIME_INDEX].Value; - } - - return 1; -} - - -int VCS_clock_settime(VCS_clockid_t clock_id, const struct VCS_timespec * tp) -{ - time_sec = tp->tv_sec; - time_nsec = tp->tv_nsec; - - if (OsApi_UseReturnCode(OSAPI_CLOCKSETTIME_INDEX)) - { - return (int)OsApi_ReturnCodeTable[OSAPI_CLOCKSETTIME_INDEX].Value; - } - - return 1; -} - - - -VCS_STATUS VCS_intConnect(VCS_VOIDFUNCPTR *vector, VCS_VOIDFUNCPTR routine, int parameter) -{ - if (OsApi_UseReturnCode(OSAPI_INTCONNECT_INDEX)) - { - return (int)OsApi_ReturnCodeTable[OSAPI_INTCONNECT_INDEX].Value; - } - - return 1; -} - - -int VCS_intDisable(int level) -{ - if (OsApi_UseReturnCode(OSAPI_INTDISABLE_INDEX)) - { - return (int)OsApi_ReturnCodeTable[OSAPI_INTDISABLE_INDEX].Value; - } - - return 1; -} - - -int VCS_intEnable(int level) -{ - if (OsApi_UseReturnCode(OSAPI_INTENABLE_INDEX)) - { - return (int)OsApi_ReturnCodeTable[OSAPI_INTENABLE_INDEX].Value; - } - - return 1; -} - - -int VCS_intLock(void) -{ - if (OsApi_UseReturnCode(OSAPI_INTLOCK_INDEX)) - { - return (int)OsApi_ReturnCodeTable[OSAPI_INTLOCK_INDEX].Value; - } - - return 1; -} - - -int VCS_intUnlock(int lockKey) -{ - if (OsApi_UseReturnCode(OSAPI_INTUNLOCK_INDEX)) - { - return (int)OsApi_ReturnCodeTable[OSAPI_INTUNLOCK_INDEX].Value; - } - - return 1; -} - - -int VCS_logMsg(char * fmt, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) -{ - nLogMsg_calls++; - - return 0; -} - -VCS_STATUS VCS_memPartShow(VCS_PART_ID partId, int type) -{ - return 1; -} - - -VCS_STATUS VCS_memPartInfoGet(VCS_PART_ID partId, VCS_MEM_PART_STATS * ppartStats) -{ - if (ppartStats != NULL) - { - ppartStats->numBytesFree = heap_freeBytes; - ppartStats->numBlocksFree = heap_freeBlocks; - ppartStats->maxBlockSizeFree = heap_maxFreeBlock; - } - - if (OsApi_UseReturnCode(OSAPI_MEMPARTINFOGET_INDEX)) - { - return (VCS_STATUS)OsApi_ReturnCodeTable[OSAPI_MEMPARTINFOGET_INDEX].Value; - } - - return 1; -} - - -VCS_MSG_Q_ID VCS_msgQCreate(int maxMsgs, int maxMsgLength, int options) -{ - if (OsApi_UseReturnCode(OSAPI_MSGQCREATE_INDEX)) - { - return (VCS_MSG_Q_ID)OsApi_ReturnCodeTable[OSAPI_MSGQCREATE_INDEX].Value; - } - - return (VCS_MSG_Q_ID)1; -} - - -VCS_STATUS VCS_msgQDelete(VCS_MSG_Q_ID msgQId) -{ - if (OsApi_UseReturnCode(OSAPI_MSGQDELETE_INDEX)) - { - return (VCS_STATUS)OsApi_ReturnCodeTable[OSAPI_MSGQDELETE_INDEX].Value; - } - - return VCS_OK; -} - - -int VCS_msgQReceive(VCS_MSG_Q_ID msgQId, char * buffer, uint32 maxNBytes, int timeout) -{ - msgQReceiveTimeout = timeout; - - if (OsApi_UseReturnCode(OSAPI_MSGQRECEIVE_INDEX)) - { - return (VCS_STATUS)OsApi_ReturnCodeTable[OSAPI_MSGQRECEIVE_INDEX].Value; - } - - return 1; -} - - -VCS_STATUS VCS_msgQSend(VCS_MSG_Q_ID msgQId, char *buffer, uint32 nBytes, int timeout, int priority) -{ - if (OsApi_UseReturnCode(OSAPI_MSGQSEND_INDEX)) - { - return (VCS_STATUS)OsApi_ReturnCodeTable[OSAPI_MSGQSEND_INDEX].Value; - } - - return VCS_OK; -} - - -VCS_SEM_ID VCS_semBCreate(int options, VCS_SEM_B_STATE initialState) -{ - semBInitialValue = initialState; - - if (OsApi_UseReturnCode(OSAPI_SEMBCREATE_INDEX)) - { - return (VCS_SEM_ID)OsApi_ReturnCodeTable[OSAPI_SEMBCREATE_INDEX].Value; - } - - return (VCS_SEM_ID)1; -} - - -VCS_SEM_ID VCS_semCCreate(int flags, int count) -{ - if (OsApi_UseReturnCode(OSAPI_SEMCCREATE_INDEX)) - { - return (VCS_SEM_ID)OsApi_ReturnCodeTable[OSAPI_SEMCCREATE_INDEX].Value; - } - - return (VCS_SEM_ID)1; -} - - -VCS_STATUS VCS_semDelete(VCS_SEM_ID semId) -{ - if (OsApi_UseReturnCode(OSAPI_SEMDELETE_INDEX)) - { - return (VCS_STATUS)OsApi_ReturnCodeTable[OSAPI_SEMDELETE_INDEX].Value; - } - - return VCS_OK; -} - - -VCS_STATUS VCS_semFlush(VCS_SEM_ID semId) -{ - if (OsApi_UseReturnCode(OSAPI_SEMFLUSH_INDEX)) - { - return (VCS_STATUS)OsApi_ReturnCodeTable[OSAPI_SEMFLUSH_INDEX].Value; - } - - return VCS_OK; -} - - -VCS_SEM_ID VCS_semMCreate(int options) -{ - if (OsApi_UseReturnCode(OSAPI_SEMMCREATE_INDEX)) - { - return (VCS_SEM_ID)OsApi_ReturnCodeTable[OSAPI_SEMMCREATE_INDEX].Value; - } - - return (VCS_SEM_ID)1; -} - - -uint32 getSemIdIndex(VCS_SEM_ID semId) -{ - uint32 idx = 0; - - if (semId == NULL) - { - return idx; - } - - if (semId == OsApi_Adaptor_Get_Os_Task_Table_Sem()) - { - idx = OS_TASK_TABLE_SEM; - } - else if (semId == OsApi_Adaptor_Get_Os_Queue_Table_Sem()) - { - idx = OS_QUEUE_TABLE_SEM; - } - else if (semId == OsApi_Adaptor_Get_Os_Bin_Sem_Table_Sem()) - { - idx = OS_BIN_SEM_TABLE_SEM; - } - else if (semId == OsApi_Adaptor_Get_Os_Count_Sem_Table_Sem()) - { - idx = OS_COUNT_SEM_TABLE_SEM; - } - else if (semId == OsApi_Adaptor_Get_Os_Mut_Sem_Table_Sem()) - { - idx = OS_MUT_SEM_TABLE_SEM; - } - - return idx; -} - - -VCS_STATUS VCS_semTake(VCS_SEM_ID semId, int timeout) -{ - semTakeTicks = timeout; - - if (OsApi_UseReturnCode(OSAPI_SEMTAKE_INDEX)) - { - return (VCS_STATUS)OsApi_ReturnCodeTable[OSAPI_SEMTAKE_INDEX].Value; - } - - if (semId != NULL) - { - nSemTake[getSemIdIndex(semId)]++; - } - - return VCS_OK; -} - - -VCS_STATUS VCS_semGive(VCS_SEM_ID semId) -{ - semIdCalled = semId; - - if (OsApi_UseReturnCode(OSAPI_SEMGIVE_INDEX)) - { - return (VCS_STATUS)OsApi_ReturnCodeTable[OSAPI_SEMGIVE_INDEX].Value; - } - - if (semId != NULL) - { - nSemGive[getSemIdIndex(semId)]++; - } - - return VCS_OK; -} - - -int VCS_sysClkRateGet(void) -{ - if (OsApi_UseReturnCode(OSAPI_SYSCLKRATEGET_INDEX)) - { - return OsApi_ReturnCodeTable[OSAPI_SYSCLKRATEGET_INDEX].Value; - } - - return 1; -} - - -VCS_STATUS VCS_taskDelay(int ticks) -{ - taskDelayTicks = ticks; - - if (OsApi_UseReturnCode(OSAPI_TASKDELAY_INDEX)) - { - return OsApi_ReturnCodeTable[OSAPI_TASKDELAY_INDEX].Value; - } - - return VCS_OK; -} - - -VCS_STATUS VCS_taskDelete(int tid) -{ - if (OsApi_UseReturnCode(OSAPI_TASKDELETE_INDEX)) - { - return OsApi_ReturnCodeTable[OSAPI_TASKDELETE_INDEX].Value; - } - - return VCS_OK; -} - - -VCS_STATUS VCS_taskDeleteForce(int tid) -{ - nTaskDeleteForce++; - - return VCS_OK; -} - - -void VCS_taskExit(int code) -{ - exitCalled = TRUE; -} - - -int VCS_taskIdSelf(void) -{ - if (OsApi_UseReturnCode(OSAPI_TASKIDSELF_INDEX)) - { - return OsApi_ReturnCodeTable[OSAPI_TASKIDSELF_INDEX].Value; - } - - return 0; -} - - -VCS_STATUS VCS_taskPrioritySet(int tid, int newPriority) -{ - if (OsApi_UseReturnCode(OSAPI_TASKPRIORITYSET_INDEX)) - { - return OsApi_ReturnCodeTable[OSAPI_TASKPRIORITYSET_INDEX].Value; - } - - return VCS_OK; -} - - -int VCS_taskSpawn(char * name, - int priority, - int options, - int stackSize, - VCS_FUNCPTR entryPt, - int arg1, - int arg2, - int arg3, - int arg4, - int arg5, - int arg6, - int arg7, - int arg8, - int arg9, - int arg10) -{ - taskSpawnFlags = options; - - if (OsApi_UseReturnCode(OSAPI_TASKSPAWN_INDEX)) - return OsApi_ReturnCodeTable[OSAPI_TASKSPAWN_INDEX].Value; - - return 1; -} - - -VCS_STATUS VCS_taskVarAdd(int tid, int *pVar) -{ - if (OsApi_UseReturnCode(OSAPI_TASKVARADD_INDEX)) - return OsApi_ReturnCodeTable[OSAPI_TASKVARADD_INDEX].Value; - - return VCS_OK; -} - -uint32 VCS_vxFpscrGet() -{ - if (OsApi_UseReturnCode(OSAPI_VXFPSCRGET_INDEX)) - return OsApi_ReturnCodeTable[OSAPI_VXFPSCRGET_INDEX].Value; - - return 1; -} - -void VCS_vxFpscrSet (uint32 mask) -{ - fpuMask = mask; -} - -void VCS_memset(void *ptr, int c, unsigned int size) -{ - memset(ptr, c, size); -} - -int VCS_printf(const char *format, ...) -{ - va_list va; - int ret; - - va_start(va, format); - ret = vprintf(format, va); - va_end(va); - - return ret; -} - -VCS_SEM_ID VCS_semBInitialize(char *pSemMem, int options, VCS_SEM_B_STATE initialState) -{ - return (VCS_SEM_ID)pSemMem; -} - - -/* OSAL functions */ -int32 OS_FS_Init(void) -{ - if (OsApi_UseReturnCode(OSAPI_OSFSINIT_INDEX)) - return OsApi_ReturnCodeTable[OSAPI_OSFSINIT_INDEX].Value; - - return 0; -} - - -int32 OS_ModuleTableInit(void) -{ - if (OsApi_UseReturnCode(OSAPI_OSMODULETABLEINIT_INDEX)) - return OsApi_ReturnCodeTable[OSAPI_OSMODULETABLEINIT_INDEX].Value; - - return 1; -} - - -int32 OS_TimerAPIInit(void) -{ - if (OsApi_UseReturnCode(OSAPI_OSTIMERAPIINIT_INDEX)) - return OsApi_ReturnCodeTable[OSAPI_OSTIMERAPIINIT_INDEX].Value; - - return 1; -} - -/* These 3 functions are referenced by OS_DeleteAllObjects() */ -int32 OS_TimerDelete(uint32 timer_id) -{ - return 0; -} - -int32 OS_ModuleUnload(uint32 module_id) -{ - return 0; -} - -int32 OS_close(uint32 filedes) -{ - return 0; -} - - diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_stubs.h b/src/unit-test-coverage/vxworks6/osapi-test/osapi_stubs.h deleted file mode 100644 index 64673a16e..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_stubs.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * File: osapi_stubs.h - * - * Purpose: - * Provide stubs for unit testing - * - * History: - * 06/25/2015 A. Asp, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSAPI_STUBS_H_ -#define _OSAPI_STUBS_H_ - -#include "osapi.h" /* cfe.h not available from within osal. */ -#include "uttools.h" -#include "vxworks6-coverage-stubs.h" - - -/* Define test enums and structs */ -typedef enum -{ - OS_TASK_TABLE_SEM, - OS_QUEUE_TABLE_SEM, - OS_BIN_SEM_TABLE_SEM, - OS_COUNT_SEM_TABLE_SEM, - OS_MUT_SEM_TABLE_SEM, - OS_MAX_SEM -} OsApi_Semaphore_t; - - -typedef enum -{ - OSAPI_EXIT_INDEX, - OSAPI_STRLEN_INDEX, - OSAPI_STRCMP_INDEX, - OSAPI_STRCPY_INDEX, - OSAPI_CLOCKGETTIME_INDEX, - OSAPI_CLOCKSETTIME_INDEX, - OSAPI_INTCONNECT_INDEX, - OSAPI_INTDISABLE_INDEX, - OSAPI_INTENABLE_INDEX, - OSAPI_INTLOCK_INDEX, - OSAPI_INTUNLOCK_INDEX, - OSAPI_MEMPARTINFOGET_INDEX, - OSAPI_MSGQCREATE_INDEX, - OSAPI_MSGQDELETE_INDEX, - OSAPI_MSGQRECEIVE_INDEX, - OSAPI_MSGQSEND_INDEX, - OSAPI_SEMBCREATE_INDEX, - OSAPI_SEMCCREATE_INDEX, - OSAPI_SEMDELETE_INDEX, - OSAPI_SEMFLUSH_INDEX, - OSAPI_SEMMCREATE_INDEX, - OSAPI_SEMTAKE_INDEX, - OSAPI_SEMGIVE_INDEX, - OSAPI_SYSCLKRATEGET_INDEX, - OSAPI_TASKDELAY_INDEX, - OSAPI_TASKDELETE_INDEX, - OSAPI_TASKIDSELF_INDEX, - OSAPI_TASKNAMETOID_INDEX, - OSAPI_TASKPRIORITYSET_INDEX, - OSAPI_TASKSPAWN_INDEX, - OSAPI_TASKVARADD_INDEX, - OSAPI_OSFSINIT_INDEX, - OSAPI_OSMODULETABLEINIT_INDEX, - OSAPI_OSTIMERAPIINIT_INDEX, - OSAPI_VXFPSCRGET_INDEX, - OSAPI_MAX_INDEX -} OsApi_Index_t; - -typedef struct -{ - int32 Value; - uint32 Count; -} OsApi_ReturnCodeTable_t; - -typedef struct -{ - size_t (*strlen)(const char *str); - int (*strcmp)(const char *str1, const char *str2); - char * (*strcpy)(const char *str1, const char *str2); - VCS_SEM_ID (*semMCreate)(uint16 *); - VCS_STATUS (*semTake)(VCS_SEM_ID, int); - VCS_STATUS (*semGive)(VCS_SEM_ID); - VCS_STATUS (*taskDelay)(int ticks); - int (*taskNameToId)(char *name); - int (*sysClkRateGet)(void); - uint32 (*OS_FindCreator)(void); -} OsApi_HookTable_t; - - -void OsApi_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt); -void OsApi_SetFunctionHook(uint32 Index, void *FunPtr); -void OsApi_Reset(void); - -uint32 getFpuMask(void); -int getMsgQReceiveTimeout(void); -uint32 getNLogMsg_calls(void); -uint32 getNSeconds(void); -int32 getNSemTake(uint32 id); -int32 getNSemGive(uint32 id); -int32 getNTaskDeleteForce(void); -uint32 getNVsnprintf_calls(void); -uint32 getSeconds(void); -uint32 getSemBInitialValue(void); -VCS_SEM_ID getSemGiveArg(void); -int32 getSemTakeTicks(void); -int getTaskDelayTicks(void); -boolean getTaskExitCalled(void); -int getTaskSpawnFlags(void); - -void setHeapInfo(unsigned long freeBytes, unsigned long freeBlocks, unsigned long maxFreeBlock); -void setTime(uint32 sec, uint32 nsec); - - -#endif diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase.c b/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase.c deleted file mode 100644 index 5dfd5e553..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Filename: osapi_testcase.c - * - * Purpose: This file provides functions for adding unit test cases - * - * Notes: - * - * Modification History: - * 06/25/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include "osapi_testcase.h" - - - -/* Prototypes for non-exported functions */ -void Osapi_AddTestCase_Tasks(void); -void Osapi_AddTestCase_Queues(void); -void Osapi_AddTestCase_BinSem(void); -void Osapi_AddTestCase_CntSem(void); -void Osapi_AddTestCase_MutSem(void); -void Osapi_AddTestCase_Time_Int(void); - - - -/* -------------------- Define variables to match UUT ----------------------- */ -const uint32 MAX_PRIORITY = 255; /* matches #define value in uut */ -const uint32 UNINITIALIZED = 0; /* matches #define value in uut */ - - -/* -------------------- Special Test Case Variables ------------------------- */ -const uint32 test_OS_task_table_sem = OS_TASK_TABLE_SEM; -const uint32 test_OS_queue_table_sem = OS_QUEUE_TABLE_SEM; -const uint32 test_OS_bin_sem_table_sem = OS_BIN_SEM_TABLE_SEM; -const uint32 test_OS_count_sem_table_sem = OS_COUNT_SEM_TABLE_SEM; -const uint32 test_OS_mut_sem_table_sem = OS_MUT_SEM_TABLE_SEM; - - -/* -------------------------------------------------------------------------- */ -/* - * Osapi_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osapi_Setup(void) -{ - OsApi_Reset(); - - OsApi_Adaptor_Reset_Tables(); - OsApi_Adaptor_Set_Os_Task_Table_Sem((VCS_SEM_ID)&test_OS_task_table_sem); - OsApi_Adaptor_Set_Os_Queue_Table_Sem((VCS_SEM_ID)&test_OS_queue_table_sem); - OsApi_Adaptor_Set_Os_Bin_Sem_Table_Sem((VCS_SEM_ID)&test_OS_bin_sem_table_sem); - OsApi_Adaptor_Set_Os_Count_Sem_Table_Sem((VCS_SEM_ID)&test_OS_count_sem_table_sem); - OsApi_Adaptor_Set_Os_Mut_Sem_Table_Sem((VCS_SEM_ID)&test_OS_mut_sem_table_sem); -} - - -/* - * Osapi_TearDown - * - * Purpose: - * Called by the unit test tool to tear down the app after each test - */ -void Osapi_TearDown(void) -{ - -} - - -#define ADD_TEST(test,setup,teardown) UtTest_Add((test), (setup), (teardown), #test) - -/* Osapi_AddTestCase - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void OS_Application_Startup(void) -{ - Osapi_AddTestCase_Tasks(); - Osapi_AddTestCase_Queues(); - Osapi_AddTestCase_BinSem(); - Osapi_AddTestCase_CntSem(); - Osapi_AddTestCase_MutSem(); - Osapi_AddTestCase_Time_Int(); -} - - - - diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase.h b/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase.h deleted file mode 100644 index f403f63f1..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Filename: osapi_testcase.h - * - * Purpose: This file declares common variables and functions used among the - * unit test case source files - * - * Notes: - * - * Modification History: - * 06/25/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include "osapi.h" /* cfe.h not available from within osal. */ - -#include "utassert.h" -#include "uttest.h" -#include "utlist.h" - -#include "osapi_stubs.h" -#include "osapi_adaptor.h" - - -#define OS_INCLUDE_MODULE_LOADER - - - -/* Variables defined in osapi.c */ -extern const uint32 MAX_PRIORITY; -extern const uint32 UNINITIALIZED; - - -/* Utility functions */ -void deleteFnc(void); -void setTaskTableEntry(uint32 idx, int free, int id, char *name, int creator, - uint32 stack_size, uint32 priority, void *delete_hook_pointer); - - - -/* -------------------------------------------------------------------------- */ -#define ADD_TEST(test,setup,teardown) UtTest_Add((test), (setup), (teardown), #test) - -void Osapi_Setup(void); -void Osapi_TearDown(void); -void Osapi_AddTestCase(void); - - diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_binsem.c b/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_binsem.c deleted file mode 100644 index b0df11cba..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_binsem.c +++ /dev/null @@ -1,1019 +0,0 @@ -/* - * Filename: osapi_testcase_binsem.c - * - * Purpose: This file contains unit test cases - * - * Notes: - * - * Modification History: - * 06/28/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include "osapi_testcase.h" - - - -/* Prototypes for non-exported functions */ - - - -/* -------------------- Special Test Case Variables ------------------------- */ -static uint32 sem_id; -static const char *sem_name = "testName"; -static uint32 options; -static OsApi_Adaptor_OS_bin_sem_record_t *osBinSemRecord_ptr; - -/* -------------------------------------------------------------------------- */ -/* Utility functions */ - - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_BinSemCreate Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemCreate_NullId(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - - /* Execute Test */ - actual = OS_BinSemCreate(NULL, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemCreate_NullName(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - - /* Execute Test */ - actual = OS_BinSemCreate(&sem_id, NULL, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemCreate_NameTooLong(void) -{ - int32 expected = OS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_BinSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemCreate_NoFreeIds(void) -{ - int32 expected = OS_ERR_NO_FREE_IDS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - - /* Execute Test */ - actual = OS_BinSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NO_FREE_IDS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemCreate_NameTaken(void) -{ - int32 expected = OS_ERR_NAME_TAKEN; - int32 actual = 99; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - OsApi_Adaptor_setBinSemTableEntry(3, TRUE, 0, "", 0); - OsApi_Adaptor_setBinSemTableEntry(OS_MAX_BIN_SEMAPHORES - 1, FALSE, 0, sem_name, 0); - - /* Execute Test */ - actual = OS_BinSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TAKEN"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemCreate_Failure(void) -{ - int32 expected = OS_SEM_FAILURE; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 10; - uint32 sem_initial_value = 20; - OsApi_Adaptor_setBinSemTableEntry(idx, TRUE, 0, "", 0); - - OsApi_SetReturnCode(OSAPI_SEMBCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_BinSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - UtAssert_True(getSemBInitialValue() == 1, "sem_initial_value limited to valid value"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemCreate_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 10; - uint32 sem_initial_value = 0; - VCS_SEM_ID creator = (VCS_SEM_ID)55; - uint32 creatorIdx = 20; - OsApi_Adaptor_setBinSemTableEntry(idx, TRUE, 0, "", 0); - OsApi_Adaptor_setTaskTableEntry(creatorIdx, FALSE, (int32)creator, "", 0, 0, 0, NULL); - - OsApi_SetReturnCode(OSAPI_SEMBCREATE_INDEX, 1, 1); - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, (int32)creator, 1); - - /* Execute Test */ - actual = OS_BinSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - osBinSemRecord_ptr = OsApi_Adaptor_getBinSemTableEntry(idx); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(getSemBInitialValue() == 0, "sem_initial_value == expected"); - UtAssert_True(osBinSemRecord_ptr->free == FALSE, "free == expected"); - UtAssert_StrCmp(osBinSemRecord_ptr->name, sem_name, "name == expected"); - UtAssert_True(osBinSemRecord_ptr->creator == creatorIdx, "creator == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_BinSemDelete Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemDelete_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_BinSemDelete(OS_MAX_BIN_SEMAPHORES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemDelete_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setBinSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_BinSemDelete(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemDelete_Failure(void) -{ - int32 expected = OS_SEM_FAILURE; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMDELETE_INDEX, VCS_ERROR, 1); - -/* OS_bin_sem_table[sem_id].free = FALSE; - strcpy(OS_bin_sem_table[sem_id].name, sem_name);*/ - - /* Execute Test */ - actual = OS_BinSemDelete(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemDelete_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setBinSemTableEntry(sem_id, FALSE, (VCS_SEM_ID)11, sem_name, 9); - - OsApi_SetReturnCode(OSAPI_SEMDELETE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_BinSemDelete(sem_id); - - /* Verify Outputs */ - osBinSemRecord_ptr = OsApi_Adaptor_getBinSemTableEntry(sem_id); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(osBinSemRecord_ptr->free == TRUE, "free == expected"); - UtAssert_StrCmp(osBinSemRecord_ptr->name, "", "name == expected"); - UtAssert_True(osBinSemRecord_ptr->creator == UNINITIALIZED, "creator == expected"); - UtAssert_True(osBinSemRecord_ptr->id == NULL, "id == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_BinSemGive Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGive_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_BinSemGive(OS_MAX_BIN_SEMAPHORES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGive_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setBinSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_BinSemGive(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGive_Failure(void) -{ - int32 expected = OS_SEM_FAILURE; - int32 actual = 99; - - /* Setup Inputs */ - VCS_SEM_ID id = OsApi_Adaptor_Get_Os_Bin_Sem_Table_Sem(); - OsApi_Adaptor_setBinSemTableEntry(sem_id, FALSE, id, "", 0); - - OsApi_SetReturnCode(OSAPI_SEMGIVE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_BinSemGive(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - UtAssert_True(getSemGiveArg() == id, "semGive call arg == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGive_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - VCS_SEM_ID id = OsApi_Adaptor_Get_Os_Bin_Sem_Table_Sem(); - OsApi_Adaptor_setBinSemTableEntry(sem_id, FALSE, id, "", 0); - - OsApi_SetReturnCode(OSAPI_SEMGIVE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_BinSemGive(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(getSemGiveArg() == id, "semGive call arg == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_BinSemFlush Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemFlush_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_BinSemFlush(OS_MAX_BIN_SEMAPHORES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemFlush_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 id = OS_MAX_BIN_SEMAPHORES - 1; - OsApi_Adaptor_setBinSemTableEntry(id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_BinSemFlush(id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemFlush_Failure(void) -{ - int32 expected = OS_SEM_FAILURE; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMFLUSH_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_BinSemFlush(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemFlush_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMFLUSH_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_BinSemFlush(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_BinSemTake Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTake_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_BinSemTake(OS_MAX_BIN_SEMAPHORES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTake_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setBinSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_BinSemTake(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTake_Failure(void) -{ - int32 expected = OS_SEM_FAILURE; - int32 actual = 99; - - /* Setup Inputs */ - VCS_SEM_ID id = OsApi_Adaptor_Get_Os_Bin_Sem_Table_Sem(); - OsApi_Adaptor_setBinSemTableEntry(sem_id, FALSE, id, "", 0); - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_BinSemTake(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTake_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - sem_id = OS_MAX_BIN_SEMAPHORES - 1; - VCS_SEM_ID id = OsApi_Adaptor_Get_Os_Bin_Sem_Table_Sem(); - OsApi_Adaptor_setBinSemTableEntry(sem_id, FALSE, id, "", 0); - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_BinSemTake(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_BinSemTimedWait Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTimedWait_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 msecs = 0; - - /* Execute Test */ - actual = OS_BinSemTimedWait(OS_MAX_BIN_SEMAPHORES, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTimedWait_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 msecs = 0; - OsApi_Adaptor_setBinSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_BinSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTimedWait_TimeOut(void) -{ - int32 expected = OS_SEM_TIMEOUT; - int32 actual = 99; - - /* Setup Inputs */ - uint32 msecs = 0; - sem_id = OS_MAX_BIN_SEMAPHORES - 1; - VCS_errno = VCS_S_objLib_OBJ_TIMEOUT; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_BinSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_TIMEOUT"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTimedWait_FailWithErr(void) -{ - int32 expected = OS_SEM_FAILURE; - int32 actual = 99; - - /* Setup Inputs */ - uint32 msecs = 0; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_BinSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTimedWait_FailNotErr(void) -{ - int32 expected = OS_SEM_FAILURE; - int32 actual = 99; - - /* Setup Inputs */ - uint32 msecs = 0; - int32 notErrNorOk = 2; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, notErrNorOk, 1); /* for full MCDC coverage */ - - /* Execute Test */ - actual = OS_BinSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemTimedWait_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 msecs = 45; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_OK, 1); - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1000000, 1); /* make the math simple */ - - /* Execute Test */ - actual = OS_BinSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(getSemTakeTicks() == msecs * 1000, "timeoutTicks == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_BinSemGetIdByName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGetIdByName_NullId(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *sem_name = "testName"; - - /* Execute Test */ - actual = OS_BinSemGetIdByName(NULL, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGetIdByName_NullName(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_BinSemGetIdByName(&sem_id, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGetIdByName_NameTooLong(void) -{ - int32 expected = OS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *sem_name = "testName"; - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_BinSemGetIdByName(&sem_id, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGetIdByName_NameNotFound(void) -{ - int32 expected = OS_ERR_NAME_NOT_FOUND; - int32 actual = 99; - - /* Setup Inputs */ - const char *sem_name = "testName"; - - /* Execute Test */ - actual = OS_BinSemGetIdByName(&sem_id, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_NOT_FOUND"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGetIdByName_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *sem_name = "testName"; - uint32 id = OS_MAX_BIN_SEMAPHORES - 1; - OsApi_Adaptor_setBinSemTableEntry(0, TRUE, 0, "", 0); /* for full MCDC coverage */ - OsApi_Adaptor_setBinSemTableEntry(id, FALSE, 0, sem_name, 0); - - /* Execute Test */ - actual = OS_BinSemGetIdByName(&sem_id, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(sem_id == id, "sem_id == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_BinSemGetInfo Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGetInfo_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - static OS_bin_sem_prop_t bin_prop; - - /* Execute Test */ - actual = OS_BinSemGetInfo(OS_MAX_BIN_SEMAPHORES, &bin_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGetInfo_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - static OS_bin_sem_prop_t bin_prop; - OsApi_Adaptor_setBinSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_BinSemGetInfo(sem_id, &bin_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGetInfo_NullProp(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_BinSemGetInfo(sem_id, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_BinSemGetInfo_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - static OS_bin_sem_prop_t bin_prop; - OsApi_Adaptor_setBinSemTableEntry(sem_id, FALSE, 0, "testName", 32); - - /* Execute Test */ - actual = OS_BinSemGetInfo(sem_id, &bin_prop); - - /* Verify Outputs */ - osBinSemRecord_ptr = OsApi_Adaptor_getBinSemTableEntry(sem_id); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(bin_prop.creator == osBinSemRecord_ptr->creator, "creator == expected"); - UtAssert_True(bin_prop.value == 0, "value == expected"); - UtAssert_StrCmp(bin_prop.name, osBinSemRecord_ptr->name, "name == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_BIN_SEM_TABLE_SEM) == getNSemGive(OS_BIN_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/* ------------------- End of test cases --------------------------------------*/ - - -/* Osapi_BinSem_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osapi_BinSem_Setup(void) -{ - Osapi_Setup(); - - sem_id = 3; - options = 4; - VCS_errno = 0; -} - - -/* Osapi_AddTestCase_Tasks - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void Osapi_AddTestCase_BinSem(void) -{ - /* OS_BinSemCreate Tests */ - ADD_TEST(Test_OS_BinSemCreate_NullId, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemCreate_NullName, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemCreate_NameTooLong, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemCreate_NoFreeIds, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemCreate_NameTaken, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemCreate_Failure, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemCreate_Success, Osapi_BinSem_Setup, Osapi_TearDown); - - /* OS_BinSemDelete Tests */ - ADD_TEST(Test_OS_BinSemDelete_IdInvalid, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemDelete_IdIsFree, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemDelete_Failure, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemDelete_Success, Osapi_BinSem_Setup, Osapi_TearDown); - - /* OS_BinSemGive Tests */ - ADD_TEST(Test_OS_BinSemGive_IdInvalid, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGive_IdIsFree, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGive_Failure, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGive_Success, Osapi_BinSem_Setup, Osapi_TearDown); - - /* OS_BinSemFlush Tests */ - ADD_TEST(Test_OS_BinSemFlush_IdInvalid, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemFlush_IdIsFree, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemFlush_Failure, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemFlush_Success, Osapi_BinSem_Setup, Osapi_TearDown); - - /* OS_BinSemTake Tests */ - ADD_TEST(Test_OS_BinSemTake_IdInvalid, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemTake_IdIsFree, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemTake_Failure, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemTake_Success, Osapi_BinSem_Setup, Osapi_TearDown); - - /* OS_BinSemTimedWait Tests */ - ADD_TEST(Test_OS_BinSemTimedWait_IdInvalid, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemTimedWait_IdIsFree, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemTimedWait_TimeOut, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemTimedWait_FailWithErr,Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemTimedWait_FailNotErr, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemTimedWait_Success, Osapi_BinSem_Setup, Osapi_TearDown); - - /* OS_BinSemGetIdByName Tests */ - ADD_TEST(Test_OS_BinSemGetIdByName_NullId, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGetIdByName_NullName, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGetIdByName_NameTooLong, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGetIdByName_NameNotFound,Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGetIdByName_Success, Osapi_BinSem_Setup, Osapi_TearDown); - - /* OS_BinSemGetInfo Tests */ - ADD_TEST(Test_OS_BinSemGetInfo_IdInvalid, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGetInfo_IdIsFree, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGetInfo_NullProp, Osapi_BinSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_BinSemGetInfo_Success, Osapi_BinSem_Setup, Osapi_TearDown); -} - - - - diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_cntsem.c b/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_cntsem.c deleted file mode 100644 index 1eef03050..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_cntsem.c +++ /dev/null @@ -1,920 +0,0 @@ -/* - * Filename: osapi_testcase_cntsems.c - * - * Purpose: This file contains unit test cases - * - * Notes: - * - * Modification History: - * 06/28/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include "osapi_testcase.h" -#include - - - -/* Prototypes for non-exported functions */ - - - -/* -------------------- Special Test Case Variables ------------------------- */ -static uint32 sem_id; -static const char *sem_name = "testName"; -static uint32 options; -static int32 expected; -static int32 actual; -static OsApi_Adaptor_OS_count_sem_record_t *osCountSemRecord_ptr; - -/* -------------------------------------------------------------------------- */ -/* Utility functions */ - - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_CountSemCreate Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemCreate_NullId(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - - /* Execute Test */ - actual = OS_CountSemCreate(NULL, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemCreate_NullName(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - - /* Execute Test */ - actual = OS_CountSemCreate(&sem_id, NULL, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemCreate_NameTooLong(void) -{ - expected = OS_ERR_NAME_TOO_LONG; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_CountSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemCreate_InitValInvalid(void) -{ - expected = OS_INVALID_SEM_VALUE; - -#ifndef SEM_VALUE_MAX -#ifndef INT32_MAX -#define INT32_MAX ((int32)(2147483647)) /* 2**31 - 1 */ -#endif -#define SEM_VALUE_MAX INT32_MAX -#endif - /* Setup Inputs */ - uint32 sem_initial_value = (uint32)SEM_VALUE_MAX + 1; - - /* Execute Test */ - actual = OS_CountSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_SEM_VALUE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemCreate_NoFreeIds(void) -{ - expected = OS_ERR_NO_FREE_IDS; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - - /* Execute Test */ - actual = OS_CountSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NO_FREE_IDS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemCreate_NameTaken(void) -{ - expected = OS_ERR_NAME_TAKEN; - - /* Setup Inputs */ - uint32 sem_initial_value = 1; - OsApi_Adaptor_setCountSemTableEntry(3, TRUE, 0, "", 0); - OsApi_Adaptor_setCountSemTableEntry(OS_MAX_COUNT_SEMAPHORES - 1, FALSE, 0, sem_name, 0); - - /* Execute Test */ - actual = OS_CountSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TAKEN"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemCreate_Failure(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - uint32 idx = 10; - uint32 sem_initial_value = 20; - OsApi_Adaptor_setCountSemTableEntry(idx, TRUE, 0, "", 0); - - OsApi_SetReturnCode(OSAPI_SEMCCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_CountSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemCreate_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - uint32 idx = 10; - uint32 sem_initial_value = 0; - VCS_SEM_ID creator = (VCS_SEM_ID)55; - uint32 creatorIdx = 20; - OsApi_Adaptor_setCountSemTableEntry(idx, TRUE, 0, "", 0); - OsApi_Adaptor_setTaskTableEntry(creatorIdx, FALSE, (int32)creator, "", 0, 0, 0, NULL); - - OsApi_SetReturnCode(OSAPI_SEMCCREATE_INDEX, 1, 1); - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, (int32)creator, 1); - - /* Execute Test */ - actual = OS_CountSemCreate(&sem_id, sem_name, sem_initial_value, options); - - /* Verify Outputs */ - osCountSemRecord_ptr = OsApi_Adaptor_getCountSemTableEntry(idx); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(osCountSemRecord_ptr->free == FALSE, "free == expected"); - UtAssert_StrCmp(osCountSemRecord_ptr->name, sem_name, "name == expected"); - UtAssert_True(osCountSemRecord_ptr->creator == creatorIdx, "creator == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_CountSemDelete Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemDelete_IdInvalid(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_CountSemDelete(OS_MAX_COUNT_SEMAPHORES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemDelete_IdIsFree(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - OsApi_Adaptor_setCountSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_CountSemDelete(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemDelete_Failure(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMDELETE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_CountSemDelete(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemDelete_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - sem_id = OS_MAX_COUNT_SEMAPHORES - 1; - OsApi_Adaptor_setCountSemTableEntry(sem_id, FALSE, (VCS_SEM_ID)11, sem_name, 9); - - OsApi_SetReturnCode(OSAPI_SEMDELETE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_CountSemDelete(sem_id); - - /* Verify Outputs */ - osCountSemRecord_ptr = OsApi_Adaptor_getCountSemTableEntry(sem_id); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(osCountSemRecord_ptr->free == TRUE, "free == expected"); - UtAssert_StrCmp(osCountSemRecord_ptr->name, "", "name == expected"); - UtAssert_True(osCountSemRecord_ptr->creator == UNINITIALIZED, "creator == expected"); - UtAssert_True(osCountSemRecord_ptr->id == NULL, "id == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_CountSemGive Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGive_IdInvalid(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_CountSemGive(OS_MAX_COUNT_SEMAPHORES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGive_IdIsFree(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - OsApi_Adaptor_setCountSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_CountSemGive(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGive_Failure(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMGIVE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_CountSemGive(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGive_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - sem_id = OS_MAX_COUNT_SEMAPHORES - 1; - OsApi_SetReturnCode(OSAPI_SEMGIVE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_CountSemGive(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_CountSemTake Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTake_IdInvalid(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_CountSemTake(OS_MAX_COUNT_SEMAPHORES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTake_IdIsFree(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - OsApi_Adaptor_setCountSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_CountSemTake(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTake_Failure(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_CountSemTake(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTake_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - sem_id = OS_MAX_COUNT_SEMAPHORES - 1; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_CountSemTake(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_CountSemTimedWait Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTimedWait_IdInvalid(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - uint32 msecs = 0; - - /* Execute Test */ - actual = OS_CountSemTimedWait(OS_MAX_COUNT_SEMAPHORES, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTimedWait_IdIsFree(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - uint32 msecs = 0; - OsApi_Adaptor_setCountSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_CountSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTimedWait_Timeout(void) -{ - expected = OS_SEM_TIMEOUT; - - /* Setup Inputs */ - uint32 msecs = 0; - VCS_errno = VCS_S_objLib_OBJ_TIMEOUT; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_CountSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_TIMEOUT"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTimedWait_FailWithErr(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - uint32 msecs = 0; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_CountSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTimedWait_FailNotErr(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - uint32 msecs = 0; - int32 notErrNorOk = 2; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, notErrNorOk, 1); - - /* Execute Test */ - actual = OS_CountSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemTimedWait_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - uint32 msecs = 321; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_OK, 1); - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1000000, 1); /* make the math simple */ - - /* Execute Test */ - actual = OS_CountSemTimedWait(sem_id, msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(getSemTakeTicks() == msecs * 1000, "timeoutTicks == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_CountSemGetIdByName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGetIdByName_NullId(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_CountSemGetIdByName(NULL, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGetIdByName_NullName(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_CountSemGetIdByName(&sem_id, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGetIdByName_NameTooLong(void) -{ - expected = OS_ERR_NAME_TOO_LONG; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_CountSemGetIdByName(&sem_id, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGetIdByName_NameNotFound(void) -{ - expected = OS_ERR_NAME_NOT_FOUND; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_CountSemGetIdByName(&sem_id, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_NOT_FOUND"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGetIdByName_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - uint32 id = OS_MAX_COUNT_SEMAPHORES - 1; - OsApi_Adaptor_setCountSemTableEntry(1, TRUE, 0, "", 0); /* for full MCDC coverage */ - OsApi_Adaptor_setCountSemTableEntry(id, FALSE, 0, sem_name, 0); - - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME - 1, 1); - - /* Execute Test */ - actual = OS_CountSemGetIdByName(&sem_id, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(sem_id == id, "id == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_CountSemGetInfo Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGetInfo_IdInvalid(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - static OS_count_sem_prop_t count_prop; - - /* Execute Test */ - actual = OS_CountSemGetInfo(OS_MAX_COUNT_SEMAPHORES, &count_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGetInfo_IdIsFree(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - static OS_count_sem_prop_t count_prop; - OsApi_Adaptor_setCountSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_CountSemGetInfo(sem_id, &count_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGetInfo_NullProp(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - sem_id = OS_MAX_COUNT_SEMAPHORES - 1; - - /* Execute Test */ - actual = OS_CountSemGetInfo(sem_id, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CountSemGetInfo_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - static OS_count_sem_prop_t count_prop; - count_prop.value = 99; - OsApi_Adaptor_setCountSemTableEntry(sem_id, FALSE, 0, sem_name, 37); - - /* Execute Test */ - actual = OS_CountSemGetInfo(sem_id, &count_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(count_prop.creator == OsApi_Adaptor_getCountSemTableEntry(sem_id)->creator, - "creator == expected"); - UtAssert_True(count_prop.value == 0, "value == expected"); - UtAssert_StrCmp(count_prop.name, sem_name, "name == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_COUNT_SEM_TABLE_SEM) == getNSemGive(OS_COUNT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/* ------------------- End of test cases --------------------------------------*/ - - -/* Osapi_CntSem_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osapi_CntSem_Setup(void) -{ - Osapi_Setup(); - - sem_id = 3; - options = 4; - VCS_errno = 0; - - expected = 0; - actual = 99; -} - - -/* Osapi_AddTestCase_Tasks - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void Osapi_AddTestCase_CntSem(void) -{ - /* OS_CountSemCreate Tests */ - ADD_TEST(Test_OS_CountSemCreate_NullId, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemCreate_NullName, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemCreate_NameTooLong, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemCreate_InitValInvalid,Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemCreate_NoFreeIds, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemCreate_NameTaken, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemCreate_Failure, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemCreate_Success, Osapi_CntSem_Setup, Osapi_TearDown); - - /* OS_CountSemDelete Tests */ - ADD_TEST(Test_OS_CountSemDelete_IdInvalid, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemDelete_IdIsFree, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemDelete_Failure, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemDelete_Success, Osapi_CntSem_Setup, Osapi_TearDown); - - /* OS_CountSemGive Tests */ - ADD_TEST(Test_OS_CountSemGive_IdInvalid, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGive_IdIsFree, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGive_Failure, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGive_Success, Osapi_CntSem_Setup, Osapi_TearDown); - - /* OS_CountSemTake Tests */ - ADD_TEST(Test_OS_CountSemTake_IdInvalid, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemTake_IdIsFree, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemTake_Failure, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemTake_Success, Osapi_CntSem_Setup, Osapi_TearDown); - - /* OS_CountSemTimedWait Tests */ - ADD_TEST(Test_OS_CountSemTimedWait_IdInvalid, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemTimedWait_IdIsFree, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemTimedWait_Timeout, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemTimedWait_FailWithErr,Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemTimedWait_FailNotErr, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemTimedWait_Success, Osapi_CntSem_Setup, Osapi_TearDown); - - /* OS_CountSemGetIdByName Tests */ - ADD_TEST(Test_OS_CountSemGetIdByName_NullId, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGetIdByName_NullName, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGetIdByName_NameTooLong, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGetIdByName_NameNotFound,Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGetIdByName_Success, Osapi_CntSem_Setup, Osapi_TearDown); - - /* OS_CountSemGetInfo Tests */ - ADD_TEST(Test_OS_CountSemGetInfo_IdInvalid, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGetInfo_IdIsFree, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGetInfo_NullProp, Osapi_CntSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_CountSemGetInfo_Success, Osapi_CntSem_Setup, Osapi_TearDown); -} - - - - diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_mutsem.c b/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_mutsem.c deleted file mode 100644 index 274f905dd..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_mutsem.c +++ /dev/null @@ -1,739 +0,0 @@ -/* - * Filename: osapi_testcase_mutsems.c - * - * Purpose: This file contains unit test cases - * - * Notes: - * - * Modification History: - * 07/07/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include "osapi_testcase.h" -#include "osapi_adaptor.h" - - -/* Prototypes for non-exported functions */ - - - -/* -------------------- Special Test Case Variables ------------------------- */ -static uint32 sem_id; -static const char *sem_name = "testName"; -static uint32 options; -static int32 expected; -static int32 actual; -static OsApi_Adaptor_OS_mut_sem_record_t *osMuttSemRecord_ptr; - -/* -------------------------------------------------------------------------- */ -/* Utility functions */ - - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_MutSemCreate Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemCreate_NullId(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_MutSemCreate(NULL, sem_name, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemCreate_NullName(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_MutSemCreate(&sem_id, NULL, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemCreate_NameTooLong(void) -{ - expected = OS_ERR_NAME_TOO_LONG; - - /* Setup Inputs */ - - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_MutSemCreate(&sem_id, sem_name, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemCreate_NoFreeIds(void) -{ - expected = OS_ERR_NO_FREE_IDS; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_MutSemCreate(&sem_id, sem_name, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NO_FREE_IDS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemCreate_NameTaken(void) -{ - expected = OS_ERR_NAME_TAKEN; - - /* Setup Inputs */ - OsApi_Adaptor_setMutSemTableEntry(11, TRUE, 0, "", 0); /* for full MCDC coverage */ - OsApi_Adaptor_setMutSemTableEntry(OS_MAX_MUTEXES - 1, FALSE, 0, (char *)sem_name, 0); - - /* Execute Test */ - actual = OS_MutSemCreate(&sem_id, sem_name, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TAKEN"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemCreate_Failure(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - uint32 idx = 5; - OsApi_Adaptor_setMutSemTableEntry(idx, TRUE, 0, "", 0); - - OsApi_SetReturnCode(OSAPI_SEMMCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_MutSemCreate(&sem_id, sem_name, options); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - UtAssert_True(OsApi_Adaptor_getMutSemTableEntry(idx)->free == TRUE, "table entry still free"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemCreate_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - uint32 idx = 9; - VCS_SEM_ID creator = (VCS_SEM_ID)109; - uint32 creatorIdx = 19; - OsApi_Adaptor_setMutSemTableEntry(idx, TRUE, 0, "", 0); - OsApi_Adaptor_setMutSemTableEntry(creatorIdx, FALSE, creator, "", 0); - OsApi_Adaptor_setTaskTableEntry(creatorIdx, FALSE, (uint32)creator, "", 0, 0, 0, NULL); - - OsApi_SetReturnCode(OSAPI_SEMMCREATE_INDEX, 1, 1); - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, (uint32)creator, 1); - - /* Execute Test */ - actual = OS_MutSemCreate(&sem_id, sem_name, options); - - /* Verify Outputs */ - osMuttSemRecord_ptr = OsApi_Adaptor_getMutSemTableEntry(idx); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(osMuttSemRecord_ptr->free == FALSE, "free == expected"); - UtAssert_StrCmp(osMuttSemRecord_ptr->name, sem_name, "name == expected"); - UtAssert_True(osMuttSemRecord_ptr->creator == creatorIdx, "creator == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_MutSemDelete Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemDelete_IdInvalid(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_MutSemDelete(OS_MAX_MUTEXES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemDelete_IdIsFree(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - OsApi_Adaptor_setMutSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_MutSemDelete(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemDelete_Failure(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMDELETE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_MutSemDelete(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemDelete_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - sem_id = OS_MAX_MUTEXES - 1; - OsApi_Adaptor_setMutSemTableEntry(sem_id, FALSE, (VCS_SEM_ID)11, sem_name, 9); - - OsApi_SetReturnCode(OSAPI_SEMDELETE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_MutSemDelete(sem_id); - - /* Verify Outputs */ - osMuttSemRecord_ptr = OsApi_Adaptor_getMutSemTableEntry(sem_id); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(osMuttSemRecord_ptr->free == TRUE, "free == expected"); - UtAssert_StrCmp(osMuttSemRecord_ptr->name, "", "name == expected"); - UtAssert_True(osMuttSemRecord_ptr->creator == UNINITIALIZED, "creator == expected"); - UtAssert_True(osMuttSemRecord_ptr->id == NULL, "id == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_MutSemGive Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGive_IdInvalid(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_MutSemGive(OS_MAX_MUTEXES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGive_IdIsFree(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - OsApi_Adaptor_setMutSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_MutSemGive(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGive_Failure(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMGIVE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_MutSemGive(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGive_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - sem_id = OS_MAX_MUTEXES - 1; - OsApi_SetReturnCode(OSAPI_SEMGIVE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_MutSemGive(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_MutSemTake Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemTake_IdInvalid(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_MutSemTake(OS_MAX_MUTEXES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemTake_IdIsFree(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - OsApi_Adaptor_setMutSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_MutSemTake(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemTake_Failure(void) -{ - expected = OS_SEM_FAILURE; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_MutSemTake(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SEM_FAILURE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemTake_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - sem_id = OS_MAX_MUTEXES - 1; - - OsApi_SetReturnCode(OSAPI_SEMTAKE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_MutSemTake(sem_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_MutSemGetIdByName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGetIdByName_NullId(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_MutSemGetIdByName(NULL, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGetIdByName_NullName(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_MutSemGetIdByName(&sem_id, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGetIdByName_NameTooLong(void) -{ - expected = OS_ERR_NAME_TOO_LONG; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_MutSemGetIdByName(&sem_id, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGetIdByName_NameNotFound(void) -{ - expected = OS_ERR_NAME_NOT_FOUND; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_MutSemGetIdByName(&sem_id, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_NOT_FOUND"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGetIdByName_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - uint32 id = OS_MAX_MUTEXES - 1; - OsApi_Adaptor_setMutSemTableEntry(4, TRUE, 0, "", 0); /* for full MCDC coverage */ - OsApi_Adaptor_setMutSemTableEntry(id, FALSE, 0, sem_name, 0); - - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME - 1, 1); - - /* Execute Test */ - actual = OS_MutSemGetIdByName(&sem_id, sem_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(sem_id == id, "id == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_MutSemGetInfo Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGetInfo_IdInvalid(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - static OS_mut_sem_prop_t prop; - - /* Execute Test */ - actual = OS_MutSemGetInfo(OS_MAX_MUTEXES, &prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGetInfo_IdIsFree(void) -{ - expected = OS_ERR_INVALID_ID; - - /* Setup Inputs */ - static OS_mut_sem_prop_t prop; - OsApi_Adaptor_setMutSemTableEntry(sem_id, TRUE, 0, "", 0); - - /* Execute Test */ - actual = OS_MutSemGetInfo(sem_id, &prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGetInfo_NullProp(void) -{ - expected = OS_INVALID_POINTER; - - /* Setup Inputs */ - sem_id = OS_MAX_MUTEXES - 1; - - /* Execute Test */ - actual = OS_MutSemGetInfo(sem_id, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_MutSemGetInfo_Success(void) -{ - expected = OS_SUCCESS; - - /* Setup Inputs */ - static OS_mut_sem_prop_t prop; - OsApi_Adaptor_setMutSemTableEntry(sem_id, FALSE, 0, sem_name, 232); - - - /* Execute Test */ - actual = OS_MutSemGetInfo(sem_id, &prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(prop.creator == OsApi_Adaptor_getMutSemTableEntry(sem_id)->creator, - "creator == expected"); - UtAssert_StrCmp(prop.name, sem_name, "name == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_MUT_SEM_TABLE_SEM) == getNSemGive(OS_MUT_SEM_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/* ------------------- End of test cases --------------------------------------*/ - - -/* Osapi_MutSem_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osapi_MutSem_Setup(void) -{ - Osapi_Setup(); - - sem_id = 3; - options = 4; - VCS_errno = 0; - - expected = 0; - actual = 99; -} - - -/* Osapi_AddTestCase_Tasks - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void Osapi_AddTestCase_MutSem(void) -{ - /* OS_MutSemCreate Tests */ - ADD_TEST(Test_OS_MutSemCreate_NullId, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemCreate_NullName, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemCreate_NameTooLong, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemCreate_NoFreeIds, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemCreate_NameTaken, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemCreate_Failure, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemCreate_Success, Osapi_MutSem_Setup, Osapi_TearDown); - - /* OS_MutSemDelete Tests */ - ADD_TEST(Test_OS_MutSemDelete_IdInvalid, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemDelete_IdIsFree, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemDelete_Failure, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemDelete_Success, Osapi_MutSem_Setup, Osapi_TearDown); - - /* OS_MutSemGive Tests */ - ADD_TEST(Test_OS_MutSemGive_IdInvalid, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGive_IdIsFree, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGive_Failure, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGive_Success, Osapi_MutSem_Setup, Osapi_TearDown); - - /* OS_MutSemTake Tests */ - ADD_TEST(Test_OS_MutSemTake_IdInvalid, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemTake_IdIsFree, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemTake_Failure, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemTake_Success, Osapi_MutSem_Setup, Osapi_TearDown); - - /* OS_MutSemGetIdByName Tests */ - ADD_TEST(Test_OS_MutSemGetIdByName_NullId, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGetIdByName_NullName, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGetIdByName_NameTooLong, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGetIdByName_NameNotFound,Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGetIdByName_Success, Osapi_MutSem_Setup, Osapi_TearDown); - - /* OS_MutSemGetInfo Tests */ - ADD_TEST(Test_OS_MutSemGetInfo_IdInvalid, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGetInfo_IdIsFree, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGetInfo_NullProp, Osapi_MutSem_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_MutSemGetInfo_Success, Osapi_MutSem_Setup, Osapi_TearDown); -} - - - - diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_queues.c b/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_queues.c deleted file mode 100644 index 175f70e18..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_queues.c +++ /dev/null @@ -1,972 +0,0 @@ -/* - * Filename: osapi_testcase_queues.c - * - * Purpose: This file contains unit test cases - * - * Notes: - * - * Modification History: - * 06/27/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include "osapi_testcase.h" - - - -/* Prototypes for non-exported functions */ - - - -/* -------------------- Special Test Case Variables ------------------------- */ -static uint32 queue_id; -static const char *queue_name = "testName"; -static uint32 queue_depth; -static uint32 data_size; -static uint32 flags; -static uint32 data; -static uint32 size_copied; -static OsApi_Adaptor_OS_queue_record_t *osQueueRecord_ptr; - - -/* -------------------------------------------------------------------------- */ -/* Utility functions */ - - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_QueueCreate Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueCreate_NullId(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueCreate(NULL, queue_name, queue_depth, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueCreate_NullName(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueCreate(&queue_id, NULL, queue_depth, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueCreate_NameTooLong(void) -{ - int32 expected = OS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_QueueCreate(&queue_id, queue_name, queue_depth, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueCreate_NoFreeIds(void) -{ - int32 expected = OS_ERR_NO_FREE_IDS; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueCreate(&queue_id, queue_name, queue_depth, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NO_FREE_IDS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueCreate_NameTaken(void) -{ - int32 expected = OS_ERR_NAME_TAKEN; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setQueueTableEntry(OS_MAX_QUEUES - 1, TRUE, 0, 0, "", 0); - OsApi_Adaptor_setQueueTableEntry(1, FALSE, 0, 0, (char *)queue_name, 0);/* for full MCDC coverage */ - - /* Execute Test */ - actual = OS_QueueCreate(&queue_id, queue_name, queue_depth, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TAKEN"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueCreate_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setQueueTableEntry(1, TRUE, 0, 0, "", 0); - - OsApi_SetReturnCode(OSAPI_MSGQCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_QueueCreate(&queue_id, queue_name, queue_depth, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueCreate_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 12; - uint32 creator_idx = 13; - OsApi_Adaptor_setTaskTableEntry(creator_idx, FALSE, task_id, "testTask", 2, 3, 4, deleteFnc); - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, task_id, 1); - - uint32 idx = 6; - OsApi_Adaptor_setQueueTableEntry(idx, TRUE, 0, 0, "", 0); - - VCS_MSG_Q_ID msg_id = (VCS_MSG_Q_ID)300; - OsApi_SetReturnCode(OSAPI_MSGQCREATE_INDEX, (int32)msg_id, 1); - - /* Execute Test */ - actual = OS_QueueCreate(&queue_id, queue_name, queue_depth, data_size, flags); - - /* Verify Outputs */ - osQueueRecord_ptr = OsApi_Adaptor_getQueueTableEntry(idx); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(osQueueRecord_ptr->id == msg_id, "id == expected"); - UtAssert_True(osQueueRecord_ptr->free == FALSE, "free == expected"); - UtAssert_StrCmp(osQueueRecord_ptr->name, queue_name, "name == expected"); - UtAssert_True(osQueueRecord_ptr->max_size == data_size, "max_size == expected"); - UtAssert_True(osQueueRecord_ptr->creator == creator_idx, "creator == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_QueueDelete Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueDelete_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueDelete(OS_MAX_QUEUES); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueDelete_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setQueueTableEntry(queue_id, TRUE, 0, 0, "", 0); - - /* Execute Test */ - actual = OS_QueueDelete(queue_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueDelete_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_MSGQDELETE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_QueueDelete(queue_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueDelete_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_MSGQDELETE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_QueueDelete(queue_id); - - /* Verify Outputs */ - osQueueRecord_ptr = OsApi_Adaptor_getQueueTableEntry(queue_id); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(osQueueRecord_ptr->id == NULL, "id == expected"); - UtAssert_True(osQueueRecord_ptr->free == TRUE, "free == expected"); - UtAssert_StrCmp(osQueueRecord_ptr->name, "", "name == expected"); - UtAssert_True(osQueueRecord_ptr->max_size == 0, "max_size == expected"); - UtAssert_True(osQueueRecord_ptr->creator == UNINITIALIZED, "creator == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_QueueGet Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueGet(OS_MAX_QUEUES, &data, data_size, &size_copied, OS_PEND); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setQueueTableEntry(queue_id, TRUE, 0, 0, "", 0); - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, &size_copied, OS_PEND); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_NullData(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueGet(queue_id, NULL, 1, &size_copied, OS_PEND); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == 0, "no semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_NullSizeCopied(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, NULL, OS_PEND); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == 0, "no semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_SizeInvalid(void) -{ - int32 expected = OS_QUEUE_INVALID_SIZE; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setQueueTableEntry(queue_id, FALSE, 0, data_size + 1, "", 0); - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, &size_copied, OS_PEND); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_QUEUE_INVALID_SIZE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_TimeoutPend(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 expected_size_copied = 77; - OsApi_Adaptor_setQueueTableEntry(queue_id, FALSE, 0, data_size, "", 0); - OsApi_SetReturnCode(OSAPI_MSGQRECEIVE_INDEX, expected_size_copied, 1); - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, &size_copied, OS_PEND); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(size_copied == expected_size_copied, "size_copied == expected"); - UtAssert_True(getMsgQReceiveTimeout() == VCS_WAIT_FOREVER, "timeout == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_TimeoutChkQEmpty(void) -{ - int32 expected = OS_QUEUE_EMPTY; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setQueueTableEntry(queue_id, FALSE, 0, data_size, "", 0); - VCS_errno = VCS_S_objLib_OBJ_UNAVAILABLE; - OsApi_SetReturnCode(OSAPI_MSGQRECEIVE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, &size_copied, OS_CHECK); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_QUEUE_EMPTY"); - UtAssert_True(size_copied == 0, "size_copied == expected"); - UtAssert_True(getMsgQReceiveTimeout() == VCS_NO_WAIT, "timeout == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_TimeoutChkErr(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setQueueTableEntry(queue_id, FALSE, 0, data_size, "", 0); - OsApi_SetReturnCode(OSAPI_MSGQRECEIVE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, &size_copied, OS_CHECK); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - UtAssert_True(size_copied == 0, "size_copied == expected"); - UtAssert_True(getMsgQReceiveTimeout() == VCS_NO_WAIT, "timeout == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_TimeoutChkSuccess(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 expected_size_copied = 22; - OsApi_Adaptor_setQueueTableEntry(queue_id, FALSE, 0, data_size, "", 0); - OsApi_SetReturnCode(OSAPI_MSGQRECEIVE_INDEX, expected_size_copied, 1); - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, &size_copied, OS_CHECK); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(size_copied == expected_size_copied, "size_copied == expected"); - UtAssert_True(getMsgQReceiveTimeout() == VCS_NO_WAIT, "timeout == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_QTimeout(void) -{ - int32 expected = OS_QUEUE_TIMEOUT; - int32 actual = 99; - - /* Setup Inputs */ - int32 timeout = 1; - OsApi_Adaptor_setQueueTableEntry(queue_id, FALSE, 0, data_size, "", 0); - VCS_errno = VCS_S_objLib_OBJ_TIMEOUT; - OsApi_SetReturnCode(OSAPI_MSGQRECEIVE_INDEX, VCS_ERROR, 1); - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1000000, 1); /* make the math simple */ - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, &size_copied, timeout); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_QUEUE_TIMEOUT"); - UtAssert_True(size_copied == 0, "size_copied == expected"); - UtAssert_True(getMsgQReceiveTimeout() == timeout * 1000, "timeout == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 timeout = 1; - OsApi_Adaptor_setQueueTableEntry(queue_id, FALSE, 0, data_size, "", 0); - OsApi_SetReturnCode(OSAPI_MSGQRECEIVE_INDEX, VCS_ERROR, 1); - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1000000, 1); /* make the math simple */ - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, &size_copied, timeout); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - UtAssert_True(size_copied == 0, "size_copied == expected"); - UtAssert_True(getMsgQReceiveTimeout() == timeout * 1000, "timeout == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGet_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 timeout = 1; - int32 expected_size_copied = 199; - OsApi_Adaptor_setQueueTableEntry(queue_id, FALSE, 0, data_size, "", 0); - OsApi_SetReturnCode(OSAPI_MSGQRECEIVE_INDEX, expected_size_copied, 1); - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1000000, 1); /* make the math simple */ - - /* Execute Test */ - actual = OS_QueueGet(queue_id, &data, data_size, &size_copied, timeout); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(size_copied == expected_size_copied, "size_copied == expected"); - UtAssert_True(getMsgQReceiveTimeout() == timeout * 1000, "timeout == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_QueuePut Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_QueuePut_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueuePut(OS_MAX_QUEUES, &data, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueuePut_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setQueueTableEntry(queue_id, TRUE, 0, 0, "", 0); - - /* Execute Test */ - actual = OS_QueuePut(queue_id, &data, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueuePut_NullData(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueuePut(queue_id, NULL, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == 0, "semaphore not taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueuePut_QFull(void) -{ - int32 expected = OS_QUEUE_FULL; - int32 actual = 99; - - /* Setup Inputs */ - VCS_errno = VCS_S_objLib_OBJ_UNAVAILABLE; - OsApi_SetReturnCode(OSAPI_MSGQSEND_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_QueuePut(queue_id, &data, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_QUEUE_FULL"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueuePut_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_MSGQSEND_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_QueuePut(queue_id, &data, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueuePut_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_MSGQSEND_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_QueuePut(queue_id, &data, data_size, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_QueueGetIdByName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGetIdByName_NullId(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueGetIdByName(NULL, queue_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGetIdByName_NullName(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueGetIdByName(&queue_id, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGetIdByName_NameTooLong(void) -{ - int32 expected = OS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_QueueGetIdByName(&queue_id, queue_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGetIdByName_NotFound(void) -{ - int32 expected = OS_ERR_NAME_NOT_FOUND; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueGetIdByName(&queue_id, queue_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_NOT_FOUND"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGetIdByName_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 expected_idx = OS_MAX_QUEUES - 1; - OsApi_Adaptor_setQueueTableEntry(5, TRUE, 0, 0, "", 0); /* for full MCDC coverage */ - OsApi_Adaptor_setQueueTableEntry(expected_idx, FALSE, 0, 0, (char *)queue_name, 0); - - /* Execute Test */ - actual = OS_QueueGetIdByName(&queue_id, queue_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(queue_id == expected_idx, "queue_id == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_QueueGetInfo Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGetInfo_NullProp(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_QueueGetInfo(queue_id, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGetInfo_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - static OS_queue_prop_t queue_prop; - - /* Execute Test */ - actual = OS_QueueGetInfo(OS_MAX_QUEUES, &queue_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGetInfo_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - static OS_queue_prop_t queue_prop; - OsApi_Adaptor_setQueueTableEntry(queue_id, TRUE, 0, 0, "", 0); - - /* Execute Test */ - actual = OS_QueueGetInfo(queue_id, &queue_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_QueueGetInfo_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - static OS_queue_prop_t queue_prop; - OsApi_Adaptor_setQueueTableEntry(queue_id, FALSE, 0, 0, (char *)queue_name, 8); - - /* Execute Test */ - actual = OS_QueueGetInfo(queue_id, &queue_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(queue_prop.creator == OsApi_Adaptor_getQueueTableEntry(queue_id)->creator, - "creator == expected"); - UtAssert_StrCmp(queue_prop.name, queue_name, "name == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_QUEUE_TABLE_SEM) == getNSemGive(OS_QUEUE_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/* ------------------- End of test cases --------------------------------------*/ - - -/* Osapi_Queue_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osapi_Queue_Setup(void) -{ - Osapi_Setup(); - - queue_id = 1; - queue_depth = 2; - data_size = 3; - flags = 4; - data = 5; - size_copied = 6; - VCS_errno = 0; -} - - -/* Osapi_AddTestCase_Tasks - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void Osapi_AddTestCase_Queues(void) -{ - /* OS_QueueCreate Tests */ - ADD_TEST(Test_OS_QueueCreate_NullId, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueCreate_NullName, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueCreate_NameTooLong, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueCreate_NoFreeIds, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueCreate_NameTaken, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueCreate_Error, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueCreate_Success, Osapi_Queue_Setup, Osapi_TearDown); - - /* OS_QueueDelete Tests */ - ADD_TEST(Test_OS_QueueDelete_IdInvalid, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueDelete_IdIsFree, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueDelete_Error, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueDelete_Success, Osapi_Queue_Setup, Osapi_TearDown); - - /* OS_QueueGet Tests */ - ADD_TEST(Test_OS_QueueGet_IdInvalid, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_IdIsFree, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_NullData, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_NullSizeCopied, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_SizeInvalid, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_TimeoutPend, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_TimeoutChkQEmpty,Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_TimeoutChkErr, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_TimeoutChkSuccess,Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_QTimeout, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_Error, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGet_Success, Osapi_Queue_Setup, Osapi_TearDown); - - /* OS_QueuePut Tests */ - ADD_TEST(Test_OS_QueuePut_IdInvalid, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueuePut_IdIsFree, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueuePut_NullData, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueuePut_QFull, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueuePut_Error, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueuePut_Success, Osapi_Queue_Setup, Osapi_TearDown); - - /* OS_QueueGetIdByname Tests */ - ADD_TEST(Test_OS_QueueGetIdByName_NullId, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGetIdByName_NullName,Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGetIdByName_NameTooLong,Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGetIdByName_NotFound,Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGetIdByName_Success, Osapi_Queue_Setup, Osapi_TearDown); - - /* OS_QueueGetInfo Tests */ - ADD_TEST(Test_OS_QueueGetInfo_NullProp, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGetInfo_IdInvalid, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGetInfo_IdIsFree, Osapi_Queue_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_QueueGetInfo_Success, Osapi_Queue_Setup, Osapi_TearDown); -} - - - - diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_tasks.c b/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_tasks.c deleted file mode 100644 index 0f46383a5..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_tasks.c +++ /dev/null @@ -1,1398 +0,0 @@ -/* - * Filename: osapi_testcase_tasks.c - * - * Purpose: This file contains unit test cases - * - * Notes: - * - * Modification History: - * 06/25/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include "osapi_testcase.h" - - - -/* Prototypes for non-exported functions */ - - - -/* -------------------- Special Test Case Variables ------------------------- */ -static boolean deleteFncCalled = FALSE; -static OsApi_Adaptor_OS_task_record_t *osTaskRecord_ptr; - - -/* -------------------------------------------------------------------------- */ -/* Utility functions */ - -/* Dummy functions for OSAL calls */ -void deleteFnc(void) -{ - /* Task delete hook */ - deleteFncCalled += 1; -} - - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_API_Init Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_API_Init_ModTblInit_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_OSMODULETABLEINIT_INDEX, OS_ERROR, 1); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -void Test_OS_API_Init_TimerApiInit_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_OSTIMERAPIINIT_INDEX, OS_ERROR, 1); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -void Test_OS_API_Init_TaskTableSem_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMMCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -void Test_OS_API_Init_QueueTableSem_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMMCREATE_INDEX, 0, 2); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -void Test_OS_API_Init_BinTableSem_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMMCREATE_INDEX, 0, 3); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -void Test_OS_API_Init_CountTableSem_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMMCREATE_INDEX, 0, 4); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -void Test_OS_API_Init_MutTableSem_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SEMMCREATE_INDEX, 0, 5); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -void Test_OS_API_Init_OsFsInit_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_OSFSINIT_INDEX, OS_ERROR, 1); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -void Test_OS_API_Init_TaskSpawn_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_TASKSPAWN_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -void Test_OS_API_Init_MsgQCreate_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_MSGQCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - UtAssert_True(getNTaskDeleteForce() == 1, "taskDeleteForce called"); -} - -void Test_OS_API_Init_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - uint32 ii = 0; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_API_Init(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(getNTaskDeleteForce() == 0, "taskDeleteForce not called"); - for (ii = 0; ii < OS_MAX_TASKS; ++ii) - { - UtAssert_True(OsApi_Adaptor_getTaskTableEntry(ii)->free == TRUE, - "OS_task_table entry is free"); - } - for (ii = 0; ii < OS_MAX_QUEUES; ++ii) - { - UtAssert_True(OsApi_Adaptor_getQueueTableEntry(ii)->free == TRUE, - "OS_queue_table entry is free"); - } - for (ii = 0; ii < OS_MAX_BIN_SEMAPHORES; ++ii) - { - UtAssert_True(OsApi_Adaptor_getBinSemTableEntry(ii)->free == TRUE, - "OS_bin_sem_table entry is free"); - } - for (ii = 0; ii < OS_MAX_COUNT_SEMAPHORES; ++ii) - { - UtAssert_True(OsApi_Adaptor_getCountSemTableEntry(ii)->free == TRUE, - "OS_count_sem_table entry is free"); - } - for (ii = 0; ii < OS_MAX_MUTEXES; ++ii) - { - UtAssert_True(OsApi_Adaptor_getMutSemTableEntry(ii)->free == TRUE, - "OS_mut_sem_table_entry is free"); - } -} - - -/******************************************************************************* -** -** OS_TaskCreate Tests -** -*******************************************************************************/ -void dummyFnc(void) -{ - return; -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_NullName(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - char *task_name = NULL; - uint32 stack = 1; - uint32 stack_size = 1; - uint32 priority = 1; - uint32 flags = 1; - - /* Execute Test */ - actual = OS_TaskCreate(&task_id, task_name, dummyFnc, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 0, "No OS_TASK_TABLE_SEM taken"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_NullFnc(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - char *task_name = "test"; - uint32 stack = 1; - uint32 stack_size = 1; - uint32 priority = 1; - uint32 flags = 1; - - /* Execute Test */ - actual = OS_TaskCreate(&task_id, task_name, NULL, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 0, "No OS_TASK_TABLE_SEM taken"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_NullId(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint32 *task_id = NULL; - char *task_name = "test"; - uint32 stack = 1; - uint32 stack_size = 1; - uint32 priority = 1; - uint32 flags = 1; - - /* Execute Test */ - actual = OS_TaskCreate(task_id, task_name, dummyFnc, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 0, "No OS_TASK_TABLE_SEM taken"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_NameTooLong(void) -{ - int32 expected = OS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - char *task_name = "test"; - uint32 stack = 1; - uint32 stack_size = 1; - uint32 priority = 1; - uint32 flags = 1; - - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_TaskCreate(&task_id, task_name, dummyFnc, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 0, "No OS_TASK_TABLE_SEM taken"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_PriorityError(void) -{ - int32 expected = OS_ERR_INVALID_PRIORITY; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - char *task_name = "test"; - uint32 stack = 1; - uint32 stack_size = 1; - uint32 priority = MAX_PRIORITY + 1; - uint32 flags = 1; - - /* Execute Test */ - actual = OS_TaskCreate(&task_id, task_name, dummyFnc, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_PRIORITY"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 0, "No OS_TASK_TABLE_SEM taken"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_NoFreeIds(void) -{ - int32 expected = OS_ERR_NO_FREE_IDS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - char *task_name = "test"; - uint32 stack = 1; - uint32 stack_size = 1; - uint32 priority = 1; - uint32 flags = 1; - - /* Execute Test */ - actual = OS_TaskCreate(&task_id, task_name, dummyFnc, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NO_FREE_IDS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 1, "semaphore taken once"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_NameTaken(void) -{ - int32 expected = OS_ERR_NAME_TAKEN; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - char *task_name = "test"; - uint32 stack = 1; - uint32 stack_size = 1; - uint32 priority = 1; - uint32 flags = 1; - - OsApi_Adaptor_setTaskTableEntry(0, TRUE, 0, "", 0, 0, 0, NULL); - OsApi_Adaptor_setTaskTableEntry(1, FALSE, 0, "bad_task_name", 0, 0, 0, NULL); - OsApi_Adaptor_setTaskTableEntry(OS_MAX_TASKS - 1, FALSE, 0, task_name, 0, 0, 0, NULL); - - /* Execute Test */ - actual = OS_TaskCreate(&task_id, task_name, dummyFnc, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TAKEN"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 1, "semaphore taken once"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_SpawnError(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - char *task_name = "test"; - uint32 stack = 1; - uint32 stack_size = 1; - uint32 priority = 1; - uint32 flags = OS_FP_ENABLED; - - OsApi_Adaptor_setTaskTableEntry(0, TRUE, 0, "", 0, 0, 0, NULL); - OsApi_SetReturnCode(OSAPI_TASKSPAWN_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_TaskCreate(&task_id, task_name, dummyFnc, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - UtAssert_True(OsApi_Adaptor_getTaskTableEntry(0)->free == TRUE, - "task table entry still free"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) >= 1, "semaphore taken >1"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_FpEnabled(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 taskIdIdx = OS_MAX_TASKS - 1; - uint32 task_id = 1; - char *task_name = "test"; - uint32 stack = 2; - uint32 stack_size = 3; - uint32 priority = 4; - uint32 flags = OS_FP_ENABLED; - uint32 taskSpawnId = 21; - uint32 creatorId = 9; - uint32 creatorIndex = 2; - - OsApi_Adaptor_setTaskTableEntry(taskIdIdx, TRUE, 0, "", 0, 0, 0, NULL); - OsApi_SetReturnCode(OSAPI_TASKSPAWN_INDEX, taskSpawnId, 1); - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, creatorId, 1); - OsApi_Adaptor_setTaskTableEntry(creatorIndex, FALSE, creatorId, "", 0, 0, 0, NULL); - - /* Execute Test */ - actual = OS_TaskCreate(&task_id, task_name, dummyFnc, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - osTaskRecord_ptr = OsApi_Adaptor_getTaskTableEntry(taskIdIdx); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(getTaskSpawnFlags() == VCS_VX_FP_TASK, "taskSpawn called with expected flags"); - UtAssert_StrCmp(task_name, osTaskRecord_ptr->name, "task name == expected"); - UtAssert_True(osTaskRecord_ptr->free == FALSE, "task entry not free"); - UtAssert_True(osTaskRecord_ptr->id == taskSpawnId, "task id == expected"); - UtAssert_True(task_id == taskIdIdx, "input task id == expected"); - UtAssert_True(osTaskRecord_ptr->creator == creatorIndex, "creator ID == input"); - UtAssert_True(osTaskRecord_ptr->stack_size == stack_size, "stack size == input"); - UtAssert_True(osTaskRecord_ptr->priority == priority, "priority == input"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) >= 1, "semaphore taken >1"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskCreate_FpNotEnabled(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 taskIdIdx = 7; - uint32 task_id = 5; - char *task_name = "test"; - uint32 stack = 4; - uint32 stack_size = 3; - uint32 priority = 2; - uint32 flags = 0; - uint32 taskSpawnId = 101; - uint32 creatorId = 15; - uint32 creatorIndex = 5; - - OsApi_Adaptor_setTaskTableEntry(taskIdIdx, TRUE, 0, "", 0, 0, 0, NULL); - OsApi_SetReturnCode(OSAPI_TASKSPAWN_INDEX, taskSpawnId, 1); - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, creatorId, 1); - OsApi_Adaptor_setTaskTableEntry(creatorIndex, FALSE, creatorId, "", 0, 0, 0, NULL); - - /* Execute Test */ - actual = OS_TaskCreate(&task_id, task_name, dummyFnc, &stack, stack_size, priority, flags); - - /* Verify Outputs */ - osTaskRecord_ptr = OsApi_Adaptor_getTaskTableEntry(taskIdIdx); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(getTaskSpawnFlags() == 0, "taskSpawn called with expected flags"); - UtAssert_StrCmp(task_name, osTaskRecord_ptr->name, "task name == expected"); - UtAssert_True(osTaskRecord_ptr->free == FALSE, "task entry not free"); - UtAssert_True(osTaskRecord_ptr->id == taskSpawnId, "task id == expected"); - UtAssert_True(task_id == taskIdIdx, "input task id == expected"); - UtAssert_True(osTaskRecord_ptr->creator == creatorIndex, "creator ID == input"); - UtAssert_True(osTaskRecord_ptr->stack_size == stack_size, "stack size == input"); - UtAssert_True(osTaskRecord_ptr->priority == priority, "priority == input"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) >= 1, "semaphore taken >1"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_TaskDelete Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskDelete_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = OS_MAX_TASKS; - - /* Execute Test */ - actual = OS_TaskDelete(task_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 1, "semaphore taken once"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskDelete_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = OS_MAX_TASKS - 1; - OsApi_Adaptor_setTaskTableEntry(task_id, TRUE, 1, "testTask", 2, 3, 4, deleteFnc); - - /* Execute Test */ - actual = OS_TaskDelete(task_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 1, "semaphore taken once"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskDelete_DelHookCall(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 8; - OsApi_Adaptor_setTaskTableEntry(task_id, FALSE, 1, "testTask", 2, 3, 4, deleteFnc); - - deleteFncCalled = FALSE; - OsApi_SetReturnCode(OSAPI_TASKDELETE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_TaskDelete(task_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(deleteFncCalled == TRUE, "delete function hook called"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 1, "semaphore taken once"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskDelete_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 13; - - OsApi_SetReturnCode(OSAPI_TASKDELETE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_TaskDelete(task_id); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) >= 1, "semaphore taken >1"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskDelete_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 6; - OsApi_Adaptor_setTaskTableEntry(task_id, FALSE, 1, "testTask", 2, 3, 4, deleteFnc); - - OsApi_SetReturnCode(OSAPI_TASKDELETE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_TaskDelete(task_id); - - /* Verify Outputs */ - osTaskRecord_ptr = OsApi_Adaptor_getTaskTableEntry(task_id); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp("", osTaskRecord_ptr->name, "task name == expected"); - UtAssert_True(osTaskRecord_ptr->free == TRUE, "task entry is free"); - UtAssert_True(osTaskRecord_ptr->id == UNINITIALIZED, "task id == expected"); - UtAssert_True(osTaskRecord_ptr->creator == UNINITIALIZED, "creator ID == input"); - UtAssert_True(osTaskRecord_ptr->stack_size == UNINITIALIZED, "stack size == input"); - UtAssert_True(osTaskRecord_ptr->priority == UNINITIALIZED, "priority == input"); - UtAssert_True(osTaskRecord_ptr->delete_hook_pointer == NULL, "priority == input"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) >= 1, "semaphore taken >1"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_TaskExit Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskExit_Success(void) -{ - int32 expected = TRUE; - - /* Setup Inputs */ - uint32 task_id = 2; - OsApi_Adaptor_setOsTaskKey(task_id); - OsApi_Adaptor_setTaskTableEntry(task_id, FALSE, 1, "testTask", 2, 3, 4, deleteFnc); - - OsApi_SetReturnCode(OSAPI_EXIT_INDEX, 0, 1); - - /* Execute Test */ - OS_TaskExit(); - - /* Verify Outputs */ - osTaskRecord_ptr = OsApi_Adaptor_getTaskTableEntry(task_id); - UtAssert_True(getTaskExitCalled() == expected, "taskExit called"); - UtAssert_StrCmp("", osTaskRecord_ptr->name, "task name == expected"); - UtAssert_True(osTaskRecord_ptr->free == TRUE, "task entry is free"); - UtAssert_True(osTaskRecord_ptr->id == UNINITIALIZED, "task id == expected"); - UtAssert_True(osTaskRecord_ptr->creator == UNINITIALIZED, "creator ID == expected"); - UtAssert_True(osTaskRecord_ptr->stack_size == UNINITIALIZED, "stack size == expected"); - UtAssert_True(osTaskRecord_ptr->priority == UNINITIALIZED, "priority == expected"); - UtAssert_True(osTaskRecord_ptr->delete_hook_pointer == NULL, "priority == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_TaskDelay Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskDelay_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1000000, 1); - OsApi_SetReturnCode(OSAPI_TASKDELAY_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_TaskDelay(1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_True(getTaskDelayTicks() == 1000, "sys_ticks == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskDelay_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_TASKDELAY_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_TaskDelay(1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - - -/******************************************************************************* -** -** OS_TaskSetPriority Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskSetPriority_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = OS_MAX_TASKS; - uint32 priority = 7; - - /* Execute Test */ - actual = OS_TaskSetPriority(task_id, priority); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskSetPriority_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = OS_MAX_TASKS - 1; - uint32 priority = 7; - OsApi_Adaptor_setTaskTableEntry(task_id, TRUE, 0, "", 0, 0, 0, NULL); - - - /* Execute Test */ - actual = OS_TaskSetPriority(task_id, priority); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskSetPriority_PriInvalid(void) -{ - int32 expected = OS_ERR_INVALID_PRIORITY; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 8; - uint32 priority = MAX_PRIORITY + 1; - - /* Execute Test */ - actual = OS_TaskSetPriority(task_id, priority); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_PRIORITY"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskSetPriority_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 8; - uint32 priority = MAX_PRIORITY; - OsApi_Adaptor_setTaskTableEntry(task_id, FALSE, 0, "", 0, 0, 1, NULL); - - OsApi_SetReturnCode(OSAPI_TASKPRIORITYSET_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_TaskSetPriority(task_id, priority); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - UtAssert_True(OsApi_Adaptor_getTaskTableEntry(task_id)->priority == 1, "priority unchanged"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskSetPriority_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 8; - uint32 priority = MAX_PRIORITY; - OsApi_Adaptor_setTaskTableEntry(task_id, FALSE, 0, "", 0, 0, 1, NULL); - - OsApi_SetReturnCode(OSAPI_TASKPRIORITYSET_INDEX, OS_SUCCESS, 1); - - /* Execute Test */ - actual = OS_TaskSetPriority(task_id, priority); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_TaskRegister Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskRegister_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 4; - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, task_id, 1); - - /* Execute Test */ - actual = OS_TaskRegister(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskRegister_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 4; - OsApi_Adaptor_setOsTaskKey(77); - OsApi_Adaptor_setTaskTableEntry(1, FALSE, task_id, "", 0, 0, 1, NULL); - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, task_id, 1); - OsApi_SetReturnCode(OSAPI_TASKVARADD_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_TaskRegister(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - UtAssert_True(OsApi_Adaptor_getOsTaskKey() == 77, "OS_task_key unchanged"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskRegister_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 tableIdx = 1; - uint32 task_id = 4; - OsApi_Adaptor_setOsTaskKey(77); - OsApi_Adaptor_setTaskTableEntry(tableIdx, FALSE, task_id, "", 0, 0, 1, NULL); - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, task_id, 1); - OsApi_SetReturnCode(OSAPI_TASKVARADD_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_TaskRegister(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(OsApi_Adaptor_getOsTaskKey() == tableIdx, "OS_task_key == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_TaskGetId Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetId(void) -{ - int32 expected = 10; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setOsTaskKey(expected); - - /* Execute Test */ - actual = OS_TaskGetId(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - - -/******************************************************************************* -** -** OS_TaskGetIdByName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetIdByName_NullId(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint32 *task_id = NULL; - const char *task_name = "testTaskName"; - - /* Execute Test */ - actual = OS_TaskGetIdByName(task_id, task_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 0, "No OS_TASK_TABLE_SEM taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetIdByName_NullName(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - const char *task_name = NULL; - - /* Execute Test */ - actual = OS_TaskGetIdByName(&task_id, task_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 0, "No OS_TASK_TABLE_SEM taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetIdByName_NameLong(void) -{ - int32 expected = OS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - const char *task_name = "testTaskName"; - - OsApi_SetReturnCode(OSAPI_STRLEN_INDEX, OS_MAX_API_NAME, 1); - - /* Execute Test */ - actual = OS_TaskGetIdByName(&task_id, task_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_TOO_LONG"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 0, "No OS_TASK_TABLE_SEM taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetIdByName_NameErr(void) -{ - int32 expected = OS_ERR_NAME_NOT_FOUND; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - const char *task_name = "testTaskName"; - - /* Execute Test */ - actual = OS_TaskGetIdByName(&task_id, task_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_NAME_NOT_FOUND"); - UtAssert_True(task_id == 1, "task_id unchanged"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetIdByName_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id_idx = 5; - uint32 task_id = 1; - const char *task_name = "testTaskName"; - OsApi_Adaptor_setTaskTableEntry(0, FALSE, 0, "", 0, 0, 0, NULL); - OsApi_Adaptor_setTaskTableEntry(0, TRUE, 0, "", 0, 0, 0, NULL); /* for full MCDC coverage */ - OsApi_Adaptor_setTaskTableEntry(task_id_idx, FALSE, 0, (char *)task_name, 0, 0, 0, NULL); - - /* Execute Test */ - actual = OS_TaskGetIdByName(&task_id, task_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(task_id == task_id_idx, "task_id updated"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_TaskGetInfo Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetInfo_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = OS_MAX_TASKS; - static OS_task_prop_t task_prop; - - /* Execute Test */ - actual = OS_TaskGetInfo(task_id, &task_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetInfo_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = OS_MAX_TASKS - 1; - static OS_task_prop_t task_prop; - OsApi_Adaptor_setTaskTableEntry(task_id, TRUE, 0, "", 0, 0, 0, NULL); - - /* Execute Test */ - actual = OS_TaskGetInfo(task_id, &task_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetInfo_NullProp(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - OS_task_prop_t *task_prop = NULL; - - /* Execute Test */ - actual = OS_TaskGetInfo(task_id, task_prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskGetInfo_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 task_id = 1; - static OS_task_prop_t task_prop; - OsApi_Adaptor_setTaskTableEntry(task_id, FALSE, 1, "testTask", 2, 3, 4, deleteFnc); - - /* Execute Test */ - actual = OS_TaskGetInfo(task_id, &task_prop); - - /* Verify Outputs */ - osTaskRecord_ptr = OsApi_Adaptor_getTaskTableEntry(task_id); - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(task_prop.creator == osTaskRecord_ptr->creator, "creator == expected"); - UtAssert_True(task_prop.stack_size == osTaskRecord_ptr->stack_size, "stack_size == expected"); - UtAssert_True(task_prop.priority == osTaskRecord_ptr->priority, "priority == expected"); - UtAssert_True(task_prop.OStask_id == osTaskRecord_ptr->id, "OStask_id == expected"); - UtAssert_StrCmp(task_prop.name, osTaskRecord_ptr->name, "name == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_TaskInstallDeleteHandler Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskInstallDeleteHandler_IdInvalid(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setOsTaskKey(OS_MAX_TASKS); - - /* Execute Test */ - actual = OS_TaskInstallDeleteHandler(dummyFnc); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == 0, "No semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskInstallDeleteHandler_IdIsFree(void) -{ - int32 expected = OS_ERR_INVALID_ID; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_Adaptor_setOsTaskKey(OS_MAX_TASKS - 1); - OsApi_Adaptor_setTaskTableEntry(OS_MAX_TASKS - 1, TRUE, 0, "", 0, 0, 0, NULL); - - /* Execute Test */ - actual = OS_TaskInstallDeleteHandler(dummyFnc); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TaskInstallDeleteHandler_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 1; - OsApi_Adaptor_setOsTaskKey(idx); - - /* Execute Test */ - actual = OS_TaskInstallDeleteHandler(dummyFnc); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(OsApi_Adaptor_getTaskTableEntry(idx)->delete_hook_pointer == dummyFnc, - "delete_hook_pointer == expected"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) > 0, "semaphore taken"); - UtAssert_True(getNSemTake(OS_TASK_TABLE_SEM) == getNSemGive(OS_TASK_TABLE_SEM), - "nSemTake == nSemGive"); -} - - -/* ------------------- End of test cases --------------------------------------*/ - - -/* Osapi_Task_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osapi_Task_Setup(void) -{ - Osapi_Setup(); - -} - - - -/* Osapi_AddTestCase_Tasks - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void Osapi_AddTestCase_Tasks(void) -{ - /* OS_API_Init Tests */ - ADD_TEST(Test_OS_API_Init_ModTblInit_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_TimerApiInit_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_TaskTableSem_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_QueueTableSem_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_BinTableSem_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_CountTableSem_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_MutTableSem_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_OsFsInit_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_TaskSpawn_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_MsgQCreate_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_API_Init_Success, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskCreate Tests */ - ADD_TEST(Test_OS_TaskCreate_NullName, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskCreate_NullFnc, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskCreate_NullId, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskCreate_NameTooLong, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskCreate_PriorityError, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskCreate_NoFreeIds, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskCreate_NameTaken, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskCreate_SpawnError, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskCreate_FpEnabled, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskCreate_FpNotEnabled, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskDelete Tests */ - ADD_TEST(Test_OS_TaskDelete_IdInvalid, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskDelete_IdIsFree, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskDelete_DelHookCall, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskDelete_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskDelete_Success, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskExit Tests */ - ADD_TEST(Test_OS_TaskExit_Success, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskDelay Tests */ - ADD_TEST(Test_OS_TaskDelay_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskDelay_Success, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskSetPriority Tests */ - ADD_TEST(Test_OS_TaskSetPriority_IdInvalid, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskSetPriority_IdIsFree, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskSetPriority_PriInvalid, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskSetPriority_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskSetPriority_Success, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskRegister Tests */ - ADD_TEST(Test_OS_TaskRegister_IdInvalid, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskRegister_Error, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskRegister_Success, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskGetId Tests */ - ADD_TEST(Test_OS_TaskGetId, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskGetIdByName Tests */ - ADD_TEST(Test_OS_TaskGetIdByName_NullId, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskGetIdByName_NullName, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskGetIdByName_NameLong, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskGetIdByName_NameErr, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskGetIdByName_Success, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskGetInfo Tests */ - ADD_TEST(Test_OS_TaskGetInfo_IdInvalid, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskGetInfo_IdIsFree, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskGetInfo_NullProp, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskGetInfo_Success, Osapi_Task_Setup, Osapi_TearDown); - - /* OS_TaskInstallDeleteHandler Tests */ - ADD_TEST(Test_OS_TaskInstallDeleteHandler_IdInvalid,Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskInstallDeleteHandler_IdIsFree, Osapi_Task_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_TaskInstallDeleteHandler_Success, Osapi_Task_Setup, Osapi_TearDown); -} - - - - diff --git a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_time_int.c b/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_time_int.c deleted file mode 100644 index f0e9cbc23..000000000 --- a/src/unit-test-coverage/vxworks6/osapi-test/osapi_testcase_time_int.c +++ /dev/null @@ -1,1429 +0,0 @@ -/* - * Filename: osapi_testcase_time_int.c - * - * Purpose: This file contains unit test cases - * - * Notes: - * * Currently no test for sysClkRateGet() returning a 0 value in OS_Tick2Micros. - * This is not an expected value and there is no protection in the code for it. - * * Currently no test for OS_Tick2Micros() returning a 0 value (caused by - * integer truncation during the divide). Is it possible the value from - * sysClkRateGet() exceeds the size of the numerator (1,000,000 in this case)? - * - * Modification History: - * 07/07/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include "osapi_testcase.h" - - -#include - - -/* Global variables defined in osapi.c */ -extern uint32 OS_printf_enabled; -extern int32 OS_DroppedMessages; - - -/* Prototypes for non-exported functions */ -uint32 OS_FindCreator(void); - - -/* -------------------- Special Test Case Variables ------------------------- */ -#ifndef INT32_MAX -#define INT32_MAX ((int32)(2147483647)) /* 2**31 - 1 */ -#endif -static int32 error_num; -static os_err_name_t err_name; - - -/* -------------------------------------------------------------------------- */ -/* Utility functions */ - - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_Milli2Ticks Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_Milli2Ticks_Min(void) -{ - int32 expected = 0; - int32 actual = 99; - - /* Setup Inputs */ - uint32 msecs = 0; - - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1000000, 1); /* make the math simple */ - - /* Execute Test */ - actual = OS_Milli2Ticks(msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_Milli2Ticks_Max(void) -{ - int32 expected = INT32_MAX; - uint32 actual = 99; /* actual return value is int32, check value is limited */ - - /* Setup Inputs */ - uint32 msecs = INT32_MAX/500; /* leave in factor of 2 (1000/500) and check if limited */ - - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1000000, 1); /* make the math simple */ - - /* Execute Test */ - actual = OS_Milli2Ticks(msecs); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_Milli2Ticks_DivideByZero(void) -{ - int32 expected = INT_MAX; /* what's a good expected value for div by zero? */ - uint32 actual = 99; - - /* Setup Inputs */ - - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 0, 1); - - /* Execute Test */ - /*actual = OS_Milli2Ticks(msecs); Commented out - no protection for divide by zero */ - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - - -/******************************************************************************* -** -** OS_Tick2Micros Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_Tick2Micros_Pos(void) -{ - int32 expected = 1000000; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1, 1); - - /* Execute Test */ - actual = OS_Tick2Micros(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_Tick2Micros_Neg(void) -{ - int32 expected = -1000000; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, -1, 1); - - /* Execute Test */ - actual = OS_Tick2Micros(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_Tick2Micros_DivTruncation(void) -{ - int32 expected = 1; /* output should be limited */ - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 1000001, 1); - - /* Execute Test */ - actual = OS_Tick2Micros(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_Tick2Micros_DivideByZero(void) -{ - int32 expected = INT_MAX; /* what's a good expected value for div by zero? */ - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_SYSCLKRATEGET_INDEX, 0, 1); - - /* Execute Test */ - /*actual = OS_Tick2Micros(); Commented out - no protection for divide by zero */ - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - - -/******************************************************************************* -** -** OS_GetLocalTime Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_GetLocalTime_NullTime(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_GetLocalTime(NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetLocalTime_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - static OS_time_t time; - - OsApi_SetReturnCode(OSAPI_CLOCKGETTIME_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_GetLocalTime(&time); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetLocalTime_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - static OS_time_t time; - uint32 sec = 21; - uint32 nsec = 5000; - - setTime(sec, nsec); - OsApi_SetReturnCode(OSAPI_CLOCKGETTIME_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_GetLocalTime(&time); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(time.seconds == sec, "seconds == expected"); - UtAssert_True(time.microsecs == nsec/1000, "microsecs == expected"); -} - - -/******************************************************************************* -** -** OS_SetLocalTime Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_SetLocalTime_NullTime(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_SetLocalTime(NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_SetLocalTime_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - static OS_time_t time; - - OsApi_SetReturnCode(OSAPI_CLOCKSETTIME_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_SetLocalTime(&time); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_SetLocalTime_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - static OS_time_t time; - - OsApi_SetReturnCode(OSAPI_CLOCKSETTIME_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_SetLocalTime(&time); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(getSeconds() == time.seconds, "tv_sec == expected"); - UtAssert_True(getNSeconds() == time.microsecs * 1000, "tv_nsec == expected"); -} - - -/******************************************************************************* -** -** OS_IntAttachHandler Tests -** -*******************************************************************************/ -void dummyIntFnc(void) -{ - -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_IntAttachHandler_NullHandler(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint32 intNumber = 0; - int32 parameter = 0; - - /* Execute Test */ - actual = OS_IntAttachHandler(intNumber, NULL, parameter); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_IntAttachHandler_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 intNumber = 0; - int32 parameter = 0; - - OsApi_SetReturnCode(OSAPI_INTCONNECT_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_IntAttachHandler(intNumber, dummyIntFnc, parameter); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_IntAttachHandler_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 intNumber = 0; - int32 parameter = 0; - - OsApi_SetReturnCode(OSAPI_INTCONNECT_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_IntAttachHandler(intNumber, dummyIntFnc, parameter); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); -} - - -/******************************************************************************* -** -** OS_IntDisable Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_IntDisable_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 level = 0; - - OsApi_SetReturnCode(OSAPI_INTDISABLE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_IntDisable(level); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_IntDisable_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 level = 0; - - OsApi_SetReturnCode(OSAPI_INTDISABLE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_IntDisable(level); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); -} - - -/******************************************************************************* -** -** OS_IntEnable Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_IntEnable_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 level = 0; - - OsApi_SetReturnCode(OSAPI_INTENABLE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_IntEnable(level); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_IntEnable_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 level = 0; - - OsApi_SetReturnCode(OSAPI_INTENABLE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_IntEnable(level); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); -} - - -/******************************************************************************* -** -** OS_IntUnlock Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_IntUnlock_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 level = 0; - - OsApi_SetReturnCode(OSAPI_INTUNLOCK_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_IntUnlock(level); - - /* Verify Outputs */ -#if ( _WRS_VXWORKS_MINOR > 3 ) - UtAssert_True(actual == OS_SUCCESS, "actual == OS_SUCCESS"); -#else - UtAssert_True(actual == expected, "actual == OS_ERROR"); -#endif -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_IntUnlock_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 level = 0; - int notErrOrOk = 2; - - OsApi_SetReturnCode(OSAPI_INTUNLOCK_INDEX, notErrOrOk, 1); - - /* Execute Test */ - actual = OS_IntUnlock(level); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); -} - - -/******************************************************************************* -** -** OS_IntLock Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_IntLock(void) -{ - int32 expected = 10; - int32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_INTLOCK_INDEX, expected, 1); - - /* Execute Test */ - actual = OS_IntLock(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - - -/******************************************************************************* -** -** OS_HeapGetInfo Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_HeapGetInfo_NullProp(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_HeapGetInfo(NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_HeapGetInfo_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - static OS_heap_prop_t prop; - - OsApi_SetReturnCode(OSAPI_MEMPARTINFOGET_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_HeapGetInfo(&prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_HeapGetInfo_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - unsigned long bytesFree = 1010; - unsigned long blocksFree = 2020; - unsigned long maxBlockFree = 3030; - static OS_heap_prop_t prop; - - setHeapInfo(bytesFree, blocksFree, maxBlockFree); - OsApi_SetReturnCode(OSAPI_MEMPARTINFOGET_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_HeapGetInfo(&prop); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_True(prop.free_bytes == bytesFree, "free_bytes == expected"); - UtAssert_True(prop.free_blocks == blocksFree, "free_blocks == expected"); - UtAssert_True(prop.largest_free_block == maxBlockFree, "largest_free_block == expected"); -} - - -/******************************************************************************* -** -** OS_GetErrorName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_NullName(void) -{ - int32 expected = OS_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_GetErrorName(error_num, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_SUCCESS; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_SUCCESS", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_Error(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERROR; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERROR", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_InvalidPtr(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_INVALID_POINTER; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_INVALID_POINTER", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_AddrMisaligned(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERROR_ADDRESS_MISALIGNED; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERROR_ADDRESS_MISALIGNED", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_Timeout(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERROR_TIMEOUT; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERROR_TIMEOUT", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_InvalidIntNum(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_INVALID_INT_NUM; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_INVALID_INT_NUM", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_SemFailure(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_SEM_FAILURE; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_SEM_FAILURE", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_SemTimeout(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_SEM_TIMEOUT; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_SEM_TIMEOUT", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_QueueEmpty(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_QUEUE_EMPTY; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_QUEUE_EMPTY", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_QueueFull(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_QUEUE_FULL; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_QUEUE_FULL", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_QueueTimeout(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_QUEUE_TIMEOUT; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_QUEUE_TIMEOUT", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_QueueInvalidSize(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_QUEUE_INVALID_SIZE; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_QUEUE_INVALID_SIZE", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_QueueIdError(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_QUEUE_ID_ERROR; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_QUEUE_ID_ERROR", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_NameTooLong(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERR_NAME_TOO_LONG; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERR_NAME_TOO_LONG", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_NoFreeIds(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERR_NO_FREE_IDS; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERR_NO_FREE_IDS", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_NameTaken(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERR_NAME_TAKEN; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERR_NAME_TAKEN", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_InvalidId(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERR_INVALID_ID; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERR_INVALID_ID", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_NameNotFound(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERR_NAME_NOT_FOUND; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERR_NAME_NOT_FOUND", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_SemNotFull(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERR_SEM_NOT_FULL; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERR_SEM_NOT_FULL", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_InvalidPriority(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERR_INVALID_PRIORITY; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERR_INVALID_PRIORITY", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_InvalidSemValue(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_INVALID_SEM_VALUE; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_INVALID_SEM_VALUE", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_File(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERR_FILE; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERR_FILE", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_NotImplemented(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_ERR_NOT_IMPLEMENTED; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_ERR_NOT_IMPLEMENTED", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_TimerInvalidArgs(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_TIMER_ERR_INVALID_ARGS; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_TIMER_ERR_INVALID_ARGS", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_TimerId(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_TIMER_ERR_TIMER_ID; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_TIMER_ERR_TIMER_ID", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_TimerUnavailable(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_TIMER_ERR_UNAVAILABLE; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_TIMER_ERR_UNAVAILABLE", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_TimerInternal(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - error_num = OS_TIMER_ERR_INTERNAL; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(err_name, "OS_TIMER_ERR_INTERNAL", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetErrorName_Unknown(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - error_num = 100; - - /* Execute Test */ - actual = OS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_ERROR"); - UtAssert_StrCmp(err_name, "ERROR_UNKNOWN", "err_name == expected"); -} - - -/******************************************************************************* -** -** OS_FindCreator Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_FindCreator_NotFound(void) -{ - uint32 expected = OS_MAX_TASKS; - uint32 actual = 99; - - /* Setup Inputs */ - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, 2, 1); - - /* Execute Test */ - actual = OS_FindCreator(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FindCreator_Found(void) -{ - uint32 expected = 3; - uint32 actual = 99; - - /* Setup Inputs */ - int id = 88; - OsApi_Adaptor_setTaskTableEntry(expected, FALSE, id, "", 0, 0, 0, NULL); - OsApi_SetReturnCode(OSAPI_TASKIDSELF_INDEX, id, 1); - - /* Execute Test */ - actual = OS_FindCreator(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - - -/******************************************************************************* -** -** OS_printf Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_printf_PrintDisabled(void) -{ - /* Setup Inputs */ - OsApi_Adaptor_setOsPrintfEnabled(FALSE); - - /* Execute Test */ - OS_printf("testString"); - - /* Verify Outputs */ - UtAssert_True(getNVsnprintf_calls() == 0, "vsnprintf not called"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_printf_PrintEnabled_Err(void) -{ - /* Setup Inputs */ - OsApi_Adaptor_setOsPrintfEnabled(TRUE); - -#ifdef OS_UTILITY_TASK_ON - OsApi_SetReturnCode(OSAPI_MSGQSEND_INDEX, VCS_ERROR, 1); - OS_DroppedMessages = 0; -#endif - - /* Execute Test */ - OS_printf("testString"); - - /* Verify Outputs */ - UtAssert_True(getNVsnprintf_calls() == 1, "vsnprintf called"); -#ifdef OS_UTILITY_TASK_ON - UtAssert_True(OS_DroppedMessages == 1, "OS_DroppedMessages == expected"); -#endif -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_printf_PrintEnabled_Ok(void) -{ - /* Setup Inputs */ - OsApi_Adaptor_setOsPrintfEnabled(TRUE); - -#ifdef OS_UTILITY_TASK_ON - OsApi_SetReturnCode(OSAPI_MSGQSEND_INDEX, VCS_OK, 1); - OS_DroppedMessages = 0; -#endif - - /* Execute Test */ - OS_printf("testString"); - - /* Verify Outputs */ - UtAssert_True(getNVsnprintf_calls() == 1, "vsnprintf called"); -#ifdef OS_UTILITY_TASK_ON - UtAssert_True(OS_DroppedMessages == 0, "OS_DroppedMessages == expected"); -#else - UtAssert_True(getNLogMsg_calls() == 1, "logMsg called"); -#endif -} - - -/******************************************************************************* -** -** OS_printf_disable Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_printf_disable(void) -{ - /* Setup Inputs */ - OsApi_Adaptor_setOsPrintfEnabled(TRUE); - - /* Execute Test */ - OS_printf_disable(); - - /* Verify Outputs */ - UtAssert_True(OsApi_Adaptor_getOsPrintfEnabled() == FALSE, "OS_printf_enabled == expected"); -} - - -/******************************************************************************* -** -** OS_printf_enable Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_printf_enable(void) -{ - /* Setup Inputs */ - OsApi_Adaptor_setOsPrintfEnabled(FALSE); - - /* Execute Test */ - OS_printf_enable(); - - /* Verify Outputs */ - UtAssert_True(OsApi_Adaptor_getOsPrintfEnabled() == TRUE, "OS_printf_enabled == expected"); -} - - -/******************************************************************************* -** -** OS_FPUExcSetMask Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_FPUExcSetMask(void) -{ - int32 expected = OS_ERR_NOT_IMPLEMENTED; - int32 actual = 99; -#if defined(_PPC_) && CPU != PPC440 - expected = OS_SUCCESS; -#endif - - /* Setup Inputs */ - uint32 mask = 0xAA; - - /* Execute Test */ - actual = OS_FPUExcSetMask(mask); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -#if defined(_PPC_) && CPU != PPC440 - UtAssert_True(getFpuMask() == mask, "mask == expected"); -#else - UtAssert_True(TRUE, "INTENTIONALLY SKIPPED: mask == expected"); -#endif -} - - -/******************************************************************************* -** -** OS_FPUExcGetMask Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_FPUExcGetMask_NullPtr(void) -{ - int32 expected = OS_ERR_NOT_IMPLEMENTED; - int32 actual = 99; -#if defined(_PPC_) && CPU != PPC440 - expected = OS_INVALID_POINTER; -#endif - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_FPUExcGetMask(NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FPUExcGetMask_Success(void) -{ - int32 expected = OS_ERR_NOT_IMPLEMENTED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 mask = 0; -#if defined(_PPC_) && CPU != PPC440 - int32 expected = OS_SUCCESS; - uint32 vxMask = 4829; -#else - uint32 vxMask = mask; -#endif - - OsApi_SetReturnCode(OSAPI_VXFPSCRGET_INDEX, vxMask, 1); - - /* Execute Test */ - actual = OS_FPUExcGetMask(&mask); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_True(vxMask == mask, "mask == expected"); -} - - -/* ------------------- End of test cases --------------------------------------*/ - - -/* Osapi_Time_Int_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osapi_Time_Int_Setup(void) -{ - Osapi_Setup(); - - memset(err_name, '\0', sizeof(os_err_name_t)); - error_num = 0; -} - - -/* Osapi_AddTestCase_Tasks - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void Osapi_AddTestCase_Time_Int(void) -{ - /* OS_Milli2Ticks Tests */ - ADD_TEST(Test_OS_Milli2Ticks_Min, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_Milli2Ticks_Max, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_Milli2Ticks_DivideByZero, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_Tick2Micros Tests */ - ADD_TEST(Test_OS_Tick2Micros_Pos, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_Tick2Micros_Neg, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_Tick2Micros_DivTruncation,Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_Tick2Micros_DivideByZero, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_GetLocalTime Tests */ - ADD_TEST(Test_OS_GetLocalTime_NullTime, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetLocalTime_Error, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetLocalTime_Success, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_SetLocalTime Tests */ - ADD_TEST(Test_OS_SetLocalTime_NullTime, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_SetLocalTime_Error, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_SetLocalTime_Success, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_IntAttachHandler Tests */ - ADD_TEST(Test_OS_IntAttachHandler_NullHandler,Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_IntAttachHandler_Error, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_IntAttachHandler_Success, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_IntDisable Tests */ - ADD_TEST(Test_OS_IntDisable_Error, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_IntDisable_Success, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_IntEnable Tests */ - ADD_TEST(Test_OS_IntEnable_Error, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_IntEnable_Success, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_IntUnlock Tests */ - ADD_TEST(Test_OS_IntUnlock_Error, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_IntUnlock_Success, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_IntLock Tests */ - ADD_TEST(Test_OS_IntLock, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_HeapGetInfo Tests */ - ADD_TEST(Test_OS_HeapGetInfo_NullProp, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_HeapGetInfo_Error, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_HeapGetInfo_Success, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_GetErrorName Tests */ - ADD_TEST(Test_OS_GetErrorName_NullName, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_Success, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_Error, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_InvalidPtr, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_AddrMisaligned, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_Timeout, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_InvalidIntNum, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_SemFailure, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_SemTimeout, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_QueueEmpty, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_QueueFull, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_QueueTimeout, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_QueueInvalidSize,Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_QueueIdError, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_NameTooLong, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_NoFreeIds, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_NameTaken, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_InvalidId, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_NameNotFound, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_SemNotFull, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_InvalidPriority, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_InvalidSemValue, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_File, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_NotImplemented, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_TimerInvalidArgs,Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_TimerId, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_TimerUnavailable,Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_TimerInternal, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_GetErrorName_Unknown, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_FindCreator Tests */ - ADD_TEST(Test_OS_FindCreator_NotFound, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_FindCreator_Found, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_printf_disable Tests */ - ADD_TEST(Test_OS_printf_PrintDisabled, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_printf_PrintEnabled_Err, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_printf_PrintEnabled_Ok, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_printf_disable Tests */ - ADD_TEST(Test_OS_printf_disable, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_printf_enable Tests */ - ADD_TEST(Test_OS_printf_enable, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_FPUExcSetMask Tests */ - ADD_TEST(Test_OS_FPUExcSetMask, Osapi_Time_Int_Setup, Osapi_TearDown); - - /* OS_FPUExcGetMask Tests */ - ADD_TEST(Test_OS_FPUExcGetMask_NullPtr, Osapi_Time_Int_Setup, Osapi_TearDown); - ADD_TEST(Test_OS_FPUExcGetMask_Success, Osapi_Time_Int_Setup, Osapi_TearDown); -} - - - - diff --git a/src/unit-test-coverage/vxworks6/osfileapi-test/CMakeLists.txt b/src/unit-test-coverage/vxworks6/osfileapi-test/CMakeLists.txt deleted file mode 100644 index e6a5b3ff0..000000000 --- a/src/unit-test-coverage/vxworks6/osfileapi-test/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} TESTCASE_FILES) -add_executable(osfileapi-test ${TESTCASE_FILES}) -set_target_properties(osfileapi-test PROPERTIES LINK_FLAGS "${UT_C_FLAGS}") -target_link_libraries(osfileapi-test ut_osal_osfileapi ${OSALCOVERAGE_LINK_LIBRARIES}) -add_test(osapi-test osapi-test) diff --git a/src/unit-test-coverage/vxworks6/osfileapi-test/Makefile b/src/unit-test-coverage/vxworks6/osfileapi-test/Makefile deleted file mode 100644 index 5cc2727f0..000000000 --- a/src/unit-test-coverage/vxworks6/osfileapi-test/Makefile +++ /dev/null @@ -1,81 +0,0 @@ -############################################################################## -## GNU Makefile for building UT unit tests in a Linux environment for easy -## debug and code coverage - -# -# Supported MAKEFILE targets: -# clean - deletes object files, executables, output files, and gcov files -# all - makes utf_test_runner.exe -# run - runs utf_test_runner.exe -# gcov - prints a GCOV coverage report (make all, make run, make gcov) -# -# GCOV is disabled by default. If you are using the source level debugger you will want to -# disable GCOV. To enable GCOV you can override the ENABLE_GCOV variable on the command line -# by setting it to TRUE. For example "make ENABLE_GCOV=TRUE". -# - -APP=osfileapi - -OSAL ?= $(CFS_HOME)/osal - -# -# INCLUDES specifies the search paths for include files outside of the current directory. -# Note that the -I is required. -# -INCLUDES += -I../ut-stubs/inc -INCLUDES += -I$(OSAL)/ut_assert/inc -INCLUDES += -I$(OSAL)/src/os/inc -INCLUDES += -I$(OSAL)/build/inc - -# -# UT_OBJS specifies unit test object files. -# -UT_OBJS += $(APP)_testcase.o -UT_OBJS += $(APP)_stubs.o - - - -############################################################################### - -COMPILER=gcc -LINKER=gcc - -# -# Compiler and Linker Options -# -ENABLE_GCOV = TRUE -ifeq ($(ENABLE_GCOV), TRUE) -GCOV_COPT = --coverage -GCOV_LOPT = --coverage -endif - -#WARNINGS = -Wall -W -ansi -Werror -Wstrict-prototypes -Wundef -WARNINGS = -Wall -Wstrict-prototypes -DEBUGGER = -g - -#COPT = $(WARNINGS) $(DEBUGGER) $(GCOV_COPT) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D__x86_64__ -D_LINUX_OS_ -COPT = $(WARNINGS) $(DEBUGGER) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D_ix86_ $(OSAL_M32) - -LOPT = $(OSAL_M32) - -############################################################################### -## "C" COMPILER RULE -## -%.o: %.c - $(COMPILER) -c $(COPT) $(INCLUDES) $< - -############################################################################## -## - -all:$(APP)_testrunner.exe - -$(APP)_testrunner.exe: $(UT_OBJS) - $(LINKER) $(GCOV_LOPT) $(LOPT) -o $@ $^ ../ut-osal/osfileapi.o ../testrunner.o - -clean :: - rm -f *.o *.exe *.gcda *.gcno *.gcov gmon.out $(APP)_log.txt - -run :: - ./$(APP)_testrunner.exe | tee ./$(APP)_log.txt - -# end of file diff --git a/src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_stubs.c b/src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_stubs.c deleted file mode 100644 index 4c491f396..000000000 --- a/src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_stubs.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - * File: osfileapu_stubs.c - * - * Purpose: - * Stub out various functions not stubbed out by the UT-Assert code - * - * Modification History: - * 05/28/2015 Alan Asp, Odyssey Space Research, LLC - * * Created - * - */ - -#include - -#include "osapi.h" /* cfe.h not available from within osal. */ - -#include "osfileapi_stubs.h" - -int VCS_errno; - -OsFileApi_HookTable_t OsFileApi_HookTable; -OsFileApi_ReturnCodeTable_t OsFileApi_ReturnCodeTable[OSFILEAPI_MAX_INDEX]; - - -const char testFileName[] = "/test"; -int32 nSemTake = 0; -int32 nSemGive = 0; -int32 nRewinddirCalls = 0; - -void OsFileApi_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt) -{ - if (Index < OSFILEAPI_MAX_INDEX) { - OsFileApi_ReturnCodeTable[Index].Value = RtnVal; - OsFileApi_ReturnCodeTable[Index].Count = CallCnt; - } - else { - printf("Unsupported Index In SetReturnCode Call %u\n", (unsigned int)Index); - } -} - - -boolean OsFileApi_UseReturnCode(uint32 Index) -{ - if (OsFileApi_ReturnCodeTable[Index].Count > 0) { - OsFileApi_ReturnCodeTable[Index].Count--; - if (OsFileApi_ReturnCodeTable[Index].Count == 0) - return(TRUE); - } - - return(FALSE); -} - - -uint32 OsFileApi_CheckCount(uint32 Index) -{ - return (OsFileApi_ReturnCodeTable[Index].Count); -} - -void OsFileApi_SetFunctionHook(uint32 Index, void *FunPtr) -{ - if (Index == OSFILEAPI_STRLEN_INDEX) { OsFileApi_HookTable.strlen = FunPtr; } - else if (Index == OSFILEAPI_STRCMP_INDEX) { OsFileApi_HookTable.strcmp = FunPtr; } - else if (Index == OSFILEAPI_OPEN_INDEX) { OsFileApi_HookTable.open = FunPtr; } - else if (Index == OSFILEAPI_SEMMCREATE_INDEX) { OsFileApi_HookTable.semMCreate = FunPtr; } - else if (Index == OSFILEAPI_SEMTAKE_INDEX) { OsFileApi_HookTable.semTake = FunPtr; } - else if (Index == OSFILEAPI_SEMGIVE_INDEX) { OsFileApi_HookTable.semGive = FunPtr; } - else - { - printf("Unsupported OsFileApi Index In SetFunctionHook Call %u\n", (unsigned int)Index); - } -} - - -void OsFileApi_Reset(void) -{ - memset(&OsFileApi_HookTable, 0, sizeof(OsFileApi_HookTable)); - memset(&OsFileApi_ReturnCodeTable, 0, sizeof(OsFileApi_ReturnCodeTable)); - nSemTake = 0; - nSemGive = 0; - nRewinddirCalls = 0; -} - -int32 getNSemTake() -{ - return nSemTake; -} - -int32 getNSemGive() -{ - return nSemGive; -} - -int32 getRewinddirCalls() -{ - return nRewinddirCalls; -} - -size_t VCS_strlen(const char *str) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_STRLEN_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_STRLEN_INDEX].Value; - - return strlen(str); -} - -int VCS_strcmp(const char *str1, const char *str2) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_STRCMP_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_STRCMP_INDEX].Value; - - return strcmp(str1, str2); -} - -char *VCS_strcpy(char *str1, const char *str2) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_STRCPY_INDEX)) - return (char *)OsFileApi_ReturnCodeTable[OSFILEAPI_STRCPY_INDEX].Value; - - return strcpy(str1, str2); -} - -char *VCS_strncpy(char *str1, const char *str2, size_t size) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_STRNCPY_INDEX)) - return (char *)OsFileApi_ReturnCodeTable[OSFILEAPI_STRNCPY_INDEX].Value; - - return strncpy(str1, str2, size); -} - -char *VCS_strrchr(const char *string, int c) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_STRRCHR_INDEX)) - { - return (char *)OsFileApi_ReturnCodeTable[OSFILEAPI_STRRCHR_INDEX].Value; - } - - return strrchr(string, c); -} - -char *VCS_strchr(const char *string, int c) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_STRCHR_INDEX)) - { - return (char *)OsFileApi_ReturnCodeTable[OSFILEAPI_STRCHR_INDEX].Value; - } - - return strchr(string, c); -} - - -int VCS_open(const char *filename, int oflag, ...) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_OPEN_INDEX)) - { - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_OPEN_INDEX].Value; - } - else if (strcmp(filename, testFileName) == 0) - { - return oflag; /* to allow verification that flags is set correctly */ - } - - return VCS_OK; - //return open(filename, 0, 0); -} - -VCS_STATUS VCS_close (int fd) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_CLOSE_INDEX)) { - /*printf("Inside VCS_close(), returning table value.\n");*/ - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_CLOSE_INDEX].Value; - } - else if (OsFileApi_ReturnCodeTable[OSFILEAPI_CLOSE_INDEX].Count > 0) /* deal with multiple calls */ - { - /*printf("Inside VCS_close(), faking VCS_OK. \n");*/ - return VCS_OK; - } - - /*printf("Inside VCS_close(), calling close() !!!!\n");*/ - return VCS_OK; - //return close(fd); -} - -int VCS_read (int fd, char *buffer, int maxbytes) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_READ_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_READ_INDEX].Value; - - return 0; - //return read(fd, buffer, maxbytes); -} - -int VCS_write(int fd, char *buffer, int nbytes) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_WRITE_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_WRITE_INDEX].Value; - - return 0; - //return write(fd, buffer, nbytes); -} - - -int VCS_lseek(int fd, long offset, int whence) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_LSEEK_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_LSEEK_INDEX].Value; - else if (offset < 0) - { - return whence; - } - - return 0; //lseek(fd, offset, whence); -} - - -VCS_STATUS VCS_mkdir(const char *dirName) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_MKDIR_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_MKDIR_INDEX].Value; - - return VCS_OK; //mkdir(dirName, 0); -} - -VCS_STATUS VCS_rmdir(const char *dirName) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_RMDIR_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_RMDIR_INDEX].Value; - - return VCS_OK; //rmdir(dirName); -} - -VCS_DIR *VCS_opendir(const char * dirName) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_OPENDIR_INDEX)) - return (VCS_DIR *)OsFileApi_ReturnCodeTable[OSFILEAPI_OPENDIR_INDEX].Value; - - return NULL; //(DIR *)dirName; -} - -int VCS_closedir(VCS_DIR * dirp) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_CLOSEDIR_INDEX)) - return OsFileApi_ReturnCodeTable[OSFILEAPI_CLOSEDIR_INDEX].Value; - - return 0; -} - -struct VCS_dirent *VCS_readdir (VCS_DIR *__dirp) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_READDIR_INDEX)) - return (struct VCS_dirent *)OsFileApi_ReturnCodeTable[OSFILEAPI_READDIR_INDEX].Value; - - return NULL; -} - -void VCS_rewinddir(VCS_DIR *dirp) -{ - nRewinddirCalls += 1; -} - -int VCS_stat(const char *path, struct VCS_stat *buf) -{ - //struct stat stbuf; - if (OsFileApi_UseReturnCode(OSFILEAPI_STAT_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_STAT_INDEX].Value; - - return VCS_OK; //stat(path, &stbuf); -} - -int VCS_rename(const char *old_filename, const char *new_filename) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_RENAME_INDEX)) - return (int)OsFileApi_ReturnCodeTable[OSFILEAPI_RENAME_INDEX].Value; - - return VCS_OK; //rename(old_filename, new_filename); -} - -int VCS_remove(const char *filename) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_REMOVE_INDEX)) - return (int)OsFileApi_ReturnCodeTable[OSFILEAPI_REMOVE_INDEX].Value; - - return VCS_OK; //remove(filename); -} - -VCS_STATUS VCS_cp(const char *src, const char *dest) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_CP_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_CP_INDEX].Value; - - return 0; -} - -VCS_SEM_ID VCS_semMCreate(int options) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_SEMMCREATE_INDEX)) - return (VCS_SEM_ID)OsFileApi_ReturnCodeTable[OSFILEAPI_SEMMCREATE_INDEX].Value; - - return (VCS_SEM_ID)NULL; -} - -VCS_STATUS VCS_semTake(VCS_SEM_ID semId, int timeout) -{ - nSemTake += 1; - - return nSemTake; -} - - -VCS_STATUS VCS_semGive(VCS_SEM_ID semId) -{ - nSemGive += 1; - - return nSemGive; -} - -int VCS_shellGenericInit(const char *arg1, const char *arg2, const char *arg3, char **arg4, - int arg5, int arg6, int arg7, int arg8, int arg9) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_SHELLGENERICINIT_INDEX)) - { - /*printf("Inside linux fake shellGenericInit(), returning table value.\n");*/ - return OsFileApi_ReturnCodeTable[OSFILEAPI_SHELLGENERICINIT_INDEX].Value; - } - - return VCS_OK; -} - -#if 0 -int shellGenericInit(const char *arg1, const char *arg2, const char *arg3, char **arg4, - int arg5, int arg6, int arg7, int arg8, int arg9); -int VCS_shellGenericInit(const char *arg1, const char *arg2, const char *arg3, char **arg4, - int arg5, int arg6, int arg7, int arg8, int arg9) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_SHELLGENERICINIT_INDEX)) - { - /*printf("Inside VCS_shellGenericInit(), returning table value.\n");*/ - return OsFileApi_ReturnCodeTable[OSFILEAPI_SHELLGENERICINIT_INDEX].Value; - } - - /*printf("Inside VCS_shellGenericInit(), calling shellGenericInit()!!!\n");*/ - return shellGenericInit(arg1, arg2, arg3, arg4, - arg5, arg6, arg7, arg8, arg9); -} -#endif - -VCS_STATUS VCS_taskDelay(int ticks) -{ - return VCS_ERROR; -} - -int VCS_taskNameToId(char *name) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_TASKNAMETOID_INDEX)) - return OsFileApi_ReturnCodeTable[OSFILEAPI_TASKNAMETOID_INDEX].Value; - - return VCS_ERROR; -} - -int VCS_sysClkRateGet(void) -{ - return 1; -} - -int32 OS_TranslatePath(const char* VirtualPath, char* LocalPath) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX)) - return OsFileApi_ReturnCodeTable[OSFILEAPI_OSTRANSLATEPATH_INDEX].Value; - - strcpy(LocalPath, VirtualPath); - - return OS_FS_SUCCESS; -} - -uint32 OS_FindCreator(void) -{ - if (OsFileApi_UseReturnCode(OSFILEAPI_OSFINDCREATOR_INDEX)) - return (size_t)OsFileApi_ReturnCodeTable[OSFILEAPI_OSFINDCREATOR_INDEX].Value; - - return 0; -} - diff --git a/src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_stubs.h b/src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_stubs.h deleted file mode 100644 index 32c9a8734..000000000 --- a/src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_stubs.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * File: osfileapi_stubs.h - * - * Purpose: - * Provide stubs for unit testing - * - * History: - * 05/28/2015 A. Asp, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSFILEAPI_STUBS_H_ -#define _OSFILEAPI_STUBS_H_ - -#include "uttools.h" -#include "vxworks6-coverage-stubs.h" - - -/* Define missing types */ -typedef struct -{ - int32 Dir; -} __dirstream; - -typedef enum -{ - OSFILEAPI_STRLEN_INDEX, - OSFILEAPI_STRCMP_INDEX, - OSFILEAPI_STRCPY_INDEX, - OSFILEAPI_STRNCPY_INDEX, - OSFILEAPI_STRRCHR_INDEX, - OSFILEAPI_STRCHR_INDEX, - OSFILEAPI_OPEN_INDEX, - OSFILEAPI_CLOSE_INDEX, - OSFILEAPI_READ_INDEX, - OSFILEAPI_WRITE_INDEX, - OSFILEAPI_LSEEK_INDEX, - OSFILEAPI_STAT_INDEX, - OSFILEAPI_REMOVE_INDEX, - OSFILEAPI_RENAME_INDEX, - OSFILEAPI_CP_INDEX, - OSFILEAPI_MKDIR_INDEX, - OSFILEAPI_RMDIR_INDEX, - OSFILEAPI_OPENDIR_INDEX, - OSFILEAPI_CLOSEDIR_INDEX, - OSFILEAPI_READDIR_INDEX, - OSFILEAPI_SEMMCREATE_INDEX, - OSFILEAPI_SEMTAKE_INDEX, - OSFILEAPI_SEMGIVE_INDEX, - OSFILEAPI_SHELLGENERICINIT_INDEX, - OSFILEAPI_TASKDELAY_INDEX, - OSFILEAPI_TASKNAMETOID_INDEX, - OSFILEAPI_SYSCLKRATEGET_INDEX, - OSFILEAPI_OSTRANSLATEPATH_INDEX, - OSFILEAPI_OSFINDCREATOR_INDEX, - OSFILEAPI_MAX_INDEX -} OsFileApi_Index_t; - -typedef struct -{ - int32 Value; - uint32 Count; -} OsFileApi_ReturnCodeTable_t; - -typedef struct -{ - size_t (*strlen)(const char *str); - int (*strcmp)(const char *str1, const char *str2); - char * (*strcpy)(const char *str1, const char *str2); - char * (*strncpy)(const char *str1, const char *str2, size_t size); - int (*open)(const char *, int, int); - VCS_STATUS (*close)(int fd); - int (*read)(int fd, char *buffer, size_t maxbytes); - int (*write)(int fd, char *buffer, size_t nbytes); - int (*lseek)(int fd, long offset, int whence); - VCS_STATUS (*mkdir)(const char *dirName); - VCS_STATUS (*cp)(const char *src, const char *dest); - VCS_STATUS (*rmdir)(const char *dirName); - VCS_SEM_ID (*semMCreate)(uint16 *); - VCS_STATUS (*semTake)(VCS_SEM_ID, int); - VCS_STATUS (*semGive)(VCS_SEM_ID); - int (*shellGenericInit)(const char *arg1, const char *arg2, const char *arg3, char **arg4, - int arg5, int arg6, int arg7, int arg8, int arg9); - VCS_STATUS (*taskDelay)(int ticks); - int (*taskNameToId)(char *name); - int (*sysClkRateGet)(void); - int32 (*OS_TranslatePath)(const char* VirtualPath, char* LocalPath); - uint32 (*OS_FindCreator)(void); -} OsFileApi_HookTable_t; - -extern const char testFileName[]; - - -void OsFileApi_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt); -void OsFileApi_SetFunctionHook(uint32 Index, void *FunPtr); -void OsFileApi_Reset(void); -uint32 OsFileApi_CheckCount(uint32 Index); - -int32 getNSemTake(void); -int32 getNSemGive(void); -int32 getRewinddirCalls(void); - -#endif diff --git a/src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_testcase.c b/src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_testcase.c deleted file mode 100644 index ef1d48c94..000000000 --- a/src/unit-test-coverage/vxworks6/osfileapi-test/osfileapi_testcase.c +++ /dev/null @@ -1,3726 +0,0 @@ -/* - * Filename: osfileapi_testcase.c - * - * Purpose: This file contains unit test cases - * - * Notes: - * -Tests for path length assume OS_MAX_PATH_LEN includes the terminating null - * character, the same as the POSIX.1 standard for PATH_MAX - * - * Modification History: - * 04/28/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include /* for O_WRONLY etc. */ - -#include "osapi.h" /* cfe.h not available from within osal. */ - -#include "utassert.h" -#include "uttest.h" -#include "utlist.h" - -#include "osfileapi_stubs.h" - - - -extern OS_FDTableEntry OS_FDTable[OS_MAX_NUM_OPEN_FILES]; -extern const char testFileName[]; - -#define MAX_BUF 100 - -/* Prototypes for non-exported functions */ - - -/* -------------------- Special Test Case Variables ------------------------- */ -static const OS_FDTableEntry zero_OS_FDTableEntry = {0, "", 0, 0}; -static const OS_FDTableEntry nonDefault_OS_FDTableEntry = {2, "/test", 5, TRUE}; - -static const __dirstream testDir = { 1 }; - -static char testCmd[] = "testCmd"; - - -/* Utility functions */ -/* -------------------------------------------------------------------------- */ -/* - * OsFileApi_Set_NonZeroFdTable_Values - * - * Purpose: - * Sets the entire OS_FDTable to non-zero values - */ -void OsFileApi_Set_NonZeroFdTable_Values(void) -{ - uint32 ii = 0; - - for (ii = 0; ii < OS_MAX_NUM_OPEN_FILES; ++ii) - { - OS_FDTable[ii] = nonDefault_OS_FDTableEntry; - } -} - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_FS_Init Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_Init_Error(void) -{ - int32 expected = OS_ERROR; - int32 actual = 99; - uint32 ii = 0; - - /* Setup Inputs */ - OsFileApi_Set_NonZeroFdTable_Values(); - - OsFileApi_SetReturnCode(OSFILEAPI_SEMMCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_FS_Init(); - - /* Verify Outputs */ - for (ii = 0; ii < OS_MAX_NUM_OPEN_FILES; ++ii) - { - UtAssert_True(OS_FDTable[ii].OSfd == -1, "OSFd == expected"); - UtAssert_MemCmp(OS_FDTable[ii].Path, "\0", 1, "Path == empty"); - UtAssert_True(OS_FDTable[ii].User == 0, "User == expected"); - UtAssert_True(OS_FDTable[ii].IsValid == FALSE, "IsValid == FALSE"); - } - UtAssert_True(actual == expected, "actual == OS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_Init_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - uint32 ii = 0; - - /* Setup Inputs */ - OsFileApi_Set_NonZeroFdTable_Values(); - - OsFileApi_SetReturnCode(OSFILEAPI_SEMMCREATE_INDEX, 1, 1); - - /* Execute Test */ - actual = OS_FS_Init(); - - /* Verify Outputs */ - for (ii = 0; ii < OS_MAX_NUM_OPEN_FILES; ++ii) - { - UtAssert_True(OS_FDTable[ii].OSfd == -1, "OSFd == expected"); - UtAssert_MemCmp(OS_FDTable[ii].Path, "\0", 1, "Path == empty"); - UtAssert_True(OS_FDTable[ii].User == 0, "User == expected"); - UtAssert_True(OS_FDTable[ii].IsValid == FALSE, "IsValid == FALSE"); - } - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); -} - - -/******************************************************************************* -** -** OS_creat Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = NULL; - int32 access = OS_WRITE_ONLY; - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_PathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - int32 access = OS_WRITE_ONLY; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_PathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - int32 access = OS_WRITE_ONLY; - - /* Verify max path length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_NameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - int32 access = OS_WRITE_ONLY; - - /* Create early exit from OS_check_name_length */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 2); - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_NameMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - int32 access = OS_WRITE_ONLY; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_TransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - int32 access = OS_WRITE_ONLY; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_INVALID_POINTER, 1); - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_NoFreeFds(void) -{ - int32 expected = OS_FS_ERR_NO_FREE_FDS; - int32 actual = 99; - uint32 ii = 0; - - /* Setup Inputs */ - const char *fileName = testFileName; - int32 access = OS_WRITE_ONLY; - for (ii = 0; ii < OS_MAX_NUM_OPEN_FILES; ++ii) - { - OS_FDTable[ii].IsValid = TRUE; - } - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NO_FREE_FDS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_OpenWriteOnly(void) -{ - int32 expected = 0; - int32 actual = 99; - int32 user = 2; - - OS_FDTable[expected].OSfd = -1; /* set non-default values that should be overridden */ - OS_FDTable[expected].User = -1; - - /* Setup Inputs */ - const char *fileName = testFileName; /* value for open stub to return 'perm' value (set to OSFd) */ - int32 access = OS_WRITE_ONLY; - - OsFileApi_SetReturnCode(OSFILEAPI_OSFINDCREATOR_INDEX, user, 1); - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected index"); - UtAssert_True(OS_FDTable[expected].IsValid == TRUE, "IsValid == TRUE"); - UtAssert_True(OS_FDTable[expected].OSfd == (O_WRONLY | O_CREAT | O_TRUNC), "OSfd == expected"); - UtAssert_True(OS_FDTable[expected].User == user, "User == expected"); - UtAssert_MemCmp(OS_FDTable[expected].Path, fileName, strlen(fileName), "Path == input"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_OpenReadWrite(void) -{ - int32 expected = 5; - int32 actual = 99; - int32 user = 10; - uint32 ii = 0; - - OS_FDTable[expected].OSfd = -1; /* set non-default values that should be overridden */ - OS_FDTable[expected].User = -1; - for (ii = 0; ii < expected; ++ii) - { - OS_FDTable[ii].IsValid = TRUE; - } - - /* Setup Inputs */ - const char *fileName = testFileName; /* value for open stub to return 'perm' value (set to OSFd) */ - int32 access = OS_READ_WRITE; - - OsFileApi_SetReturnCode(OSFILEAPI_OSFINDCREATOR_INDEX, user, 1); - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected index"); - UtAssert_True(OS_FDTable[expected].IsValid == TRUE, "IsValid == TRUE"); - UtAssert_True(OS_FDTable[expected].OSfd == (O_RDWR | O_CREAT | O_TRUNC), "OSFd == expected"); - UtAssert_True(OS_FDTable[expected].User == user, "User == expected"); - UtAssert_MemCmp(OS_FDTable[expected].Path, fileName, strlen(fileName), "Path == input"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_BadAccess(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; /* value for open stub to return 'perm' value (set to OSFd) */ - int32 access = -1; /* invalid value */ - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_creat_OpenError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; /* value for open stub to return 'perm' value (set to OSFd) */ - int32 access = OS_READ_WRITE; - - OsFileApi_SetReturnCode(OSFILEAPI_OPEN_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_creat(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(OS_FDTable[0].IsValid == FALSE, "IsValid == FALSE"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_open Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_open_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = NULL; - int32 access = OS_READ_ONLY; - uint32 mode = 0; - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_PathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = "/test"; - int32 access = OS_READ_ONLY; - uint32 mode = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_PathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = "/test"; - int32 access = OS_READ_ONLY; - uint32 mode = 0; - - /* Verify max name length passes, if not, exit with non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_NameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = "/test"; - int32 access = OS_READ_ONLY; - uint32 mode = 0; - - /* Create early exit from OS_check_name_length */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 2); - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_NameMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = "/test"; - int32 access = OS_READ_ONLY; - uint32 mode = 0; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_TransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = "/test"; - int32 access = OS_READ_ONLY; - uint32 mode = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_INVALID_POINTER, 1); - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_NoFreeFds(void) -{ - int32 expected = OS_FS_ERR_NO_FREE_FDS; - int32 actual = 99; - uint32 ii = 0; - - /* Setup Inputs */ - const char *fileName = testFileName; - int32 access = OS_READ_ONLY; - uint32 mode = 0; - for (ii = 0; ii < OS_MAX_NUM_OPEN_FILES; ++ii) - { - OS_FDTable[ii].IsValid = TRUE; - } - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NO_FREE_FDS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_OpenReadOnly(void) -{ - int32 expected = 0; - int32 actual = 99; - int32 user = 1; - - OS_FDTable[expected].OSfd = -1; /* set non-default values */ - OS_FDTable[expected].User = -1; - - /* Setup Inputs */ - const char *fileName = testFileName; /* value for open stub to return 'perm' value (set to OSFd) */ - int32 access = OS_READ_ONLY; - uint32 mode = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_OSFINDCREATOR_INDEX, user, 1); - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected index"); - UtAssert_True(OS_FDTable[expected].IsValid == TRUE, "IsValid == TRUE"); - UtAssert_True(OS_FDTable[expected].OSfd == O_RDONLY, "OSFd == expected"); - UtAssert_True(OS_FDTable[expected].User == user, "User == expected"); - UtAssert_MemCmp(OS_FDTable[expected].Path, fileName, strlen(fileName), "Path == input"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_OpenWriteOnly(void) -{ - int32 expected = 0; - int32 actual = 99; - int32 user = 2; - - OS_FDTable[expected].OSfd = -1; /* set non-default values that should be overridden */ - OS_FDTable[expected].User = -1; - - /* Setup Inputs */ - const char *fileName = testFileName; /* value for open stub to return 'perm' value (set to OSFd) */ - int32 access = OS_WRITE_ONLY; - uint32 mode = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_OSFINDCREATOR_INDEX, user, 1); - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected index"); - UtAssert_True(OS_FDTable[expected].IsValid == TRUE, "IsValid == TRUE"); - UtAssert_True(OS_FDTable[expected].OSfd == (O_WRONLY | O_CREAT), "OSFd == expected"); - UtAssert_True(OS_FDTable[expected].User == user, "User == expected"); - UtAssert_MemCmp(OS_FDTable[expected].Path, fileName, strlen(fileName), "Path == input"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_OpenReadWrite(void) -{ - int32 expected = 5; - int32 actual = 99; - int32 user = 10; - uint32 ii = 0; - - OS_FDTable[expected].OSfd = -1; /* set non-default values that should be overridden */ - OS_FDTable[expected].User = -1; - for (ii = 0; ii < expected; ++ii) - { - OS_FDTable[ii].IsValid = TRUE; - } - - /* Setup Inputs */ - const char *fileName = testFileName; /* value for open stub to return 'perm' value (set to OSFd) */ - int32 access = OS_READ_WRITE; - uint32 mode = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_OSFINDCREATOR_INDEX, user, 1); - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected index"); - UtAssert_True(OS_FDTable[expected].IsValid == TRUE, "IsValid == TRUE"); - UtAssert_True(OS_FDTable[expected].OSfd == (O_RDWR | O_CREAT), "OSFd == expected"); - UtAssert_True(OS_FDTable[expected].User == user, "User == expected"); - UtAssert_MemCmp(OS_FDTable[expected].Path, fileName, strlen(fileName), "Path == input"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_BadAccess(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; /* value for open stub to return 'perm' value (set to OSFd) */ - int32 access = -1; /* invalid value */ - uint32 mode = 0; - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_open_OpenError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; /* value for open stub to return 'perm' value (set to OSFd) */ - int32 access = OS_READ_WRITE; - uint32 mode = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_OPEN_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_open(fileName, access, mode); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(OS_FDTable[0].IsValid == FALSE, "IsValid == FALSE"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_close Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_close_FdNeg(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = -1; - - /* Execute Test */ - actual = OS_close(fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_close_FdTooLarge(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = OS_MAX_NUM_OPEN_FILES; - - /* Execute Test */ - actual = OS_close(fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_close_FdNotValid(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 0; - OS_FDTable[fd].IsValid = FALSE; - - /* Execute Test */ - actual = OS_close(fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_close_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 9; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - OsFileApi_SetReturnCode(OSFILEAPI_CLOSE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_close(fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(OS_FDTable[fd].IsValid == FALSE, "IsValid == FALSE"); - UtAssert_True(OS_FDTable[fd].OSfd == -1, "OSFd == expected"); - UtAssert_True(OS_FDTable[fd].User == 0, "User == expected"); - UtAssert_MemCmp(OS_FDTable[fd].Path, "\0", 1, "Path == empty"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_close_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 3; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - OsFileApi_SetReturnCode(OSFILEAPI_CLOSE_INDEX, OS_FS_SUCCESS, 1); - - /* Execute Test */ - actual = OS_close(fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(OS_FDTable[fd].IsValid == FALSE, "IsValid == FALSE"); - UtAssert_True(OS_FDTable[fd].OSfd == -1, "OSFd == expected"); - UtAssert_True(OS_FDTable[fd].User == 0, "User == expected"); - UtAssert_MemCmp(OS_FDTable[fd].Path, "\0", 1, "Path == empty"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_read Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_read_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 1; - char *buffer = NULL; - uint32 nbytes = 10; - - /* Execute Test */ - actual = OS_read(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_read_FdNeg(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = -1; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - - /* Execute Test */ - actual = OS_read(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_read_FdTooLarge(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = OS_MAX_NUM_OPEN_FILES; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - - /* Execute Test */ - actual = OS_read(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_read_FdNotValid(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 1; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - - /* Execute Test */ - actual = OS_read(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_read_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 1; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - OsFileApi_SetReturnCode(OSFILEAPI_READ_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_read(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_read_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 7; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - OsFileApi_SetReturnCode(OSFILEAPI_READ_INDEX, OS_FS_SUCCESS, 1); - - /* Execute Test */ - actual = OS_read(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_write Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_write_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 1; - char *buffer = NULL; - uint32 nbytes = 10; - - /* Execute Test */ - actual = OS_write(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_write_FdNeg(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = -1; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - - /* Execute Test */ - actual = OS_write(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_write_FdTooLarge(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = OS_MAX_NUM_OPEN_FILES; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - - /* Execute Test */ - actual = OS_write(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_write_FdNotValid(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 1; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - - /* Execute Test */ - actual = OS_write(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_write_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 1; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - OsFileApi_SetReturnCode(OSFILEAPI_WRITE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_write(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_write_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 7; - char buffer[MAX_BUF] = {0}; - uint32 nbytes = MAX_BUF; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - OsFileApi_SetReturnCode(OSFILEAPI_WRITE_INDEX, OS_FS_SUCCESS, 1); - - /* Execute Test */ - actual = OS_write(fd, buffer, nbytes); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_chmod Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_chmod(void) -{ - int32 expected = OS_FS_UNIMPLEMENTED; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - uint32 access = O_RDONLY; - - /* Execute Test */ - actual = OS_chmod(fileName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_UNIMPLEMENTED"); -} - - -/******************************************************************************* -** -** OS_stat Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_stat_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = NULL; - os_fstat_t fileStats; - - /* Execute Test */ - actual = OS_stat(fileName, &fileStats); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_stat_NullFileStats(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - os_fstat_t *fileStats = NULL; - - /* Execute Test */ - actual = OS_stat(fileName, fileStats); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_stat_PathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - os_fstat_t fileStats; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_stat(fileName, &fileStats); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_stat_PathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - os_fstat_t fileStats; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - - /* Execute Test */ - actual = OS_stat(fileName, &fileStats); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_stat_TransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - os_fstat_t fileStats; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_INVALID_POINTER, 1); - - /* Execute Test */ - actual = OS_stat(fileName, &fileStats); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_stat_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - os_fstat_t fileStats; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_SUCCESS, 1); - OsFileApi_SetReturnCode(OSFILEAPI_STAT_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_stat(fileName, &fileStats); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_stat_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - os_fstat_t fileStats; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_SUCCESS, 1); - OsFileApi_SetReturnCode(OSFILEAPI_STAT_INDEX, OS_FS_SUCCESS, 1); - - /* Execute Test */ - actual = OS_stat(fileName, &fileStats); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_lseek Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_lseek_FdNeg(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = -1; - int32 offset = 0; - uint32 whence = OS_SEEK_SET; - - /* Execute Test */ - actual = OS_lseek(fd, offset, whence); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_lseek_FdTooLarge(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = OS_MAX_NUM_OPEN_FILES; - int32 offset = 0; - uint32 whence = OS_SEEK_SET; - - /* Execute Test */ - actual = OS_lseek(fd, offset, whence); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_lseek_FdNotValid(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 0; - int32 offset = 0; - uint32 whence = OS_SEEK_SET; - - /* Execute Test */ - actual = OS_lseek(fd, offset, whence); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_lseek_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 0; - int32 offset = 0; - uint32 whence = OS_SEEK_SET; - OS_FDTable[fd].IsValid = TRUE; - - OsFileApi_SetReturnCode(OSFILEAPI_LSEEK_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_lseek(fd, offset, whence); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_lseek_SeekSet(void) -{ - int32 expected = SEEK_SET; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 8; - int32 offset = -1; /* value for the lseek stub to return 'where' value */ - uint32 whence = OS_SEEK_SET; - OS_FDTable[fd].IsValid = TRUE; - - /* Execute Test */ - actual = OS_lseek(fd, offset, whence); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == SEEK_SET"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_lseek_SeekCur(void) -{ - int32 expected = SEEK_CUR; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 4; - int32 offset = -1; /* value for the lseek stub to return 'where' value */ - uint32 whence = OS_SEEK_CUR; - OS_FDTable[fd].IsValid = TRUE; - - /* Execute Test */ - actual = OS_lseek(fd, offset, whence); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == SEEK_CUR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_lseek_SeekEnd(void) -{ - int32 expected = SEEK_END; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 2; - int32 offset = -1; /* value for the lseek stub to return 'where' value */ - uint32 whence = OS_SEEK_END; - OS_FDTable[fd].IsValid = TRUE; - - /* Execute Test */ - actual = OS_lseek(fd, offset, whence); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == SEEK_END"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_lseek_SeekInvalid(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 fd = 7; - int32 offset = 0; - uint32 whence = -1; - OS_FDTable[fd].IsValid = TRUE; - - /* Execute Test */ - actual = OS_lseek(fd, offset, whence); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_remove Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_remove_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = NULL; - - /* Execute Test */ - actual = OS_remove(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_remove_PathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_remove(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_remove_PathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_remove(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_remove_NameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - - /* Create early exit from OS_check_name_length */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 2); - - /* Execute Test */ - actual = OS_remove(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_remove_NameMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_remove(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_remove_FileOpenError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - OS_FDTable[0] = nonDefault_OS_FDTableEntry; - strcpy(OS_FDTable[0].Path, "/fakePath"); /* extra entry for MCDC coverage */ - OS_FDTable[1] = nonDefault_OS_FDTableEntry; - - /* Execute Test */ - actual = OS_remove(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_remove_TransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERROR, 1); - - /* Execute Test */ - actual = OS_remove(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_remove_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_REMOVE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_remove(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_remove_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_REMOVE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_remove(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_rename Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_NullOldPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = NULL; - const char *newFileName = testFileName; - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_NullNewPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = NULL; - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_OldPathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_OldPathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_NewPathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 2); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_NewPathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 2); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_OldNameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - /* Create early exit from OS_check_name_length */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 3); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_OldNameMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_NewNameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 4); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_NewNameMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_OldTransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_INVALID_POINTER, 1); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_NewTransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_INVALID_POINTER, 2); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_RENAME_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rename_Success(void) -{ /* Probably should be a break after the valid file is found and renamed */ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *oldFileName = testFileName; - const char *newFileName = testFileName; - OS_FDTable[0] = nonDefault_OS_FDTableEntry; - OS_FDTable[OS_MAX_NUM_OPEN_FILES-1] = nonDefault_OS_FDTableEntry; - OS_FDTable[OS_MAX_NUM_OPEN_FILES-1].IsValid = FALSE; /* for full MCDC coverage */ - - OsFileApi_SetReturnCode(OSFILEAPI_RENAME_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_rename(oldFileName, newFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_cp Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_NullSrcPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = NULL; - const char *dst = testFileName; - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_NullDstPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = NULL; - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_SrcPathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_SrcPathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_DstPathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 2); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_DstPathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - /* Verify max name length passes, if so, exit with non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 2); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_SrcNameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - /* Create early exit from OS_check_name_length */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 3); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_SrcNameMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_DstNameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - /* Create early exit from OS_check_name_length */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 4); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_DstNameMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_SrcTransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERROR, 1); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_DstTransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERROR, 2); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_DstIsOpenError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - OS_FDTable[1].IsValid = TRUE; /* for full MCDC testing */ - OS_FDTable[OS_MAX_NUM_OPEN_FILES-1] = nonDefault_OS_FDTableEntry; - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_CP_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_cp_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_CP_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_cp(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_mv Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_NullSrcPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *srcFileName = NULL; - const char *dstFileName = testFileName; - - /* Execute Test */ - actual = OS_mv(srcFileName, dstFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_NullDstPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *srcFileName = testFileName; - const char *dstFileName = NULL; - - /* Execute Test */ - actual = OS_mv(srcFileName, dstFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_SrcPathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *srcFileName = testFileName; - const char *dstFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_mv(srcFileName, dstFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_SrcPathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *srcFileName = testFileName; - const char *dstFileName = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_mv(srcFileName, dstFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_DstPathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *srcFileName = testFileName; - const char *dstFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 2); - - /* Execute Test */ - actual = OS_mv(srcFileName, dstFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_DstPathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *srcFileName = testFileName; - const char *dstFileName = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 2); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_mv(srcFileName, dstFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_SrcNameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *srcFileName = testFileName; - const char *dstFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 3); - - /* Execute Test */ - actual = OS_mv(srcFileName, dstFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_DstNameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *srcFileName = testFileName; - const char *dstFileName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 4); - - /* Execute Test */ - actual = OS_mv(srcFileName, dstFileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_SrcIsOpenError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - OS_FDTable[1].IsValid = TRUE; /* for full MCDC testing */ - OS_FDTable[OS_MAX_NUM_OPEN_FILES-1] = nonDefault_OS_FDTableEntry; - - /* Execute Test */ - actual = OS_mv(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_CP_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_mv(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mv_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *src = testFileName; - const char *dst = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_CP_INDEX, VCS_OK, 1); - OsFileApi_SetReturnCode(OSFILEAPI_REMOVE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_mv(src, dst); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_mkdir Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_mkdir_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *pathName = NULL; - uint32 access = 0; - - /* Execute Test */ - actual = OS_mkdir(pathName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkdir_PathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *pathName = testFileName; - uint32 access = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_mkdir(pathName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkdir_PathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *pathName = testFileName; - uint32 access = 0; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_mkdir(pathName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkdir_TransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *pathName = testFileName; - uint32 access = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERROR, 1); - - /* Execute Test */ - actual = OS_mkdir(pathName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkdir_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *pathName = testFileName; - uint32 access = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_MKDIR_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_mkdir(pathName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkdir_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *pathName = testFileName; - uint32 access = 0; - - OsFileApi_SetReturnCode(OSFILEAPI_MKDIR_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_mkdir(pathName, access); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); -} - - -/******************************************************************************* -** -** OS_opendir Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_opendir_NullPath(void) -{ - DIR *expected = NULL; - DIR *actual = (DIR *)(&testDir); - - /* Setup Inputs */ - const char *pathName = NULL; - - /* Execute Test */ - actual = OS_opendir(pathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == NULL"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_opendir_PathTooLong(void) -{ - DIR *expected = NULL; - DIR *actual = (DIR *)(&testDir); - - /* Setup Inputs */ - const char *pathName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_opendir(pathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == NULL"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_opendir_PathMaxValid(void) /* Also covers a Success test */ -{ - DIR *expected = (DIR *)(1); - DIR *actual = (DIR *)(&testDir); - - /* Setup Inputs */ - const char *pathName = testFileName; - - /* Verify max name length passes, if so, exit with next non-null return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_SUCCESS, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OPENDIR_INDEX, 1, 1); - - /* Execute Test */ - actual = OS_opendir(pathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_opendir_TransPathError(void) -{ - DIR *expected = NULL; - DIR *actual = (DIR *)(&testDir); - - /* Setup Inputs */ - const char *pathName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_opendir(pathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == NULL"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_opendir_Error(void) -{ - DIR *expected = NULL; - DIR *actual = (DIR *)(&testDir); - - /* Setup Inputs */ - const char *pathName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, 0, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_SUCCESS, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OPENDIR_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_opendir(pathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == NULL"); -} - - -/******************************************************************************* -** -** OS_closedir Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_closedir_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - os_dirp_t dirPtr = NULL; - - /* Execute Test */ - actual = OS_closedir(dirPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_closedir_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - os_dirp_t dir = (os_dirp_t)1; - - OsFileApi_SetReturnCode(OSFILEAPI_CLOSEDIR_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_closedir(dir); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_closedir_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - os_dirp_t dir = (os_dirp_t)1; - - OsFileApi_SetReturnCode(OSFILEAPI_CLOSEDIR_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_closedir(dir); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); -} - - -/******************************************************************************* -** -** OS_readdir Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_readdir_NullPath(void) -{ - struct dirent *expected = NULL; - struct dirent *actual = (struct dirent *)99; - - /* Setup Inputs */ - os_dirp_t dirPtr = NULL; - - /* Execute Test */ - actual = OS_readdir(dirPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == NULL"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_readdir_Error(void) -{ - struct dirent *expected = NULL; - struct dirent *actual = (struct dirent *)99; - - /* Setup Inputs */ - os_dirp_t dirPtr = (os_dirp_t)2; - - OsFileApi_SetReturnCode(OSFILEAPI_READDIR_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_readdir(dirPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == NULL"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_readdir_Success(void) -{ - struct dirent *expected = (struct dirent *)1; - struct dirent *actual = NULL; - - /* Setup Inputs */ - os_dirp_t dirPtr = (os_dirp_t)2; - - OsFileApi_SetReturnCode(OSFILEAPI_READDIR_INDEX, 1, 1); - - /* Execute Test */ - actual = OS_readdir(dirPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); -} - - -/******************************************************************************* -** -** OS_rewinddir Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_rewinddir_NullPath(void) -{ - int32 expected = 0; - - /* Setup Inputs */ - os_dirp_t dirPtr = NULL; - - /* Execute Test */ - OS_rewinddir(dirPtr); - - /* Verify Outputs */ - UtAssert_True(getRewinddirCalls() == expected, "actual == rewinddir not called"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rewinddir_Success(void) -{ - int32 expected = 1; - - /* Setup Inputs */ - os_dirp_t dirPtr = (os_dirp_t)1; - - /* Execute Test */ - OS_rewinddir(dirPtr); - - /* Verify Outputs */ - UtAssert_True(getRewinddirCalls() == expected, "actual == rewinddir called"); -} - - -/******************************************************************************* -** -** OS_rmdir Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_rmdir_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - const char *dirName = NULL; - - /* Execute Test */ - actual = OS_rmdir(dirName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rmdir_PathTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - const char *dirName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_rmdir(dirName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rmdir_PathMaxValid(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *dirName = testFileName; - - /* Verify max name length passes, if so, exit with next non-zero return */ - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN-1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - actual = OS_rmdir(dirName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rmdir_TransPathError(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - const char *dirName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_OSTRANSLATEPATH_INDEX, OS_FS_ERROR, 1); - - /* Execute Test */ - actual = OS_rmdir(dirName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rmdir_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *dirName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_RMDIR_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_rmdir(dirName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rmdir_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *dirName = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_RMDIR_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_rmdir(dirName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); -} - - -/******************************************************************************* -** -** OS_check_name_length Tests -** -*******************************************************************************/ -extern int32 OS_check_name_length(const char *path); - -/*----------------------------------------------------------------------------*/ -void Test_OS_check_name_length_NullPath(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *path = NULL; - - /* Execute Test */ - actual = OS_check_name_length(path); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_check_name_length_PathTooLong(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *path = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_check_name_length(path); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_check_name_length_NoPathSep(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *path = testFileName; - - OsFileApi_SetReturnCode(OSFILEAPI_STRRCHR_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_check_name_length(path); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_check_name_length_NameTooLong(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *path = testFileName; - - /* Linker may replace call to strrchr(str, '\0') to call strchr directly */ - OsFileApi_SetReturnCode(OSFILEAPI_STRCHR_INDEX, - (uint32)(path + 1000), 1); - OsFileApi_SetReturnCode(OSFILEAPI_STRRCHR_INDEX, - (uint32)(path + 1000), 2); - - /* Execute Test */ - actual = OS_check_name_length(path); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_check_name_length_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *path = testFileName; - - /* Execute Test */ - actual = OS_check_name_length(path); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); -} - - -/******************************************************************************* -** -** OS_ShellOutputToFile Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_ShellOutputToFile_NullCmd(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - char *cmd = NULL; - int32 fd = 0; - - /* Execute Test */ - actual = OS_ShellOutputToFile(cmd, fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_ShellOutputToFile_FdNeg(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - char *cmd = testCmd; - int32 fd = -1; - - /* Execute Test */ - actual = OS_ShellOutputToFile(cmd, fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_ShellOutputToFile_FdTooLarge(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - char *cmd = testCmd; - int32 fd = OS_MAX_NUM_OPEN_FILES; - - /* Execute Test */ - actual = OS_ShellOutputToFile(cmd, fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_ShellOutputToFile_FdInvalid(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - char *cmd = testCmd; - int32 fd = 0; - - /* Execute Test */ - actual = OS_ShellOutputToFile(cmd, fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_ShellOutputToFile_CmdFileCreateError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - char *cmd = testCmd; - int32 fd = 0; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, OS_MAX_PATH_LEN+1, 1); - - /* Execute Test */ - actual = OS_ShellOutputToFile(cmd, fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_ShellOutputToFile_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - int32 user = 2; - - /* Setup Inputs */ - char *cmd = testCmd; - int32 fd = 5; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, 1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OPEN_INDEX, VCS_OK, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSFINDCREATOR_INDEX, user, 1); - OsFileApi_SetReturnCode(OSFILEAPI_WRITE_INDEX, OS_FS_SUCCESS, 1); - OsFileApi_SetReturnCode(OSFILEAPI_LSEEK_INDEX, VCS_OK, 1); - OsFileApi_SetReturnCode(OSFILEAPI_SHELLGENERICINIT_INDEX, VCS_ERROR, 1); - OsFileApi_SetReturnCode(OSFILEAPI_TASKNAMETOID_INDEX, VCS_OK, 3); /* cycle multiple times */ - OsFileApi_SetReturnCode(OSFILEAPI_CLOSE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_ShellOutputToFile(cmd, fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 1, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_ShellOutputToFile_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - int32 user = 2; - - /* Setup Inputs */ - char *cmd = testCmd; - int32 fd = 9; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - OsFileApi_SetReturnCode(OSFILEAPI_STRLEN_INDEX, 1, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OPEN_INDEX, VCS_OK, 1); - OsFileApi_SetReturnCode(OSFILEAPI_OSFINDCREATOR_INDEX, user, 1); - OsFileApi_SetReturnCode(OSFILEAPI_WRITE_INDEX, OS_FS_SUCCESS, 1); - OsFileApi_SetReturnCode(OSFILEAPI_LSEEK_INDEX, VCS_OK, 1); - OsFileApi_SetReturnCode(OSFILEAPI_SHELLGENERICINIT_INDEX, VCS_OK, 1); - OsFileApi_SetReturnCode(OSFILEAPI_TASKNAMETOID_INDEX, VCS_OK, 1); - OsFileApi_SetReturnCode(OSFILEAPI_CLOSE_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_ShellOutputToFile(cmd, fd); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 1, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_FdGetInfo Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_FDGetInfo_NullFdEntry(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - OS_FDTableEntry *fdEntry = NULL; - int32 fd = 0; - - /* Execute Test */ - actual = OS_FDGetInfo(fd, fdEntry); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FDGetInfo_FdNeg(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - OS_FDTableEntry fdEntry = nonDefault_OS_FDTableEntry; - int32 fd = -1; - - /* Execute Test */ - actual = OS_FDGetInfo(fd, &fdEntry); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(fdEntry.IsValid == FALSE, "entry IsValid == FALSE"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FDGetInfo_FdTooLarge(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - OS_FDTableEntry fdEntry = nonDefault_OS_FDTableEntry; - int32 fd = OS_MAX_NUM_OPEN_FILES; - - /* Execute Test */ - actual = OS_FDGetInfo(fd, &fdEntry); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(fdEntry.IsValid == FALSE, "entry IsValid == FALSE"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FDGetInfo_FdInvalid(void) -{ - int32 expected = OS_FS_ERR_INVALID_FD; - int32 actual = 99; - - /* Setup Inputs */ - OS_FDTableEntry fdEntry = nonDefault_OS_FDTableEntry; - int32 fd = 0; - - /* Execute Test */ - actual = OS_FDGetInfo(fd, &fdEntry); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_FD"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(fdEntry.IsValid == FALSE, "entry IsValid == FALSE"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FDGetInfo_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - OS_FDTableEntry fdEntry = zero_OS_FDTableEntry; - int32 fd = OS_MAX_NUM_OPEN_FILES - 1; - OS_FDTable[fd] = nonDefault_OS_FDTableEntry; - - /* Execute Test */ - actual = OS_FDGetInfo(fd, &fdEntry); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(fdEntry.IsValid == nonDefault_OS_FDTableEntry.IsValid, "Isvalid == expected"); - UtAssert_True(fdEntry.OSfd == nonDefault_OS_FDTableEntry.OSfd, "OSfd == expected"); - UtAssert_True(0 == strcmp(fdEntry.Path, nonDefault_OS_FDTableEntry.Path), "Path == expected"); - UtAssert_True(fdEntry.User == nonDefault_OS_FDTableEntry.User, "User == expected"); -} - - -/******************************************************************************* -** -** OS_FileOpenCheck Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_FileOpenCheck_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = NULL; - - /* Execute Test */ - actual = OS_FileOpenCheck(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FileOpenCheck_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = "/uniqueFilename"; - OS_FDTable[0] = nonDefault_OS_FDTableEntry; - - /* Execute Test */ - actual = OS_FileOpenCheck(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FileOpenCheck_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - OS_FDTable[OS_MAX_NUM_OPEN_FILES-1] = nonDefault_OS_FDTableEntry; - - /* Execute Test */ - actual = OS_FileOpenCheck((char *)fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_CloseFileByName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_CloseFileByName_NullPath(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = NULL; - - /* Execute Test */ - actual = OS_CloseFileByName(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CloseFileByName_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - OS_FDTable[5].IsValid = TRUE; - strcpy(OS_FDTable[5].Path, testFileName); - - OsFileApi_SetReturnCode(OSFILEAPI_CLOSE_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_CloseFileByName((char *)fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(OS_FDTable[5].IsValid == FALSE, "IsValid == FALSE"); - UtAssert_True(OS_FDTable[5].OSfd == -1, "OSFd == expected"); - UtAssert_True(OS_FDTable[5].User == 0, "User == expected"); - UtAssert_MemCmp(OS_FDTable[5].Path, "\0", 1, "Path == empty"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CloseFileByName_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - const char *fileName = testFileName; - OS_FDTable[2].IsValid = TRUE; - strcpy(OS_FDTable[2].Path, testFileName); - - OsFileApi_SetReturnCode(OSFILEAPI_CLOSE_INDEX, OS_FS_SUCCESS, 1); - - /* Execute Test */ - actual = OS_CloseFileByName((char *)fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(OS_FDTable[2].IsValid == FALSE, "IsValid == FALSE"); - UtAssert_True(OS_FDTable[2].OSfd == -1, "OSFd == expected"); - UtAssert_True(OS_FDTable[2].User == 0, "User == expected"); - UtAssert_MemCmp(OS_FDTable[2].Path, "\0", 1, "Path == empty"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CloseFileByName_InvalidPath(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - char *fileName = "/falsePath"; - OS_FDTable[8] = nonDefault_OS_FDTableEntry; - - /* Execute Test */ - actual = OS_CloseFileByName(fileName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(OS_FDTable[8].IsValid == TRUE, "IsValid == TRUE"); - UtAssert_True(OS_FDTable[8].OSfd != -1, "OSFd != -1"); - UtAssert_True(OS_FDTable[8].User != 0, "User != 0"); - UtAssert_MemCmp(OS_FDTable[8].Path, nonDefault_OS_FDTableEntry.Path, - OS_MAX_PATH_LEN, "Path != empty"); - UtAssert_True(getNSemTake() == 0, "semTake NOT called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_CloseAllFiles Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_CloseAllFiles_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - uint32 ii = 0; - - /* Setup Inputs */ - for (ii = 0; ii < OS_MAX_NUM_OPEN_FILES; ++ii) - { - OS_FDTable[ii] = nonDefault_OS_FDTableEntry; - } - OsFileApi_SetReturnCode(OSFILEAPI_CLOSE_INDEX, VCS_ERROR, OS_MAX_NUM_OPEN_FILES); - - /* Execute Test */ - actual = OS_CloseAllFiles(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_CloseAllFiles_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - /* Note, no files to close. */ - - /* Execute Test */ - actual = OS_CloseAllFiles(); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() == 0, "semTake NOT called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/* ------------------- End of test cases --------------------------------------*/ - - - - - -/* - * OsFileApi_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void OsFileApi_Setup(void) -{ - uint32 ii = 0; - - OsFileApi_Reset(); - //Ut_OSAPI_Reset(); - - for (ii = 0; ii < OS_MAX_NUM_OPEN_FILES; ++ii) - { - OS_FDTable[ii] = zero_OS_FDTableEntry; - } -} - - -/* - * OsFileApi_TearDown - * - * Purpose: - * Called by the unit test tool to tear down the app after each test - */ -void OsFileApi_TearDown(void) -{ - OsFileApi_Reset(); -} - - -#define ADD_TEST(test,setup,teardown) UtTest_Add((test), (setup), (teardown), #test) - -/* OsFileApi_AddTestCase - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void OS_Application_Startup(void) -{ - /* OS_FS_Init Tests */ - ADD_TEST(Test_OS_FS_Init_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_FS_Init_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_creat Tests */ - ADD_TEST(Test_OS_creat_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_PathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_PathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_NameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_NameMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_TransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_NoFreeFds, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_OpenWriteOnly, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_OpenReadWrite, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_BadAccess, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_creat_OpenError, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_Open Tests */ - ADD_TEST(Test_OS_open_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_PathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_PathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_NameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_NameMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_TransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_NoFreeFds, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_OpenReadOnly, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_OpenWriteOnly, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_OpenReadWrite, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_BadAccess, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_open_OpenError, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_close Tests */ - ADD_TEST(Test_OS_close_FdNeg, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_close_FdTooLarge, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_close_FdNotValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_close_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_close_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_read Tests */ - ADD_TEST(Test_OS_read_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_read_FdNeg, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_read_FdTooLarge, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_read_FdNotValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_read_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_read_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_write Tests */ - ADD_TEST(Test_OS_write_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_write_FdNeg, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_write_FdTooLarge, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_write_FdNotValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_write_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_write_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_chmod Tests */ - ADD_TEST(Test_OS_chmod, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_stat Tests */ - ADD_TEST(Test_OS_stat_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_stat_NullFileStats, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_stat_PathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_stat_PathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_stat_TransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_stat_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_stat_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_lseek Tests */ - ADD_TEST(Test_OS_lseek_FdNeg, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_lseek_FdTooLarge, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_lseek_FdNotValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_lseek_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_lseek_SeekSet, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_lseek_SeekCur, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_lseek_SeekEnd, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_lseek_SeekInvalid, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_remove Tests */ - ADD_TEST(Test_OS_remove_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_remove_PathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_remove_PathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_remove_NameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_remove_NameMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_remove_FileOpenError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_remove_TransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_remove_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_remove_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_rename Tests */ - ADD_TEST(Test_OS_rename_NullOldPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_NullNewPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_OldPathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_OldPathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_NewPathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_NewPathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_OldNameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_OldNameMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_NewNameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_NewNameMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_OldTransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_NewTransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rename_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_cp Tests */ - ADD_TEST(Test_OS_cp_NullSrcPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_NullDstPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_SrcPathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_SrcPathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_DstPathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_DstPathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_SrcNameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_SrcNameMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_DstNameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_DstNameMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_SrcTransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_DstTransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_DstIsOpenError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_cp_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_mv Tests */ - ADD_TEST(Test_OS_mv_NullSrcPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_NullDstPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_SrcPathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_SrcPathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_DstPathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_DstPathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_SrcNameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_DstNameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_SrcIsOpenError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mv_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_mkdir Tests */ - ADD_TEST(Test_OS_mkdir_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mkdir_PathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mkdir_PathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mkdir_TransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mkdir_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_mkdir_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_opendir Tests */ - ADD_TEST(Test_OS_opendir_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_opendir_PathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_opendir_PathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_opendir_TransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_opendir_Error, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_closedir Tests */ - ADD_TEST(Test_OS_closedir_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_closedir_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_closedir_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_readdir Tests */ - ADD_TEST(Test_OS_readdir_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_readdir_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_readdir_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_rewinddir Tests */ - ADD_TEST(Test_OS_rewinddir_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rewinddir_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_rmdir Tests */ - ADD_TEST(Test_OS_rmdir_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rmdir_PathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rmdir_PathMaxValid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rmdir_TransPathError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rmdir_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_rmdir_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_check_name_length Tests */ - ADD_TEST(Test_OS_check_name_length_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_check_name_length_PathTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_check_name_length_NoPathSep, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_check_name_length_NameTooLong, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_check_name_length_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_ShellOutputToFile Tests */ - ADD_TEST(Test_OS_ShellOutputToFile_NullCmd, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_ShellOutputToFile_FdNeg, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_ShellOutputToFile_FdTooLarge, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_ShellOutputToFile_FdInvalid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_ShellOutputToFile_CmdFileCreateError, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_ShellOutputToFile_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_ShellOutputToFile_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_FDGetInfo Tests */ - ADD_TEST(Test_OS_FDGetInfo_NullFdEntry, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_FDGetInfo_FdNeg, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_FDGetInfo_FdTooLarge, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_FDGetInfo_FdInvalid, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_FDGetInfo_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_FileOpenCheck Tests */ - ADD_TEST(Test_OS_FileOpenCheck_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_FileOpenCheck_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_FileOpenCheck_Success, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_CloseFileByName Tests */ - ADD_TEST(Test_OS_CloseFileByName_NullPath, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_CloseFileByName_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_CloseFileByName_Success, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_CloseFileByName_InvalidPath, OsFileApi_Setup, OsFileApi_TearDown); - - /* OS_CloseAllFiles Tests */ - ADD_TEST(Test_OS_CloseAllFiles_Error, OsFileApi_Setup, OsFileApi_TearDown); - ADD_TEST(Test_OS_CloseAllFiles_Success, OsFileApi_Setup, OsFileApi_TearDown); -} - - - - diff --git a/src/unit-test-coverage/vxworks6/osfilesys-test/CMakeLists.txt b/src/unit-test-coverage/vxworks6/osfilesys-test/CMakeLists.txt deleted file mode 100644 index 25c35202f..000000000 --- a/src/unit-test-coverage/vxworks6/osfilesys-test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} TESTCASE_FILES) -add_executable(osfilesys-test ${TESTCASE_FILES}) -set_target_properties(osfilesys-test PROPERTIES LINK_FLAGS "${UT_C_FLAGS}") -target_link_libraries(osfilesys-test ut_osal_osfilesys ${OSALCOVERAGE_LINK_LIBRARIES}) diff --git a/src/unit-test-coverage/vxworks6/osfilesys-test/Makefile b/src/unit-test-coverage/vxworks6/osfilesys-test/Makefile deleted file mode 100644 index 225dcc2ba..000000000 --- a/src/unit-test-coverage/vxworks6/osfilesys-test/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -############################################################################## -## GNU Makefile for building UT unit tests in a Linux environment for easy -## debug and code coverage - -# -# Supported MAKEFILE targets: -# clean - deletes object files, executables, output files, and gcov files -# all - makes utf_test_runner.exe -# run - runs utf_test_runner.exe -# gcov - prints a GCOV coverage report (make all, make run, make gcov) -# -# GCOV is disabled by default. If you are using the source level debugger you will want to -# disable GCOV. To enable GCOV you can override the ENABLE_GCOV variable on the command line -# by setting it to TRUE. For example "make ENABLE_GCOV=TRUE". -# - -APP=osfilesys - -OSAL ?= $(CFS_HOME)/osal - -# -# INCLUDES specifies the search paths for include files outside of the current directory. -# Note that the -I is required. -# -INCLUDES += -I../ut-stubs/inc -INCLUDES += -I$(OSAL)/ut_assert/inc -INCLUDES += -I$(OSAL)/src/os/inc -INCLUDES += -I$(OSAL)/build/inc - -# -# UT_OBJS specifies unit test object files. -# -UT_OBJS += $(APP)_testcase.o -UT_OBJS += $(APP)_stubs.o - - - -############################################################################### - -COMPILER=gcc -LINKER=gcc - -# -# Compiler and Linker Options -# -ENABLE_GCOV = TRUE -ifeq ($(ENABLE_GCOV), TRUE) -GCOV_COPT = --coverage -GCOV_LOPT = --coverage -endif - -#WARNINGS = -Wall -W -ansi -Werror -Wstrict-prototypes -Wundef -WARNINGS = -Wall -Wstrict-prototypes -DEBUGGER = -g - -#COPT = $(WARNINGS) $(DEBUGGER) $(GCOV_COPT) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D__x86_64__ -D_LINUX_OS_ -COPT = $(WARNINGS) $(DEBUGGER) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D_ix86_ $(OSAL_M32) - -LOPT = $(OSAL_M32) - -############################################################################### -## "C" COMPILER RULE -## -%.o: %.c - $(COMPILER) -c $(COPT) $(INCLUDES) $< - -############################################################################## -## - -all:$(APP)_testrunner.exe - -$(APP)_testrunner.exe: $(UT_OBJS) - $(LINKER) $(GCOV_LOPT) $(LOPT) -o $@ $^ ../ut-osal/osfilesys.o ../testrunner.o - -clean :: - rm -f *.o *.exe *.gcda *.gcno *.gcov gmon.out $(APP)_log.txt - -run :: - ./$(APP)_testrunner.exe | tee ./$(APP)_log.txt - -# end of file - diff --git a/src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_stubs.c b/src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_stubs.c deleted file mode 100644 index 203ec9b6d..000000000 --- a/src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_stubs.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - * File: osfilesys_stubs.c - * - * Purpose: - * Stub out various functions not stubbed out by the UT-Assert code - * - * Modification History: - * 07/14/2015 Alan Asp, Odyssey Space Research, LLC - * * Created - * - */ - -#include - -#include "osfilesys_stubs.h" - - - -OsFileSys_HookTable_t OsFileSys_HookTable; -OsFileSys_ReturnCodeTable_t OsFileSys_ReturnCodeTable[OSFILESYS_MAX_INDEX]; - - -/* Utility variables */ -static uint32 nSemTake = 0; -static uint32 nSemGive = 0; -static uint32 nCloseCalls = 0; -static uint32 nOpenCalls = 0; - - -void OsFileSys_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt) -{ - if (Index < OSFILESYS_MAX_INDEX) { - OsFileSys_ReturnCodeTable[Index].Value = RtnVal; - OsFileSys_ReturnCodeTable[Index].Count = CallCnt; - } - else { - printf("Unsupported Index In SetReturnCode Call %lu\n", (unsigned long)Index); - } -} - - -boolean OsFileSys_UseReturnCode(uint32 Index) -{ - if (OsFileSys_ReturnCodeTable[Index].Count > 0) { - OsFileSys_ReturnCodeTable[Index].Count--; - if (OsFileSys_ReturnCodeTable[Index].Count == 0) - return(TRUE); - } - - return(FALSE); -} - - -void OsFileSys_SetFunctionHook(uint32 Index, void *FunPtr) -{ - if (Index == OSFILESYS_OPEN_INDEX) { OsFileSys_HookTable.open = FunPtr; } - else - { - printf("Unsupported OsFileSys Index In SetFunctionHook Call %lu\n", (unsigned long)Index); - } -} - - -void OsFileSys_Reset(void) -{ - memset(&OsFileSys_HookTable, 0, sizeof(OsFileSys_HookTable)); - memset(&OsFileSys_ReturnCodeTable, 0, sizeof(OsFileSys_ReturnCodeTable)); - memset(&OS_FDTable, 0, sizeof(OS_FDTable)); - - nSemTake = 0; - nSemGive = 0; - nCloseCalls = 0; - nOpenCalls = 0; -} - -/* Utilities */ -uint32 getNSemTake() -{ - return nSemTake; -} - -uint32 getNSemGive() -{ - return nSemGive; -} - - -uint32 getNCloseCalls() -{ - return nCloseCalls; -} - -uint32 getNOpenCalls() -{ - return nOpenCalls; -} - - -/* Stubbed functions */ -size_t VCS_strlen(const char *str) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_STRLEN_INDEX)) - return (size_t)OsFileSys_ReturnCodeTable[OSFILESYS_STRLEN_INDEX].Value; - - return strlen(str); -} - -int VCS_strcmp(const char *str1, const char *str2) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_STRCMP_INDEX)) - return (int)OsFileSys_ReturnCodeTable[OSFILESYS_STRCMP_INDEX].Value; - - return strcmp(str1, str2); -} - -int VCS_strncmp(const char *str1, const char *str2, size_t n) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_STRNCMP_INDEX)) - return (int)OsFileSys_ReturnCodeTable[OSFILESYS_STRNCMP_INDEX].Value; - - return strncmp(str1, str2, n); -} - -char *VCS_strcpy(char *str1, const char *str2) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_STRCPY_INDEX)) - return (char *)OsFileSys_ReturnCodeTable[OSFILESYS_STRCPY_INDEX].Value; - - return strcpy(str1, str2); -} - -char *VCS_strncpy(char *str1, const char *str2, size_t n) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_STRNCPY_INDEX)) - return (char *)OsFileSys_ReturnCodeTable[OSFILESYS_STRNCPY_INDEX].Value; - - return strncpy(str1, str2, n); -} - - -int VCS_ioctl (int fd, int function, ...) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_IOCTL_INDEX)) - return OsFileSys_ReturnCodeTable[OSFILESYS_IOCTL_INDEX].Value; - - return 0; -} - - -int VCS_open (const char *filename, int flags, ...) -{ - nOpenCalls++; - - if (OsFileSys_UseReturnCode(OSFILESYS_OPEN_INDEX)) - { - return (int)OsFileSys_ReturnCodeTable[OSFILESYS_OPEN_INDEX].Value; - } - - return 0; //open(filename, flags, mode); -} - -VCS_STATUS VCS_close (int fd) -{ - nCloseCalls++; - - if (OsFileSys_UseReturnCode(OSFILESYS_CLOSE_INDEX)) - return (VCS_STATUS)OsFileSys_ReturnCodeTable[OSFILESYS_CLOSE_INDEX].Value; - - return VCS_OK; //close(fd); -} - - -VCS_STATUS VCS_semTake(VCS_SEM_ID semId, int timeout) -{ - nSemTake += 1; - - return nSemTake; -} - - -VCS_STATUS VCS_semGive(VCS_SEM_ID semId) -{ - nSemGive += 1; - - return nSemGive; -} - - -VCS_BLK_DEV *VCS_ataDevCreate(int ctrl, int drive, unsigned int nBlocks, unsigned int blkOffset) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_ATADEVCREATE_INDEX)) - return (VCS_BLK_DEV *)OsFileSys_ReturnCodeTable[OSFILESYS_ATADEVCREATE_INDEX].Value; - - return (VCS_BLK_DEV *)1; -} - -VCS_STATUS VCS_dosFsVolFormat(char *path, int opt, VCS_FUNCPTR pPromptFunc) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_DOSFSVOLFORMAT_INDEX)) - return (VCS_STATUS)OsFileSys_ReturnCodeTable[OSFILESYS_DOSFSVOLFORMAT_INDEX].Value; - - return VCS_OK; -} - -int VCS_statfs(char *_name, struct VCS_statfs *_pStat) -{ - if (_pStat != NULL) - { - _pStat->f_bfree = 50; - _pStat->f_bsize = 4; - } - - if (OsFileSys_UseReturnCode(OSFILESYS_STATFS_INDEX)) - return OsFileSys_ReturnCodeTable[OSFILESYS_STATFS_INDEX].Value; - - return VCS_OK; -} - -VCS_BLK_DEV *VCS_ramDevCreate (char *ramAddr, int bytesPerSec, int secPerTrack, - int nSectors, int secOffset) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_RAMDEVCREATE_INDEX)) - return (VCS_BLK_DEV *)OsFileSys_ReturnCodeTable[OSFILESYS_RAMDEVCREATE_INDEX].Value; - - return (VCS_BLK_DEV *)1; -} - - -VCS_device_t VCS_xbdBlkDevCreateSync (VCS_BLK_DEV *bd, const char *name) -{ - if (OsFileSys_UseReturnCode(OSFILESYS_XBDBLKDEVCREATESYNC_INDEX)) - return (VCS_device_t)OsFileSys_ReturnCodeTable[OSFILESYS_XBDBLKDEVCREATESYNC_INDEX].Value; - - return (VCS_device_t)1; -} - -void VCS_memset(void *ptr, int c, unsigned int size) -{ - memset(ptr, c, size); -} - -int VCS_snprintf(char *buf, unsigned int sz, const char *format, ...) -{ - va_list va; - int ret; - - va_start(va, format); - ret = vsnprintf(buf, sz, format, va); - va_end(va); - - return ret; -} - -char *VCS_strcat(char *dest, const char *src) -{ - return (strcat(dest, src)); -} - -char *VCS_strncat(char *dest, const char *src, unsigned int size) -{ - return (strncat(dest, src, size)); -} - - - - diff --git a/src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_stubs.h b/src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_stubs.h deleted file mode 100644 index 1b41a5992..000000000 --- a/src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_stubs.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * File: osfilesys_stubs.h - * - * Purpose: - * Provide stubs for unit testing - * - * History: - * 05/28/2015 A. Asp, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSFILESYS_STUBS_H_ -#define _OSFILESYS_STUBS_H_ - -#include "osapi.h" /* cfe.h not available from within osal. */ -#include "uttools.h" -#include "vxworks6-coverage-stubs.h" - - -/* Global table from osfileapi.c */ -OS_FDTableEntry OS_FDTable[OS_MAX_NUM_OPEN_FILES]; -/* Global table from cfe_psp_voltab.c */ -OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES]; - - -/* Define missing types */ -typedef enum -{ - OSFILESYS_STRLEN_INDEX, - OSFILESYS_STRCMP_INDEX, - OSFILESYS_STRNCMP_INDEX, - OSFILESYS_STRCPY_INDEX, - OSFILESYS_STRNCPY_INDEX, - OSFILESYS_SNPRINTF_INDEX, - OSFILESYS_STATFS_INDEX, - OSFILESYS_CLOSE_INDEX, - OSFILESYS_IOCTL_INDEX, - OSFILESYS_OPEN_INDEX, - OSFILESYS_ATADEVCREATE_INDEX, - OSFILESYS_DOSFSVOLFORMAT_INDEX, - OSFILESYS_RAMDEVCREATE_INDEX, - OSFILESYS_XBDBLKDEVCREATESYNC_INDEX, - OSFILESYS_MAX_INDEX -} OsFileSys_Index_t; - -typedef struct -{ - int32 Value; - uint32 Count; -} OsFileSys_ReturnCodeTable_t; - -typedef struct -{ - int (*open) (const char *filename, int flags, int mode); - -} OsFileSys_HookTable_t; - - -void OsFileSys_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt); -void OsFileSys_SetFunctionHook(uint32 Index, void *FunPtr); -void OsFileSys_Reset(void); - -/* Test utilities */ -uint32 getNSemTake(void); -uint32 getNSemGive(void); -uint32 getNCloseCalls(void); -uint32 getNOpenCalls(void); - -#endif diff --git a/src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_testcase.c b/src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_testcase.c deleted file mode 100644 index d6d642a2c..000000000 --- a/src/unit-test-coverage/vxworks6/osfilesys-test/osfilesys_testcase.c +++ /dev/null @@ -1,2483 +0,0 @@ -/* - * Filename: osfilesys_testcase.c - * - * Purpose: This file contains unit test cases - * - * Modification History: - * 07/14/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include /* for O_WRONLY etc. */ - -#include "osapi.h" /* cfe.h not available from within osal. */ - -#include "utassert.h" -#include "uttest.h" -#include "utlist.h" - -#include "osfilesys_stubs.h" - - - -/* Prototypes for non-exported functions */ -int32 OS_FS_GetErrorName(int32 error_num, os_fs_err_name_t * err_name); -int32 OS_GetPhysDeviceName(char *PhysDevName, char *LocalVolname); - - -/* -------------------- Special Test Case Variables ------------------------- */ -static char testName[] = "/testDev/testName"; -static char testMaxVolName[OS_FS_VOL_NAME_LEN]; -static char testMaxPhysName[OS_FS_PHYS_NAME_LEN]; -static char testMaxPathName[OS_MAX_LOCAL_PATH_LEN]; -static char *charPtr; - - -/* Utility functions */ -/* -------------------------------------------------------------------------- */ -int open_hook_RtnError (const char *filename, int flags, int mode) -{ - return VCS_ERROR; -} - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_mkfs Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_NullDevName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_mkfs(charPtr, NULL, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_NullVolName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, NULL, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_DevNameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_FS_DEV_NAME_LEN, 1); - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_VolNameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_FS_DEV_NAME_LEN, 2); - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_NoFreeDev(void) -{ - int32 expected = OS_FS_ERR_DEVICE_NOT_FREE; - int32 actual = 99; - - /* Setup Inputs */ - OS_VolumeTable[0].FreeFlag = TRUE; /* for full branch coverage */ - OS_VolumeTable[0].IsMounted = FALSE; - OS_VolumeTable[1].FreeFlag = TRUE; - OS_VolumeTable[0].IsMounted = TRUE; - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DEVICE_NOT_FREE"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_Error(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = EEPROM_DISK; - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_RamDevCreateNull(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 1; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = RAM_DISK; - - OsFileSys_SetReturnCode(OSFILESYS_RAMDEVCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_RamBlkCreateSyncNull(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 2; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = RAM_DISK; - - OsFileSys_SetReturnCode(OSFILESYS_XBDBLKDEVCREATESYNC_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_RamVolFmtError(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 3; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = RAM_DISK; - - OsFileSys_SetReturnCode(OSFILESYS_DOSFSVOLFORMAT_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_RamDiskSuccess(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - static char phyDevName[OS_FS_PHYS_NAME_LEN]; - - /* Setup Inputs */ - uint32 idx = 0; - uint32 blocksize = 30; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = RAM_DISK; - - strcpy(phyDevName, testMaxVolName); - strcat(phyDevName, ":0"); - - /* Execute Test */ - actual = OS_mkfs(testName, testName, testMaxVolName, blocksize, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == FALSE, "FreeFlag == expected"); - UtAssert_StrCmp(OS_VolumeTable[idx].DeviceName, testName, "DeviceName == expected"); - UtAssert_True(OS_VolumeTable[idx].BlockSize == blocksize, "blocksize == expected"); - UtAssert_StrCmp(OS_VolumeTable[idx].PhysDevName, phyDevName, "PhysDevName == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_FsBasedSuccess(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 0; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = FS_BASED; - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -#ifdef USE_VXWORKS_ATA_DRIVER -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_AtaDevCreateNull(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 1; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = ATA_DISK; - - OsFileSys_SetReturnCode(OSFILESYS_ATADEVCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_AtaBlkCreateSyncNull(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 2; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = ATA_DISK; - - OsFileSys_SetReturnCode(OSFILESYS_XBDBLKDEVCREATESYNC_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_AtaPhysDevNameError(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 3; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = ATA_DISK; - - /* open used in OS_GetPhysDeviceName */ - OsFileSys_SetFunctionHook(OSFILESYS_OPEN_INDEX, open_hook_RtnError); - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_AtaVolFmtError(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 4; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = ATA_DISK; - - /* open used in OS_GetPhysDeviceName */ - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_DOSFSVOLFORMAT_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_mkfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mkfs_AtaSuccess(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - static char phyDevName[OS_FS_PHYS_NAME_LEN]; - - /* Setup Inputs */ - uint32 idx = 5; - uint32 blocksize = 30; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = ATA_DISK; - - strcpy(phyDevName, testName); - strcat(phyDevName, ":0"); - - /* open used in OS_GetPhysDeviceName */ - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_DOSFSVOLFORMAT_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_mkfs(charPtr, testName, charPtr, blocksize, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == FALSE, "FreeFlag == expected"); - UtAssert_StrCmp(OS_VolumeTable[idx].DeviceName, testName, "DeviceName == expected"); - UtAssert_True(OS_VolumeTable[idx].BlockSize == blocksize, "blocksize == expected"); - UtAssert_StrCmp(OS_VolumeTable[idx].PhysDevName, phyDevName, "PhysDevName == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -#endif - -/******************************************************************************* -** -** OS_rmfs Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_rmfs_NullDevName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_rmfs(NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rmfs_DevNameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_FS_DEV_NAME_LEN, 1); - - /* Execute Test */ - actual = OS_rmfs(charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rmfs_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_rmfs(charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_rmfs_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - - OS_VolumeTable[0].FreeFlag = FALSE; /* for full test branch coverage */ - OS_VolumeTable[0].IsMounted = FALSE; - OS_VolumeTable[1].FreeFlag = FALSE; - OS_VolumeTable[1].IsMounted = TRUE; - strcpy(OS_VolumeTable[1].DeviceName, testName); - OS_VolumeTable[2].FreeFlag = TRUE; - OS_VolumeTable[2].IsMounted = FALSE; - strcpy(OS_VolumeTable[2].DeviceName, testName); - - - /* Execute Test */ - actual = OS_rmfs(testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_initfs Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_NullDevName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_initfs(charPtr, NULL, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_NullVolName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, NULL, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_DevNameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_FS_DEV_NAME_LEN, 1); - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_VolNameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_FS_DEV_NAME_LEN, 2); - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_NoFreeDev(void) -{ - int32 expected = OS_FS_ERR_DEVICE_NOT_FREE; - int32 actual = 99; - - /* Setup Inputs */ - OS_VolumeTable[0].FreeFlag = TRUE; /* for full branch coverage */ - OS_VolumeTable[0].IsMounted = FALSE; - OS_VolumeTable[1].FreeFlag = TRUE; - OS_VolumeTable[0].IsMounted = TRUE; - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DEVICE_NOT_FREE"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_Error(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = EEPROM_DISK; - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_RamDevCreateNull(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 1; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = RAM_DISK; - - OsFileSys_SetReturnCode(OSFILESYS_RAMDEVCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_RamBlkCreateSyncNull(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 2; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = RAM_DISK; - - OsFileSys_SetReturnCode(OSFILESYS_XBDBLKDEVCREATESYNC_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_RamDiskSuccess(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - static char phyDevName[OS_FS_PHYS_NAME_LEN]; - - /* Setup Inputs */ - uint32 idx = 0; - uint32 blocksize = 30; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = RAM_DISK; - - strcpy(phyDevName, testMaxVolName); - strcat(phyDevName, ":0"); - - /* Execute Test */ - actual = OS_initfs(testName, testName, testMaxVolName, blocksize, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == FALSE, "FreeFlag == expected"); - UtAssert_StrCmp(OS_VolumeTable[idx].DeviceName, testName, "DeviceName == expected"); - UtAssert_True(OS_VolumeTable[idx].BlockSize == blocksize, "blocksize == expected"); - UtAssert_StrCmp(OS_VolumeTable[idx].PhysDevName, phyDevName, "PhysDevName == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_FsBasedSuccess(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 0; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = FS_BASED; - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -#ifdef USE_VXWORKS_ATA_DRIVER -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_AtaDevCreateNull(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 1; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = ATA_DISK; - - OsFileSys_SetReturnCode(OSFILESYS_ATADEVCREATE_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_AtaBlkCreateSyncNull(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 2; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = ATA_DISK; - - OsFileSys_SetReturnCode(OSFILESYS_XBDBLKDEVCREATESYNC_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_AtaPhysDevNameError(void) -{ - int32 expected = OS_FS_ERR_DRIVE_NOT_CREATED; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 3; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = ATA_DISK; - - /* open used in OS_GetPhysDeviceName */ - OsFileSys_SetFunctionHook(OSFILESYS_OPEN_INDEX, open_hook_RtnError); - - /* Execute Test */ - actual = OS_initfs(charPtr, charPtr, charPtr, 1, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_DRIVE_NOT_CREATED"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == TRUE, "FreeFlag == TRUE on VCS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_initfs_AtaSuccess(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - static char phyDevName[OS_FS_PHYS_NAME_LEN]; - - /* Setup Inputs */ - uint32 idx = 5; - uint32 blocksize = 30; - OS_VolumeTable[idx].FreeFlag = TRUE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, testName); - OS_VolumeTable[idx].VolumeType = ATA_DISK; - - strcpy(phyDevName, testName); - strcat(phyDevName, ":0"); - - /* open used in OS_GetPhysDeviceName */ - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_DOSFSVOLFORMAT_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_initfs(charPtr, testName, charPtr, blocksize, 1); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(OS_VolumeTable[idx].FreeFlag == FALSE, "FreeFlag == expected"); - UtAssert_StrCmp(OS_VolumeTable[idx].DeviceName, testName, "DeviceName == expected"); - UtAssert_True(OS_VolumeTable[idx].BlockSize == blocksize, "blocksize == expected"); - UtAssert_StrCmp(OS_VolumeTable[idx].PhysDevName, phyDevName, "PhysDevName == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -#endif - - -/******************************************************************************* -** -** OS_mount Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_mount_NullDevName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_mount(NULL, charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mount_NullMount(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_mount(charPtr, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mount_DevNameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_FS_DEV_NAME_LEN, 1); - - /* Execute Test */ - actual = OS_mount(charPtr, charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mount_MountTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_MAX_PATH_LEN, 2); - - /* Execute Test */ - actual = OS_mount(charPtr, charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mount_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_mount(charPtr, charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_mount_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 4; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].DeviceName, charPtr); - - /* for full branch coverage */ - OS_VolumeTable[0].FreeFlag = FALSE; - OS_VolumeTable[0].IsMounted = FALSE; - OS_VolumeTable[1].FreeFlag = FALSE; - OS_VolumeTable[1].IsMounted = TRUE; - OS_VolumeTable[2].FreeFlag = TRUE; - - /* Execute Test */ - actual = OS_mount(charPtr, charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_StrCmp(OS_VolumeTable[idx].MountPoint, charPtr, "MountPoint == expected"); - UtAssert_True(OS_VolumeTable[idx].IsMounted == TRUE, "IsMounted == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_unmount Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_unmount_NullMount(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_unmount(NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_unmount_MountTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_unmount(charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_unmount_MountNotFound(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_unmount(charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_unmount_OpenError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_unmount(testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_unmount_IoctlError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_IOCTL_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_unmount(testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_unmount_BadMountpoint(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - - /* OS_TranslatePath() assumes the mountpoint starts with "/", so - * let's clobber that and make it fail in OS_unmount() */ - const char tempName[] = "noSlashInPathName"; - - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - - /* for full branch coverage */ - OS_VolumeTable[0].FreeFlag = FALSE; - OS_VolumeTable[0].IsMounted = TRUE; - OS_VolumeTable[1].FreeFlag = FALSE; - OS_VolumeTable[1].IsMounted = FALSE; - OS_VolumeTable[3].FreeFlag = TRUE; - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, VCS_ERROR, 1); - OsFileSys_SetReturnCode(OSFILESYS_IOCTL_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_unmount(tempName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_unmount_AlreadyUnmounted(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = FALSE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - - /* for full branch coverage */ - OS_VolumeTable[0].FreeFlag = FALSE; - OS_VolumeTable[0].IsMounted = TRUE; - OS_VolumeTable[1].FreeFlag = FALSE; - OS_VolumeTable[1].IsMounted = FALSE; - OS_VolumeTable[3].FreeFlag = TRUE; - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, VCS_ERROR, 1); - OsFileSys_SetReturnCode(OSFILESYS_IOCTL_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_unmount(testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_unmount_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - - /* for full branch coverage */ - OS_VolumeTable[0].FreeFlag = FALSE; - OS_VolumeTable[0].IsMounted = TRUE; - OS_VolumeTable[1].FreeFlag = FALSE; - OS_VolumeTable[1].IsMounted = FALSE; - OS_VolumeTable[3].FreeFlag = TRUE; - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, VCS_ERROR, 1); - OsFileSys_SetReturnCode(OSFILESYS_IOCTL_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_unmount(testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_fsBlocksFree Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBlocksFree_NullName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_fsBlocksFree(NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBlocksFree_NameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_fsBlocksFree(testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBlocksFree_NameNotFound(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_fsBlocksFree(testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBlocksFree_NameError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - const char tempName[] = "noSlashInPathName"; - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, tempName); - - /* Execute Test */ - actual = OS_fsBlocksFree(tempName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBlocksFree_StatfsError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 7; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - - OsFileSys_SetReturnCode(OSFILESYS_STATFS_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_fsBlocksFree(testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBlocksFree_StatfsSuccess(void) -{ - int32 expected = 50; /* in stub, f_bfree set to 50, f_bsize set to 4 */ - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 9; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - - /* for full branch coverage */ - OS_VolumeTable[0].FreeFlag = FALSE; - OS_VolumeTable[0].IsMounted = TRUE; - OS_VolumeTable[1].FreeFlag = FALSE; - OS_VolumeTable[1].IsMounted = FALSE; - OS_VolumeTable[1].FreeFlag = TRUE; - - OsFileSys_SetReturnCode(OSFILESYS_STATFS_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_fsBlocksFree(testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_fsBytesFree Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBytesFree_NullName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - uint64 bytes_free = 88; - - /* Execute Test */ - actual = OS_fsBytesFree(NULL, &bytes_free); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBytesFree_NullBytePtr(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_fsBytesFree(testName, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBytesFree_NameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - uint64 bytes_free = 88; - - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_fsBytesFree(testName, &bytes_free); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBytesFree_NameNotFound(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint64 bytes_free = 88; - - /* Execute Test */ - actual = OS_fsBytesFree(testName, &bytes_free); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBytesFree_NameError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint64 bytes_free = 88; - const char tempName[] = "noSlashInPathName"; - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, tempName); - - /* Execute Test */ - actual = OS_fsBytesFree(tempName, &bytes_free); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBytesFree_StatfsError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint64 bytes_free = 88; - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - - OsFileSys_SetReturnCode(OSFILESYS_STATFS_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_fsBytesFree(testName, &bytes_free); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_fsBytesFree_StatfsSuccess(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint64 bytes_free = 88; - uint32 idx = 5; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - - /* for full branch coverage */ - OS_VolumeTable[0].FreeFlag = FALSE; - OS_VolumeTable[0].IsMounted = TRUE; - OS_VolumeTable[1].FreeFlag = FALSE; - OS_VolumeTable[1].IsMounted = FALSE; - OS_VolumeTable[2].FreeFlag = TRUE; - - OsFileSys_SetReturnCode(OSFILESYS_STATFS_INDEX, 0, 1); - - /* Execute Test */ - actual = OS_fsBytesFree(testName, &bytes_free); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_True(bytes_free == 50*4, "bytes_free == expected"); /* stub values 50 and 4 */ - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_chkfs Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_chkfs_NullName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - boolean repair = FALSE; - - /* Execute Test */ - actual = OS_chkfs(NULL, repair); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_chkfs_NameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - boolean repair = FALSE; - - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_chkfs(testName, repair); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_chkfs_OpenError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - boolean repair = FALSE; - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_chkfs(testName, repair); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_chkfs_RepairError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - boolean repair = TRUE; - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_IOCTL_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_chkfs(testName, repair); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNOpenCalls() == getNCloseCalls(), "Calls to open == Calls to close"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_chkfs_RepairSuccess(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - boolean repair = TRUE; - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_IOCTL_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_chkfs(testName, repair); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNOpenCalls() == getNCloseCalls(), "Calls to open == Calls to close"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_chkfs_CheckOnlyError(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - boolean repair = FALSE; - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_IOCTL_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - actual = OS_chkfs(testName, repair); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNOpenCalls() == getNCloseCalls(), "Calls to open == Calls to close"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_chkfs_CheckOnlyBadName(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - boolean repair = FALSE; - - /* OS_TranslatePath() assumes the mountpoint starts with "/", so - * let's clobber that and make it fail in OS_unmount() */ - const char tempName[] = "noSlashInPathName"; - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_IOCTL_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_chkfs(tempName, repair); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNOpenCalls() == getNCloseCalls(), "Calls to open == Calls to close"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_chkfs_CheckOnlySuccess(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - OS_VolumeTable[idx].IsMounted = TRUE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - boolean repair = FALSE; - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_IOCTL_INDEX, VCS_OK, 1); - - /* Execute Test */ - actual = OS_chkfs(testName, repair); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(getNOpenCalls() == getNCloseCalls(), "Calls to open == Calls to close"); -} - - -/******************************************************************************* -** -** OS_FS_GetPhysDriveName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetPhysDriveName_NullName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_FS_GetPhysDriveName(NULL, testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetPhysDriveName_NullMount(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_FS_GetPhysDriveName(testName, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetPhysDriveName_NameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_FS_DEV_NAME_LEN, 1); - - /* Execute Test */ - actual = OS_FS_GetPhysDriveName(testName, testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetPhysDriveName_MountTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_MAX_PATH_LEN, 2); - - /* Execute Test */ - actual = OS_FS_GetPhysDriveName(testName, testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetPhysDriveName_MountNotFound(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_FS_GetPhysDriveName(testName, testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetPhysDriveName_Success(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = NUM_TABLE_ENTRIES - 1; - char physDevName[] = "testPhysDevName"; - strcpy(OS_VolumeTable[idx].PhysDevName, physDevName); - OS_VolumeTable[idx].FreeFlag = FALSE; - strcpy(OS_VolumeTable[idx].MountPoint, testName); - memset(testMaxPhysName, 0, sizeof(testMaxPhysName)); - - /* for full branch coverage */ - OS_VolumeTable[0].FreeFlag = FALSE; - OS_VolumeTable[1].FreeFlag = TRUE; - - /* Execute Test */ /* Note: 1st arg must point to a large enough char array */ - actual = OS_FS_GetPhysDriveName(testMaxPhysName, testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_SUCCESS"); - UtAssert_StrCmp(testMaxPhysName, OS_VolumeTable[idx].PhysDevName, "PhysDriveName == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_TranslatePath Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TranslatePath_NullVirtualName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_TranslatePath(NULL, testMaxPathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TranslatePath_NullLocalName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_TranslatePath(testMaxPathName, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TranslatePath_VirtualNameTooLong(void) -{ - int32 expected = OS_FS_ERR_PATH_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetReturnCode(OSFILESYS_STRLEN_INDEX, OS_MAX_PATH_LEN, 1); - - /* Execute Test */ - actual = OS_TranslatePath(testName, testMaxPathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TranslatePath_MissingFirstDelim(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - static char missingStartChar[] = "missingStartChar"; - - /* Execute Test */ - actual = OS_TranslatePath(missingStartChar, testMaxPathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TranslatePath_InvalidPath(void) -{ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = 99; - - /* Setup Inputs */ - static char noName[OS_MAX_PATH_LEN]; - noName[0] = '/'; - - /* Execute Test */ - actual = OS_TranslatePath(noName, testMaxPathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_PATH_INVALID"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TranslatePath_MaxPath(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - uint32 idx = 0; - char mountPoint[] = "/"; - char devName[OS_MAX_PATH_LEN]; - char validName[OS_MAX_PATH_LEN]; - - memset(devName, 'a', OS_MAX_PATH_LEN); - devName[OS_MAX_PATH_LEN - 1] = '\0'; - memset(validName, 'b', OS_MAX_PATH_LEN); - validName[OS_MAX_PATH_LEN - 1] = '\0'; - strcpy(validName, mountPoint); - validName[sizeof(mountPoint) - 1] = '/'; /* filename will now be /bbb... */ - - OS_VolumeTable[idx].FreeFlag = FALSE; - strcpy(OS_VolumeTable[idx].MountPoint, mountPoint); - strcpy(OS_VolumeTable[idx].PhysDevName, devName); - - /* Execute Test */ - actual = OS_TranslatePath(validName, testMaxPathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(strlen(testMaxPathName) <= OS_MAX_LOCAL_PATH_LEN, "path length <= max"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/*----------------------------------------------------------------------------*/ -void Test_OS_TranslatePath_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - char validName[] = "/mountPoint/arbitrary/File/Name/"; - uint32 idx = NUM_TABLE_ENTRIES - 1; - OS_VolumeTable[idx].FreeFlag = FALSE; - strcpy(OS_VolumeTable[idx].MountPoint, "/mountPoint"); - strcpy(OS_VolumeTable[idx].PhysDevName, "physDevName"); - - /* Execute Test */ - actual = OS_TranslatePath(validName, testMaxPathName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_StrCmp("physDevName/arbitrary/File/Name/", testMaxPathName, - "translated path == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/******************************************************************************* -** -** OS_FS_GetErrorName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_NullName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_SUCCESS; - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_SUCCESS; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_SUCCESS", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_Error(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_ERROR; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_ERROR", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_InvalidPtr(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_ERR_INVALID_POINTER; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_ERR_INVALID_POINTER", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_PathTooLong(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_ERR_PATH_TOO_LONG; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_ERR_PATH_TOO_LONG", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_NameTooLong(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_ERR_NAME_TOO_LONG; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_ERR_NAME_TOO_LONG", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_Unimplemented(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_UNIMPLEMENTED; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_UNIMPLEMENTED", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_DriveNotCreated(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_ERR_DRIVE_NOT_CREATED; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_ERR_DRIVE_NOT_CREATED", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_DeviceNotFree(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_ERR_DEVICE_NOT_FREE; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_ERR_DEVICE_NOT_FREE", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_PathInvalid(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_ERR_PATH_INVALID; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_ERR_PATH_INVALID", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_NoFreeFds(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_ERR_NO_FREE_FDS; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_ERR_NO_FREE_FDS", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_InvalidFd(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = OS_FS_ERR_INVALID_FD; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "OS_FS_ERR_INVALID_FD", "err_name == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_FS_GetErrorName_Unknown(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - int32 error_num = 111; - static os_fs_err_name_t err_name; - - - /* Execute Test */ - actual = OS_FS_GetErrorName(error_num, &err_name); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == expected"); - UtAssert_StrCmp(err_name, "ERROR_UNKNOWN", "err_name == expected"); -} - - -/******************************************************************************* -** -** OS_GetPhysDeviceName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_GetPhysDeviceName_NullDevName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_GetPhysDeviceName(NULL, testName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetPhysDeviceName_NullVolName(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_GetPhysDeviceName(testName, NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetPhysDeviceName_VolNameTooLong(void) -{ - int32 expected = OS_FS_ERR_NAME_TOO_LONG; - int32 actual = 99; - - /* Setup Inputs */ - static char maxVolName[OS_FS_VOL_NAME_LEN + 1]; - memset(maxVolName, 'a', OS_FS_VOL_NAME_LEN); - - /* Execute Test */ - actual = OS_GetPhysDeviceName(testName, maxVolName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_NAME_TOO_LONG"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetPhysDeviceName_MaxVolName(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - static char expectedName[OS_FS_PHYS_NAME_LEN]; - static char maxVolName[OS_FS_VOL_NAME_LEN]; - memset(maxVolName, 'a', sizeof(maxVolName) - 1); - strncpy(expectedName, maxVolName, sizeof(maxVolName) - 1); - strcat(expectedName, ":0"); /* add device number */ - memset(testMaxPhysName, 0, sizeof(testMaxPhysName)); - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - - /* Execute Test */ - actual = OS_GetPhysDeviceName(testMaxPhysName, maxVolName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_StrCmp(testMaxPhysName, expectedName, "PhysDevName == expected"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetPhysDeviceName_Error(void) -{ - int32 expected = OS_FS_ERROR; - int32 actual = 99; - - /* Setup Inputs */ - OsFileSys_SetFunctionHook(OSFILESYS_OPEN_INDEX, open_hook_RtnError); - - /* Execute Test */ - actual = OS_GetPhysDeviceName(testMaxPhysName, charPtr); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERROR"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetPhysDeviceName_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - char expectedName[OS_FS_PHYS_NAME_LEN]; - strcpy(testMaxVolName, "/successTestName"); - memset(testMaxPhysName, 0, sizeof(testMaxPhysName)); - strcpy(expectedName, testMaxVolName); - strcat(expectedName, ":0"); - - OsFileSys_SetReturnCode(OSFILESYS_OPEN_INDEX, 1, 1); - OsFileSys_SetReturnCode(OSFILESYS_CLOSE_INDEX, 1, 1); - - /* Execute Test */ - actual = OS_GetPhysDeviceName(testMaxPhysName, testMaxVolName); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_StrCmp(testMaxPhysName, expectedName, "PhysDevName == expected"); -} - - -/******************************************************************************* -** -** OS_GetFsInfo Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_GetFsInfo_NullPtr(void) -{ - int32 expected = OS_FS_ERR_INVALID_POINTER; - int32 actual = 99; - - /* Setup Inputs */ - - /* Execute Test */ - actual = OS_GetFsInfo(NULL); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_ERR_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_GetFsInfo_Success(void) -{ - int32 expected = OS_FS_SUCCESS; - int32 actual = 99; - - /* Setup Inputs */ - static os_fsinfo_t filesys_info; - OS_FDTable[0].IsValid = TRUE; /* verify the full range is checked */ - OS_VolumeTable[NUM_TABLE_ENTRIES - 1].FreeFlag = TRUE; - - /* Execute Test */ - actual = OS_GetFsInfo(&filesys_info); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "actual == OS_FS_SUCCESS"); - UtAssert_True(filesys_info.MaxFds == OS_MAX_NUM_OPEN_FILES, "MaxFds == expected"); - UtAssert_True(filesys_info.MaxVolumes == NUM_TABLE_ENTRIES, "MaxVolumes == expected"); - UtAssert_True(filesys_info.FreeFds == OS_MAX_NUM_OPEN_FILES - 1, "FreeFds == expected"); - UtAssert_True(filesys_info.FreeVolumes == 1, "FreeVolumes == expected"); - UtAssert_True(getNSemTake() > 0, "semTake called"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); -} - - -/* ------------------- End of test cases --------------------------------------*/ - - - - - -/* - * OsFileSys_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void OsFileSys_Setup(void) -{ - - OsFileSys_Reset(); - memset(OS_VolumeTable, 0, sizeof(OS_VolumeTable)); - memset(testMaxVolName, 'a', sizeof(testMaxVolName)); - testMaxVolName[OS_FS_VOL_NAME_LEN - 1] = '\0'; - - charPtr = testName; -} - - -/* - * OsFileSys_TearDown - * - * Purpose: - * Called by the unit test tool to tear down the app after each test - */ -void OsFileSys_TearDown(void) -{ - -} - - -#define ADD_TEST(test,setup,teardown) UtTest_Add((test), (setup), (teardown), #test) - -/* OsFileSys_AddTestCase - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void OS_Application_Startup(void) -{ - /* OS_mkfs Tests */ - ADD_TEST(Test_OS_mkfs_NullDevName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_NullVolName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_DevNameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_VolNameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_NoFreeDev, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_Error, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_RamDevCreateNull, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_RamBlkCreateSyncNull,OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_RamVolFmtError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_RamDiskSuccess, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_FsBasedSuccess, OsFileSys_Setup, OsFileSys_TearDown); -#ifdef USE_VXWORKS_ATA_DRIVER - ADD_TEST(Test_OS_mkfs_AtaDevCreateNull, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_AtaBlkCreateSyncNull,OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_AtaPhysDevNameError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_AtaVolFmtError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mkfs_AtaSuccess, OsFileSys_Setup, OsFileSys_TearDown); -#endif - - /* OS_rmfs Tests */ - ADD_TEST(Test_OS_rmfs_NullDevName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_rmfs_DevNameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_rmfs_Error, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_rmfs_Success, OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_initfs Tests */ - ADD_TEST(Test_OS_initfs_NullDevName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_NullVolName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_DevNameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_VolNameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_NoFreeDev, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_Error, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_RamDevCreateNull, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_RamBlkCreateSyncNull,OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_RamDiskSuccess, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_FsBasedSuccess, OsFileSys_Setup, OsFileSys_TearDown); -#ifdef USE_VXWORKS_ATA_DRIVER - ADD_TEST(Test_OS_initfs_AtaDevCreateNull, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_AtaBlkCreateSyncNull,OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_AtaPhysDevNameError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_initfs_AtaSuccess, OsFileSys_Setup, OsFileSys_TearDown); -#endif - - /* OS_mount Tests */ - ADD_TEST(Test_OS_mount_NullDevName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mount_NullMount, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mount_DevNameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mount_MountTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mount_Error, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_mount_Success, OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_unmount Tests */ - ADD_TEST(Test_OS_unmount_NullMount, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_unmount_MountTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_unmount_MountNotFound, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_unmount_OpenError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_unmount_IoctlError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_unmount_BadMountpoint, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_unmount_AlreadyUnmounted, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_unmount_Success, OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_fsBlocksFree Tests */ - ADD_TEST(Test_OS_fsBlocksFree_NullName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBlocksFree_NameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBlocksFree_NameNotFound, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBlocksFree_NameError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBlocksFree_StatfsError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBlocksFree_StatfsSuccess,OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_fsBytesFree Tests */ - ADD_TEST(Test_OS_fsBytesFree_NullName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBytesFree_NullBytePtr, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBytesFree_NameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBytesFree_NameNotFound, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBytesFree_NameError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBytesFree_StatfsError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_fsBytesFree_StatfsSuccess,OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_chkfs Tests */ - ADD_TEST(Test_OS_chkfs_NullName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_chkfs_NameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_chkfs_OpenError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_chkfs_RepairError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_chkfs_RepairSuccess, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_chkfs_CheckOnlyError, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_chkfs_CheckOnlyBadName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_chkfs_CheckOnlySuccess, OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_FS_GetPhysDriveName Tests */ - ADD_TEST(Test_OS_FS_GetPhysDriveName_NullName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetPhysDriveName_NullMount, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetPhysDriveName_NameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetPhysDriveName_MountTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetPhysDriveName_MountNotFound, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetPhysDriveName_Success, OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_TranslatePath Tests */ - ADD_TEST(Test_OS_TranslatePath_NullVirtualName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_TranslatePath_NullLocalName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_TranslatePath_VirtualNameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_TranslatePath_MissingFirstDelim, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_TranslatePath_InvalidPath, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_TranslatePath_MaxPath, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_TranslatePath_Success, OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_FS_GetErrorName Tests */ - ADD_TEST(Test_OS_FS_GetErrorName_NullName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_Success, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_Error, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_InvalidPtr, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_PathTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_NameTooLong, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_Unimplemented, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_DriveNotCreated,OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_DeviceNotFree, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_PathInvalid, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_NoFreeFds, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_InvalidFd, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_FS_GetErrorName_Unknown, OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_GetPhysDeviceName Tests */ - ADD_TEST(Test_OS_GetPhysDeviceName_NullDevName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_GetPhysDeviceName_NullVolName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_GetPhysDeviceName_VolNameTooLong,OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_GetPhysDeviceName_MaxVolName, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_GetPhysDeviceName_Error, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_GetPhysDeviceName_Success, OsFileSys_Setup, OsFileSys_TearDown); - - /* OS_GetFsInfo Tests */ - ADD_TEST(Test_OS_GetFsInfo_NullPtr, OsFileSys_Setup, OsFileSys_TearDown); - ADD_TEST(Test_OS_GetFsInfo_Success, OsFileSys_Setup, OsFileSys_TearDown); -} - - - diff --git a/src/unit-test-coverage/vxworks6/osloader-test/CMakeLists.txt b/src/unit-test-coverage/vxworks6/osloader-test/CMakeLists.txt deleted file mode 100644 index 6587858d0..000000000 --- a/src/unit-test-coverage/vxworks6/osloader-test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} TESTCASE_FILES) -add_executable(osloader-test ${TESTCASE_FILES}) -set_target_properties(osloader-test PROPERTIES LINK_FLAGS "${UT_C_FLAGS}") -target_link_libraries(osloader-test ut_osal_osloader ${OSALCOVERAGE_LINK_LIBRARIES}) diff --git a/src/unit-test-coverage/vxworks6/osloader-test/Makefile b/src/unit-test-coverage/vxworks6/osloader-test/Makefile deleted file mode 100644 index 96b16bc75..000000000 --- a/src/unit-test-coverage/vxworks6/osloader-test/Makefile +++ /dev/null @@ -1,89 +0,0 @@ -############################################################################## -## GNU Makefile for building UT unit tests in a Linux environment for easy -## debug and code coverage -# -# Supported MAKEFILE targets: -# clean - deletes object files, executables, output files, and gcov files -# all - makes utf_test_runner.exe -# run - runs utf_test_runner.exe -# gcov - prints a GCOV coverage report (make all, make run, make gcov) -# -# Makefile Switches: -#------------------- -# ENABLE_GCOV -# GCOV is enabled by default. If you are using the source level debugger you will want to -# disable GCOV. To enable GCOV you can override the ENABLE_GCOV variable on the command line -# by setting it to TRUE. For example "make ENABLE_GCOV=TRUE". -# -# OSPRINTF -# make OSPRINTF=TRUE sets the #define OS_DEBUG_PRINTF so that osloader.c uses the -# OS_DEBUG_PRINTF #define sections. -# - -APP=osloader - -OSAL ?= $(CFS_HOME)/osal - -# -# INCLUDES specifies the search paths for include files outside of the current directory. -# Note that the -I is required. -# -INCLUDES += -I../ut-stubs/inc -INCLUDES += -I$(OSAL)/ut_assert/inc -INCLUDES += -I$(OSAL)/src/os/inc -INCLUDES += -I$(OSAL)/build/inc - -# -# UT_OBJS specifies unit test object files. -# -UT_OBJS += $(APP)_testcase.o -UT_OBJS += $(APP)_stubs.o - - - -############################################################################### - -COMPILER=gcc -LINKER=gcc - -# -# Compiler and Linker Options -# -ENABLE_GCOV = TRUE -ifeq ($(ENABLE_GCOV), TRUE) -GCOV_COPT = --coverage -GCOV_LOPT = --coverage -endif - -#WARNINGS = -Wall -W -ansi -Werror -Wstrict-prototypes -Wundef -WARNINGS = -Wall -Wstrict-prototypes -DEBUGGER = -g - -#COPT = $(WARNINGS) $(DEBUGGER) $(GCOV_COPT) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D__x86_64__ -D_LINUX_OS_ -COPT = $(WARNINGS) $(DEBUGGER) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D_ix86_ $(OSAL_M32) - -LOPT = $(OSAL_M32) - -############################################################################### -## "C" COMPILER RULE -## -%.o: %.c - $(COMPILER) -c $(COPT) $(INCLUDES) $< - -############################################################################## -## - -all:$(APP)_testrunner.exe - -$(APP)_testrunner.exe: $(UT_OBJS) - $(LINKER) $(GCOV_LOPT) $(LOPT) -o $@ $^ ../ut-osal/osloader.o ../testrunner.o - -clean :: - rm -f *.o *.exe *.gcda *.gcno *.gcov gmon.out $(APP)_log.txt - -run :: - ./$(APP)_testrunner.exe | tee ./$(APP)_log.txt - -# end of file - - diff --git a/src/unit-test-coverage/vxworks6/osloader-test/osloader_stubs.c b/src/unit-test-coverage/vxworks6/osloader-test/osloader_stubs.c deleted file mode 100644 index 58ddabf2f..000000000 --- a/src/unit-test-coverage/vxworks6/osloader-test/osloader_stubs.c +++ /dev/null @@ -1,276 +0,0 @@ -/* - * File: osloader_stubs.c - * - * Purpose: - * Stub out various functions not stubbed out by the UT-Assert code - * - * Modification History: - * 06/23/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - * - */ - -#include - -#include "vxworks6-coverage-stubs.h" - -#include "common_types.h" -#include "osapi.h" - -#include "osloader_stubs.h" - -VCS_SYMTAB stubSymbolTable; -VCS_SYMTAB_ID sysSymTbl = &stubSymbolTable; - -Osloader_HookTable_t Osloader_HookTable; -Osloader_ReturnCodeTable_t Osloader_ReturnCodeTable[OSLOADER_MAX_INDEX]; - -boolean semCreated; -uint32 nSemTaken; -uint32 nSemGiven; - -char StubSymbolName[] = "StubSymbolName"; - -void Osloader_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt) -{ - if (Index < OSLOADER_MAX_INDEX) - { - Osloader_ReturnCodeTable[Index].Value = RtnVal; - Osloader_ReturnCodeTable[Index].Count = CallCnt; - } - else - { - printf("Unsupported Index In SetReturnCode Call %lu\n", (unsigned long)Index); - } -} - -boolean Osloader_UseReturnCode(uint32 Index) -{ - if (Osloader_ReturnCodeTable[Index].Count > 0) - { - Osloader_ReturnCodeTable[Index].Count--; - return (TRUE); - } - - return (FALSE); -} - -void Osloader_SetFunctionHook(uint32 Index, void *FunPtr) -{ - switch (Index) - { - case (OSLOADER_SEMMCREATE_INDEX): - Osloader_HookTable.semMCreate = FunPtr; - break; - case (OSLOADER_OS_TANSLATE_PATH_INDEX): - Osloader_HookTable.OS_TranslatePath = FunPtr; - break; - case (OSLOADER_SYMFINDBYNAME_INDEX): - Osloader_HookTable.symFindByName = FunPtr; - break; - case (OSLOADER_SYMEACH_INDEX): - Osloader_HookTable.symEach = FunPtr; - break; - case (OSLOADER_MODULEINFOGET_INDEX): - Osloader_HookTable.moduleInfoGet = FunPtr; - break; - case (OSLOADER_LOADMODULE_INDEX): - Osloader_HookTable.loadModule = FunPtr; - break; - case (OSLOADER_UNLDBYMODULEID_INDEX): - Osloader_HookTable.unldByModuleId = FunPtr; - break; - case (OSLOADER_WRITE_INDEX): - Osloader_HookTable.write = FunPtr; - break; - case (OSLOADER_OPEN_INDEX): - Osloader_HookTable.open = FunPtr; - break; - case (OSLOADER_CLOSE_INDEX): - Osloader_HookTable.close = FunPtr; - break; - default: - printf("Unsupported Osloader Index In SetFunctionHook Call %lu\n", - (unsigned long)Index); - break; - } - -} - -void Osloader_Reset(void) -{ - memset(&Osloader_HookTable, 0, sizeof(Osloader_HookTable)); - memset(&Osloader_ReturnCodeTable, 0, sizeof(Osloader_ReturnCodeTable)); - - semCreated = FALSE; - nSemTaken = 0; - nSemGiven = 0; -} - -VCS_SEM_ID VCS_semMCreate(int options) -{ - semCreated = FALSE; - if (Osloader_UseReturnCode(OSLOADER_SEMMCREATE_INDEX)) - { - VCS_SEM_ID retval = - (VCS_SEM_ID) Osloader_ReturnCodeTable[OSLOADER_SEMMCREATE_INDEX].Value; - if (retval > 0) - { - semCreated = TRUE; - } - return retval; - } - return 0; -} - -boolean isSemCreated(void) -{ - return semCreated; -} - -VCS_STATUS VCS_semTake(VCS_SEM_ID semId, int timeout) -{ - nSemTaken++; - return 0; -} - -VCS_STATUS VCS_semGive(VCS_SEM_ID semId) -{ - nSemGiven++; - return 0; -} - -int32 getNSemTake(void) -{ - return nSemTaken; -} - -int32 getNSemGive(void) -{ - return nSemGiven; -} - -int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) -{ - if (Osloader_UseReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX)) - { - return (int32) Osloader_ReturnCodeTable[OSLOADER_OS_TANSLATE_PATH_INDEX].Value; - } - return 0; -} - -VCS_STATUS VCS_symFindByName(VCS_SYMTAB_ID symTblId, char * name, char ** pValue, - VCS_SYM_TYPE * pType) -{ - if (Osloader_UseReturnCode(OSLOADER_SYMFINDBYNAME_INDEX)) - { - *pValue = (char*) 4; - return (VCS_STATUS) Osloader_ReturnCodeTable[OSLOADER_SYMFINDBYNAME_INDEX].Value; - } - return 0; -} - -VCS_SYMBOL * VCS_symEach(VCS_SYMTAB_ID symTblId, VCS_FUNCPTR routine, int routineArg) -{ - if (Osloader_UseReturnCode(OSLOADER_SYMEACH_INDEX)) - { - return (VCS_SYMBOL *) Osloader_ReturnCodeTable[OSLOADER_SYMEACH_INDEX].Value; - } - return 0; -} - -VCS_STATUS VCS_moduleInfoGet(VCS_MODULE_ID moduleId, VCS_MODULE_INFO * pModuleInfo) -{ - if (Osloader_UseReturnCode(OSLOADER_MODULEINFOGET_INDEX)) - { - pModuleInfo->format = 100; - pModuleInfo->group = 102; - strncpy(pModuleInfo->name, "testmodname", sizeof(pModuleInfo->name)); - pModuleInfo->segInfo.textAddr = (void*)103; - pModuleInfo->segInfo.dataAddr = (void*)104; - pModuleInfo->segInfo.bssAddr = (void*)105; - pModuleInfo->segInfo.textSize = 106; - pModuleInfo->segInfo.dataSize = 107; - pModuleInfo->segInfo.bssSize = 108; - pModuleInfo->segInfo.textFlags = 109; - pModuleInfo->segInfo.dataFlags = 110; - pModuleInfo->segInfo.bssFlags = 111; - return (VCS_STATUS) Osloader_ReturnCodeTable[OSLOADER_MODULEINFOGET_INDEX].Value; - } - return VCS_ERROR; -} - -VCS_MODULE_ID VCS_loadModule(int fd, unsigned int symFlag) -{ - if (Osloader_UseReturnCode(OSLOADER_LOADMODULE_INDEX)) - { - return (VCS_MODULE_ID) Osloader_ReturnCodeTable[OSLOADER_LOADMODULE_INDEX].Value; - } - return 0; -} - -VCS_STATUS VCS_unldByModuleId(VCS_MODULE_ID moduleId, int options) -{ - if (Osloader_UseReturnCode(OSLOADER_UNLDBYMODULEID_INDEX)) - { - return (VCS_STATUS) Osloader_ReturnCodeTable[OSLOADER_UNLDBYMODULEID_INDEX].Value; - } - return VCS_OK; -} - -int VCS_write(int fd, char *buffer, int nbytes) -{ - if (Osloader_UseReturnCode(OSLOADER_WRITE_INDEX)) - { - return (size_t)Osloader_ReturnCodeTable[OSLOADER_WRITE_INDEX].Value; - } - return 0; //write(fd, buffer, nbytes); -} - - -int VCS_open (const char *filename, int flags, ...) -/*int open (const char *name, int dummy, ...)*/ -{ - if (Osloader_UseReturnCode(OSLOADER_OPEN_INDEX)) - { - return (ssize_t) Osloader_ReturnCodeTable[OSLOADER_OPEN_INDEX].Value; - } - return 0; //open(filename, flags, mode); -} - -VCS_STATUS VCS_close (int fd) -{ - if (Osloader_UseReturnCode(OSLOADER_CLOSE_INDEX)) - { - return (size_t)Osloader_ReturnCodeTable[OSLOADER_CLOSE_INDEX].Value; - } - return 0; //close(fd); -} - -/* The osloader implementation uses strcpy, strlen, etc but we do not implement stubs for them */ -size_t VCS_strlen(const char *str) -{ - return strlen(str); -} - -int VCS_strcmp(const char *str1, const char *str2) -{ - return strcmp(str1, str2); -} - -int VCS_strncmp(const char *str1, const char *str2, size_t n) -{ - return strncmp(str1, str2, n); -} - -char *VCS_strcpy(char *str1, const char *str2) -{ - return strcpy(str1, str2); -} - -char *VCS_strncpy(char *str1, const char *str2, size_t n) -{ - return strncpy(str1, str2, n); -} - - diff --git a/src/unit-test-coverage/vxworks6/osloader-test/osloader_stubs.h b/src/unit-test-coverage/vxworks6/osloader-test/osloader_stubs.h deleted file mode 100644 index 4f1fb0f1a..000000000 --- a/src/unit-test-coverage/vxworks6/osloader-test/osloader_stubs.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * File: osloader_stubs.h - * - * Purpose: - * Provide stubs for unit testing osnetwork.c - * - * History: - * 06/23/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSLOADER_STUBS_H_ -#define _OSLOADER_STUBS_H_ - -#include "uttools.h" -#include "vxworks6-coverage-stubs.h" - -/* Define missing types */ - -typedef enum -{ - OSLOADER_SEMMCREATE_INDEX, - OSLOADER_OS_TANSLATE_PATH_INDEX, - OSLOADER_SYMFINDBYNAME_INDEX, - OSLOADER_SYMEACH_INDEX, - OSLOADER_MODULEINFOGET_INDEX, - OSLOADER_LOADMODULE_INDEX, - OSLOADER_UNLDBYMODULEID_INDEX, - OSLOADER_WRITE_INDEX, - OSLOADER_OPEN_INDEX, - OSLOADER_CLOSE_INDEX, - OSLOADER_MAX_INDEX -} Osloader_Index_t; - -typedef struct -{ - int32 Value; - uint32 Count; -} Osloader_ReturnCodeTable_t; - -typedef struct -{ - VCS_SEM_ID (*semMCreate)(int); - int32 (*OS_TranslatePath)(const char *, char *); - VCS_STATUS (*symFindByName)(VCS_SYMTAB_ID, char *, char **, - VCS_SYM_TYPE *); - VCS_SYMBOL* (*symEach)(VCS_SYMTAB_ID, VCS_FUNCPTR, int); - VCS_STATUS (*moduleInfoGet)(VCS_MODULE_ID, VCS_MODULE_INFO *); - VCS_MODULE_ID (*loadModule)(int, int); - VCS_STATUS (*unldByModuleId)(VCS_MODULE_ID, int); - ssize_t (*write) (int, const void *, size_t); - int (*open) (const char *, int, ...); - VCS_STATUS (*close) (int); -} Osloader_HookTable_t; - -extern const char testFileName[]; - - -void Osloader_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt); -void Osloader_SetFunctionHook(uint32 Index, void *FunPtr); -void Osloader_Reset(void); - -int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath); - -int32 getNSemTake(void); -int32 getNSemGive(void); - -boolean isSemCreated(void); - -/* For other stub functions, see VxWorks.h */ - -#endif /* _OSLOADER_STUBS_H_ */ diff --git a/src/unit-test-coverage/vxworks6/osloader-test/osloader_testcase.c b/src/unit-test-coverage/vxworks6/osloader-test/osloader_testcase.c deleted file mode 100644 index c6eb63351..000000000 --- a/src/unit-test-coverage/vxworks6/osloader-test/osloader_testcase.c +++ /dev/null @@ -1,1188 +0,0 @@ -/* - * Filename: osloader_testcase.c - * - * Purpose: This file contains unit test cases - * - * Modification History: - * 07/09/2015, A. Brown, Odyssey Space Research, LLC - * * Created - * - */ - -/* - * Includes - */ -#include "osapi.h" - -#include "utassert.h" -#include "uttest.h" -#include "utlist.h" - -#include "osloader_stubs.h" - -/* items in vxworks6/osloader.c */ - -typedef struct { - /* NOTE: this has to match the INTERNAL structure layout - ** in the specific "osloader.c" implementation that is - ** being tested. - ** - ** Currently, this means the one in os/vxworks6 ... - */ - int free; - cpuaddr entry_point; - uint32 host_module_id; - char filename[OS_MAX_PATH_LEN]; - char name[OS_MAX_API_NAME]; - OS_module_address_t addr; /* Note, this can probably be removed, just wasting memory */ -} OS_module_internal_record_t; - -extern OS_module_internal_record_t OS_module_table[OS_MAX_MODULES]; -extern int OS_sym_table_file_fd; - -/* Prototypes for non-exported functions, from osloader.c */ -VCS_BOOL OS_SymTableIterator ( char *name, int val, VCS_SYM_TYPE type, int32 max_size, VCS_UINT16 group ); - -/* Extern items from osloader.c */ -extern int OS_symbol_table_size; - -/* -------------------- Special Test Case Variables ------------------------- */ - -/* Many osloader.c functions have logic based on the sizeof(SymbolRecord_t), - * so let's make our equivalent copy here for convenience, rather than hard- - * coding assumptions everywhere. */ -typedef struct -{ - char SymbolName[OS_MAX_SYM_LEN]; - uint32 SymbolAddress; -} TESTCOPYSymbolRecord_t; - -#define OS_SYMBOL_RECORD_SIZE sizeof(TESTCOPYSymbolRecord_t) - -/* ------------------------Utility functions--------------------------------- */ -/* set OS_module_table to unusable data */ -void Osloader_ScrambleModuleTable(void) -{ - unsigned int i; - for (i = 0; i < OS_MAX_MODULES; i++) - { - OS_module_table[i].free = FALSE; - OS_module_table[i].entry_point = i+100; - OS_module_table[i].host_module_id = i+100; - OS_module_table[i].addr.valid = FALSE; - strcpy(OS_module_table[i].name, "JUNK"); - strcpy(OS_module_table[i].filename, "JUNK"); - } -} - -/* Returns the number of free entries in the OS_module_table. */ -unsigned int numModuleTableFree(void) { - - unsigned int count = 0; - unsigned int i; - for (i = 0; i < OS_MAX_MODULES; i++) - { - if (OS_module_table[i].free == TRUE) { - count++; - } - } - return count; -} - -/* Returns true if all entries in the OS_module_table are free, false otherwise */ -VCS_BOOL isModuleTableFree(void) { - return (numModuleTableFree() == OS_MAX_MODULES); -} - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* - ** - ** OS_ModuleTableInit Tests - ** - *******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleTableInit_SemFail(void) -{ - int32 retval = 0; - unsigned int i; - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 0, 1); - - /* Scramble the memory */ - Osloader_ScrambleModuleTable(); - - /* Execute Test */ - retval = OS_ModuleTableInit(); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - - /* Check Side-Effects */ - UtAssert_True(isSemCreated() == FALSE, "isSemCreated() == F"); - - for (i = 0; i < OS_MAX_MODULES; i++) - { - UtAssert_True(OS_module_table[i].free == TRUE, "module table check #1"); - UtAssert_True(OS_module_table[i].entry_point == 0, "module table check #2"); - UtAssert_True(OS_module_table[i].host_module_id == 0, "module table check #3"); - UtAssert_True(OS_module_table[i].addr.valid == FALSE, "module table check #4"); - /* Didn't bother to check names. */ - } - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); - - /* Verify table assumption */ - UtAssert_True(isModuleTableFree() == TRUE, "Table is empty"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleTableInit(void) -{ - int32 retval = 0; - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - - /* Scramble the memory */ - Osloader_ScrambleModuleTable(); - - /* Execute Test */ - retval = OS_ModuleTableInit(); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - - /* Check Side-Effects */ - UtAssert_True(isSemCreated(), "isSemCreated() == T"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); - - /* Verify table assumption */ - UtAssert_True(isModuleTableFree() == TRUE, "Table is empty"); -} - -/******************************************************************************* - ** - ** OS_SymbolLookup Tests - ** - *******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_SymbolLookup(void) -{ - int32 retval = 0; - uint32 symaddr = 0; - char symName[] = "SymName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_SYMFINDBYNAME_INDEX, VCS_OK, 1); - - /* Execute Test */ - retval = OS_SymbolLookup(&symaddr, &(symName[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(symaddr == 4, "symaddr == 4"); - - /* Verify Semaphore Usage - should not be accessing the OS_module_table */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymbolLookup_LookupFail(void) -{ - int32 retval = 0; - uint32 symaddr = 0; - char symName[] = "SymName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_SYMFINDBYNAME_INDEX, VCS_ERROR, 1); - - /* Execute Test */ - retval = OS_SymbolLookup(&symaddr, &(symName[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - - /* Verify Semaphore Usage - should not be accessing the OS_module_table */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymbolLookup_NullArg1(void) -{ - int32 retval = 0; - char symName[] = "SymName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_SYMFINDBYNAME_INDEX, VCS_OK, 1); - - /* Execute Test */ - retval = OS_SymbolLookup(NULL, &(symName[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage - should not be accessing the OS_module_table */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymbolLookup_NullArg2(void) -{ - int32 retval = 0; - uint32 symaddr = 0; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_SYMFINDBYNAME_INDEX, VCS_OK, 1); - - /* Execute Test */ - retval = OS_SymbolLookup(&symaddr, NULL); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage - should not be accessing the OS_module_table */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} - -/******************************************************************************* - ** - ** OS_SymTableIterator Tests - ** - *******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_SymTableIterator(void) -{ - VCS_BOOL retval = FALSE; - char name[] = "TESTNAME"; - int val = 0; - VCS_SYM_TYPE type = 0; - int32 max_size = OS_SYMBOL_RECORD_SIZE+1; - VCS_UINT16 group = 0; - - /* Initialize the osloader */ - OS_symbol_table_size = 0; - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_WRITE_INDEX, max_size, 1); - - /* Execute Test */ - retval = OS_SymTableIterator(&(name[0]), val, type, max_size, group); - - /* Verify Outputs*/ - UtAssert_True(retval == TRUE, "retval == TRUE"); - - /* Verify Semaphore Usage - check and make sure a semaphore is NOT taken. - * This is a support function called by OS_SymbolTableDump() and nowhere - * else. */ - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymTableIterator_HitMax(void) -{ - VCS_BOOL retval = FALSE; - char name[] = "TESTNAME"; - int val = 0; - VCS_SYM_TYPE type = 0; - int32 max_size = 1; - VCS_UINT16 group = 0; - - /* Initialize the osloader */ - OS_symbol_table_size = 0; - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_WRITE_INDEX, OS_SYMBOL_RECORD_SIZE, 1); - - /* Execute Test */ - retval = OS_SymTableIterator(&(name[0]), val, type, max_size, group); - - /* Verify Outputs*/ - UtAssert_True(retval == FALSE, "retval == FALSE"); - - /* Verify Semaphore Usage - check and make sure a semaphore is NOT taken. - * This is a support function called by OS_SymbolTableDump() and nowhere - * else. */ - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymTableIterator_FailedWrite(void) -{ - VCS_BOOL retval = FALSE; - char name[] = "TESTNAME"; - int val = 0; - VCS_SYM_TYPE type = 0; - int32 max_size = OS_SYMBOL_RECORD_SIZE+1; - VCS_UINT16 group = 0; - - /* Initialize the osloader */ - OS_symbol_table_size = 0; - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_WRITE_INDEX, -1, 1); - - /* Execute Test */ - retval = OS_SymTableIterator(&(name[0]), val, type, max_size, group); - - /* Verify Outputs*/ - UtAssert_True(retval == FALSE, "retval == FALSE"); - - /* Verify Semaphore Usage - check and make sure a semaphore is NOT taken. - * This is a support function called by OS_SymbolTableDump() and nowhere - * else. */ - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymTableIterator_UnfinishedWrite(void) -{ - VCS_BOOL retval = FALSE; - char name[] = "TESTNAME"; - int val = 0; - VCS_SYM_TYPE type = 0; - int32 max_size = OS_SYMBOL_RECORD_SIZE+1; - VCS_UINT16 group = 0; - - /* Initialize the osloader */ - OS_symbol_table_size = 0; - - /* Setup Inputs */ - /* the unexpected happened, write() didn't write everything, say - * one last bit? */ - Osloader_SetReturnCode(OSLOADER_WRITE_INDEX, (OS_SYMBOL_RECORD_SIZE-1), 1); - - /* Execute Test */ - retval = OS_SymTableIterator(&(name[0]), val, type, max_size, group); - - /* Verify Outputs*/ - UtAssert_True(retval == FALSE, "retval == FALSE"); - - /* Verify Semaphore Usage - check and make sure a semaphore is NOT taken. - * This is a support function called by OS_SymbolTableDump() and nowhere - * else. */ - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymTableIterator_NameTooLong(void) -{ - VCS_BOOL retval = FALSE; - char name[OS_MAX_SYM_LEN+1]; - int val = 0; - VCS_SYM_TYPE type = 0; - int32 max_size = OS_SYMBOL_RECORD_SIZE; - VCS_UINT16 group = 0; - - memset(&(name[0]),(int)"A",OS_MAX_SYM_LEN); - name[OS_MAX_SYM_LEN]=(char)0; - - /* Initialize the osloader */ - OS_symbol_table_size = 0; - - /* Setup Inputs */ - - /* Execute Test */ - retval = OS_SymTableIterator(&(name[0]), val, type, max_size, group); - - /* Verify Outputs*/ - UtAssert_True(retval == FALSE, "retval == FALSE"); - - /* Verify Semaphore Usage - check and make sure a semaphore is NOT taken. - * This is a support function called by OS_SymbolTableDump() and nowhere - * else. */ - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} - -/******************************************************************************* - ** - ** OS_SymbolTableDump Tests - ** - *******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_SymbolTableDump(void) -{ - int32 retval = 0; - char filename[] = "TESTFILENAME"; - int32 size = OS_SYMBOL_RECORD_SIZE; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX, OS_FS_SUCCESS, 1); - Osloader_SetReturnCode(OSLOADER_OPEN_INDEX, 1, 1); - Osloader_SetReturnCode(OSLOADER_SYMEACH_INDEX, 1, 1); - Osloader_SetReturnCode(OSLOADER_CLOSE_INDEX, 0, 1); - - /* Execute Test */ - retval = OS_SymbolTableDump(&(filename[0]), size); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymbolTableDump_BadArg1(void) -{ - int32 retval = 0; - int32 size = OS_SYMBOL_RECORD_SIZE; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - - /* Execute Test */ - retval = OS_SymbolTableDump(NULL, size); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymbolTableDump_BadArg2(void) -{ - int32 retval = 0; - char filename[] = "TESTFILENAME"; - int32 size = 1; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - - /* Execute Test */ - retval = OS_SymbolTableDump(&(filename[0]), size); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymbolTableDump_TransPathFail(void) -{ - int32 retval = 0; - char filename[] = "TESTFILENAME"; - int32 size = OS_SYMBOL_RECORD_SIZE; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX, OS_FS_ERR_PATH_INVALID, 1); - - /* Execute Test */ - retval = OS_SymbolTableDump(&(filename[0]), size); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_FS_ERR_PATH_INVALID, "retval == OS_FS_ERR_PATH_INVALID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_SymbolTableDump_OpenFail(void) -{ - int32 retval = 0; - char filename[] = "TESTFILENAME"; - int32 size = OS_SYMBOL_RECORD_SIZE; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX, OS_FS_SUCCESS, 1); - Osloader_SetReturnCode(OSLOADER_OPEN_INDEX, -1, 1); - - /* Execute Test */ - retval = OS_SymbolTableDump(&(filename[0]), size); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); -} - -/******************************************************************************* - ** - ** OS_ModuleLoad Tests - ** - *******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char modulename[OS_MAX_API_NAME] = "TestModuleName"; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX, OS_FS_SUCCESS, 1); - Osloader_SetReturnCode(OSLOADER_OPEN_INDEX, 1, 1); - Osloader_SetReturnCode(OSLOADER_LOADMODULE_INDEX, 1, 1); - Osloader_SetReturnCode(OSLOADER_CLOSE_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, &(modulename[0]), &(filename[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(module_id == 0, "module_id set"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_BadArg1(void) -{ - int32 retval = 0; - char modulename[OS_MAX_API_NAME] = "TestModuleName"; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - - /* Execute Test */ - retval = OS_ModuleLoad(NULL, &(modulename[0]), &(filename[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); - - /* Verify table assumption */ - UtAssert_True(isModuleTableFree() == TRUE, "Table is empty"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_BadArg2(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, NULL, &(filename[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - UtAssert_True(module_id == -99, "module_id NOT set"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); - - /* Verify table assumption */ - UtAssert_True(isModuleTableFree() == TRUE, "Table is empty"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_BadArg3(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char modulename[OS_MAX_API_NAME] = "TestModuleName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, &(modulename[0]), NULL); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - UtAssert_True(module_id == -99, "module_id NOT set"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); - - /* Verify table assumption */ - UtAssert_True(isModuleTableFree() == TRUE, "Table is empty"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_BadArg3b_TooLong(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - char checkval = -1; - - /* Make the module name too long */ - char modulename[OS_MAX_API_NAME+1]; - memset(&modulename,(int)"A",OS_MAX_API_NAME+1); - modulename[OS_MAX_API_NAME] = (char)0; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX, OS_FS_SUCCESS, 1); - Osloader_SetReturnCode(OSLOADER_OPEN_INDEX, 1, 1); - Osloader_SetReturnCode(OSLOADER_LOADMODULE_INDEX, 1, 1); - Osloader_SetReturnCode(OSLOADER_CLOSE_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, &(modulename[0]), &(filename[0])); - - /* Verify Outputs */ - UtAssert_True(retval != OS_SUCCESS, "retval != OS_SUCCESS"); - checkval = OS_module_table[0].name[OS_MAX_API_NAME-1]; - UtAssert_True(checkval == 0, "Terminating filename null in table.name"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); - - /* Verify table assumption */ - UtAssert_True(isModuleTableFree() == TRUE, "Table is empty"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_AllTaken(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char modulename[OS_MAX_API_NAME] = "TestModuleName"; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - unsigned int i; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - /* Fill up the OS_module_table */ - for (i = 0; i < OS_MAX_MODULES; i++) { - OS_module_table[i].free = FALSE; - } - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, &(modulename[0]), &(filename[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERR_NO_FREE_IDS, "retval == OS_ERR_NO_FREE_IDS"); - UtAssert_True(module_id == -99, "module_id NOT set"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); - - /* Verify table assumption */ - UtAssert_True(numModuleTableFree() == 0, "all module slots loaded"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_AlreadyLoaded(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char modulename[OS_MAX_API_NAME] = "TestModuleName"; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - /* set the name on one of them */ - OS_module_table[1].free = FALSE; - strncpy(OS_module_table[1].name , modulename, OS_MAX_API_NAME); - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, &(modulename[0]), &(filename[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERR_NAME_TAKEN, "retval == OS_ERR_NAME_TAKEN"); - UtAssert_True(module_id == -99, "module_id NOT set"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); - - /* Verify table assumption */ - UtAssert_True(numModuleTableFree() == (OS_MAX_MODULES-1), "Only 1 module loaded"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_OtherModsLoaded(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char modulename[OS_MAX_API_NAME] = "TestModuleName"; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX, OS_FS_SUCCESS, 1); - Osloader_SetReturnCode(OSLOADER_OPEN_INDEX, 1, 1); - Osloader_SetReturnCode(OSLOADER_LOADMODULE_INDEX, 1, 1); - Osloader_SetReturnCode(OSLOADER_CLOSE_INDEX, 1, 1); - OS_module_table[1].free = FALSE; - strncpy(OS_module_table[1].name , "SomeOtherName", OS_MAX_API_NAME); - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, &(modulename[0]), &(filename[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(module_id == 0, "module_id set"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); - - /* Verify table assumption */ - UtAssert_True(numModuleTableFree() == (OS_MAX_MODULES-2), "Only 2 modules loaded"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_TransPathFail(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char modulename[OS_MAX_API_NAME] = "TestModuleName"; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX, OS_ERROR, 1); - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, &(modulename[0]), &(filename[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - UtAssert_True(module_id == -99, "module_id NOT set"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); - - /* Verify table assumption */ - UtAssert_True(isModuleTableFree() == TRUE, "Table is empty"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_OpenFail(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char modulename[OS_MAX_API_NAME] = "TestModuleName"; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX, OS_FS_SUCCESS, 1); - Osloader_SetReturnCode(OSLOADER_OPEN_INDEX, -1, 1); - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, &(modulename[0]), &(filename[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - UtAssert_True(module_id == -99, "module_id NOT set"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); - - /* Verify table assumption */ - UtAssert_True(isModuleTableFree() == TRUE, "Table is empty"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleLoad_loadModuleFail(void) -{ - int32 retval = 0; - uint32 module_id = -99; - char modulename[OS_MAX_API_NAME] = "TestModuleName"; - char filename[OS_MAX_PATH_LEN] = "TestFileName"; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_OS_TANSLATE_PATH_INDEX, OS_FS_SUCCESS, 1); - Osloader_SetReturnCode(OSLOADER_OPEN_INDEX, 1, 1); - Osloader_SetReturnCode(OSLOADER_LOADMODULE_INDEX, (int32)NULL, 1); - Osloader_SetReturnCode(OSLOADER_CLOSE_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_ModuleLoad(&module_id, &(modulename[0]), &(filename[0])); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - UtAssert_True(module_id == -99, "module_id NOT set"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); - - /* Verify table assumption */ - UtAssert_True(isModuleTableFree() == TRUE, "Table is empty"); -} - -/******************************************************************************* - ** - ** OS_ModuleUnload Tests - ** - *******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleUnload(void) -{ - int32 retval = 0; - uint32 module_id = 0; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_UNLDBYMODULEID_INDEX, VCS_OK, 1); - OS_module_table[module_id].free = FALSE; - - /* Execute Test */ - retval = OS_ModuleUnload(module_id); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleUnload_BadArg(void) -{ - int32 retval = 0; - uint32 module_id = OS_MAX_MODULES; /* out of range */ - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - - /* Execute Test */ - retval = OS_ModuleUnload(module_id); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleUnload_NoModule(void) -{ - int32 retval = 0; - uint32 module_id = 0; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - OS_module_table[module_id].free = TRUE; - - /* Execute Test */ - retval = OS_ModuleUnload(module_id); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleUnload_unldByModuleIdFail(void) -{ - int32 retval = 0; - uint32 module_id = 0; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_UNLDBYMODULEID_INDEX, VCS_ERROR, 1); - OS_module_table[module_id].free = FALSE; - - /* Execute Test */ - retval = OS_ModuleUnload(module_id); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); -} - -/******************************************************************************* - ** - ** OS_ModuleInfo Tests - ** - *******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleInfo(void) -{ - int32 retval = 0; - uint32 module_id = 0; - OS_module_record_t module_info = {0}; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_MODULEINFOGET_INDEX, VCS_OK, 1); - OS_module_table[module_id].free = FALSE; - - /* Execute Test */ - retval = OS_ModuleInfo(module_id, &module_info); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(module_info.addr.valid == TRUE, "module_info.addr.valid == TRUE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleInfo_BadArg2(void) -{ - int32 retval = 0; - uint32 module_id = 0; - OS_module_record_t module_info = {0}; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - - /* Execute Test */ - retval = OS_ModuleInfo(module_id, NULL); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - UtAssert_True(module_info.addr.valid == FALSE, "module_info.addr.valid == FALSE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleInfo_BadArg1(void) -{ - int32 retval = 0; - uint32 module_id = OS_MAX_MODULES; - OS_module_record_t module_info = {0}; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - - /* Execute Test */ - retval = OS_ModuleInfo(module_id, &module_info); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - UtAssert_True(module_info.addr.valid == FALSE, "module_info.addr.valid == FALSE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() == 0, "getNSemTake() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleInfo_BadArg1Free(void) -{ - int32 retval = 0; - uint32 module_id = 0; - OS_module_record_t module_info = {0}; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_MODULEINFOGET_INDEX, VCS_OK, 1); - OS_module_table[module_id].free = TRUE; - - /* Execute Test */ - retval = OS_ModuleInfo(module_id, &module_info); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - UtAssert_True(module_info.addr.valid == FALSE, "module_info.addr.valid == FALSE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_ModuleInfo_ModuleInfoGetFail(void) -{ - int32 retval = 0; - uint32 module_id = 0; - OS_module_record_t module_info = {0}; - - /* Initialize the osloader */ - Osloader_SetReturnCode(OSLOADER_SEMMCREATE_INDEX, 1, 1); - UtAssert_True(OS_ModuleTableInit() == OS_SUCCESS, "OS_ModuleTableInit() before executing test."); - - /* Setup Inputs */ - Osloader_SetReturnCode(OSLOADER_MODULEINFOGET_INDEX, VCS_ERROR, 1); - OS_module_table[module_id].free = FALSE; - - /* Execute Test */ - retval = OS_ModuleInfo(module_id, &module_info); - - /* Verify Outputs*/ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(module_info.addr.valid == FALSE, "module_info.addr.valid == FALSE"); - - /* Verify Semaphore Usage */ - UtAssert_True(getNSemTake() == getNSemGive(), "getNSemTake() == getNSemGive()"); - UtAssert_True(getNSemTake() > 0, "getNSemTake() > 0"); -} -/* ------------------- End of test cases --------------------------------------*/ - -/* - * Osloader_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osloader_Setup(void) -{ - Osloader_Reset(); - /*Ut_OSAPI_Reset();*/ - - OS_sym_table_file_fd = -1; -} - -/* - * Osloader_TearDown - * - * Purpose: - * Called by the unit test tool to tear down the app after each test - */ -void Osloader_TearDown(void) -{ - Osloader_Reset(); -} - -#define ADD_TEST(test,setup,teardown) UtTest_Add((test), (setup), (teardown), #test) - -/* Osloader_AddTestCase - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void OS_Application_Startup(void) -{ - ADD_TEST(Test_OS_ModuleTableInit, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleTableInit_SemFail, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymbolLookup, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymbolLookup_LookupFail, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymbolLookup_NullArg1, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymbolLookup_NullArg2, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymTableIterator, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymTableIterator_HitMax, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymTableIterator_FailedWrite, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymTableIterator_UnfinishedWrite,Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymTableIterator_NameTooLong, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymbolTableDump, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymbolTableDump_BadArg1, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymbolTableDump_BadArg2, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymbolTableDump_TransPathFail, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_SymbolTableDump_OpenFail, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_BadArg1, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_BadArg2, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_BadArg3, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_BadArg3b_TooLong, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_AllTaken, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_AlreadyLoaded, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_OtherModsLoaded, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_TransPathFail, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_OpenFail, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleLoad_loadModuleFail, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleUnload, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleUnload_BadArg, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleUnload_NoModule, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleUnload_unldByModuleIdFail, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleInfo, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleInfo_BadArg2, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleInfo_BadArg1, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleInfo_BadArg1Free, Osloader_Setup, Osloader_TearDown); - ADD_TEST(Test_OS_ModuleInfo_ModuleInfoGetFail, Osloader_Setup, Osloader_TearDown); -} - diff --git a/src/unit-test-coverage/vxworks6/osnetwork-test/CMakeLists.txt b/src/unit-test-coverage/vxworks6/osnetwork-test/CMakeLists.txt deleted file mode 100644 index f8d80904a..000000000 --- a/src/unit-test-coverage/vxworks6/osnetwork-test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} TESTCASE_FILES) -add_executable(osnetwork-test ${TESTCASE_FILES}) -set_target_properties(osnetwork-test PROPERTIES LINK_FLAGS "${UT_C_FLAGS}") -target_link_libraries(osnetwork-test ut_osal_osnetwork ${OSALCOVERAGE_LINK_LIBRARIES}) diff --git a/src/unit-test-coverage/vxworks6/osnetwork-test/Makefile b/src/unit-test-coverage/vxworks6/osnetwork-test/Makefile deleted file mode 100644 index 05d1dcca9..000000000 --- a/src/unit-test-coverage/vxworks6/osnetwork-test/Makefile +++ /dev/null @@ -1,83 +0,0 @@ -############################################################################## -## GNU Makefile for building UT unit tests in a Linux environment for easy -## debug and code coverage -# -# Supported MAKEFILE targets: -# clean - deletes object files, executables, output files, and gcov files -# all - makes utf_test_runner.exe -# run - runs utf_test_runner.exe -# gcov - prints a GCOV coverage report (make all, make run, make gcov) -# -# Makefile Switches: -#------------------- -# ENABLE_GCOV -# GCOV is enabled by default. If you are using the source level debugger you will want to -# disable GCOV. To enable GCOV you can override the ENABLE_GCOV variable on the command line -# by setting it to TRUE. For example "make ENABLE_GCOV=TRUE". -# - -APP=osnetwork - -OSAL ?= $(CFS_HOME)/osal - -# -# INCLUDES specifies the search paths for include files outside of the current directory. -# Note that the -I is required. -# -INCLUDES += -I../ut-stubs/inc -INCLUDES += -I$(OSAL)/ut_assert/inc -INCLUDES += -I$(OSAL)/src/os/inc -INCLUDES += -I$(OSAL)/build/inc - -# -# UT_OBJS specifies unit test object files. -# -UT_OBJS += $(APP)_testcase.o -UT_OBJS += $(APP)_stubs.o - - -############################################################################### - -COMPILER=gcc -LINKER=gcc - -# -# Compiler and Linker Options -# -ENABLE_GCOV = TRUE -ifeq ($(ENABLE_GCOV), TRUE) -GCOV_COPT = --coverage -GCOV_LOPT = --coverage -endif - -#WARNINGS = -Wall -W -ansi -Werror -Wstrict-prototypes -Wundef -WARNINGS = -Wall -Wstrict-prototypes -DEBUGGER = -g - -#COPT = $(WARNINGS) $(DEBUGGER) $(GCOV_COPT) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D__x86_64__ -D_LINUX_OS_ -COPT = $(WARNINGS) $(DEBUGGER) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D_ix86_ $(OSAL_M32) - -LOPT = $(OSAL_M32) - -############################################################################### -## "C" COMPILER RULE -## -%.o: %.c - $(COMPILER) -c $(COPT) $(INCLUDES) $< - -############################################################################## -## - -all:$(APP)_testrunner.exe - -$(APP)_testrunner.exe: $(UT_OBJS) - $(LINKER) $(GCOV_LOPT) $(LOPT) -o $@ $^ ../ut-osal/osnetwork.o ../testrunner.o - -clean :: - rm -f *.o *.exe *.gcda *.gcno *.gcov gmon.out $(APP)_log.txt - -run :: - ./$(APP)_testrunner.exe | tee ./$(APP)_log.txt - -# end of file - diff --git a/src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_stubs.c b/src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_stubs.c deleted file mode 100644 index 85d7b5996..000000000 --- a/src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_stubs.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * File: osnetwork_stubs.c - * - * Purpose: - * Stub out various functions not stubbed out by the UT-Assert code - * - * Modification History: - * 06/23/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - * - */ - -#include - -#include "osapi.h" /* cfe.h not available from within osal. */ - -#include "osnetwork_stubs.h" - - -Osnetwork_HookTable_t Osnetwork_HookTable; -Osnetwork_ReturnCodeTable_t Osnetwork_ReturnCodeTable[OSNETWORK_MAX_INDEX]; - -char testname[] = "testname"; - -void Osnetwork_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt) -{ - if (Index < OSNETWORK_MAX_INDEX) { - Osnetwork_ReturnCodeTable[Index].Value = RtnVal; - Osnetwork_ReturnCodeTable[Index].Count = CallCnt; - } - else { - printf("Unsupported Index In SetReturnCode Call %u\n", (unsigned)Index); - } -} - - -boolean Osnetwork_UseReturnCode(uint32 Index) -{ - if (Osnetwork_ReturnCodeTable[Index].Count > 0) { - Osnetwork_ReturnCodeTable[Index].Count--; - if (Osnetwork_ReturnCodeTable[Index].Count == 0) - return(TRUE); - } - - return(FALSE); -} - - -void Osnetwork_SetFunctionHook(uint32 Index, void *FunPtr) -{ - if (Index == OSNETWORK_HOSTGETBYNAME_INDEX) { - Osnetwork_HookTable.hostGetByName = FunPtr; - } - else - { - printf("Unsupported Osnetwork Index In SetFunctionHook Call %u\n", (unsigned)Index); - } -} - - -void Osnetwork_Reset(void) -{ - memset(&Osnetwork_HookTable, 0, sizeof(Osnetwork_HookTable)); - memset(&Osnetwork_ReturnCodeTable, 0, sizeof(Osnetwork_ReturnCodeTable)); -} - -int VCS_gethostname(char *name, int name_len) -{ - if (Osnetwork_UseReturnCode(OSNETWORK_GETHOSTNAME_INDEX)) { - return (int)Osnetwork_ReturnCodeTable[OSNETWORK_GETHOSTNAME_INDEX].Value; - } - - strcpy(name, testname); - return 0; - -} - -int VCS_hostGetByName(char *name) -{ - if (Osnetwork_UseReturnCode(OSNETWORK_HOSTGETBYNAME_INDEX)) { - return (int)Osnetwork_ReturnCodeTable[OSNETWORK_HOSTGETBYNAME_INDEX].Value; - } - - strcpy(name, testname); - return 0; - -} diff --git a/src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_stubs.h b/src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_stubs.h deleted file mode 100644 index ad60b1a0e..000000000 --- a/src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_stubs.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * File: osnetwork_stubs.h - * - * Purpose: - * Provide stubs for unit testing osnetwork.c - * - * History: - * 06/23/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSNETWORK_STUBS_H_ -#define _OSNETWORK_STUBS_H_ - -#include "uttools.h" -#include "vxworks6-coverage-stubs.h" - - -/* Define missing types */ -typedef struct -{ - int32 Dir; -} __dirstream; - -typedef enum -{ - OSNETWORK_GETHOSTNAME_INDEX, - OSNETWORK_HOSTGETBYNAME_INDEX, - OSNETWORK_MAX_INDEX -} Osnetwork_Index_t; - -typedef struct -{ - int32 Value; - uint32 Count; -} Osnetwork_ReturnCodeTable_t; - -typedef struct -{ - int (*gethostname)(char *name, int); - int (*hostGetByName)(char *name); -} Osnetwork_HookTable_t; - -extern const char testFileName[]; - - -void Osnetwork_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt); -void Osnetwork_SetFunctionHook(uint32 Index, void *FunPtr); -void Osnetwork_Reset(void); - -int32 getNSemTake(void); -int32 getNSemGive(void); -int32 getRewinddirCalls(void); - -#endif /* _OSNETWORK_STUBS_H_ */ diff --git a/src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_testcase.c b/src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_testcase.c deleted file mode 100644 index 9c9821f2d..000000000 --- a/src/unit-test-coverage/vxworks6/osnetwork-test/osnetwork_testcase.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Filename: osnetwork_testcase.c - * - * Purpose: This file contains unit test cases - * - * Modification History: - * 04/28/2015, A. Asp, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include /* for O_WRONLY etc. */ - -#include "osapi.h" /* cfe.h not available from within osal. */ - -#include "utassert.h" -#include "uttest.h" -#include "utlist.h" - -#include "osnetwork_stubs.h" - - -#define MAX_BUF 100 - -/* Prototypes for non-exported functions */ - - -/* -------------------- Special Test Case Variables ------------------------- */ - - -/* Utility functions */ -/* -------------------------------------------------------------------------- */ - - - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_NetworkGetID Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_NetworkGetID_Nominal(void) -{ - /* Setup Inputs */ - Osnetwork_SetReturnCode(OSNETWORK_GETHOSTNAME_INDEX, 0, 1); - Osnetwork_SetReturnCode(OSNETWORK_HOSTGETBYNAME_INDEX, 99, 1); - - /* Execute Test */ - int32 retval = OS_NetworkGetID(); - -#ifdef OS_INCLUDE_NETWORK - /* Verify Outputs - WITH NETWORK */ - UtAssert_True(retval == 99, "retval == 99"); -#else - /* Verify Outputs - NO NETWORK */ - UtAssert_True(retval == OS_ERR_NOT_IMPLEMENTED, "retval == OS_ERR_NOT_IMPLEMENTED"); -#endif - -} - -void Test_OS_NetworkGetID_Failgethostname(void) -{ - /* Setup Inputs */ - Osnetwork_SetReturnCode(OSNETWORK_GETHOSTNAME_INDEX, -1, 1); - Osnetwork_SetReturnCode(OSNETWORK_HOSTGETBYNAME_INDEX, 99, 1); - - /* Execute Test */ - int32 retval = OS_NetworkGetID(); - - /* Verify Outputs - WITH NETWORK */ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); -} - -void Test_OS_NetworkGetID_FailhostGetByName(void) -{ - /* Setup Inputs */ - Osnetwork_SetReturnCode(OSNETWORK_GETHOSTNAME_INDEX, 0, 1); - Osnetwork_SetReturnCode(OSNETWORK_HOSTGETBYNAME_INDEX, -1, 1); - - /* Execute Test */ - int32 retval = OS_NetworkGetID(); - - /* Verify Outputs - WITH NETWORK */ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); -} - -/******************************************************************************* -** -** OS_NetworkGetHostName Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_NetworkGetHostName_Nominal(void) -{ - /* Setup Inputs */ - char hostname[255] = "UNSET"; - uint32 name_len = 13; - - /* Execute Test */ - int32 retval = OS_NetworkGetHostName(hostname, name_len); - -#ifdef OS_INCLUDE_NETWORK - /* Verify Outputs - WITH NETWORK */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_StrCmp(hostname, "testname", "hostname == testname"); -#else - /* Verify Outputs - NO NETWORK */ - UtAssert_True(retval == OS_ERR_NOT_IMPLEMENTED, "retval == OS_ERR_NOT_IMPLEMENTED"); - UtAssert_StrCmp(hostname, "UNSET", "hostname == UNSET"); -#endif -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_NetworkGetHostName_NullArg1(void) -{ - /* Setup Inputs */ - uint32 name_len = 13; - - /* Execute Test */ - int32 retval = OS_NetworkGetHostName(NULL, name_len); - - /* Verify Outputs - WITH OR WITHOUT NETWORK */ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_NetworkGetHostName_ZeroLenArg2(void) -{ - /* Setup Inputs */ - char hostname[255] = "UNSET"; - uint32 name_len = 0; - - /* Execute Test */ - int32 retval = OS_NetworkGetHostName(hostname, name_len); - - /* Verify Outputs - WITH OR WITHOUT NETWORK */ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - UtAssert_StrCmp(hostname, "UNSET", "hostname == UNSET"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_NetworkGetHostName_gethostnameFail(void) -{ - /* Setup Inputs */ - char hostname[255] = "UNSET"; - uint32 name_len = 13; - Osnetwork_SetReturnCode(OSNETWORK_GETHOSTNAME_INDEX, -1, 1); - - /* Execute Test */ - int32 retval = OS_NetworkGetHostName(hostname, name_len); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERROR, "retval == OS_ERROR"); - UtAssert_StrCmp(hostname, "UNSET", "hostname == UNSET"); -} - -/* ------------------- End of test cases --------------------------------------*/ - - - - - -/* - * Osnetwork_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osnetwork_Setup(void) -{ - Osnetwork_Reset(); -} - - -/* - * Osnetwork_TearDown - * - * Purpose: - * Called by the unit test tool to tear down the app after each test - */ -void Osnetwork_TearDown(void) -{ - -} - - -#define ADD_TEST(test,setup,teardown) UtTest_Add((test), (setup), (teardown), #test) - -/* Osnetwork_AddTestCase - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void OS_Application_Startup(void) -{ - /* OS_NetworkGetID */ - ADD_TEST(Test_OS_NetworkGetID_Nominal, Osnetwork_Setup, Osnetwork_TearDown); -#ifdef OS_INCLUDE_NETWORK - ADD_TEST(Test_OS_NetworkGetID_Failgethostname, Osnetwork_Setup, Osnetwork_TearDown); - ADD_TEST(Test_OS_NetworkGetID_FailhostGetByName, Osnetwork_Setup, Osnetwork_TearDown); -#endif - - /* OS_NetworkGetHostName Tests */ - ADD_TEST(Test_OS_NetworkGetHostName_Nominal, Osnetwork_Setup, Osnetwork_TearDown); - ADD_TEST(Test_OS_NetworkGetHostName_NullArg1, Osnetwork_Setup, Osnetwork_TearDown); - ADD_TEST(Test_OS_NetworkGetHostName_ZeroLenArg2, Osnetwork_Setup, Osnetwork_TearDown); -#ifdef OS_INCLUDE_NETWORK - ADD_TEST(Test_OS_NetworkGetHostName_gethostnameFail, Osnetwork_Setup, Osnetwork_TearDown); -#endif -} - - - - diff --git a/src/unit-test-coverage/vxworks6/ostimer-test/CMakeLists.txt b/src/unit-test-coverage/vxworks6/ostimer-test/CMakeLists.txt deleted file mode 100644 index 70a1bf192..000000000 --- a/src/unit-test-coverage/vxworks6/ostimer-test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} TESTCASE_FILES) -add_executable(ostimer-test ${TESTCASE_FILES}) -set_target_properties(ostimer-test PROPERTIES LINK_FLAGS "${UT_C_FLAGS}") -target_link_libraries(ostimer-test ut_osal_ostimer ${OSALCOVERAGE_LINK_LIBRARIES}) diff --git a/src/unit-test-coverage/vxworks6/ostimer-test/Makefile b/src/unit-test-coverage/vxworks6/ostimer-test/Makefile deleted file mode 100644 index 81669258d..000000000 --- a/src/unit-test-coverage/vxworks6/ostimer-test/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -############################################################################## -## GNU Makefile for building UT unit tests in a Linux environment for easy -## debug and code coverage -# -# Supported MAKEFILE targets: -# clean - deletes object files, executables, output files, and gcov files -# all - makes utf_test_runner.exe -# run - runs utf_test_runner.exe -# gcov - prints a GCOV coverage report (make all, make run, make gcov) -# -# Makefile Switches: -#------------------- -# ENABLE_GCOV -# GCOV is enabled by default. If you are using the source level debugger you will want to -# disable GCOV. To enable GCOV you can override the ENABLE_GCOV variable on the command line -# by setting it to TRUE. For example "make ENABLE_GCOV=TRUE". -# - -APP=ostimer - -OSAL ?= $(CFS_HOME)/osal - -# -# INCLUDES specifies the search paths for include files outside of the current directory. -# Note that the -I is required. -# -INCLUDES += -I../ut-stubs/inc -INCLUDES += -I$(OSAL)/ut_assert/inc -INCLUDES += -I$(OSAL)/src/os/inc -INCLUDES += -I$(OSAL)/build/inc - -# -# UT_OBJS specifies unit test object files. -# -UT_OBJS += $(APP)_testcase.o -UT_OBJS += $(APP)_stubs.o - - -############################################################################### - -COMPILER=gcc -LINKER=gcc - -# -# Compiler and Linker Options -# -ENABLE_GCOV = TRUE -ifeq ($(ENABLE_GCOV), TRUE) -GCOV_COPT = --coverage -GCOV_LOPT = --coverage -endif - -#WARNINGS = -Wall -W -ansi -Werror -Wstrict-prototypes -Wundef -WARNINGS = -Wall -Wstrict-prototypes -DEBUGGER = -g - -#COPT = $(WARNINGS) $(DEBUGGER) $(GCOV_COPT) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D__x86_64__ -D_LINUX_OS_ -COPT = $(WARNINGS) $(DEBUGGER) -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D_ix86_ $(OSAL_M32) - -LOPT = $(OSAL_M32) - -############################################################################### -## "C" COMPILER RULE -## -%.o: %.c - $(COMPILER) -c $(COPT) $(INCLUDES) $< - -############################################################################## -## - -all:$(APP)_testrunner.exe - -$(APP)_testrunner.exe: $(UT_OBJS) - $(LINKER) $(GCOV_LOPT) $(LOPT) -o $@ $^ ../ut-osal/ostimer.o ../testrunner.o - -clean :: - rm -f *.o *.exe *.gcda *.gcno *.gcov gmon.out $(APP)_log.txt - -run :: - ./$(APP)_testrunner.exe | tee ./$(APP)_log.txt - -# end of file diff --git a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_accessor.h b/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_accessor.h deleted file mode 100644 index 0e3276bd2..000000000 --- a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_accessor.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * File: ostimer_accessor.h - * - * Purpose: - * Provide private accessors for getting/manipulating ostimer.c's static data. - * - * History: - * 06/30/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSTIMER_ACCESSOR_H_ -#define _OSTIMER_ACCESSOR_H_ - -/* - * File: ostimer_accessor.h - * - * Purpose: - * Provide accesssor functions for unit testing ostimer.c - * - * History: - * 06/30/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - */ - -#include "uttools.h" -#include "vxworks6-coverage-stubs.h" -#include "common_types.h" -#include "osapi.h" - -/* --------------- Prototypes for non-exported functions -------------------- */ -void OS_UsecToTimespec(uint32 usecs, struct timespec *time_spec); -void OS_TimespecToUsec(struct timespec time_spec, uint32 *usecs); - -/* -------------- Delegation function for static functions ------------------ */ -void Pvt_OS_TimerSignalHandler(int host_timer_id); - -/* --------------------- Custom Accessors ----------------------------------- */ -/* Note, the types that support these prototypes - * are in ostimer_copiedstatictypes.h */ - -/* Setters & getters for pointers to the OS_timer_table and - * os_clock_accuracy. */ -OS_timer_record_t* getOSTimeTablePtr(void); -void setOSTimeTablePtr(OS_timer_record_t* ptr); - -uint32* getOSClockAccuracyPtr(void); -uint32 getOSClockAccuracy(void); -void setOSClockAccuracyPtr(uint32* ptr); -void setOSClockAccuracy(uint32 accuracy); - -uint32 getMaxSecsInUSec(void); - -/* An initialization function to set the pointers before any -* ostimer.c calls occur. */ -void initStaticPointers(void); - -#endif /* _OSTIMER_ACCESSOR_H_ */ - diff --git a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_copiedstatictypes.h b/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_copiedstatictypes.h deleted file mode 100644 index 6ab98ffa3..000000000 --- a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_copiedstatictypes.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * File: ostimer_copiedstatictypes.h - * - * Purpose: - * Provides a copy of the types from ostimer.c to support - * use of private accessors. - * - * History: - * 06/30/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSTIMER_COPIEDSTATICTYPES_H_ -#define _OSTIMER_COPIEDSTATICTYPES_H_ - -/* - * File: ostimer_accessor.h - * - * Purpose: - * Provide accesssor functions for unit testing ostimer.c - * - * History: - * 06/30/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - */ - -#include "uttools.h" -#include "vxworks6-coverage-stubs.h" -#include "common_types.h" -#include "osapi.h" - -/* This type is copied directly from ostimer.c - * so that the tests can access them. We put - * it here in a separate header so we don't get - * multiply-defined types in the same compilation - * unit as the 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; - -#endif /* _OSTIMER_COPIEDSTATICTYPES_H_ */ - diff --git a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_stubs.c b/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_stubs.c deleted file mode 100644 index 30f573cf2..000000000 --- a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_stubs.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * File: ostimer_stubs.c - * - * Purpose: - * Stub out various functions not stubbed out by the UT-Assert code - * - * Modification History: - * 06/29/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - * - */ - -#include - -#include "osapi.h" /* cfe.h not available from within osal. */ - -#include "ostimer_stubs.h" - - -OsTimer_HookTable_t OsTimer_HookTable; -OsTimer_ReturnCodeTable_t OsTimer_ReturnCodeTable[OSTIMER_MAX_INDEX]; - -char testname[] = "testname"; -int32 nSemTake = 0; -int32 nSemGive = 0; - -uint32 callbackCount; - -VCS_SEM_ID VCS_semMCreate(int options) -{ - if (OsTimer_UseReturnCode(OSTIMER_SEMMCREATE_INDEX)) - return (VCS_SEM_ID)OsTimer_ReturnCodeTable[OSTIMER_SEMMCREATE_INDEX].Value; - - return NULL; -} - -VCS_STATUS VCS_semTake(VCS_SEM_ID semId, int timeout) -{ - nSemTake += 1; - - return nSemTake; -} - - -VCS_STATUS VCS_semGive(VCS_SEM_ID semId) -{ - nSemGive += 1; - - return nSemGive; -} - -int32 getNSemTake() -{ - return nSemTake; -} - -int32 getNSemGive() -{ - return nSemGive; -} - -uint32 OS_FindCreator(void) -{ - if (OsTimer_UseReturnCode(OSTIMER_OS_FINDCREATOR_INDEX)) - return (uint32)OsTimer_ReturnCodeTable[OSTIMER_OS_FINDCREATOR_INDEX].Value; - - return 0; -} - -int VCS_timer_create (VCS_clockid_t clock_id, - struct VCS_sigevent *evp, - VCS_timer_t *timerid) -{ - if (OsTimer_UseReturnCode(OSTIMER_TIMER_CREATE_INDEX)) - return (int)OsTimer_ReturnCodeTable[OSTIMER_TIMER_CREATE_INDEX].Value; - - return 0; -} - -int VCS_timer_delete (VCS_timer_t __timerid) -{ - if (OsTimer_UseReturnCode(OSTIMER_TIMER_DELETE_INDEX)) - return (int)OsTimer_ReturnCodeTable[OSTIMER_TIMER_DELETE_INDEX].Value; - - return 0; -} -int VCS_timer_connect (VCS_timer_t timerid, VCS_VOIDFUNCPTR routine, int possible_id) -{ - if (OsTimer_UseReturnCode(OSTIMER_TIMER_CONNECT_INDEX)) - return (int)OsTimer_ReturnCodeTable[OSTIMER_TIMER_CONNECT_INDEX].Value; - - return 0; -} - -int VCS_timer_settime (VCS_timer_t timerid, int flags, - const struct VCS_itimerspec *value, - struct VCS_itimerspec * ovalue) -{ - if (OsTimer_UseReturnCode(OSTIMER_TIMER_SETTIME_INDEX)) - return (int)OsTimer_ReturnCodeTable[OSTIMER_TIMER_SETTIME_INDEX].Value; - - return 0; -} - -void OsTimer_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt) -{ - if (Index < OSTIMER_MAX_INDEX) { - OsTimer_ReturnCodeTable[Index].Value = RtnVal; - OsTimer_ReturnCodeTable[Index].Count = CallCnt; - } - else { - printf("Unsupported Index In SetReturnCode Call %u\n", (unsigned int)Index); - } -} - - -boolean OsTimer_UseReturnCode(uint32 Index) -{ - if (OsTimer_ReturnCodeTable[Index].Count > 0) { - OsTimer_ReturnCodeTable[Index].Count--; - if (OsTimer_ReturnCodeTable[Index].Count == 0) - return(TRUE); - } - - return(FALSE); -} - - -void OsTimer_SetFunctionHook(uint32 Index, void *FunPtr) -{ - if (Index == OSTIMER_SEMMCREATE_INDEX) { OsTimer_HookTable.semMCreate = FunPtr; } - else if (Index == OSTIMER_SEMTAKE_INDEX) { OsTimer_HookTable.semTake = FunPtr; } - else if (Index == OSTIMER_SEMGIVE_INDEX) { OsTimer_HookTable.semGive = FunPtr; } - else if (Index == OSTIMER_CLOCKGETRES_INDEX) { OsTimer_HookTable.clock_getres = FunPtr; } - else if (Index == OSTIMER_OS_FINDCREATOR_INDEX) { OsTimer_HookTable.OS_FindCreator = FunPtr; } - else - { - printf("Unsupported OsTimer Index In SetFunctionHook Call %u\n", (unsigned int)Index); - } -} - - -void OsTimer_Reset(void) -{ - memset(&OsTimer_HookTable, 0, sizeof(OsTimer_HookTable)); - memset(&OsTimer_ReturnCodeTable, 0, sizeof(OsTimer_ReturnCodeTable)); - nSemTake = 0; - nSemGive = 0; -} - -int VCS_clock_getres(VCS_clockid_t clock, struct VCS_timespec *clock_resolution) -{ - if (OsTimer_UseReturnCode(OSTIMER_CLOCKGETRES_INDEX)) { - return (int)OsTimer_ReturnCodeTable[OSTIMER_CLOCKGETRES_INDEX].Value; - } - clock_resolution->tv_sec = 0; - clock_resolution->tv_nsec = 1000; - return 0; -} - -void FakeTimerCallback(uint32 timer_id) { - callbackCount++; -} - -void ResetFakeTimerCallback(void) { - callbackCount = 0; -} - -uint32 GetFakeTimerCallbackCount() { - return callbackCount; -} - -/* C library calls that are just straight-through wrappers in this test */ -size_t VCS_strlen(const char *str) -{ - return strlen(str); -} - -int VCS_strcmp(const char *str1, const char *str2) -{ - return strcmp(str1, str2); -} - -int VCS_strncmp(const char *str1, const char *str2, size_t n) -{ - return strncmp(str1, str2, n); -} - -char *VCS_strcpy(char *str1, const char *str2) -{ - return strcpy(str1, str2); -} - -char *VCS_strncpy(char *str1, const char *str2, size_t n) -{ - return strncpy(str1, str2, n); -} - -void VCS_memset(void *ptr, int c, unsigned int size) -{ - memset(ptr, c, size); -} - - diff --git a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_stubs.h b/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_stubs.h deleted file mode 100644 index 20c1dd197..000000000 --- a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_stubs.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * File: ostimer_stubs.h - * - * Purpose: - * Provide stubs for unit testing ostimer.c - * - * History: - * 06/29/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSTIMER_STUBS_H_ -#define _OSTIMER_STUBS_H_ - -#include "uttools.h" -#include "vxworks6-coverage-stubs.h" -#include "time.h" -#include "osconfig.h" - -/* Define missing types */ -typedef struct -{ - int32 Dir; -} __dirstream; - -typedef enum -{ - OSTIMER_SEMMCREATE_INDEX, - OSTIMER_SEMTAKE_INDEX, - OSTIMER_SEMGIVE_INDEX, - OSTIMER_CLOCKGETRES_INDEX, - OSTIMER_OS_FINDCREATOR_INDEX, - OSTIMER_TIMER_CREATE_INDEX, - OSTIMER_TIMER_DELETE_INDEX, - OSTIMER_TIMER_CONNECT_INDEX, - OSTIMER_TIMER_SETTIME_INDEX, - OSTIMER_MAX_INDEX -} OsTimer_Index_t; - -typedef struct -{ - int32 Value; - uint32 Count; -} OsTimer_ReturnCodeTable_t; - -typedef struct -{ - VCS_SEM_ID (*semMCreate)(uint16 *); - VCS_STATUS (*semTake)(VCS_SEM_ID, int); - VCS_STATUS (*semGive)(VCS_SEM_ID); - int (*clock_getres)(int clocktype, struct VCS_timespec *clock_resolution); - uint32 (*OS_FindCreator)(void); - int (*timer_create)(VCS_clockid_t, struct VCS_sigevent *, VCS_timer_t *); - int (*timer_delete)(VCS_timer_t); - int (*timer_connect) (VCS_timer_t, void (*OS_TimerSignalHandler)(int host_timer_id), uint32 possible_id); - int (*timer_settime) (VCS_timer_t, int , const struct VCS_itimerspec *, struct VCS_itimerspec *); -} OsTimer_HookTable_t; - -extern const char testFileName[]; - -void OsTimer_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt); -void OsTimer_SetFunctionHook(uint32 Index, void *FunPtr); -void OsTimer_Reset(void); -boolean OsTimer_UseReturnCode(uint32 Index); - -int32 getNSemTake(void); -int32 getNSemGive(void); - -#if 0 -/* The timer_connect protoype is iffy. The commented-out prototype is more type-correct for the use - * in ostimer.c. However, the callback pointer isn't the same as the VOIDFCNPTR as defined in VxWorks. - * The difference is void (*)() vs. void (*) (int). In Linux with gcc 4.4.x we get a warning due to - * ostimer.c usage, but the test operates as desired. In VxWorks, this function signature doesn't - * match well enough to compile. -int timer_connect (timer_t t, void (*OS_TimerSignalHandler)(int host_timer_id), uint32 possible_id); - * The VxWorks version: - */ -extern int timer_connect (timer_t timerid, VOIDFUNCPTR routine, int arg); -#endif - -void FakeTimerCallback(uint32 timer_id); -void ResetFakeTimerCallback(void); -uint32 GetFakeTimerCallbackCount(void); - -#endif /* _OSTIMER_STUBS_H_ */ diff --git a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_testcase.c b/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_testcase.c deleted file mode 100644 index c8285cb56..000000000 --- a/src/unit-test-coverage/vxworks6/ostimer-test/ostimer_testcase.c +++ /dev/null @@ -1,1596 +0,0 @@ -/* - * Filename: ostimer_testcase.c - * - * Purpose: This file contains unit test cases - * - * Modification History: - * 06/29/2015, A. Brown, Odyssey Space Research, LLC - * * Created - * - */ - - -/* - * Includes - */ -#include "osapi.h" - -#include "utassert.h" -#include "uttest.h" -#include "utlist.h" - -#include "ostimer_stubs.h" - -#include "ostimer_copiedstatictypes.h" -#include "ostimer_accessor.h" - -/* ------------------ Copied info from unit under test ---------------------- */ - - -/* --------------- Prototypes for non-exported functions -------------------- */ - - -/* -------------------- Special Test Case Variables ------------------------- */ - - - -/* ------------------------Utility functions--------------------------------- */ - -/* OsTimer_ReinitStaticOSTimerTable - * - * Reinitialize ostimer.c's static OS_timer_table. - * Only call this after initStaticPointers(); - */ -void OsTimer_ReinitStaticOSTimerTable(void) -{ - unsigned int i, j; - OS_timer_record_t* tbl = getOSTimeTablePtr(); - - for ( i = 0; i < OS_MAX_TIMERS; i++ ) - { - tbl->free = TRUE; - tbl->creator = 0; - for ( j = 0; j < OS_MAX_API_NAME; j++ ) - { - tbl->name[j] = '\0'; - } - tbl->creator = 0; - tbl->start_time = 0; - tbl->interval_time = 0; - tbl->accuracy = 0; - tbl->callback_ptr = (OS_TimerCallback_t)NULL; - tbl->host_timerid = 0; - tbl++; - } -} - -/* OsTimer_SetStaticOSTimerTableNotFree - * - * Reinitialize ostimer.c's static OS_timer_table so that - * all indicators are entry->free = FALSE; - * Only call this after initStaticPointers(); - */ -void OsTimer_SetStaticOSTimerTableNotFree(void) -{ - unsigned int i; - OS_timer_record_t* tbl = getOSTimeTablePtr(); - - for ( i = 0; i < OS_MAX_TIMERS; i++ ) - { - tbl->free = FALSE; - tbl++; - } -} - -/* OsTimer_countStaticOSTimerTableUsed - * Counts the entry->free elements in - * the OS_timer_table are FALSE. - * Only call this after initStaticPointers(); - */ -unsigned int OsTimer_countStaticOSTimerTableUsed(void) -{ - unsigned int i; - OS_timer_record_t* tbl = getOSTimeTablePtr(); - unsigned int retval = 0; - - for ( i = 0; i < OS_MAX_TIMERS; i++ ) - { - if (tbl->free == FALSE) { - retval++; - } - tbl++; - } - return retval; -} - -/* OsTimer_isStaticOSTimerTableFree - * Checks that all of the entry->free elements in - * the OS_timer_table are TRUE. - * Only call this after initStaticPointers(); - */ -boolean OsTimer_isStaticOSTimerTableFree(void) -{ - return (OsTimer_countStaticOSTimerTableUsed() == 0); -} - -/* --------------------- Begin test cases --------------------------------- */ - -/******************************************************************************* -** -** OS_TimerAPIInit() Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerAPIInit_Success(void) -{ - /* Setup Inputs */ - OsTimer_SetReturnCode(OSTIMER_SEMMCREATE_INDEX, 1, 1); /* success */ - - /* Execute Test */ - int32 retval = OS_TimerAPIInit(); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "Checking OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerAPIInit_clock_getresFAIL(void) -{ - /* Setup Inputs */ - OsTimer_SetReturnCode(OSTIMER_CLOCKGETRES_INDEX, -1, 1); /* fail */ - OsTimer_SetReturnCode(OSTIMER_SEMMCREATE_INDEX, 1, 1); /* success */ - - /* Execute Test */ - int32 retval = OS_TimerAPIInit(); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERROR, "Checking OS_ERROR"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerAPIInit_semMCreateFAIL(void) -{ - /* Setup Inputs */ - OsTimer_SetReturnCode(OSTIMER_SEMMCREATE_INDEX, (int32)NULL, 1); /* fail */ - - /* Execute Test */ - int32 retval = OS_TimerAPIInit(); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERROR, "Checking OS_ERROR"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} - -/******************************************************************************* -** -** OS_UsecToTimespec() Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_UsecToTimespec_1(void) -{ - /* Setup Inputs */ - uint32 usecs = 10; - struct timespec ts = {0, 0}; - - /* Execute Test */ - OS_UsecToTimespec(usecs, &ts); - - /* Verify Outputs */ - UtAssert_True(ts.tv_sec == 0, "tv_sec == 0"); - UtAssert_True(ts.tv_nsec == (10*1000), "tv_nsec == 10k"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_UsecToTimespec_2(void) -{ - /* Setup Inputs */ - uint32 usecs = 10*1000000; - struct timespec ts = {0, 0}; - - /* Execute Test */ - OS_UsecToTimespec(usecs, &ts); - - /* Verify Outputs */ - UtAssert_True(ts.tv_sec == 10, "tv_sec == 10"); - UtAssert_True(ts.tv_nsec == 0, "tv_nsec == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_UsecToTimespec_NullPtrArg(void) -{ - /* Setup Inputs */ - uint32 usecs = 10*1000000; - - /* Execute Test */ - OS_UsecToTimespec(usecs, 0); - - /* Verify Outputs */ - UtAssert_True(TRUE, "segfault avoided!"); -} - -/******************************************************************************* -** -** OS_TimespecToUsec() Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TimespecToUsec_1(void) -{ - /* Setup Inputs */ - uint32 usecs = 0; - struct timespec ts = {0, (10*1000)}; - - /* Execute Test */ - OS_TimespecToUsec(ts, &usecs); - - /* Verify Outputs */ - UtAssert_True(usecs == 10, "usecs == 10"); -} -/*----------------------------------------------------------------------------*/ -/* The same test as 2b, with the output unset before the call. This shouldn't - * have an effect on behavior, but it does. Fails before issue 62 is resolved, - * passes after. - * See https://babelfish.arc.nasa.gov/trac/cfs_osal/ticket/62 */ -void Test_OS_TimespecToUsec_2(void) -{ - /* Setup Inputs */ - uint32 usecs = 0; - uint32 max_secs_in_usec = getMaxSecsInUSec(); - struct timespec ts = {max_secs_in_usec+1U, 0}; - - /* Execute Test */ - OS_TimespecToUsec(ts, &usecs); - - /* Verify Outputs */ - /* NOTE THE TRUNCATION - we lost a second */ - UtAssert_True(usecs == ((getMaxSecsInUSec()) * 1000000), "usecs == max"); -} -/*----------------------------------------------------------------------------*/ -/* The same test as 2, with the output set before the call. - * Passes before and after issue 62 fix. - * See https://babelfish.arc.nasa.gov/trac/cfs_osal/ticket/62 */ -void Test_OS_TimespecToUsec_2b(void) -{ - /* Setup Inputs */ - uint32 usecs = 1000000; /* set the output to get past the if-test */ - struct timespec ts = {getMaxSecsInUSec()+1, 0}; - - /* Execute Test */ - OS_TimespecToUsec(ts, &usecs); - - /* Verify Outputs */ - /* NOTE THE TRUNCATION - we lost a second */ - UtAssert_True(usecs == ((getMaxSecsInUSec()) * 1000000), "usecs == max"); -} -/*----------------------------------------------------------------------------*/ -/* The same test as 3b, with the output unset before the call. This shouldn't - * have an effect on behavior, but it does. Fails before issue 62 is resolved, - * passes after. - * See https://babelfish.arc.nasa.gov/trac/cfs_osal/ticket/62 */ -void Test_OS_TimespecToUsec_3(void) -{ - /* Setup Inputs */ - uint32 usecs = 0; - struct timespec ts = {10, 0}; - - /* Execute Test */ - OS_TimespecToUsec(ts, &usecs); - - /* Verify Outputs */ - UtAssert_True(usecs == (10*1000000), "usecs == 10million"); -} -/*----------------------------------------------------------------------------*/ -/* The same test as 3, with the output set before the call. - * Passes before and after issue 62 fix. - * See https://babelfish.arc.nasa.gov/trac/cfs_osal/ticket/62 */ -void Test_OS_TimespecToUsec_3b(void) -{ - /* Setup Inputs */ - uint32 usecs = 1000000; /* set the output to get past the if-test */ - struct timespec ts = {10, 0}; - - /* Execute Test */ - OS_TimespecToUsec(ts, &usecs); - - /* Verify Outputs */ - UtAssert_True(usecs == (10*1000000), "usecs == 10million"); -} - -/*----------------------------------------------------------------------------*/ -/* A max-range check for a signed int value of usecs. - * See https://babelfish.arc.nasa.gov/trac/cfs_osal/ticket/62 */ -void Test_OS_TimespecToUsec_4(void) -{ - /* Setup Inputs */ - uint32 usecs_in = 2147483647; - struct timespec ts = {0, 0}; - uint32 usecs_out = 0; - - /* Execute Test */ - OS_UsecToTimespec(usecs_in, &ts); - OS_TimespecToUsec(ts, &usecs_out); - - /* Verify Outputs */ - UtAssert_True(usecs_in == usecs_out, "usecs_in == usecs_out"); - UtAssert_True(ts.tv_sec >= 0, "ts.tv_sec >= 0"); - UtAssert_True(ts.tv_nsec >= 0, "ts.tv_nsec >= 0"); -} -/*----------------------------------------------------------------------------*/ -/* A max-range check to confirm where truncation begins. - * See https://babelfish.arc.nasa.gov/trac/cfs_osal/ticket/62 */ -void Test_OS_TimespecToUsec_4b(void) -{ - /* Setup Inputs */ - uint32 usecs_in = 4294000000U; /* truncation begins */ - struct timespec ts = {0, 0}; - uint32 usecs_out = 0; - - /* Execute Test */ - OS_UsecToTimespec(usecs_in, &ts); - OS_TimespecToUsec(ts, &usecs_out); - - /* Verify Outputs */ - UtAssert_True(usecs_in != usecs_out, "usecs_in != usecs_out"); - UtAssert_True(ts.tv_sec >= 0, "ts.tv_sec >= 0"); - UtAssert_True(ts.tv_nsec >= 0, "ts.tv_nsec >= 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimespecToUsec_NullPtrArg(void) -{ - /* Setup Inputs */ - struct timespec ts = {0, (10*1000)}; - - /* Execute Test */ - OS_TimespecToUsec(ts, 0); - - /* Verify Outputs */ - UtAssert_True(TRUE, "segfault avoided!"); -} -/******************************************************************************* -** -** OS_TimerCreate() Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate(void) /* Nominal behavior test */ -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[] = "test name"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_NullArg1(void) -{ - /* Setup Inputs */ - const char name[] = "test name"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Execute Test */ - retval = OS_TimerCreate(NULL, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_NullArg2(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, NULL, clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_NullArg3(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[] = "test name"; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], NULL, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_NullArg4(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[] = "test name"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = NULL; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_TIMER_ERR_INVALID_ARGS, "retval == OS_TIMER_ERR_INVALID_ARGS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_NameTooLong(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[] = "test nameTOOOOOOOOOLOOOOOOOOONGGGGGGGGG!!!!!!!"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_NAME_TOO_LONG, "retval == OS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_NameMaxLength(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - /* 20 chars including \0, OS_MAX_API_NAME, should be successful */ - const char name[20] = "0123456789012345678\0"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); - - OS_timer_record_t* tbl = getOSTimeTablePtr(); - UtAssert_MemCmp(name, tbl->name, OS_MAX_API_NAME, "Checking Name Copy In Table"); - UtAssert_True(tbl->name[OS_MAX_API_NAME-1] == 0, "timer name end with NULL char"); - UtAssert_True(strlen(tbl->name) <= OS_MAX_API_NAME, "Time name length"); -} -/*----------------------------------------------------------------------------*/ -/* See https://babelfish.arc.nasa.gov/trac/cfs_osal/ticket/65 - * This test has failures before the issue #65 fix, but should pass after. */ -void Test_OS_TimerCreate_NameMaxLengthPlus1(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[21] = "01234567890123456789\0"; /* 21 chars with, OS_MAX_API_NAME+1 */ - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - /* The given arg is too long with its terminating null. */ - UtAssert_True(retval == OS_ERR_NAME_TOO_LONG, "retval == OS_ERR_NAME_TOO_LONG"); - - /* Always, :-) */ - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - /* The too-long arg should not require a semaphore lock. */ - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); - /* If failure, then no timer should be crated: */ - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_FullTable(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[] = "test name"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Mark everything in the table as not free. */ - OsTimer_SetStaticOSTimerTableNotFree(); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_NO_FREE_IDS, "retval == OS_ERR_NO_FREE_IDS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == OS_MAX_TIMERS, "OsTimer_countStaticOSTimerTableUsed() == OS_MAX_TIMERS"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_NameNotTaken(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[] = "test name"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Mark the first element as not free and give it a name. */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - strncpy(tbl->name, "BOGUSname", OS_MAX_API_NAME); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 2, "OsTimer_countStaticOSTimerTableUsed() == 2"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_NameTaken(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[] = "test name"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Mark the first element as not free and give it a name. */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - strncpy(tbl->name, "test name", OS_MAX_API_NAME); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_NAME_TAKEN, "retval == OS_ERR_NAME_TAKEN"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerCreate_timercreateFAIL(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[] = "test name"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* make create_timer() fail */ - OsTimer_SetReturnCode(OSTIMER_TIMER_CREATE_INDEX, -1, 1); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_TIMER_ERR_UNAVAILABLE, "retval == OS_TIMER_ERR_UNAVAILABLE"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} -/*----------------------------------------------------------------------------*/ -/* See: https://babelfish.arc.nasa.gov/trac/cfs_osal/ticket/66 - * Test fails before this ticket's change, passes afterwards. */ -void Test_OS_TimerCreate_timerconnectFAIL(void) -{ - /* Setup Inputs */ - uint32 id = 0; - uint32 *timer_id = &id; - const char name[] = "test name"; - uint32 ca = 1000; - uint32 *clock_accuracy = &ca; - OS_TimerCallback_t callback_ptr = (OS_TimerCallback_t)1; - int32 retval = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* make create_timer() fail */ - OsTimer_SetReturnCode(OSTIMER_TIMER_CONNECT_INDEX, -1, 1); - - /* Execute Test */ - retval = OS_TimerCreate(timer_id, &name[0], clock_accuracy, callback_ptr); - - /* Verify Outputs */ - UtAssert_True(retval == OS_TIMER_ERR_UNAVAILABLE, "retval == OS_TIMER_ERR_UNAVAILABLE"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} - -/******************************************************************************* -** -** OS_TimerSet() Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSet(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; /* table index [0]*/ - uint32 start_time = 0; - uint32 interval_time = 1; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_SETTIME_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerSet(timer_id, start_time, interval_time); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); - UtAssert_True(tbl->start_time == 0, "tbl->start_time == 0"); - UtAssert_True(tbl->interval_time > 0, "tbl->interval_time > 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSet_BadArg1(void) -{ - /* Setup Inputs */ - uint32 timer_id = OS_MAX_TIMERS; - uint32 start_time = 0; - uint32 interval_time = 1; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_SETTIME_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerSet(timer_id, start_time, interval_time); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); - UtAssert_True(tbl->start_time == 0, "tbl->start_time == 0"); - UtAssert_True(tbl->interval_time == 0, "tbl->interval_time == 0"); -} - -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSet_FreeEntry(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; - uint32 start_time = 0; - uint32 interval_time = 1; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) free" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = TRUE; - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_SETTIME_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerSet(timer_id, start_time, interval_time); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); - UtAssert_True(tbl->start_time == 0, "tbl->start_time == 0"); - UtAssert_True(tbl->interval_time == 0, "tbl->interval_time == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSet_NonZeroStart(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; /* table index [0]*/ - uint32 start_time = 1; - uint32 interval_time = 1; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_SETTIME_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerSet(timer_id, start_time, interval_time); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); - UtAssert_True(tbl->start_time == 1, "tbl->start_time == 1"); - UtAssert_True(tbl->interval_time > 0, "tbl->interval_time > 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSet_StartLTAccuracy(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; /* table index [0]*/ - uint32 start_time = 1; - uint32 interval_time = 1; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - setOSClockAccuracy(2); /* .vs a start_time==1 */ - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_SETTIME_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerSet(timer_id, start_time, interval_time); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); - UtAssert_True(tbl->start_time == 2, "tbl->start_time == 2"); - UtAssert_True(tbl->interval_time > 0, "tbl->interval_time > 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSet_IntervalLTAccuracy(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; /* table index [0]*/ - uint32 start_time = 10; - uint32 interval_time = 1; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - setOSClockAccuracy(2); /* .vs a interval_time==1 */ - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_SETTIME_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerSet(timer_id, start_time, interval_time); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); - UtAssert_True(tbl->start_time == start_time, "tbl->start_time == start_time"); - UtAssert_True(tbl->interval_time == 2, "tbl->interval_time > 2"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSet_ZeroInterval(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; /* table index [0]*/ - uint32 start_time = 0; - uint32 interval_time = 0; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - setOSClockAccuracy(2); - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_SETTIME_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerSet(timer_id, start_time, interval_time); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); - UtAssert_True(tbl->start_time == 0, "tbl->start_time == 0"); - UtAssert_True(tbl->interval_time == 0, "tbl->interval_time == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSet_timersettimeFAIL(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; /* table index [0]*/ - uint32 start_time = 0; - uint32 interval_time = 1; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_SETTIME_INDEX, -1, 1); - - /* Execute Test */ - retval = OS_TimerSet(timer_id, start_time, interval_time); - - /* Verify Outputs */ - UtAssert_True(retval == OS_TIMER_ERR_INTERNAL, "retval == OS_TIMER_ERR_INTERNAL"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); - UtAssert_True(tbl->start_time == 0, "tbl->start_time == 0"); - UtAssert_True(tbl->interval_time > 0, "tbl->interval_time > 0"); -} - - -/******************************************************************************* -** -** OS_TimerDelete() Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerDelete(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; /* table index [0]*/ - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_DELETE_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerDelete(timer_id); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerDelete_BadArg(void) -{ - /* Setup Inputs */ - uint32 timer_id = OS_MAX_TIMERS; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_DELETE_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerDelete(timer_id); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(OsTimer_countStaticOSTimerTableUsed() == 1, "OsTimer_countStaticOSTimerTableUsed() == 1"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerDelete_FreeEntry(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) free" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = TRUE; - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_DELETE_INDEX, 1, 1); - - /* Execute Test */ - retval = OS_TimerDelete(timer_id); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerDelete_timerdeleteFAIL(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; /* table index [0]*/ - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - /* Set hooks */ - OsTimer_SetReturnCode(OSTIMER_TIMER_DELETE_INDEX, -1, 1); - - /* Execute Test */ - retval = OS_TimerDelete(timer_id); - - /* Verify Outputs */ - UtAssert_True(retval == OS_TIMER_ERR_INTERNAL, "retval == OS_TIMER_ERR_INTERNAL"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(OsTimer_isStaticOSTimerTableFree(), "OsTimer_isStaticOSTimerTableFree()"); -} - -/******************************************************************************* -** -** OS_TimerGetIdByName() Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetIdByName(void) -{ - /* Setup Inputs */ - uint32 timer_id = 99; - const char name[] = "test name"; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - /* Give it the expected name */ - strncpy(&(tbl->name[0]), &(name[0]), OS_MAX_API_NAME); - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetIdByName(&timer_id, name); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(timer_id == 0, "timer_id == 0"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetIdByName_NullArg1(void) -{ - /* Setup Inputs */ - uint32 timer_id = 99; - const char name[] = "test name"; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - /* Give it the expected name */ - strncpy(&(tbl->name[0]), &(name[0]), OS_MAX_API_NAME); - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetIdByName(NULL, name); - - /* Verify Outputs */ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - UtAssert_True(timer_id == 99, "timer_id == 99"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetIdByName_NullArg2(void) -{ - /* Setup Inputs */ - uint32 timer_id = 99; - const char name[] = "test name"; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - /* Give it the expected name */ - strncpy(&(tbl->name[0]), &(name[0]), OS_MAX_API_NAME); - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetIdByName(&timer_id, NULL); - - /* Verify Outputs */ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - UtAssert_True(timer_id == 99, "timer_id == 99"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetIdByName_NameMaxLength(void) -{ - /* Setup Inputs */ - uint32 timer_id = 99; - const char name[20] = "0123456789012345678\0"; /* 20 chars, OS_MAX_API_NAME */ - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - /* Give it the expected name */ - strncpy(&(tbl->name[0]), &(name[0]), OS_MAX_API_NAME); - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetIdByName(&timer_id, name); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(timer_id == 0, "timer_id == 0"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); -} -/*----------------------------------------------------------------------------*/ -/* See https://babelfish.arc.nasa.gov/trac/cfs_osal/ticket/65 - * This test has failures before the issue #65 fix, but should pass after. */ -void Test_OS_TimerGetIdByName_NameMaxLengthPlus1(void) -{ - /* Setup Inputs */ - uint32 timer_id = 99; - const char name[21] = "01234567890123456789\0"; /* 21 chars, OS_MAX_API_NAME+1 */ - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - /* Give it the expected name */ - strncpy(&(tbl->name[0]), &(name[0]), OS_MAX_API_NAME); /* shorter than above */ - tbl->name[OS_MAX_API_NAME-1] = 0; /* Properly null-terminate it. */ - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetIdByName(&timer_id, name); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_NAME_TOO_LONG, "retval == OS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetIdByName_NameTooLong(void) -{ - /* Setup Inputs */ - uint32 timer_id = 99; - const char name[] = "REEEEEAAAAALLLLLLYYYYYYYTOOOOOOOOLLOOOONNNNGGGG"; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - /* Give it the expected name */ - strncpy(&(tbl->name[0]), &(name[0]), OS_MAX_API_NAME); /* shorter than above */ - tbl->name[OS_MAX_API_NAME-1] = 0; /* Properly null-terminate it. */ - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetIdByName(&timer_id, name); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_NAME_TOO_LONG, "retval == OS_ERR_NAME_TOO_LONG"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetIdByName_FreeEntry(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; - const char name[] = "test name"; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetIdByName(&timer_id, name); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_NAME_NOT_FOUND, "retval == OS_ERR_NAME_NOT_FOUND"); - UtAssert_True(timer_id == 0, "timer_id == 0"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetIdByName_NameMismatch(void) -{ - /* Setup Inputs */ - uint32 timer_id = 99; - const char name[] = "test name"; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - /* Give it the expected name */ - strncpy(&(tbl->name[0]), "fake name", OS_MAX_API_NAME); - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetIdByName(&timer_id, name); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_NAME_NOT_FOUND, "retval == OS_ERR_NAME_NOT_FOUND"); - UtAssert_True(timer_id == 99, "timer_id == 99"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); -} -/******************************************************************************* -** -** OS_TimerGetInfo() Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetInfo(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; - const char name[] = "test name"; - int32 retval = OS_ERROR; - OS_timer_prop_t timer_prop; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - /* Give it the expected name */ - strncpy(&(tbl->name[0]), &(name[0]), OS_MAX_API_NAME); - tbl->creator = 5; - tbl->start_time = 6; - tbl->interval_time = 4; - tbl->accuracy = 2; - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetInfo(timer_id, &timer_prop); - - /* Verify Outputs */ - UtAssert_True(retval == OS_SUCCESS, "retval == OS_SUCCESS"); - UtAssert_True(timer_prop.creator == 5, "timer_prop.creator == 5"); - UtAssert_True(timer_prop.start_time == 6, "timer_prop.start_time == 6"); - UtAssert_True(timer_prop.interval_time == 4, "timer_prop.interval_time == 4"); - UtAssert_True(timer_prop.accuracy == 2, "timer_prop.accuracy == 2"); - UtAssert_True(strcmp (&(timer_prop.name[0]),name) == 0, "timer_prop.name check"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetInfo_BadArg1(void) -{ - /* Setup Inputs */ - uint32 timer_id = OS_MAX_TIMERS; - int32 retval = OS_ERROR; - OS_timer_prop_t timer_prop; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetInfo(timer_id, &timer_prop); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetInfo_BadArg2(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; - int32 retval = OS_ERROR; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) use" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = FALSE; - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetInfo(timer_id, NULL); - - /* Verify Outputs */ - UtAssert_True(retval == OS_INVALID_POINTER, "retval == OS_INVALID_POINTER"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 0, "nSemTake == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerGetInfo_FreeEntry(void) -{ - /* Setup Inputs */ - uint32 timer_id = 0; - int32 retval = OS_ERROR; - OS_timer_prop_t timer_prop; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set a timer in the table to "(fake) not used" - * index [0] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl->free = TRUE; - - /* Set hooks */ - - /* Execute Test */ - retval = OS_TimerGetInfo(timer_id, &timer_prop); - - /* Verify Outputs */ - UtAssert_True(retval == OS_ERR_INVALID_ID, "retval == OS_ERR_INVALID_ID"); - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); -} - -/******************************************************************************* -** -** OS_TimerSignalHandler() Tests -** -*******************************************************************************/ -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSignalHandler(void) -{ - /* Setup Inputs */ - uint32 timer_id = 1; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set hooks */ - - /* Set a timer in the table to "(fake) USED" - * index [1] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl++; - tbl->free = FALSE; - tbl->callback_ptr = (*FakeTimerCallback); - tbl->host_timerid = timer_id; - - /* Execute Test */ - Pvt_OS_TimerSignalHandler(timer_id); - - /* Verify Outputs */ - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(GetFakeTimerCallbackCount() == 1, "GetFakeTimerCallbackCount() == 1"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSignalHandler_Empty(void) -{ - /* Setup Inputs */ - uint32 timer_id = 99; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set hooks */ - - /* Execute Test */ - Pvt_OS_TimerSignalHandler(timer_id); - - /* Verify Outputs */ - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(GetFakeTimerCallbackCount() == 0, "GetFakeTimerCallbackCount() == 0"); -} -/*----------------------------------------------------------------------------*/ -void Test_OS_TimerSignalHandler_Mismatch(void) -{ - /* Setup Inputs */ - uint32 timer_id = 1; - - /* Must init the static items in ostimer.c. */ - OS_TimerAPIInit(); - - /* Set hooks */ - - /* Set a timer in the table to "(fake) USED" - * index [1] */ - OS_timer_record_t* tbl = getOSTimeTablePtr(); - tbl++; - tbl->free = FALSE; - tbl->callback_ptr = (*FakeTimerCallback); - tbl->host_timerid = 99; /* mismatch */ - - /* Execute Test */ - Pvt_OS_TimerSignalHandler(timer_id); - - /* Verify Outputs */ - UtAssert_True(getNSemTake() == getNSemGive(), "nSemTake == nSemGive"); - UtAssert_True(getNSemTake() == 1, "nSemTake == 1"); - UtAssert_True(GetFakeTimerCallbackCount() == 0, "GetFakeTimerCallbackCount() == 0"); -} -/* ------------------- End of test cases --------------------------------------*/ - - -/* - * OsTimer_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void OsTimer_Setup(void) -{ - OsTimer_Reset(); /* the hooks and return tables in ostimer_stubs.c */ - ResetFakeTimerCallback(); /* for callback testing in ostimer_stubs.c */ - - initStaticPointers(); /* grab the pointers to the static items */ - OsTimer_ReinitStaticOSTimerTable(); /* reinit the static data */ -} - -/* - * OsTimer_TearDown - * - * Purpose: - * Called by the unit test tool to tear down the app after each test - */ -void OsTimer_TearDown(void) -{ - initStaticPointers(); /* grab the pointers to the static items */ - OsTimer_ReinitStaticOSTimerTable(); /* reinit the static data */ -} - - -#define ADD_TEST(test,setup,teardown) UtTest_Add((test), (setup), (teardown), #test) - -/* OsTimer_AddTestCase - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void OS_Application_Startup(void) -{ - /* OS_NetworkGetID */ - ADD_TEST(Test_OS_TimerAPIInit_Success, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerAPIInit_clock_getresFAIL, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerAPIInit_semMCreateFAIL, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_UsecToTimespec_1, NULL, NULL); - ADD_TEST(Test_OS_UsecToTimespec_2, NULL, NULL); - ADD_TEST(Test_OS_UsecToTimespec_NullPtrArg, NULL, NULL); - ADD_TEST(Test_OS_TimespecToUsec_1, NULL, NULL); - ADD_TEST(Test_OS_TimespecToUsec_2, NULL, NULL); - ADD_TEST(Test_OS_TimespecToUsec_2b, NULL, NULL); - ADD_TEST(Test_OS_TimespecToUsec_3, NULL, NULL); - ADD_TEST(Test_OS_TimespecToUsec_3b, NULL, NULL); - ADD_TEST(Test_OS_TimespecToUsec_4, NULL, NULL); - ADD_TEST(Test_OS_TimespecToUsec_4b, NULL, NULL); - ADD_TEST(Test_OS_TimespecToUsec_NullPtrArg, NULL, NULL); - ADD_TEST(Test_OS_TimerCreate, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_NullArg1, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_NullArg2, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_NullArg3, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_NullArg4, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_NameTooLong, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_NameMaxLength, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_NameMaxLengthPlus1, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_FullTable, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_NameNotTaken, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_NameTaken, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_timercreateFAIL, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerCreate_timerconnectFAIL, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSet, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSet_BadArg1, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSet_FreeEntry, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSet_NonZeroStart, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSet_StartLTAccuracy, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSet_IntervalLTAccuracy, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSet_ZeroInterval, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSet_timersettimeFAIL, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerDelete, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerDelete_BadArg, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerDelete_FreeEntry, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerDelete_timerdeleteFAIL, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetIdByName, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetIdByName_NullArg1, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetIdByName_NullArg2, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetIdByName_NameMaxLength, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetIdByName_NameMaxLengthPlus1, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetIdByName_NameTooLong, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetInfo, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetInfo_BadArg1, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetInfo_BadArg2, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetInfo_FreeEntry, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSignalHandler, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSignalHandler_Empty, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerSignalHandler_Mismatch, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetIdByName_FreeEntry, OsTimer_Setup, OsTimer_TearDown); - ADD_TEST(Test_OS_TimerGetIdByName_NameMismatch, OsTimer_Setup, OsTimer_TearDown); -} diff --git a/src/unit-test-coverage/vxworks6/ut-osal/CMakeLists.txt b/src/unit-test-coverage/vxworks6/ut-osal/CMakeLists.txt deleted file mode 100644 index 5f3b52f1a..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -include_directories(inc) -include_directories(${OSAL_SOURCE_DIR}/src) -# Flag to common_types.h to not add any special attributes/pragmas to prototypes -add_definitions(-DOSAPI_NO_SPECIAL_ATTRIBS) -aux_source_directory(src SRCFILES) -foreach(FILE ${SRCFILES}) - get_filename_component(MODULE ${FILE} NAME_WE) - add_library(ut_osal_${MODULE} STATIC ${FILE}) - set_target_properties(ut_osal_${MODULE} PROPERTIES COMPILE_FLAGS "${UT_C_FLAGS}") -endforeach() - \ No newline at end of file diff --git a/src/unit-test-coverage/vxworks6/ut-osal/Makefile b/src/unit-test-coverage/vxworks6/ut-osal/Makefile deleted file mode 100644 index dc2e1ae13..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# -# Makefile for ut osal -# - -# -# INCLUDES specifies the search paths for include files outside of the current directory. -# Note that the -I is required. -# -INCLUDES += -I./inc -INCLUDES += -I../ut-stubs/inc -INCLUDES += -I$(OSAL)/src/os/inc -INCLUDES += -I$(OSAL)/build/inc -INCLUDES += -I$(OSAL)/src - - -# -# UT_OBJS specifies unit test object files. -# -UT_OBJS := osapi.o -UT_OBJS += osfileapi.o -UT_OBJS += osfilesys.o -UT_OBJS += osloader.o -UT_OBJS += osnetwork.o -UT_OBJS += ostimer.o - -############################################################################### - -COMPILER=gcc -LINKER=ld - -# -# Compiler and Linker Options -# -ENABLE_GCOV = TRUE -ifeq ($(ENABLE_GCOV), TRUE) -GCOV_COPT = --coverage -GCOV_LOPT = --coverage -endif - -#WARNINGS = -Wall -W -ansi -Werror -Wstrict-prototypes -Wundef -WARNINGS = -Wall -Wstrict-prototypes -DEBUGGER = -g - -COPT = $(WARNINGS) $(DEBUGGER) $(GCOV_COPT) -DOSAPI_NO_SPECIAL_ATTRIBS -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D_ix86_ $(OSAL_M32) - -LOPT = $(GCOV_LOPT) $(OSAL_M32) - -############################################################################### -## "C" COMPILER RULE -## -%.o: src/%.c - $(COMPILER) -c $(COPT) $(INCLUDES) $< - -############################################################################## -## - -all: $(UT_OBJS) - -clean :: - rm -f *.o *.exe *.gcda *.gcno *.gcov gmon.out - -gcov :: - @echo - @gcov -b $(UT_OBJS:.o=.gcda) | \ - awk -f $(OSAL)/build/gcov-parse.awk - @rm -f *.gcda *.gcno - @echo - -# end of file - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/README.txt b/src/unit-test-coverage/vxworks6/ut-osal/README.txt deleted file mode 100644 index 0b40586c3..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/README.txt +++ /dev/null @@ -1,38 +0,0 @@ -UT-OSAL README FILE -=================== - -The objective here is to build the OSAL source code but with all calls/references to the underlying -OS remapped to "stub" implementations and/or local definitions of those identifiers. - -The "inc" subdirectory includes empty files for _ALL_ of the header files included by the OSAL source -code. The "inc" subdirectory is in the compiler search path so these empty files will be used in -place of the real system header file. THIS IS THE ONLY PLACE WHERE THESE EMPTY STUBS SHOULD BE -USED IN PLACE OF THE REAL FILE. - -Two exceptions are made: - - maps to the real one, so we have accurate fixed-width types. - - -The paradigm used here: -- Each source file in OSAL has a wrapper here with the same name. - -- First the wrapper includes a header with any "extra" logic that the test case needs to add - This is optional and used in cases where the test needs access to static/private data structures. - -- Then the wrapper #include's "stub-map-to-real.h" - This is an important file that has #define macros that map all identifiers typically supplied - by the C library to one with a "VCS_" prefix. For example, "strcmp" will become "VCS_strcmp". - -- Then it #include's the unmodified OSAL source code, adding that exact code into the same compilation - unit, with the stub-remap macros in place. - - In the same example as above, all calls to "strcmp()" (a library function) will become calls to - "VCS_strcmp" with the same arguments. The implementation of VCS_strcmp() is provided by the test case. - -- Finally the implementation for any "extra" logic is directly implmemented in the wrapper file. - Because this is in the same compilation unit as the OSAL source code, it can access variables that - are defined "static". IMPORTANT: The implementation of these wrappers will also have all stub-mapping - active, so these must avoid using C library calls as they will NOT go to the C library. - - - \ No newline at end of file diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/cbioLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/cbioLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/cbioLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/dirent.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/dirent.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/dirent.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/dosFsLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/dosFsLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/dosFsLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/drv/hdisk/ataDrv.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/drv/hdisk/ataDrv.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/drv/hdisk/ataDrv.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/errnoLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/errnoLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/errnoLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/fcntl.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/fcntl.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/fcntl.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/hostLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/hostLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/hostLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/intLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/intLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/intLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/ioLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/ioLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/ioLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/iv.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/iv.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/loadLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/loadLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/loadLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/logLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/logLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/logLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/memPartLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/memPartLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/memPartLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/msgQLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/msgQLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/msgQLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/objLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/objLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/objLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/ramDiskCbio.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/ramDiskCbio.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/ramDiskCbio.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/ramDrv.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/ramDrv.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/ramDrv.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/semLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/semLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/semLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/shellLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/shellLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/shellLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/stat.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/stat.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/stat.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/stdio.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/stdio.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/stdio.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/stdlib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/stdlib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/stdlib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/string.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/string.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/string.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/strings.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/strings.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/strings.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/symLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/symLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/symLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/sys/stat.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/sys/stat.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/sys/stat.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/sys/types.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/sys/types.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/sys/types.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/sysLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/sysLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/sysLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/taskLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/taskLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/taskLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/taskVarLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/taskVarLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/taskVarLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/time.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/time.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/time.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/timers.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/timers.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/timers.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/unistd.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/unistd.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/unistd.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/unldLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/unldLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/unldLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/usrLib.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/usrLib.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/usrLib.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/version.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/version.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/version.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/vxWorks.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/vxWorks.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/vxWorks.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/xbdBlkDev.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/xbdBlkDev.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/xbdBlkDev.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/inc/xbdRamDisk.h b/src/unit-test-coverage/vxworks6/ut-osal/inc/xbdRamDisk.h deleted file mode 100644 index 8b1378917..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/inc/xbdRamDisk.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/src/osapi.c b/src/unit-test-coverage/vxworks6/ut-osal/src/osapi.c deleted file mode 100644 index 38525742e..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/src/osapi.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * File: osapi_adaptor.c - * - * Purpose: - * Provide access to the unit under test static data and functions - * - * History: - * 07/10/2015 A. Asp, Odyssey Space Research, LLC - * * Created - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi_adaptor.h" -#include "stub-map-to-real.h" -/* - * Strangely, the osapi.c file does this: - * #define OK 0 - * even though "OK" is a VxWorks-supplied definition... - */ -#undef OK - -/* - * Finally include the target implementation - */ -#include "os/vxworks6/osapi.c" - - - -void OsApi_Adaptor_Reset_Tables() -{ - memset(OS_task_table, 0, sizeof(OS_task_table)); - memset(OS_queue_table, 0, sizeof(OS_queue_table)); - memset(OS_bin_sem_table, 0, sizeof(OS_bin_sem_table)); - memset(OS_count_sem_table, 0, sizeof(OS_count_sem_table)); - memset(OS_mut_sem_table, 0, sizeof(OS_mut_sem_table)); -} - -SEM_ID OsApi_Adaptor_Get_Os_Task_Table_Sem() -{ - return OS_task_table_sem; -} - -SEM_ID OsApi_Adaptor_Get_Os_Queue_Table_Sem() -{ - return OS_queue_table_sem; -} - -SEM_ID OsApi_Adaptor_Get_Os_Bin_Sem_Table_Sem() -{ - return OS_bin_sem_table_sem; -} - -SEM_ID OsApi_Adaptor_Get_Os_Count_Sem_Table_Sem() -{ - return OS_count_sem_table_sem; -} - -SEM_ID OsApi_Adaptor_Get_Os_Mut_Sem_Table_Sem() -{ - return OS_mut_sem_table_sem; -} - - -void OsApi_Adaptor_Set_Os_Task_Table_Sem(SEM_ID newVal) -{ - OS_task_table_sem = newVal; -} - -void OsApi_Adaptor_Set_Os_Queue_Table_Sem(SEM_ID newVal) -{ - OS_queue_table_sem = newVal; -} - -void OsApi_Adaptor_Set_Os_Bin_Sem_Table_Sem(SEM_ID newVal) -{ - OS_bin_sem_table_sem = newVal; -} - -void OsApi_Adaptor_Set_Os_Count_Sem_Table_Sem(SEM_ID newVal) -{ - OS_count_sem_table_sem = newVal; -} - -void OsApi_Adaptor_Set_Os_Mut_Sem_Table_Sem(SEM_ID newVal) -{ - OS_mut_sem_table_sem = newVal; -} - - -OsApi_Adaptor_OS_task_record_t *OsApi_Adaptor_getTaskTableEntry(uint32 idx) -{ - if (idx < OS_MAX_TASKS) - { - return (OsApi_Adaptor_OS_task_record_t *)&OS_task_table[idx]; - } - - return NULL; -} - -OsApi_Adaptor_OS_queue_record_t *OsApi_Adaptor_getQueueTableEntry(uint32 idx) -{ - if (idx < OS_MAX_QUEUES) - { - return (OsApi_Adaptor_OS_queue_record_t *)&OS_queue_table[idx]; - } - - return NULL; -} - -OsApi_Adaptor_OS_bin_sem_record_t *OsApi_Adaptor_getBinSemTableEntry(uint32 idx) -{ - if (idx < OS_MAX_BIN_SEMAPHORES) - { - return (OsApi_Adaptor_OS_bin_sem_record_t *)&OS_bin_sem_table[idx]; - } - - return NULL; -} - -OsApi_Adaptor_OS_count_sem_record_t *OsApi_Adaptor_getCountSemTableEntry(uint32 idx) -{ - if (idx < OS_MAX_COUNT_SEMAPHORES) - { - return (OsApi_Adaptor_OS_count_sem_record_t *)&OS_count_sem_table[idx]; - } - - return NULL; -} - -OsApi_Adaptor_OS_mut_sem_record_t *OsApi_Adaptor_getMutSemTableEntry(uint32 idx) -{ - if (idx < OS_MAX_MUTEXES) - { - return (OsApi_Adaptor_OS_mut_sem_record_t *)&OS_mut_sem_table[idx]; - } - - return NULL; -} - -void OsApi_Adaptor_setTaskTableEntry(uint32 idx, int32 free, int32 id, const char *name, - int32 creator, uint32 stack_size, uint32 priority, - void *delete_hook_pointer) -{ - if (idx < OS_MAX_TASKS) - { - OS_task_table[idx].free = free; - OS_task_table[idx].id = id; - OS_task_table[idx].creator = creator; - OS_task_table[idx].priority = priority; - OS_task_table[idx].stack_size = stack_size; - OS_task_table[idx].delete_hook_pointer = delete_hook_pointer; - strcpy(OS_task_table[idx].name, name); - } -} - -void OsApi_Adaptor_setQueueTableEntry(uint32 idx, int32 free, MSG_Q_ID id, uint32 size, - const char *name, int32 creator) -{ - if (idx < OS_MAX_QUEUES) - { - OS_queue_table[idx].free = free; - OS_queue_table[idx].id = id; - OS_queue_table[idx].max_size = size; - OS_queue_table[idx].creator = creator; - strcpy(OS_queue_table[idx].name, name); - } -} - -void OsApi_Adaptor_setBinSemTableEntry(uint32 idx, int32 free, SEM_ID id, - const char *name, int32 creator) -{ - if (idx < OS_MAX_BIN_SEMAPHORES) - { - OS_bin_sem_table[idx].free = free; - OS_bin_sem_table[idx].id = id; - OS_bin_sem_table[idx].creator = creator; - strcpy(OS_bin_sem_table[idx].name, name); - } -} - -void OsApi_Adaptor_setCountSemTableEntry(uint32 idx, int32 free, SEM_ID id, - const char *name, int32 creator) -{ - if (idx < OS_MAX_COUNT_SEMAPHORES) - { - OS_count_sem_table[idx].free = free; - OS_count_sem_table[idx].id = id; - OS_count_sem_table[idx].creator = creator; - strcpy(OS_count_sem_table[idx].name, name); - } -} - -void OsApi_Adaptor_setMutSemTableEntry(uint32 idx, int32 free, SEM_ID id, - const char *name, int32 creator) -{ - if (idx < OS_MAX_MUTEXES) - { - OS_mut_sem_table[idx].free = free; - OS_mut_sem_table[idx].id = id; - OS_mut_sem_table[idx].creator = creator; - strcpy(OS_mut_sem_table[idx].name, name); - } -} - - -uint32 OsApi_Adaptor_getOsTaskKey() -{ - return OS_task_key; -} - -void OsApi_Adaptor_setOsTaskKey(uint32 key) -{ - OS_task_key = key; -} - -uint32 OsApi_Adaptor_getOsPrintfEnabled() -{ - return OS_printf_enabled; -} - -void OsApi_Adaptor_setOsPrintfEnabled(uint32 val) -{ - OS_printf_enabled = val; -} - diff --git a/src/unit-test-coverage/vxworks6/ut-osal/src/osfileapi.c b/src/unit-test-coverage/vxworks6/ut-osal/src/osfileapi.c deleted file mode 100644 index 3b8aaa0ce..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/src/osfileapi.c +++ /dev/null @@ -1,11 +0,0 @@ -/* pull in the OSAL configuration */ -#include "osconfig.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "stub-map-to-real.h" - -/* The unmodified/untweaked source can be used for this module */ -#include "os/vxworks6/osfileapi.c" diff --git a/src/unit-test-coverage/vxworks6/ut-osal/src/osfilesys.c b/src/unit-test-coverage/vxworks6/ut-osal/src/osfilesys.c deleted file mode 100644 index 70245496f..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/src/osfilesys.c +++ /dev/null @@ -1,11 +0,0 @@ -/* pull in the OSAL configuration */ -#include "osconfig.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "stub-map-to-real.h" - -/* The unmodified/untweaked source can be used for this module */ -#include "os/vxworks6/osfilesys.c" diff --git a/src/unit-test-coverage/vxworks6/ut-osal/src/osloader.c b/src/unit-test-coverage/vxworks6/ut-osal/src/osloader.c deleted file mode 100644 index d40ad7a2e..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/src/osloader.c +++ /dev/null @@ -1,11 +0,0 @@ -/* pull in the OSAL configuration */ -#include "osconfig.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "stub-map-to-real.h" - -/* The unmodified/untweaked source can be used for this module */ -#include "os/vxworks6/osloader.c" diff --git a/src/unit-test-coverage/vxworks6/ut-osal/src/osnetwork.c b/src/unit-test-coverage/vxworks6/ut-osal/src/osnetwork.c deleted file mode 100644 index 37edeb317..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/src/osnetwork.c +++ /dev/null @@ -1,11 +0,0 @@ -/* pull in the OSAL configuration */ -#include "osconfig.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "stub-map-to-real.h" - -/* The unmodified/untweaked source can be used for this module */ -#include "os/vxworks6/osnetwork.c" diff --git a/src/unit-test-coverage/vxworks6/ut-osal/src/ostimer.c b/src/unit-test-coverage/vxworks6/ut-osal/src/ostimer.c deleted file mode 100644 index 1d2dc5b7b..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/src/ostimer.c +++ /dev/null @@ -1,52 +0,0 @@ -/* pull in the OSAL configuration */ -#include "osconfig.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "ostimer_accessor.h" -#include "stub-map-to-real.h" -#include "os/vxworks6/ostimer.c" - - -/* Pointers to the static members of ostimer.c so we can inspect or alter them. */ -OS_timer_internal_record_t *OS_timer_table_ptr; /* Points to the [0] OS_timer_table element */ -uint32 *os_clock_accuracy_ptr; - -OS_timer_internal_record_t* getOSTimeTablePtr() { - return (OS_timer_table_ptr); -} - -void setOSTimeTablePtr(OS_timer_internal_record_t* ptr) { - OS_timer_table_ptr = ptr; -} - -uint32* getOSClockAccuracyPtr() { - return os_clock_accuracy_ptr; -} - -uint32 getOSClockAccuracy() { - return *os_clock_accuracy_ptr; -} - -void setOSClockAccuracyPtr(uint32* ptr) { - os_clock_accuracy_ptr = ptr; -} - -void setOSClockAccuracy(uint32 accuracy) { - *os_clock_accuracy_ptr = accuracy; -} - -uint32 getMaxSecsInUSec(void) { - return (uint32)MAX_SECS_IN_USEC; -} - -void initStaticPointers(void) { - setOSTimeTablePtr(&(OS_timer_table[0])); - setOSClockAccuracyPtr(&os_clock_accuracy); -} - -void Pvt_OS_TimerSignalHandler(int host_timer_id) { - OS_TimerSignalHandler(host_timer_id); -} diff --git a/src/unit-test-coverage/vxworks6/ut-osal/src/stub-map-to-real.h b/src/unit-test-coverage/vxworks6/ut-osal/src/stub-map-to-real.h deleted file mode 100644 index a90cf0e5d..000000000 --- a/src/unit-test-coverage/vxworks6/ut-osal/src/stub-map-to-real.h +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2004-2015, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file stub-map-to-real.h - * - * Created on: Oct 29, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Placeholder for file content description - */ - -#ifndef STUB_MAP_TO_REAL_H_ -#define STUB_MAP_TO_REAL_H_ - -/* Include all the stub definitions */ -#include "vxworks6-coverage-stubs.h" - -/* in all cases, UNDEFINE the macro if the C library already defined it as a macro */ - -#define LOAD_ALL_SYMBOLS VCS_LOAD_ALL_SYMBOLS -#define O_RDONLY VCS_O_RDONLY -#define O_WRONLY VCS_O_WRONLY -#define O_RDWR VCS_O_RDWR -#define O_CREAT VCS_O_CREAT -#define O_TRUNC VCS_O_TRUNC -#define MSG_Q_FIFO VCS_MSG_Q_FIFO -#define MSG_Q_PRIORITY VCS_MSG_Q_PRIORITY -#define WIND_MSG_Q_OPTION_MASK VCS_WIND_MSG_Q_OPTION_MASK -#define MSG_PRI_NORMAL VCS_MSG_PRI_NORMAL -#define MSG_PRI_URGENT VCS_MSG_PRI_URGENT -#define M_objLib VCS_M_objLib -#define S_objLib_OBJ_ID_ERROR VCS_S_objLib_OBJ_ID_ERROR -#define S_objLib_OBJ_UNAVAILABLE VCS_S_objLib_OBJ_UNAVAILABLE -#define S_objLib_OBJ_DELETED VCS_S_objLib_OBJ_DELETED -#define S_objLib_OBJ_TIMEOUT VCS_S_objLib_OBJ_TIMEOUT -#define S_objLib_OBJ_NO_METHOD VCS_S_objLib_OBJ_NO_METHOD -#define VX_FP_TASK VCS_VX_FP_TASK -#define INUM_TO_IVEC(uint32) VCS_INUM_TO_IVEC(uint32) -#define NULLDEV VCS_NULLDEV -#define DOS_CHK_ONLY VCS_DOS_CHK_ONLY -#define DOS_CHK_REPAIR VCS_DOS_CHK_REPAIR -#define DOS_CHK_VERB_0 VCS_DOS_CHK_VERB_0 -#define DOS_CHK_VERB_SILENT VCS_DOS_CHK_VERB_SILENT -#define DOS_OPT_BLANK VCS_DOS_OPT_BLANK -#define FIOUNMOUNT VCS_FIOUNMOUNT -#define FIOCHKDSK VCS_FIOCHKDSK -#define S_IRUSR VCS_S_IRUSR -#define S_IWUSR VCS_S_IWUSR -#define S_IRGRP VCS_S_IRGRP -#define S_IWGRP VCS_S_IWGRP -#define S_IROTH VCS_S_IROTH -#define S_IWOTH VCS_S_IWOTH -#define CLOCK_REALTIME VCS_CLOCK_REALTIME -#define EXIT_SUCCESS VCS_EXIT_SUCCESS -#define EXIT_FAILURE VCS_EXIT_FAILURE -#define SEEK_SET VCS_SEEK_SET -#define SEEK_CUR VCS_SEEK_CUR -#define SEEK_END VCS_SEEK_END - - -/******************************************************************************* - * ENUM definitions - keeping as an enum so the usage semantics are similar - *******************************************************************************/ - -#define SEM_Q_FIFO VCS_SEM_Q_FIFO -#define SEM_Q_PRIORITY VCS_SEM_Q_PRIORITY -#define SEM_DELETE_SAFE VCS_SEM_DELETE_SAFE -#define SEM_INVERSION_SAFE VCS_SEM_INVERSION_SAFE -#define SEM_EVENTSEND_ERR_NOTIFY VCS_SEM_EVENTSEND_ERR_NOTIFY -#define SEM_EMPTY VCS_SEM_EMPTY -#define SEM_FULL VCS_SEM_FULL -#define ERROR VCS_ERROR -#define OK VCS_OK -#define WAIT_FOREVER VCS_WAIT_FOREVER -#define NO_WAIT VCS_NO_WAIT - - -/******************************************************************************* - * TYPE definitions normally supplied by VxWorks (any header) - *******************************************************************************/ - -#define SEM_B_STATE VCS_SEM_B_STATE -#define STATUS VCS_STATUS -#define BLK_DEV VCS_BLK_DEV -#define device_t VCS_device_t -#define timer_t VCS_timer_t -#define BOOL VCS_BOOL -#define SEM_ID VCS_SEM_ID -#define MODULE_ID VCS_MODULE_ID -#define SYM_TYPE VCS_SYM_TYPE -#define PART_ID VCS_PART_ID -#define UINT VCS_UINT -#define UINT16 VCS_UINT16 -#define UINT32 VCS_UINT32 -#define MSG_Q_ID VCS_MSG_Q_ID -#define FUNCPTR VCS_FUNCPTR -#define VOIDFUNCPTR VCS_VOIDFUNCPTR -#define MEM_PART_STATS VCS_MEM_PART_STATS -#define SEMAPHORE VCS_SEMAPHORE -#define MODULE_INFO VCS_MODULE_INFO -#define SYMBOL VCS_SYMBOL -#define SYMTAB VCS_SYMTAB -#define SYMTAB_ID VCS_SYMTAB_ID -#define clockid_t VCS_clockid_t -#define mode_t VCS_mode_t -#define DIR VCS_DIR - - -/* NOTE: The VCS_ structs that are not typedefs must be #defined, because the - * code will refer to them as "struct YYY" which will not compile if YYY is a typedef. - */ -#define semaphore VCS_semaphore -#define statfs VCS_statfs -#define stat VCS_stat -#define symbol VCS_symbol -#define symtab VCS_symtab - - - -/******************************************************************************* - * FUNCTION PROTOTYPE definitions normally supplied by VxWorks (any header) - *******************************************************************************/ - -#define loadModule VCS_loadModule -#define moduleInfoGet VCS_moduleInfoGet -#define ramDevCreate VCS_ramDevCreate -#define symFindByName VCS_symFindByName -#define symEach VCS_symEach -#define timer_connect VCS_timer_connect -#define unldByModuleId VCS_unldByModuleId -#define semMCreate VCS_semMCreate -#define semTake VCS_semTake -#define semGive VCS_semGive -#define semBInitialize VCS_semBInitialize -#define VX_BINARY_SEMAPHORE VCS_VX_BINARY_SEMAPHORE -#define open VCS_open -#define close VCS_close -#define read VCS_read -#define write VCS_write -#define lseek VCS_lseek -#define cp VCS_cp -#define rmdir VCS_rmdir -#define intConnect VCS_intConnect -#define intDisable VCS_intDisable -#define intEnable VCS_intEnable -#define intLock VCS_intLock -#define intUnlock VCS_intUnlock -#define memPartShow VCS_memPartShow -#define memPartInfoGet VCS_memPartInfoGet -#define msgQCreate VCS_msgQCreate -#define msgQDelete VCS_msgQDelete -#define msgQReceive VCS_msgQReceive -#define msgQSend VCS_msgQSend -#define semBCreate VCS_semBCreate -#define semCCreate VCS_semCCreate -#define semDelete VCS_semDelete -#define semFlush VCS_semFlush -#define shellGenericInit VCS_shellGenericInit -#define taskDelay VCS_taskDelay -#define taskDelete VCS_taskDelete -#define taskDeleteForce VCS_taskDeleteForce -#define taskExit VCS_taskExit -#define taskIdSelf VCS_taskIdSelf -#define taskNameToId VCS_taskNameToId -#define taskPrioritySet VCS_taskPrioritySet -#define taskSpawn VCS_taskSpawn -#define taskVarAdd VCS_taskVarAdd -#define sysClkRateGet VCS_sysClkRateGet -#define vxFpscrGet VCS_vxFpscrGet -#define vxFpscrSet VCS_vxFpscrSet -#define dosFsVolFormat VCS_dosFsVolFormat -#define nSectors VCS_nSectors -#define xbdBlkDevCreateSync VCS_xbdBlkDevCreateSync -#define memSysPartId VCS_memSysPartId -#define errno VCS_errno -#define timespec VCS_timespec -#define itimerspec VCS_itimerspec -#define mkdir VCS_mkdir -#define open VCS_open -#define gethostname VCS_gethostname -#define hostGetByName VCS_hostGetByName -#define ioctl VCS_ioctl -#define clock_getres VCS_clock_getres -#define timer_create VCS_timer_create -#define timer_delete VCS_timer_delete -#define clock_gettime VCS_clock_gettime -#define clock_settime VCS_clock_settime -#define timer_settime VCS_timer_settime -#define strncpy VCS_strncpy -#define strlen VCS_strlen -#define strcmp VCS_strcmp -#define strcpy VCS_strcpy -#define strncpy VCS_strncpy -#define vsnprintf VCS_vsnprintf -#define opendir VCS_opendir -#define closedir VCS_closedir -#define rewinddir VCS_rewinddir -#define dirent VCS_dirent -#define readdir VCS_readdir -#define strrchr VCS_strrchr -#define strchr VCS_strchr -#define open VCS_open -#define exit VCS_exit -#define memset VCS_memset -#define printf VCS_printf -#define remove VCS_remove -#define rename VCS_rename -#define strcat VCS_strcat -#define strncat VCS_strncat -#define strncmp VCS_strncmp -#define snprintf VCS_snprintf -#define logMsg VCS_logMsg - -#endif /* STUB_MAP_TO_REAL_H_ */ diff --git a/src/unit-test-coverage/vxworks6/ut-stubs/inc/osapi_adaptor.h b/src/unit-test-coverage/vxworks6/ut-stubs/inc/osapi_adaptor.h deleted file mode 100644 index f7933845b..000000000 --- a/src/unit-test-coverage/vxworks6/ut-stubs/inc/osapi_adaptor.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * File: osapi_adaptor.h - * - * Purpose: - * Provide access to the unit under test static data and functions - * - * History: - * 07/10/2015 A. Asp, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSAPI_ADAPTOR_H_ -#define _OSAPI_ADAPTOR_H_ - -#include "vxworks6-coverage-stubs.h" -#include "osconfig.h" - - -typedef struct -{ - int32 free; - int32 id; - char name [OS_MAX_API_NAME]; - int32 creator; - uint32 stack_size; - uint32 priority; - void *delete_hook_pointer; - -} OsApi_Adaptor_OS_task_record_t; - -/* queues */ -typedef struct -{ - int32 free; - VCS_SEM_ID id; /* a pointer to the id */ - uint32 max_size; - char name [OS_MAX_API_NAME]; - int32 creator; -} OsApi_Adaptor_OS_queue_record_t; - -/* Binary Semaphores */ -typedef struct -{ - int32 free; - VCS_SEM_ID id; /* a pointer to the id */ - char name [OS_MAX_API_NAME]; - int32 creator; -} OsApi_Adaptor_OS_bin_sem_record_t; - -/* Counting Semaphores */ -typedef struct -{ - int32 free; - VCS_SEM_ID id; /* a pointer to the id */ - char name [OS_MAX_API_NAME]; - int32 creator; -} OsApi_Adaptor_OS_count_sem_record_t; - - -/* Mutexes */ -typedef struct -{ - int32 free; - VCS_SEM_ID id; - char name [OS_MAX_API_NAME]; - int32 creator; -} OsApi_Adaptor_OS_mut_sem_record_t; - - -void OsApi_Adaptor_Reset_Tables(void); - -VCS_SEM_ID OsApi_Adaptor_Get_Os_Task_Table_Sem(void); -VCS_SEM_ID OsApi_Adaptor_Get_Os_Queue_Table_Sem(void); -VCS_SEM_ID OsApi_Adaptor_Get_Os_Bin_Sem_Table_Sem(void); -VCS_SEM_ID OsApi_Adaptor_Get_Os_Count_Sem_Table_Sem(void); -VCS_SEM_ID OsApi_Adaptor_Get_Os_Mut_Sem_Table_Sem(void); - -void OsApi_Adaptor_Set_Os_Task_Table_Sem(VCS_SEM_ID newVal); -void OsApi_Adaptor_Set_Os_Queue_Table_Sem(VCS_SEM_ID newVal); -void OsApi_Adaptor_Set_Os_Bin_Sem_Table_Sem(VCS_SEM_ID newVal); -void OsApi_Adaptor_Set_Os_Count_Sem_Table_Sem(VCS_SEM_ID newVal); -void OsApi_Adaptor_Set_Os_Mut_Sem_Table_Sem(VCS_SEM_ID newVal); - - -OsApi_Adaptor_OS_task_record_t *OsApi_Adaptor_getTaskTableEntry(uint32 idx); -OsApi_Adaptor_OS_queue_record_t *OsApi_Adaptor_getQueueTableEntry(uint32 idx); -OsApi_Adaptor_OS_bin_sem_record_t *OsApi_Adaptor_getBinSemTableEntry(uint32 idx); -OsApi_Adaptor_OS_count_sem_record_t *OsApi_Adaptor_getCountSemTableEntry(uint32 idx); -OsApi_Adaptor_OS_mut_sem_record_t *OsApi_Adaptor_getMutSemTableEntry(uint32 idx); - -void OsApi_Adaptor_setTaskTableEntry(uint32 idx, int32 free, int32 id, const char *name, - int32 creator, uint32 stack_size, uint32 priority, - void *delete_hook_pointer); - -void OsApi_Adaptor_setQueueTableEntry(uint32 idx, int32 free, VCS_MSG_Q_ID id, uint32 size, - const char *name, int32 creator); - -void OsApi_Adaptor_setBinSemTableEntry(uint32 idx, int32 free, VCS_SEM_ID id, - const char *name, int32 creator); - -void OsApi_Adaptor_setCountSemTableEntry(uint32 idx, int32 free, VCS_SEM_ID id, - const char *name, int32 creator); - -void OsApi_Adaptor_setMutSemTableEntry(uint32 idx, int32 free, VCS_SEM_ID id, - const char *name, int32 creator); - -uint32 OsApi_Adaptor_getOsTaskKey(void); -void OsApi_Adaptor_setOsTaskKey(uint32 key); -uint32 OsApi_Adaptor_getOsPrintfEnabled(void); -void OsApi_Adaptor_setOsPrintfEnabled(uint32 val); - -#endif diff --git a/src/unit-test-coverage/vxworks6/ut-stubs/inc/osapi_stubs.h b/src/unit-test-coverage/vxworks6/ut-stubs/inc/osapi_stubs.h deleted file mode 100644 index 0e93ce4d4..000000000 --- a/src/unit-test-coverage/vxworks6/ut-stubs/inc/osapi_stubs.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * File: osapi_stubs.h - * - * Purpose: - * Provide stubs for unit testing - * - * History: - * 06/25/2015 A. Asp, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSAPI_STUBS_H_ -#define _OSAPI_STUBS_H_ - -#include "common_types.h" -#include "uttools.h" -#include "vxworks6-coverage-stubs.h" - -/* Define test enums and structs */ -typedef enum -{ - OS_TASK_TABLE_SEM, - OS_QUEUE_TABLE_SEM, - OS_BIN_SEM_TABLE_SEM, - OS_COUNT_SEM_TABLE_SEM, - OS_MUT_SEM_TABLE_SEM, - OS_MAX_SEM -} OsApi_Semaphore_t; - - -typedef enum -{ - OSAPI_EXIT_INDEX, - OSAPI_STRLEN_INDEX, - OSAPI_STRCMP_INDEX, - OSAPI_STRCPY_INDEX, - OSAPI_CLOCKGETTIME_INDEX, - OSAPI_CLOCKSETTIME_INDEX, - OSAPI_INTCONNECT_INDEX, - OSAPI_INTDISABLE_INDEX, - OSAPI_INTENABLE_INDEX, - OSAPI_INTLOCK_INDEX, - OSAPI_INTUNLOCK_INDEX, - OSAPI_MEMPARTINFOGET_INDEX, - OSAPI_MSGQCREATE_INDEX, - OSAPI_MSGQDELETE_INDEX, - OSAPI_MSGQRECEIVE_INDEX, - OSAPI_MSGQSEND_INDEX, - OSAPI_SEMBCREATE_INDEX, - OSAPI_SEMCCREATE_INDEX, - OSAPI_SEMDELETE_INDEX, - OSAPI_SEMFLUSH_INDEX, - OSAPI_SEMMCREATE_INDEX, - OSAPI_SEMTAKE_INDEX, - OSAPI_SEMGIVE_INDEX, - OSAPI_SYSCLKRATEGET_INDEX, - OSAPI_TASKDELAY_INDEX, - OSAPI_TASKDELETE_INDEX, - OSAPI_TASKIDSELF_INDEX, - OSAPI_TASKNAMETOID_INDEX, - OSAPI_TASKPRIORITYSET_INDEX, - OSAPI_TASKSPAWN_INDEX, - OSAPI_TASKVARADD_INDEX, - OSAPI_OSFSINIT_INDEX, - OSAPI_OSMODULETABLEINIT_INDEX, - OSAPI_OSTIMERAPIINIT_INDEX, - OSAPI_VXFPSCRGET_INDEX, - OSAPI_MAX_INDEX -} OsApi_Index_t; - -typedef struct -{ - int32 Value; - uint32 Count; -} OsApi_ReturnCodeTable_t; - -typedef struct -{ - size_t (*strlen)(const char *str); - int (*strcmp)(const char *str1, const char *str2); - char * (*strcpy)(const char *str1, const char *str2); - VCS_SEM_ID (*semMCreate)(uint16 *); - VCS_STATUS (*semTake)(VCS_SEM_ID, int); - VCS_STATUS (*semGive)(VCS_SEM_ID); - VCS_STATUS (*taskDelay)(int ticks); - int (*taskNameToId)(char *name); - int (*sysClkRateGet)(void); - uint32 (*OS_FindCreator)(void); -} OsApi_HookTable_t; - - -void OsApi_SetReturnCode(uint32 Index, int32 RtnVal, uint32 CallCnt); -void OsApi_SetFunctionHook(uint32 Index, void *FunPtr); -void OsApi_Reset(void); - -uint32 getFpuMask(void); -int getMsgQReceiveTimeout(void); -uint32 getNLogMsg_calls(void); -uint32 getNSeconds(void); -int32 getNSemTake(uint32 id); -int32 getNSemGive(uint32 id); -int32 getNTaskDeleteForce(void); -uint32 getNVsnprintf_calls(void); -uint32 getSeconds(void); -uint32 getSemBInitialValue(void); -VCS_SEM_ID getSemGiveArg(void); -int32 getSemTakeTicks(void); -int getTaskDelayTicks(void); -boolean getTaskExitCalled(void); -int getTaskSpawnFlags(void); - -void setHeapInfo(unsigned long freeBytes, unsigned long freeBlocks, unsigned long maxFreeBlock); -void setTime(uint32 sec, uint32 nsec); - - -#endif diff --git a/src/unit-test-coverage/vxworks6/ut-stubs/inc/ostimer_accessor.h b/src/unit-test-coverage/vxworks6/ut-stubs/inc/ostimer_accessor.h deleted file mode 100644 index d634d7b05..000000000 --- a/src/unit-test-coverage/vxworks6/ut-stubs/inc/ostimer_accessor.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * File: ostimer_accessor.h - * - * Purpose: - * Provide private accessors for getting/manipulating ostimer.c's static data. - * - * History: - * 06/30/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - */ - -#ifndef _OSTIMER_ACCESSOR_H_ -#define _OSTIMER_ACCESSOR_H_ - -/* - * File: ostimer_accessor.h - * - * Purpose: - * Provide accesssor functions for unit testing ostimer.c - * - * History: - * 06/30/2015 Allen Brown, Odyssey Space Research, LLC - * * Created - */ - -#include "vxworks6-coverage-stubs.h" - -/* --------------- Prototypes for non-exported functions -------------------- */ -void OS_UsecToTimespec(uint32 usecs, struct VCS_timespec *time_spec); -void OS_TimespecToUsec(struct VCS_timespec time_spec, uint32 *usecs); - -/* -------------- Delegation function for static functions ------------------ */ -void Pvt_OS_TimerSignalHandler(int host_timer_id); - -/* --------------------- Custom Accessors ----------------------------------- */ -/* Note, the types that support these prototypes - * are in ostimer_copiedstatictypes.h */ - -/* Setters & getters for pointers to the OS_timer_table and - * os_clock_accuracy. */ -#ifdef JPHFIX -OS_timer_record_t* getOSTimeTablePtr(void); -void setOSTimeTablePtr(OS_timer_record_t* ptr); -#endif - -uint32* getOSClockAccuracyPtr(void); -uint32 getOSClockAccuracy(void); -void setOSClockAccuracyPtr(uint32* ptr); -void setOSClockAccuracy(uint32 accuracy); - -uint32 getMaxSecsInUSec(void); - -/* An initialization function to set the pointers before any -* ostimer.c calls occur. */ -void initStaticPointers(void); - -#endif /* _OSTIMER_ACCESSOR_H_ */ - diff --git a/src/unit-test-coverage/vxworks6/ut-stubs/inc/vxworks6-coverage-stubs.h b/src/unit-test-coverage/vxworks6/ut-stubs/inc/vxworks6-coverage-stubs.h deleted file mode 100644 index 087902617..000000000 --- a/src/unit-test-coverage/vxworks6/ut-stubs/inc/vxworks6-coverage-stubs.h +++ /dev/null @@ -1,429 +0,0 @@ -/* - * Supply "coverage stub" definitions and prototypes for all of the underlying - * OS definitions and functions that the VxWorks6 OSAL uses. The OSAL source - * code is compiled against these stubs, rather than the real VxWorks-supplied definitions. - * - * PROBLEM: - * Some of these definitions may overlap with POSIX or other definitions supplied by - * the actual C library being used to run these tests, possibly even vxworks itself if - * it is being compiled to actually run on the target. - * - * WORKAROUND: - * All definitions here should be prefixed so the namespaces will not conflict. A "VCS_" - * (vxworks coverage stub) prefix is added. - * - * To build the (unmodified) OSAL code, the non-prefixed names can be #define'd to map - * to the prefixed name. This should ideally be built using "-nostdinc" (or similar) to - * ensure that no bits of the real system C library get used during the OSAL build, but - * that doesn't work because we still need e.g. "real" fixed with types and va_list, etc. - * - * Everywhere else, the "stubs" can use the prefixed names. This should allow other code to - * simultaneously use the REAL underlying C library when needed as well as this stub-out library - * without having the names step on each other. - * - */ - -#ifndef _VXWORKS_COVERAGE_STUBS_H_ -#define _VXWORKS_COVERAGE_STUBS_H_ - -#include "common_types.h" -#include -#include /* we cannot stub out va_list, va_start, va_end, etc. */ - -/******************************************************************************* - * MACRO definitions normally supplied by VxWorks (any header) - *******************************************************************************/ - -#define VCS_LOAD_ALL_SYMBOLS 0 - -#define VCS_O_RDONLY 00 -#define VCS_O_WRONLY 01 -#define VCS_O_RDWR 02 -#define VCS_O_CREAT 0100 -#define VCS_O_TRUNC 01000 - -#define VCS_MSG_Q_FIFO 0x0 -#define VCS_MSG_Q_PRIORITY 0x1 -#define VCS_WIND_MSG_Q_OPTION_MASK (VCS_MSG_Q_FIFO|VCS_MSG_Q_PRIORITY) - -#define VCS_MSG_PRI_NORMAL 0 -#define VCS_MSG_PRI_URGENT 1 - -#define VCS_M_objLib (61 << 16) -#define VCS_S_objLib_OBJ_ID_ERROR (VCS_M_objLib | 1) -#define VCS_S_objLib_OBJ_UNAVAILABLE (VCS_M_objLib | 2) -#define VCS_S_objLib_OBJ_DELETED (VCS_M_objLib | 3) -#define VCS_S_objLib_OBJ_TIMEOUT (VCS_M_objLib | 4) -#define VCS_S_objLib_OBJ_NO_METHOD (VCS_M_objLib | 5) - -#define VCS_VX_FP_TASK 0x0008 /* execute with floating-point coprocessor support. */ - -#define VCS_INUM_TO_IVEC(uint32) ((VCS_VOIDFUNCPTR *) (uint32)) - -#define VCS_NULLDEV 0 -#define VCS_DOS_CHK_ONLY 0x00000001 -#define VCS_DOS_CHK_REPAIR 0x00000002 -#define VCS_DOS_CHK_VERB_0 0x0000ff00 /* verbosity level/flags */ -#define VCS_DOS_CHK_VERB_SILENT VCS_DOS_CHK_VERB_0 -#define VCS_DOS_OPT_BLANK 0x0002 /* create a clean boot block */ -#define VCS_FIOUNMOUNT 39 /* unmount disk volume */ -#define VCS_FIOCHKDSK 48 - -#define VCS_S_IRUSR 1 -#define VCS_S_IWUSR 2 -#define VCS_S_IRGRP 4 -#define VCS_S_IWGRP 8 -#define VCS_S_IROTH 16 -#define VCS_S_IWOTH 32 - -#define VCS_CLOCK_REALTIME 0 - -/******************************************************************************* - * ENUM definitions normally supplied by VxWorks (any header) - *******************************************************************************/ - -enum -{ - VCS_SEM_Q_FIFO = 0x0, - VCS_SEM_Q_PRIORITY = 0x1, - VCS_SEM_DELETE_SAFE = 0x4, - VCS_SEM_INVERSION_SAFE = 0x8, - VCS_SEM_EVENTSEND_ERR_NOTIFY = 0x10 - -}; - -/*for binary semaphores */ -typedef enum { - VCS_SEM_EMPTY =0, - VCS_SEM_FULL =1 -} VCS_SEM_B_STATE; - -typedef enum -{ - VCS_ERROR = -1, - VCS_OK = 0 -} VCS_STATUS; - -enum -{ - VCS_WAIT_FOREVER = -1, - VCS_NO_WAIT = 0 -}; - - -/******************************************************************************* - * TYPE definitions normally supplied by VxWorks (any header) - *******************************************************************************/ - -typedef int VCS_BLK_DEV; -typedef int VCS_device_t; -typedef int VCS_timer_t; -typedef int VCS_BOOL; -typedef void* VCS_MODULE_ID; -typedef unsigned char VCS_SYM_TYPE; -typedef void* VCS_PART_ID; -typedef uint32 VCS_UINT; -typedef uint16 VCS_UINT16; -typedef uint32 VCS_UINT32; -typedef void* VCS_MSG_Q_ID; - - -typedef void (*VCS_FUNCPTR)(long, long, long, long, long, long, long, long, long, long); -typedef void (*VCS_VOIDFUNCPTR) (void); /* ptr to function returning VOID */ - -typedef struct -{ - unsigned long numBytesFree; /* Number of Free Bytes in Partition */ - unsigned long numBlocksFree; /* Number of Free Blocks in Partition */ - unsigned long maxBlockSizeFree;/* Maximum block size that is free. */ - unsigned long numBytesAlloc; /* Number of Allocated Bytes in Partition */ - unsigned long numBlocksAlloc; /* Number of Allocated Blocks in Partition */ -} VCS_MEM_PART_STATS; - - -/* simplified definition that can be used in Linux and is available in VxWorks */ -typedef struct VCS_semaphore /* SEMAPHORE */ -{ - unsigned short recurse; /* 0x42: semaphore recursive take count */ -} VCS_SEMAPHORE; - - -typedef struct VCS_semaphore * VCS_SEM_ID; - - -typedef struct -{ - unsigned int format; - unsigned int group; - char name[32]; - struct - { - void* bssAddr; - unsigned long bssSize; - unsigned long bssFlags; - void* textAddr; - unsigned long textSize; - unsigned long textFlags; - void* dataAddr; - unsigned long dataSize; - unsigned long dataFlags; - } segInfo; -} VCS_MODULE_INFO; - -struct VCS_statfs { - long f_bfree; - long f_bsize; -}; - -struct VCS_stat -{ - char status; -}; - -typedef struct VCS_symbol /* SYMBOL - entry in symbol table */ -{ - int nameHNode; /* hash node (must come first) */ - char *name; /* pointer to symbol name */ - void *value; /* symbol value */ - int symRef; /* moduleId of module, or predefined SYMREF. */ - int group; /* symbol group */ - int type; /* symbol type */ -} VCS_SYMBOL; - -typedef VCS_SYMBOL * VCS_SYMBOL_ID; - -typedef struct VCS_symtab /* SYMTAB - symbol table */ -{ - int handle; /* object maintanance */ - int nameHashId; /* hash table for names */ - int symMutex; /* symbol table mutual exclusion sem */ - int symPartId; /* memory partition id for symbols */ - unsigned char sameNameOk; /* symbol table name clash policy */ - int nsymbols; /* current number of symbols in table */ -} VCS_SYMTAB; - -typedef struct VCS_symtab * VCS_SYMTAB_ID; - - -/******************************************************************************* - * FUNCTION PROTOTYPE definitions normally supplied by VxWorks (any header) - *******************************************************************************/ - -//int dosFsVolFormat(const char *, int , void *); - -VCS_MODULE_ID VCS_loadModule(int fd, unsigned int flags); -int VCS_moduleInfoGet(VCS_MODULE_ID, VCS_MODULE_INFO*); - -VCS_BLK_DEV *VCS_ramDevCreate (char *ramAddr, int bytesPerSec, int secPerTrack, - int nSectors, int secOffset); - -int VCS_statfs(char *_name, struct VCS_statfs *_pStat); - -int VCS_symFindByName (VCS_SYMTAB_ID, char *, char **SymValue, VCS_SYM_TYPE *); -VCS_SYMBOL * VCS_symEach(VCS_SYMTAB_ID, VCS_FUNCPTR, int ); - - -int VCS_timer_connect(VCS_timer_t, VCS_VOIDFUNCPTR, int); - -int VCS_unldByModuleId(VCS_MODULE_ID, int); - -/* Define missing functions */ -VCS_SEM_ID VCS_semMCreate(int options); - -VCS_STATUS VCS_semTake(VCS_SEM_ID semId, int timeout); - -VCS_STATUS VCS_semGive(VCS_SEM_ID semId); - -int VCS_open(const char *path, int oflag, ... ); - -VCS_STATUS VCS_close (int fd); - -int VCS_read (int fd, char *buffer, int maxbytes); - -int VCS_write(int fd, char *buffer, int nbytes); - -int VCS_lseek(int fd, long offset, int whence); - -VCS_STATUS VCS_cp(const char *src, const char *dest); - -VCS_STATUS VCS_rmdir(const char *dirName); - -VCS_STATUS VCS_intConnect(VCS_VOIDFUNCPTR * vector, /* interrupt vector to attach to */ - VCS_VOIDFUNCPTR routine, /* routine to be called */ - int parameter /* parameter to be passed to routine */); - -int VCS_intDisable(int level /* new interrupt bits (0x0 - 0xff00) */); - -int VCS_intEnable(int level /* new interrupt bits (0x00 - 0xff00) */); - -int VCS_intLock(void); - -int VCS_intUnlock(int lockKey /* lock-out key returned by preceding intLock() */); - -VCS_STATUS VCS_memPartShow(VCS_PART_ID partId, /* partition ID */ - int type /* 0 = statistics, 1 = statistics & list */); - -VCS_STATUS VCS_memPartInfoGet(VCS_PART_ID partId, /* partition ID */ - VCS_MEM_PART_STATS * ppartStats /* partition stats structure */); - -VCS_MSG_Q_ID VCS_msgQCreate(int maxMsgs, /* max messages that can be queued */ - int maxMsgLength, /* max bytes in a message */ - int options /* message queue options */); - -VCS_STATUS VCS_msgQDelete(VCS_MSG_Q_ID msgQId /* message queue to delete */); - -int VCS_msgQReceive(VCS_MSG_Q_ID msgQId, /* message queue from which to receive */ - char * buffer, /* buffer to receive message */ - uint32 maxNBytes, /* length of buffer */ - int timeout /* ticks to wait */); - -VCS_STATUS VCS_msgQSend(VCS_MSG_Q_ID msgQId, /* message queue on which to send */ - char * buffer, /* message to send */ - uint32 nBytes, /* length of message */ - int timeout, /* ticks to wait */ - int priority /* MSG_PRI_NORMAL or MSG_PRI_URGENT */); - -VCS_SEM_ID VCS_semBCreate(int options, /* semaphore options */ - VCS_SEM_B_STATE initialState /* initial semaphore state */); - -VCS_SEM_ID VCS_semCCreate(int flags, int count); - -VCS_STATUS VCS_semDelete(VCS_SEM_ID semId /* semaphore ID to delete */); - -VCS_STATUS VCS_semFlush(VCS_SEM_ID semId /* semaphore ID to unblock everyone for */); - -int VCS_shellGenericInit(const char *, const char *, const char *, char **, int, int, int, int, int); - -VCS_STATUS VCS_taskDelay(int ticks); - -VCS_STATUS VCS_taskDelete(int tid /* task ID of task to delete */); - -VCS_STATUS VCS_taskDeleteForce(int tid /* task ID of task to delete */); - -void VCS_taskExit(int code); - -int VCS_taskIdSelf(void); - -int VCS_taskNameToId(char *name); - -VCS_STATUS VCS_taskPrioritySet(int tid, /* task ID */ - int newPriority /* new priority */); - -int VCS_taskSpawn(char * name, /* name of new task (stored at pStackBase) */ - int priority, /* priority of new task */ - int options, /* task option word */ - int stackSize, /* size (bytes) of stack needed plus name */ - VCS_FUNCPTR entryPt, /* entry point of new task */ - int arg1, /* 1st of 10 req'd task args to pass to func */ - int arg2, - int arg3, - int arg4, - int arg5, - int arg6, - int arg7, - int arg8, - int arg9, - int arg10); - -VCS_STATUS VCS_taskVarAdd(int tid, /* ID of task to have new variable */ - int * pVar /* pointer to variable to be switched for task */); - -int VCS_sysClkRateGet(void); - -uint32 VCS_vxFpscrGet(void); - -void VCS_vxFpscrSet (uint32 mask); - -VCS_STATUS VCS_close (int fd); - -VCS_BLK_DEV *VCS_ataDevCreate(int ctrl, int drive, unsigned int nBlocks, unsigned int blkOffset); -VCS_STATUS VCS_dosFsVolFormat(char *path, int opt, VCS_FUNCPTR pPromptFunc); - -VCS_BLK_DEV *VCS_ramDevCreate (char *ramAddr, int bytesPerSec, int secPerTrack, - int nSectors, int secOffset); - -VCS_device_t VCS_xbdBlkDevCreateSync (VCS_BLK_DEV *bd, const char *name); - - - -/* Global variables */ -extern VCS_PART_ID VCS_memSysPartId; -extern int VCS_errno; - - -struct VCS_timespec -{ - long tv_sec; - long tv_nsec; -}; - -struct VCS_itimerspec -{ - struct VCS_timespec it_value; - struct VCS_timespec it_interval; -}; - -struct VCS_sigevent -{ -}; - -typedef unsigned int VCS_clockid_t; - -int VCS_mkdir(const char *pathname); -int VCS_open(const char *path, int oflag, ...); -int VCS_stat(const char *path, struct VCS_stat *buf); -int VCS_gethostname(char *name, int len); -int VCS_hostGetByName(char *host_name); -int VCS_ioctl(int d, int request, ...); -int VCS_clock_getres(VCS_clockid_t, struct VCS_timespec *); -int VCS_timer_create(VCS_clockid_t, struct VCS_sigevent *, VCS_timer_t *); -int VCS_timer_delete(VCS_timer_t); -int VCS_clock_gettime(unsigned int, struct VCS_timespec *); -int VCS_clock_settime(unsigned int, const struct VCS_timespec *); -int VCS_timer_settime(VCS_timer_t, int, const struct VCS_itimerspec*, struct VCS_itimerspec*); - - -typedef unsigned int VCS_mode_t; -typedef void VCS_DIR; - -size_t VCS_strlen(const char *str); -int VCS_strcmp(const char *str1, const char *str2); -char *VCS_strcpy(char *str1, const char *str2); -int VCS_vsnprintf(char *str, size_t size, const char *format, va_list ap); -char *VCS_strncpy(char *str1, const char *str2, size_t size); -char *VCS_strrchr(const char *string, int c); -char *VCS_strchr(const char *string, int c); - - -VCS_DIR *VCS_opendir(const char * dirName); -int VCS_closedir(VCS_DIR * dirp); - -struct VCS_dirent -{ - char d_name[32]; -}; -struct VCS_dirent *VCS_readdir (VCS_DIR *__dirp); -void VCS_rewinddir (VCS_DIR *); - - -#define VCS_EXIT_SUCCESS 100 -#define VCS_EXIT_FAILURE 101 -int VCS_printf(const char *format, ...); -void VCS_memset(void *, int c, unsigned int size); -void VCS_exit(int c); - -#define VCS_SEEK_SET 201 -#define VCS_SEEK_CUR 202 -#define VCS_SEEK_END 203 -int VCS_remove(const char *file); -int VCS_rename(const char *oldname, const char *newname); - -char *VCS_strcat(char *dest, const char *src); -char *VCS_strncat(char *dest, const char *src, unsigned int size); -int VCS_strncmp(const char *s1, const char *s2, unsigned int size); -int VCS_snprintf(char *buf, unsigned int sz, const char *format, ...); - -VCS_SEM_ID VCS_semBInitialize(char *pSemMem, int options, VCS_SEM_B_STATE initialState); -#define VCS_VX_BINARY_SEMAPHORE(x) char x[4] - -#endif /* _VXWORKS_COVERAGE_STUBS_H_ */ From dfa3393b5a8c4714a4c5410c3e93b9fb3595f448 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 21 Oct 2019 11:51:35 -0400 Subject: [PATCH 2/8] Fix #230: Add Test cases to improve code coverage test Add numerous unit test cases to improve the code coverage ratios on the vxworks and shared implementation layers. Prior to this change set, the coverage ratio was: lines......: 90.4% (2549 of 2820 lines) functions..: 95.9% (306 of 319 functions) After this change set, the coverage ratio is: lines......: 99.9% (2846 of 2849 lines) functions..: 100.0% (330 of 330 functions) Note these stats include some of the UT code itself, and this is what added 11 functions. No functions were added to FSW code. Note, one test condition will fail until the fix for related bug #269 is merged. This also fixes the posix coverage test so it builds and runs, but coverage is still not implemented here. --- src/unit-test-coverage/CMakeLists.txt | 16 ++- .../src => portable}/coveragetest-posixfile.c | 41 ++++++ .../coveragetest-posixgettime.c | 4 - .../src => portable}/coveragetest-posixio.c | 7 + src/unit-test-coverage/posix/CMakeLists.txt | 8 +- .../posix/modules/src/stub-map-to-real.h | 6 + .../posix/modules/src/ut-osapi.c | 1 + .../ut-stubs/src/osapi-impl-posix-stubs.c | 1 + .../shared/modules/inc/ut-osapi-idmap.h | 7 + .../shared/modules/inc/ut-osapi-sockets.h | 6 + .../shared/modules/src/ut-osapi-idmap.c | 5 + .../shared/modules/src/ut-osapi-sockets.c | 5 + .../shared/src/coveragetest-binsem.c | 11 ++ .../shared/src/coveragetest-common.c | 54 ++++--- .../shared/src/coveragetest-countsem.c | 11 ++ .../shared/src/coveragetest-dir.c | 4 + .../shared/src/coveragetest-filesys.c | 51 ++++++- .../shared/src/coveragetest-idmap.c | 133 +++++++++++++++++- .../shared/src/coveragetest-module.c | 31 ++++ .../shared/src/coveragetest-mutex.c | 12 ++ .../shared/src/coveragetest-printf.c | 21 ++- .../shared/src/coveragetest-sockets.c | 115 +++++++++++++++ .../shared/src/coveragetest-task.c | 27 +++- .../shared/src/coveragetest-time.c | 11 +- .../shared/src/coveragetest-timebase.c | 1 - .../ut-stubs/src/posix-signal-stubs.c | 9 ++ .../ut-stubs/src/vxworks-taskLib-stubs.c | 20 ++- .../vxworks/modules/inc/ut-osapi.h | 24 +++- .../vxworks/modules/inc/ut-osfileapi.h | 1 + .../vxworks/modules/inc/ut-ostimer.h | 14 +- .../vxworks/modules/src/ut-osapi.c | 20 +++ .../vxworks/modules/src/ut-ostimer.c | 25 ++++ .../vxworks/src/coveragetest-osapi.c | 89 +++++++++++- .../vxworks/src/coveragetest-osfileapi.c | 93 +++++++++++- .../vxworks/src/coveragetest-osloader.c | 41 ++++++ .../vxworks/src/coveragetest-ostimer.c | 86 ++++++++++- .../vxworks/src/coveragetest-printf.c | 47 +++++-- 37 files changed, 995 insertions(+), 63 deletions(-) rename src/unit-test-coverage/{vxworks/src => portable}/coveragetest-posixfile.c (74%) rename src/unit-test-coverage/{vxworks/src => portable}/coveragetest-posixgettime.c (91%) rename src/unit-test-coverage/{vxworks/src => portable}/coveragetest-posixio.c (95%) diff --git a/src/unit-test-coverage/CMakeLists.txt b/src/unit-test-coverage/CMakeLists.txt index eacca29e7..6579e877e 100644 --- a/src/unit-test-coverage/CMakeLists.txt +++ b/src/unit-test-coverage/CMakeLists.txt @@ -135,9 +135,19 @@ list(APPEND OSALCOVERAGE_STUB_LIB_LIST ut_osapi_stubs) # - Links to the stub libraries of everything else, plus UT assert function (add_coverage_tests SETNAME) foreach(MODNAME ${ARGN}) - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/coveragetest-${MODNAME}.c) + set (TESTCASE_SRCFILE) + foreach (SRCFILE + "${PROJECT_SOURCE_DIR}/portable/coveragetest-${MODNAME}.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/coveragetest-${MODNAME}.c" + ) + if (EXISTS "${SRCFILE}") + set (TESTCASE_SRCFILE "${SRCFILE}") + endif (EXISTS "${SRCFILE}") + endforeach() + + if (TESTCASE_SRCFILE) set(TESTNAME "${SETNAME}-${MODNAME}") - message (STATUS "Found test case for ${TESTNAME}") + message (STATUS "Found test case for ${TESTNAME} in ${TESTCASE_SRCFILE}") if (DEFINED MODULE_LINK_MAP_${MODNAME}) set(LINKMOD ${MODULE_LINK_MAP_${MODNAME}}) @@ -146,7 +156,7 @@ function (add_coverage_tests SETNAME) endif() add_executable(${TESTNAME}-testrunner - src/coveragetest-${MODNAME}.c + ${TESTCASE_SRCFILE} $) set_target_properties(${TESTNAME}-testrunner PROPERTIES LINK_FLAGS "${UT_C_FLAGS}") diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-posixfile.c b/src/unit-test-coverage/portable/coveragetest-posixfile.c similarity index 74% rename from src/unit-test-coverage/vxworks/src/coveragetest-posixfile.c rename to src/unit-test-coverage/portable/coveragetest-posixfile.c index 6fe0fbd3d..20e000d01 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-posixfile.c +++ b/src/unit-test-coverage/portable/coveragetest-posixfile.c @@ -92,6 +92,46 @@ void Test_OS_FileStat_Impl(void) } +void Test_OS_FileChmod_Impl(void) +{ + /* + * Test Case For: + * int32 OS_FileChmod_Impl(const char *local_path, uint32 access) + */ + struct OCS_stat RefStat; + + /* failure mode 1 (stat) */ + UT_SetForceFail(UT_KEY(OCS_stat), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl("local",OS_READ_WRITE), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_stat)); + + /* failure mode 2 (chmod) */ + UT_SetForceFail(UT_KEY(OCS_chmod), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl("local",OS_READ_WRITE), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_chmod)); + + /* all permission bits with uid/gid match */ + RefStat.st_uid = Osapi_Internal_GetSelfEUID(); + RefStat.st_gid = Osapi_Internal_GetSelfEGID(); + RefStat.st_mode = ~0; + RefStat.st_size = 1234; + RefStat.st_mtime = 5678; + UT_SetDataBuffer(UT_KEY(OCS_stat), &RefStat, sizeof(RefStat), false); + + /* nominal 1 - full permissions with file owned by own uid/gid */ + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl("local",OS_READ_WRITE), OS_SUCCESS); + + /* nominal 2 - partial permissions */ + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl("local", OS_READ_ONLY), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl("local", OS_WRITE_ONLY), OS_SUCCESS); + + /* nominal 3 - non-owned file */ + ++RefStat.st_uid; + ++RefStat.st_gid; + UT_SetDataBuffer(UT_KEY(OCS_stat), &RefStat, sizeof(RefStat), false); + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl("local",OS_READ_WRITE), OS_SUCCESS); +} + void Test_OS_FileRemove_Impl (void) { /* @@ -156,6 +196,7 @@ void OS_Application_Startup(void) { ADD_TEST(OS_FileOpen_Impl); ADD_TEST(OS_FileStat_Impl); + ADD_TEST(OS_FileChmod_Impl); ADD_TEST(OS_FileRemove_Impl); ADD_TEST(OS_FileRename_Impl); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-posixgettime.c b/src/unit-test-coverage/portable/coveragetest-posixgettime.c similarity index 91% rename from src/unit-test-coverage/vxworks/src/coveragetest-posixgettime.c rename to src/unit-test-coverage/portable/coveragetest-posixgettime.c index 497949b91..525191ba7 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-posixgettime.c +++ b/src/unit-test-coverage/portable/coveragetest-posixgettime.c @@ -21,10 +21,6 @@ #include -/* JPHFIX: FIXME: This should be in a header somehow, not here */ -extern int32 OS_GetLocalTime_Impl(OS_time_t *time_struct); -extern int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct); - #define OSAPI_TEST_FUNCTION_RC(func,exp) \ { \ int32 rcexp = exp; \ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-posixio.c b/src/unit-test-coverage/portable/coveragetest-posixio.c similarity index 95% rename from src/unit-test-coverage/vxworks/src/coveragetest-posixio.c rename to src/unit-test-coverage/portable/coveragetest-posixio.c index 374e24875..7f4424c0b 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-posixio.c +++ b/src/unit-test-coverage/portable/coveragetest-posixio.c @@ -43,6 +43,13 @@ void Test_OS_GenericClose_Impl(void) * int32 OS_GenericClose_Impl(uint32 local_id) */ OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl,(0), OS_SUCCESS); + + /* + * Test path where underlying close() fails. + * Should still return success. + */ + UT_SetForceFail(UT_KEY(OCS_close), -1); + OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl,(0), OS_SUCCESS); } void Test_OS_GenericSeek_Impl (void) diff --git a/src/unit-test-coverage/posix/CMakeLists.txt b/src/unit-test-coverage/posix/CMakeLists.txt index 18c83a3a5..79c940750 100644 --- a/src/unit-test-coverage/posix/CMakeLists.txt +++ b/src/unit-test-coverage/posix/CMakeLists.txt @@ -1,10 +1,11 @@ # CMake snippet for building the shared OSAL layer coverage tests -set(MODULE_LIST osapi osfileapi osfilesys osloader osnetwork osselect ostimer) +set(MODULE_LIST osapi) # This unit test is allowed to directly include any internal file in # the respective set under test. include_directories(${OSAL_SOURCE_DIR}/src/os/${SETNAME}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules/inc) # The "ut-stubs" contains additional stubs specific to this sub-module add_subdirectory(ut-stubs) @@ -13,6 +14,11 @@ add_subdirectory(ut-stubs) # (this is not a stub, this is the real code) add_subdirectory(modules) +set(MODULE_LINK_MAP_posixio osfileapi) +set(MODULE_LINK_MAP_posixfile osfileapi) +set(MODULE_LINK_MAP_posixdirs osfileapi) +set(MODULE_LINK_MAP_posixgettime ostimer) + # Add all coverage tests in the src dir add_coverage_tests(${SETNAME} ${MODULE_LIST}) diff --git a/src/unit-test-coverage/posix/modules/src/stub-map-to-real.h b/src/unit-test-coverage/posix/modules/src/stub-map-to-real.h index 7f1f09fa0..9c27d0f7e 100644 --- a/src/unit-test-coverage/posix/modules/src/stub-map-to-real.h +++ b/src/unit-test-coverage/posix/modules/src/stub-map-to-real.h @@ -44,6 +44,10 @@ #define SEEK_CUR OCS_SEEK_CUR #define SEEK_END OCS_SEEK_END +#define STDOUT_FILENO OCS_STDOUT_FILENO +#define STDIN_FILENO OCS_STDIN_FILENO +#define STDERR_FILENO OCS_STDERR_FILENO + /* pthread-related identifiers */ #define PTHREAD_PRIO_INHERIT OCS_PTHREAD_PRIO_INHERIT #define PTHREAD_MUTEX_RECURSIVE OCS_PTHREAD_MUTEX_RECURSIVE @@ -161,6 +165,7 @@ #define ntohs OCS_ntohs #define opendir OCS_opendir #define open OCS_open +#define printf(...) OCS_printf(__VA_ARGS__) #define pthread_attr_destroy OCS_pthread_attr_destroy #define pthread_attr_getschedparam OCS_pthread_attr_getschedparam #define pthread_attr_init OCS_pthread_attr_init @@ -229,6 +234,7 @@ #define stdout OCS_stdout #define strcmp OCS_strcmp #define strcpy OCS_strcpy +#define strerror OCS_strerror #define strlen OCS_strlen #define strncmp OCS_strncmp #define strncpy OCS_strncpy diff --git a/src/unit-test-coverage/posix/modules/src/ut-osapi.c b/src/unit-test-coverage/posix/modules/src/ut-osapi.c index d3de40688..e5e228da7 100644 --- a/src/unit-test-coverage/posix/modules/src/ut-osapi.c +++ b/src/unit-test-coverage/posix/modules/src/ut-osapi.c @@ -17,6 +17,7 @@ OS_common_record_t * const OS_global_queue_table = OS_stub_queue_table; OS_queue_internal_record_t OS_queue_table[OS_MAX_QUEUES]; OS_task_internal_record_t OS_task_table[OS_MAX_TASKS]; +OS_console_internal_record_t OS_console_table[OS_MAX_CONSOLES]; OS_SharedGlobalVars_t OS_SharedGlobalVars = { diff --git a/src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c b/src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c index 230d4ad68..d519a8894 100644 --- a/src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c +++ b/src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c @@ -7,4 +7,5 @@ UT_DEFAULT_STUB(OS_Posix_TimeBaseAPI_Impl_Init, (void)) UT_DEFAULT_STUB(OS_Posix_ModuleAPI_Impl_Init, (void)) UT_DEFAULT_STUB(OS_Posix_StreamAPI_Impl_Init, (void)) UT_DEFAULT_STUB(OS_Posix_DirAPI_Impl_Init, (void)) +UT_DEFAULT_STUB(OS_Posix_FileSysAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-idmap.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-idmap.h index fe43be904..09717c307 100644 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-idmap.h +++ b/src/unit-test-coverage/shared/modules/inc/ut-osapi-idmap.h @@ -27,5 +27,12 @@ void Osapi_Internal_ResetState(void); */ int32 Osapi_Call_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record); +/** + * Wrapper around the OS_ObjectIdConvertLock call so the test code can invoke it + * (it is defined as static) + */ +int32 Osapi_Call_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uint32 reference_id, OS_common_record_t *obj); + + #endif /* _OSAL_UT_OSAPI_IDMAP_H_ */ diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-sockets.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-sockets.h index 544713e99..fec3c5ce4 100644 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-sockets.h +++ b/src/unit-test-coverage/shared/modules/inc/ut-osapi-sockets.h @@ -4,6 +4,7 @@ #define _OSAL_UT_OSAPI_SOCKETS_H_ #include +#include /***************************************************** * @@ -20,6 +21,11 @@ */ void Osapi_Internal_ResetState(void); +/** + * Invoke the OS_CreateSocketName() static helper function + */ +void Osapi_Call_CreateSocketName_Static(OS_stream_internal_record_t *sock, + const OS_SockAddr_t *Addr, const char *parent_name); #endif /* _OSAL_UT_OSAPI_SOCKETS_H_ */ diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-idmap.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-idmap.c index a5a9fad1f..63b769b98 100644 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-idmap.c +++ b/src/unit-test-coverage/shared/modules/src/ut-osapi-idmap.c @@ -18,3 +18,8 @@ int32 Osapi_Call_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_ { return OS_ObjectIdFindNext(idtype, array_index, record); } + +int32 Osapi_Call_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uint32 reference_id, OS_common_record_t *obj) +{ + return OS_ObjectIdConvertLock(lock_mode, idtype, reference_id, obj); +} diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-sockets.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-sockets.c index 3b2641f5d..22bbdaf04 100644 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-sockets.c +++ b/src/unit-test-coverage/shared/modules/src/ut-osapi-sockets.c @@ -14,3 +14,8 @@ OS_stream_internal_record_t OS_stream_table[OS_MAX_NUM_OPEN_FILES]; OS_common_record_t OS_stub_socket_table[OS_MAX_NUM_OPEN_FILES]; OS_common_record_t * const OS_global_stream_table = OS_stub_socket_table; +void Osapi_Call_CreateSocketName_Static(OS_stream_internal_record_t *sock, const OS_SockAddr_t *Addr, const char *parent_name) +{ + OS_CreateSocketName(sock, Addr, parent_name); +} + diff --git a/src/unit-test-coverage/shared/src/coveragetest-binsem.c b/src/unit-test-coverage/shared/src/coveragetest-binsem.c index b8914e633..b26fd66a7 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -15,6 +15,8 @@ #include "os-shared-coveragetest.h" #include "ut-osapi-binsem.h" +#include + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -47,6 +49,10 @@ void Test_OS_BinSemCreate(void) UtAssert_True(actual == expected, "OS_BinSemCreate() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(objid != 0, "objid (%lu) != 0", (unsigned long)objid); + + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(NULL, NULL, 0, 0), OS_INVALID_POINTER); + UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG); } void Test_OS_BinSemDelete(void) @@ -141,6 +147,8 @@ void Test_OS_BinSemGetIdByName(void) actual = OS_BinSemGetIdByName(&objid, "NF"); UtAssert_True(actual == expected, "OS_BinSemGetIdByName() (%ld) == %ld", (long)actual, (long)expected); + + OSAPI_TEST_FUNCTION_RC(OS_BinSemGetIdByName(NULL, NULL), OS_INVALID_POINTER); } void Test_OS_BinSemGetInfo(void) @@ -168,6 +176,9 @@ void Test_OS_BinSemGetInfo(void) (unsigned long)prop.creator); UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); + + + OSAPI_TEST_FUNCTION_RC(OS_BinSemGetInfo(0, NULL), OS_INVALID_POINTER); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-common.c b/src/unit-test-coverage/shared/src/coveragetest-common.c index 8f9082c9b..5873d530c 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-common.c +++ b/src/unit-test-coverage/shared/src/coveragetest-common.c @@ -25,6 +25,8 @@ extern void OS_CleanUpObject(uint32 object_id, void *arg); +int32 Test_MicroSecPerTick = 0; +int32 Test_TicksPerSecond = 0; /* ********************************************************************************** @@ -35,8 +37,8 @@ extern void OS_CleanUpObject(uint32 object_id, void *arg); /* as a side effect, the OS_TimeBaseAPI_Init must initialize the globals */ static int32 TimeBaseInitGlobal(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) { - OS_SharedGlobalVars.MicroSecPerTick = 1000; - OS_SharedGlobalVars.TicksPerSecond = 1000; + OS_SharedGlobalVars.MicroSecPerTick = Test_MicroSecPerTick; + OS_SharedGlobalVars.TicksPerSecond = Test_TicksPerSecond; return StubRetcode; } @@ -71,25 +73,39 @@ static int32 SetShutdownFlagHook(void *UserObj, int32 StubRetcode, uint32 CallCo */ void Test_OS_API_Init(void) { - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - /* Setup Inputs */ - UT_SetHookFunction(UT_KEY(OS_TimeBaseAPI_Init), TimeBaseInitGlobal, NULL); /* Execute Test */ - actual = OS_API_Init(); + Test_MicroSecPerTick = 0; + Test_TicksPerSecond = 0; + OS_SharedGlobalVars.Initialized = false; + OSAPI_TEST_FUNCTION_RC(OS_API_Init(), OS_ERROR); - /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_API_Init() (%ld) != OS_SUCCESS", (long)actual); + Test_MicroSecPerTick = 1000; + Test_TicksPerSecond = 1000; + OS_SharedGlobalVars.Initialized = false; + OSAPI_TEST_FUNCTION_RC(OS_API_Init(), OS_SUCCESS); /* Second call should return ERROR */ - expected = OS_ERROR; - actual = OS_API_Init(); + OSAPI_TEST_FUNCTION_RC(OS_API_Init(), OS_ERROR); + + /* other error paths */ + OS_SharedGlobalVars.Initialized = false; + UT_SetForceFail(UT_KEY(OS_ObjectIdInit), -222); + OSAPI_TEST_FUNCTION_RC(OS_API_Init(), -222); + UT_ResetState(UT_KEY(OS_ObjectIdInit)); + + OS_SharedGlobalVars.Initialized = false; + UT_SetForceFail(UT_KEY(OS_API_Impl_Init), -333); + OSAPI_TEST_FUNCTION_RC(OS_API_Init(), -333); + UT_ResetState(UT_KEY(OS_API_Impl_Init)); + + OS_SharedGlobalVars.Initialized = false; + UT_SetForceFail(UT_KEY(OS_TaskAPI_Init), -444); + OSAPI_TEST_FUNCTION_RC(OS_API_Init(), -444); + UT_ResetState(UT_KEY(OS_TaskAPI_Init)); - /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_API_Init() (%ld) != OS_ERROR", (long)actual); } void Test_OS_ApplicationExit(void) @@ -119,6 +135,9 @@ void Test_OS_CleanUpObject(void) objtype = OS_OBJECT_TYPE_UNDEFINED; while (objtype < OS_OBJECT_TYPE_USER) { + UT_ResetState(0); + UT_SetForceFail(UT_KEY(OS_IdentifyObject), objtype); + switch(objtype) { case OS_OBJECT_TYPE_OS_TASK: @@ -158,21 +177,22 @@ void Test_OS_CleanUpObject(void) if (delhandler != 0) { - UT_ResetState(0); /* note the return code here is ignored - * the goal is simply to defeat the default * check that the objid was valid (it isn't) */ UT_SetForceFail(delhandler, OS_ERROR); - UT_SetForceFail(UT_KEY(OS_IdentifyObject), objtype); OS_CleanUpObject(0, &ActualObjs); CallCount = UT_GetStubCount(delhandler); UtAssert_True(CallCount == 1, "Objtype %lu call count (%lu) == 1", (unsigned long)objtype, (unsigned long)CallCount); - ++ExpObjs; } - + else + { + OS_CleanUpObject(0, &ActualObjs); + } ++objtype; + ++ExpObjs; } diff --git a/src/unit-test-coverage/shared/src/coveragetest-countsem.c b/src/unit-test-coverage/shared/src/coveragetest-countsem.c index 13f3845c5..a1f272b75 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -15,6 +15,8 @@ #include "os-shared-coveragetest.h" #include "ut-osapi-countsem.h" +#include + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -47,6 +49,10 @@ void Test_OS_CountSemCreate(void) UtAssert_True(actual == expected, "OS_CountSemCreate() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(objid != 0, "objid (%lu) != 0", (unsigned long)objid); + + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(NULL, NULL, 0, 0), OS_INVALID_POINTER); + UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG); } void Test_OS_CountSemDelete(void) @@ -128,6 +134,9 @@ void Test_OS_CountSemGetIdByName(void) actual = OS_CountSemGetIdByName(&objid, "NF"); UtAssert_True(actual == expected, "OS_CountSemGetIdByName() (%ld) == %ld", (long)actual, (long)expected); + + OSAPI_TEST_FUNCTION_RC(OS_CountSemGetIdByName(NULL, NULL), OS_INVALID_POINTER); + } void Test_OS_CountSemGetInfo(void) @@ -155,6 +164,8 @@ void Test_OS_CountSemGetInfo(void) (unsigned long)prop.creator); UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); + + OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo(0, NULL), OS_INVALID_POINTER); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-dir.c b/src/unit-test-coverage/shared/src/coveragetest-dir.c index 42205f9cf..a7b76a13a 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-dir.c +++ b/src/unit-test-coverage/shared/src/coveragetest-dir.c @@ -59,6 +59,8 @@ void Test_OS_DirectoryOpen(void) UtAssert_True(actual == expected, "OS_DirectoryOpen() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(objid != 0, "objid (%lu) != 0", (unsigned long)objid); + + OSAPI_TEST_FUNCTION_RC(OS_DirectoryOpen(NULL, NULL), OS_INVALID_POINTER); } @@ -87,6 +89,8 @@ void Test_OS_DirectoryRead(void) int32 actual = OS_DirectoryRead(1, &dirent); UtAssert_True(actual == expected, "OS_DirectoryRead() (%ld) == OS_SUCCESS", (long)actual); + + OSAPI_TEST_FUNCTION_RC(OS_DirectoryRead(1, NULL), OS_INVALID_POINTER); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index abb5f785a..39aba02f3 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -35,6 +35,31 @@ void Test_OS_FileSysAPI_Init(void) UtAssert_True(actual == expected, "OS_FileSysAPI_Init() (%ld) == OS_SUCCESS", (long)actual); } +void Test_OS_FileSysAddFixedMap(void) +{ + /* + * Test Case For: + * int32 OS_FileSysAddFixedMap(uint32 *filesys_id, const char *phys_path, const char *virt_path) + */ + uint32 id; + + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, NULL, NULL), OS_INVALID_POINTER); + + UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_PATH_LEN); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_ERR_NAME_TOO_LONG); + UT_ClearForceFail(UT_KEY(OCS_strlen)); + + UT_SetForceFail(UT_KEY(OCS_strrchr), -1); + UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 3, 2 + OS_MAX_API_NAME); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_ERR_NAME_TOO_LONG); + UT_ResetState(UT_KEY(OCS_strlen)); + UT_ResetState(UT_KEY(OCS_strrchr)); + + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS); +} + void Test_OS_mkfs(void) { /* @@ -48,6 +73,13 @@ void Test_OS_mkfs(void) actual = OS_mkfs("adr","/ramdev0","vol",0,0); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_SUCCESS", (long)actual); + /* + * Test an entry NOT found in the OS_VolumeTable + */ + actual = OS_mkfs("adr","/rd1","vol1",0,0); + UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_SUCCESS", (long)actual); + + expected = OS_FS_ERR_INVALID_POINTER; actual = OS_mkfs(NULL,NULL,NULL,0,0); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_INVALID_POINTER", (long)actual); @@ -58,6 +90,11 @@ void Test_OS_mkfs(void) UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); UT_ClearForceFail(UT_KEY(OCS_strlen)); + /* set up for failure due to empty strings */ + expected = OS_FS_ERR_PATH_INVALID; + actual = OS_mkfs("adr","","",0,0); + UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); + /* set up for failure due to formatting */ UT_SetForceFail(UT_KEY(OS_FileSysFormatVolume_Impl), OS_FS_ERR_DRIVE_NOT_CREATED); expected = OS_FS_ERR_DRIVE_NOT_CREATED; @@ -114,6 +151,9 @@ void Test_OS_initfs(void) actual = OS_initfs("adr","/ramdev0","vol",0,0); UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_SUCCESS", (long)actual); + actual = OS_initfs(NULL,"/hda2","vol2",0,0); + UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_SUCCESS", (long)actual); + expected = OS_FS_ERR_INVALID_POINTER; actual = OS_initfs(NULL,NULL,NULL,0,0); UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_FS_ERR_INVALID_POINTER", (long)actual); @@ -501,7 +541,8 @@ void Test_OS_FileSys_FindVirtMountPoint(void) static const OS_VolumeInfo_t UT_VOLTAB_TESTCASES[] = { { .DeviceName = "/UT1", .VolumeType = ATA_DISK, .FreeFlag = false, .IsMounted = true }, - { .DeviceName = "/UT2", .VolumeType = EEPROM_DISK, .FreeFlag = true, .IsMounted = false } + { .DeviceName = "/UT2", .VolumeType = EEPROM_DISK, .FreeFlag = true, .IsMounted = false }, + { .DeviceName = "/UT3", .VolumeType = RAM_DISK, .FreeFlag = true, .IsMounted = false } }; void Test_OS_FileSys_InitLocalFromVolTable(void) @@ -530,6 +571,13 @@ void Test_OS_FileSys_InitLocalFromVolTable(void) UtAssert_True(actual == expected, "OS_FileSys_InitLocalFromVolTable(1) (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(temprec.fstype == OS_FILESYS_TYPE_MTD, "OS_FileSys_InitLocalFromVolTable(1) fstype(%u) == OS_FILESYS_TYPE_MTD", (unsigned int)temprec.fstype); + + memset(&temprec,0,sizeof(temprec)); + expected = OS_SUCCESS; + actual = Osapi_Internal_FileSys_InitLocalFromVolTable(&temprec, &UT_VOLTAB_TESTCASES[2]); + UtAssert_True(actual == expected, "OS_FileSys_InitLocalFromVolTable(1) (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(temprec.fstype == OS_FILESYS_TYPE_VOLATILE_DISK, "OS_FileSys_InitLocalFromVolTable(2) fstype(%u) == OS_FILESYS_TYPE_MTD", + (unsigned int)temprec.fstype); } /* Osapi_Task_Setup @@ -560,6 +608,7 @@ void Osapi_TearDown(void) void OS_Application_Startup(void) { ADD_TEST(OS_FileSysAPI_Init); + ADD_TEST(OS_FileSysAddFixedMap); ADD_TEST(OS_mkfs); ADD_TEST(OS_rmfs); ADD_TEST(OS_initfs); diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index 551eb0197..82fc67216 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -26,6 +26,11 @@ typedef struct uint32 OtherCount; } Test_OS_ObjTypeCount_t; +/* a match function that always matches */ +static bool TestAlwaysMatch(void *ref, uint32 local_id, const OS_common_record_t *obj) +{ + return true; +} static void ObjTypeCounter(uint32 object_id, void *arg) { @@ -107,6 +112,85 @@ void Test_OS_ObjectIdMapUnmap(void) } } +void Test_OS_ObjectIdConvertLock(void) +{ + /* + * Test Case For: + * static int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, + * uint32 idtype, uint32 reference_id, OS_common_record_t *obj) + * + * NOTE: These test cases just focus on code paths that are not exercised + * by the other test cases in this file. + */ + int32 expected; + int32 actual; + uint32 array_index; + OS_common_record_t *record; + uint32 objid; + + /* get a valid (fake) OSAL ID to start with */ + OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "ut", &array_index, &record); + objid = record->active_id; + + /* + * Attempt to obtain a lock for the same record with a non-matching ID + * This should return an error. + */ + actual = Osapi_Call_ObjectIdConvertLock(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, + objid + 123, record); + expected = OS_ERR_INVALID_ID; + + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock() (%ld) == OS_ERR_INVALID_ID (%ld)", (long)actual, (long)expected); + + /* + * Use mode OS_LOCK_MODE_NONE with matching ID + * This should return success. + */ + actual = Osapi_Call_ObjectIdConvertLock(OS_LOCK_MODE_NONE, + OS_OBJECT_TYPE_OS_TASK, objid, record); + expected = OS_SUCCESS; + + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock() (%ld) == OS_ERR_INVALID_ID (%ld)", (long)actual, (long)expected); + + /* + * Use mode OS_LOCK_MODE_EXCLUSIVE with matching ID and no other refs. + * This should return success. + */ + record->flags = 0; + record->refcount = 0; + actual = Osapi_Call_ObjectIdConvertLock(OS_LOCK_MODE_EXCLUSIVE, + OS_OBJECT_TYPE_OS_TASK, objid, record); + expected = OS_SUCCESS; + + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock() (%ld) == OS_SUCCESS (%ld)", (long)actual, (long)expected); + +} + +void Test_OS_ObjectIdGetBySearch(void) +{ + /* + * Test Case For: + * int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, + * OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record) + * + * NOTE: These test cases just focus on code paths that are not exercised + * by the other test cases in this file. + */ + int32 expected; + int32 actual; + OS_common_record_t *record; + + OS_global_task_table[0].active_id = 0x11111; + actual = OS_ObjectIdGetBySearch(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, + TestAlwaysMatch, NULL, &record); + expected = OS_SUCCESS; + OS_global_task_table[0].active_id = 0; + + UtAssert_True(actual == expected, "OS_ObjectIdGetBySearch() (%ld) == OS_SUCCESS (%ld)", (long)actual, (long)expected); + +} + + void Test_OS_GetMaxForObjectType(void) { /* @@ -238,6 +322,19 @@ void Test_OS_ObjectIdFindByName (void) UtAssert_True(actual == expected, "OS_ObjectFindIdByName(%s) (%ld) == OS_ERR_NAME_NOT_FOUND", TaskName, (long)actual); + + /* + * Set up for the ObjectIdSearch function to return success + */ + OS_global_task_table[0].active_id = 0x11111; + OS_global_task_table[0].name_entry = TaskName; + actual = OS_ObjectIdFindByName(OS_OBJECT_TYPE_OS_TASK, TaskName, &objid); + expected = OS_SUCCESS; + OS_global_task_table[0].active_id = 0; + OS_global_task_table[0].name_entry = NULL; + + UtAssert_True(actual == expected, "OS_ObjectFindIdByName(%s) (%ld) == OS_SUCCESS", TaskName, (long)actual); + } void Test_OS_ObjectIdGetById(void) @@ -257,7 +354,7 @@ void Test_OS_ObjectIdGetById(void) OS_SharedGlobalVars.Initialized = false; actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0, 0, &local_idx, &rptr); expected = OS_ERROR; - UtAssert_True(actual == expected, "OS_ObjectIdCheck(uninitialized) (%ld) == OS_ERROR", (long)actual); + UtAssert_True(actual == expected, "OS_ObjectIdGetById(uninitialized) (%ld) == OS_ERROR", (long)actual); /* set "true" for the remainder of tests */ OS_SharedGlobalVars.Initialized = true; @@ -269,7 +366,7 @@ void Test_OS_ObjectIdGetById(void) actual = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx, &rptr); /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_ObjectIdCheck() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(local_idx == 1, "local_idx (%lu) == 1", (unsigned long)local_idx); UtAssert_True(rptr != NULL, "rptr (%p) != NULL", rptr); UtAssert_True(rptr->refcount == 1, "refcount (%u) == 1", @@ -278,7 +375,21 @@ void Test_OS_ObjectIdGetById(void) /* attempting to get an exclusive lock should return IN_USE error */ expected = OS_ERR_OBJECT_IN_USE; actual = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx, &rptr); - UtAssert_True(actual == expected, "OS_ObjectIdCheck() (%ld) == OS_ERR_OBJECT_IN_USE", (long)actual); + UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_OBJECT_IN_USE", (long)actual); + + /* attempt to get non-exclusive lock during shutdown should fail */ + OS_SharedGlobalVars.ShutdownFlag = OS_SHUTDOWN_MAGIC_NUMBER; + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx, &rptr); + UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + OS_SharedGlobalVars.ShutdownFlag = 0; + + /* attempt to get lock for invalid type object should fail */ + expected = OS_ERR_INVALID_ID; + actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0xFFFFFFFF, refobjid, &local_idx, &rptr); + UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_INVALID_ID", (long)actual); + OS_SharedGlobalVars.ShutdownFlag = 0; + /* refcount decrement should work */ expected = OS_SUCCESS; @@ -447,11 +558,25 @@ void Test_OS_ObjectIdAllocateNew(void) UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(rptr != NULL, "rptr (%p) != NULL", rptr); + /* Passing a NULL name also should work here (used for internal objects) */ + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, NULL, &objid, &rptr); + UtAssert_True(actual == expected, "OS_ObjectIdAllocate(NULL) (%ld) == OS_SUCCESS", (long)actual); + rptr->name_entry = "UT_alloc"; expected = OS_ERR_NAME_TAKEN; actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &objid, &rptr); UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_NAME_TAKEN", (long)actual); + OS_SharedGlobalVars.ShutdownFlag = OS_SHUTDOWN_MAGIC_NUMBER; + expected = OS_ERROR; + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &objid, &rptr); + OS_SharedGlobalVars.ShutdownFlag = 0; + UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_NAME_TAKEN", (long)actual); + + expected = OS_ERR_INCORRECT_OBJ_TYPE; + actual = OS_ObjectIdAllocateNew(0xFFFFFFFF, "UT_alloc", &objid, &rptr); + UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); + } void Test_OS_ConvertToArrayIndex(void) @@ -544,6 +669,8 @@ void OS_Application_Startup(void) ADD_TEST(OS_ObjectIdFindByName); ADD_TEST(OS_ObjectIdGetById); ADD_TEST(OS_ObjectIdAllocateNew); + ADD_TEST(OS_ObjectIdConvertLock); + ADD_TEST(OS_ObjectIdGetBySearch); ADD_TEST(OS_ConvertToArrayIndex); ADD_TEST(OS_ForEachObject); ADD_TEST(OS_GetMaxForObjectType); diff --git a/src/unit-test-coverage/shared/src/coveragetest-module.c b/src/unit-test-coverage/shared/src/coveragetest-module.c index 79a2ce0c9..61a0f1a22 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -82,6 +82,14 @@ void Test_OS_ModuleLoad(void) actual = OS_ModuleLoad(&objid, "UTS", "File2"); expected = OS_ERR_NAME_TOO_LONG; UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); + UT_ResetState(UT_KEY(OCS_strlen)); + + + UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_ERROR); + actual = OS_ModuleLoad(&objid, "UT", "FileBad"); + expected = OS_ERROR; + UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_ERROR", (long)actual); + } void Test_OS_ModuleUnload(void) @@ -126,6 +134,16 @@ void Test_OS_SymbolLookup(void) UtAssert_True(symaddr == testaddr, "OS_SymbolLookup(address=%lx) == %lx", (unsigned long)symaddr, (unsigned long)testaddr); + actual = OS_SymbolLookup(NULL, NULL); + expected = OS_INVALID_POINTER; + UtAssert_True(actual == expected, "OS_SymbolLookup(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + + /* + * Look up a symbol that is present in the static symbol table + */ + actual = OS_SymbolLookup(&symaddr, "UT_staticsym"); + expected = OS_SUCCESS; + UtAssert_True(actual == expected, "OS_SymbolLookup(UT_staticsym) (%ld) == OS_SUCCESS", (long)actual); } void Test_OS_StaticSymbolLookup(void) @@ -181,6 +199,14 @@ void Test_OS_SymbolTableDump(void) UtAssert_True(actual == expected, "OS_SymbolTableDump() (%ld) == OS_INVALID_POINTER", (long)actual); + + UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_ERROR); + expected = OS_ERROR; + actual = OS_SymbolTableDump ( "test", 555 ); + UtAssert_True(actual == expected, + "OS_SymbolTableDump() (%ld) == OS_ERROR", + (long)actual); + } void Test_OS_ModuleGetInfo(void) @@ -209,6 +235,11 @@ void Test_OS_ModuleGetInfo(void) module_prop.filename); UtAssert_True(strcmp(module_prop.name, "ABC") == 0, "module_prop.name (%s) == ABC", module_prop.name); + + + actual = OS_ModuleInfo(1, NULL); + expected = OS_INVALID_POINTER; + UtAssert_True(actual == expected, "OS_ModuleGetInfo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-mutex.c b/src/unit-test-coverage/shared/src/coveragetest-mutex.c index 62f77f781..ca2fe9aa5 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -15,6 +15,8 @@ #include "os-shared-coveragetest.h" #include "ut-osapi-mutex.h" +#include + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -46,6 +48,10 @@ void Test_OS_MutSemCreate(void) UtAssert_True(actual == expected, "OS_MutSemCreate() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(objid != 0, "objid (%lu) != 0", (unsigned long)objid); + + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(NULL, NULL, 0), OS_INVALID_POINTER); + UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(&objid, "UT", 0), OS_ERR_NAME_TOO_LONG); } void Test_OS_MutSemDelete(void) @@ -111,6 +117,9 @@ void Test_OS_MutSemGetIdByName(void) actual = OS_MutSemGetIdByName(&objid, "NF"); UtAssert_True(actual == expected, "OS_MutSemGetIdByName() (%ld) == %ld", (long)actual, (long)expected); + + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetIdByName(NULL, NULL), OS_INVALID_POINTER); + } void Test_OS_MutSemGetInfo(void) @@ -138,6 +147,9 @@ void Test_OS_MutSemGetInfo(void) (unsigned long)prop.creator); UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); + + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo(0, NULL), OS_INVALID_POINTER); + } diff --git a/src/unit-test-coverage/shared/src/coveragetest-printf.c b/src/unit-test-coverage/shared/src/coveragetest-printf.c index 4cb6bae98..d7079c2c7 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-printf.c +++ b/src/unit-test-coverage/shared/src/coveragetest-printf.c @@ -15,7 +15,9 @@ #include "os-shared-coveragetest.h" #include "ut-osapi-printf.h" -char TestConsoleBuffer[256]; +#include + +char TestConsoleBuffer[16]; void Test_OS_ConsoleAPI_Init(void) { @@ -64,6 +66,23 @@ void Test_OS_printf(void) CallCount = UT_GetStubCount(UT_KEY(OS_ConsoleWakeup_Impl)); UtAssert_True(CallCount == 1, "OS_ConsoleWakeup_Impl() call count (%lu) == 1", (unsigned long)CallCount); UtAssert_True(OS_console_table[0].WritePos >= 9, "WritePos (%lu) >= 9", (unsigned long)OS_console_table[0].WritePos); + + /* print a long string that does not fit in the 16-char buffer */ + OS_printf_enable(); + OS_printf("UnitTest4BufferLengthExceeded"); + + /* test writing with a non-empty console name */ + strncpy(OS_console_table[0].device_name,"ut",sizeof(OS_console_table[0].device_name)-1); + OS_printf("UnitTest5"); + + /* + * For coverage, exercise different paths depending on the return value + */ + UT_SetForceFail(UT_KEY(OCS_vsnprintf), -1); + OS_printf("UnitTest6"); + + UT_SetForceFail(UT_KEY(OCS_vsnprintf), OS_BUFFER_SIZE+10); + OS_printf("UnitTest7"); } /* Osapi_Task_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-sockets.c b/src/unit-test-coverage/shared/src/coveragetest-sockets.c index d41158a6d..658d05a4c 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -15,6 +15,7 @@ #include "os-shared-coveragetest.h" #include "ut-osapi-sockets.h" +#include void Test_OS_SocketAPI_Init(void) { @@ -28,6 +29,36 @@ void Test_OS_SocketAPI_Init(void) UtAssert_True(actual == expected, "OS_SocketAPI_Init() (%ld) == OS_SUCCESS", (long)actual); } +/***************************************************************************** + * + * Test case for OS_CreateSocketName() + * This is a static helper function invoked via a wrapper + * + *****************************************************************************/ +void Test_OS_CreateSocketName(void) +{ + /* + * Test Case For: + * static void OS_CreateSocketName(OS_stream_internal_record_t *sock, + * const OS_SockAddr_t *Addr, const char *parent_name) + * + * This focuses on coverage paths, as this function does not return a value + */ + OS_stream_internal_record_t testrec; + OS_SockAddr_t testaddr; + + memset(&testrec, 'x', sizeof(testrec)); + memset(&testaddr, 0, sizeof(testaddr)); + UT_SetForceFail(UT_KEY(OS_SocketAddrToString_Impl), OS_ERROR); + Osapi_Call_CreateSocketName_Static(&testrec, &testaddr, "ut"); + + /* + * The function should have called snprintf() to create the name + */ + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_snprintf)) == 2, "OS_CreateSocketName() invoked snprintf()"); + UtAssert_True(testrec.stream_name[0] != 'x', "OS_CreateSocketName() set stream name"); +} + /***************************************************************************** * * Test case for OS_SocketOpen() @@ -77,6 +108,22 @@ void Test_OS_SocketBind(void) actual = OS_SocketBind(1, NULL); UtAssert_True(actual == expected, "OS_SocketBind(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + /* + * Should fail if not a socket domain + */ + OS_stream_table[1].socket_domain = OS_SocketDomain_INVALID; + expected = OS_ERR_INCORRECT_OBJ_TYPE; + actual = OS_SocketBind(1, &Addr); + UtAssert_True(actual == expected, "OS_SocketBind() non-socket (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); + + /* + * Should fail if already bound + */ + OS_stream_table[1].socket_domain = OS_SocketDomain_INET; + OS_stream_table[1].stream_state = OS_STREAM_STATE_BOUND; + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_SocketBind(1, &Addr); + UtAssert_True(actual == expected, "OS_SocketBind() already bound (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); } /***************************************************************************** @@ -110,6 +157,31 @@ void Test_OS_SocketAccept(void) actual = OS_SocketAccept(1, NULL, NULL, 0); UtAssert_True(actual == expected, "OS_SocketAccept(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + /* + * Should fail if not a stream socket + */ + OS_stream_table[1].socket_type = OS_SocketType_INVALID; + expected = OS_ERR_INCORRECT_OBJ_TYPE; + actual = OS_SocketAccept(1, &connsock_id, &Addr, 0); + UtAssert_True(actual == expected, "OS_SocketAccept() non-stream (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); + + /* + * Should fail if already connected + */ + OS_stream_table[1].socket_type = OS_SocketType_STREAM; + OS_stream_table[1].stream_state = OS_STREAM_STATE_BOUND|OS_STREAM_STATE_CONNECTED; + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_SocketAccept(1, &connsock_id, &Addr, 0); + UtAssert_True(actual == expected, "OS_SocketAccept() already bound (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + + /* + * Underlying implementation failure test + */ + OS_stream_table[1].stream_state = OS_STREAM_STATE_BOUND; + expected = -1234; + UT_SetForceFail(UT_KEY(OS_SocketAccept_Impl), -1234); + actual = OS_SocketAccept(1, &connsock_id, &Addr, 0); + UtAssert_True(actual == expected, "OS_SocketAccept() underlying failure (%ld) == -1234", (long)actual); } /***************************************************************************** @@ -143,6 +215,25 @@ void Test_OS_SocketConnect(void) actual = OS_SocketConnect(1, NULL, 0); UtAssert_True(actual == expected, "OS_SocketConnect(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + /* + * Should fail if not a stream socket + */ + OS_stream_table[1].socket_domain = OS_SocketDomain_INVALID; + OS_stream_table[1].socket_type = OS_SocketType_INVALID; + expected = OS_ERR_INCORRECT_OBJ_TYPE; + actual = OS_SocketConnect(1, &Addr, 0); + UtAssert_True(actual == expected, "OS_SocketConnect() non-stream (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); + + /* + * Should fail if already connected + */ + OS_stream_table[1].socket_domain = OS_SocketDomain_INET; + OS_stream_table[1].socket_type = OS_SocketType_STREAM; + OS_stream_table[1].stream_state = OS_STREAM_STATE_CONNECTED; + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_SocketConnect(1, &Addr, 0); + UtAssert_True(actual == expected, "OS_SocketConnect() already connected (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + } /***************************************************************************** @@ -175,6 +266,22 @@ void Test_OS_SocketRecvFrom(void) actual = OS_SocketRecvFrom(1, NULL, 0, NULL, 0); UtAssert_True(actual == expected, "OS_SocketRecvFrom(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + /* + * Should fail if not a datagram socket + */ + OS_stream_table[1].socket_type = OS_SocketType_INVALID; + expected = OS_ERR_INCORRECT_OBJ_TYPE; + actual = OS_SocketRecvFrom(1, &Buf, 1, &Addr, 0); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() non-datagram (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); + + /* + * Should fail if not bound + */ + OS_stream_table[1].socket_type = OS_SocketType_DATAGRAM; + OS_stream_table[1].stream_state = 0; + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_SocketRecvFrom(1, &Buf, 1, &Addr, 0); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() non-bound (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); } /***************************************************************************** @@ -207,6 +314,13 @@ void Test_OS_SocketSendTo(void) actual = OS_SocketSendTo(1, NULL, 0, NULL); UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + /* + * Should fail if not a datagram socket + */ + OS_stream_table[1].socket_type = OS_SocketType_INVALID; + expected = OS_ERR_INCORRECT_OBJ_TYPE; + actual = OS_SocketSendTo(1, &Buf, 1, &Addr); + UtAssert_True(actual == expected, "OS_SocketSendTo() non-datagram (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); } @@ -368,6 +482,7 @@ void OS_Application_Startup(void) ADD_TEST(OS_SocketSendTo); ADD_TEST(OS_SocketGetIdByName); ADD_TEST(OS_SocketGetInfo); + ADD_TEST(OS_CreateSocketName); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index 033d5183c..d4dbb8dfe 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -15,6 +15,7 @@ #include "os-shared-coveragetest.h" #include "ut-osapi-task.h" +#include static uint32 UT_TestHook_Count = 0; @@ -104,6 +105,11 @@ void Test_OS_TaskCreate(void) UtAssert_True(actual == expected, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(objid != 0, "objid (%lu) != 0", (unsigned long)objid); + + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(NULL, NULL, NULL, NULL, 0, 0,0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 10 + OS_MAX_TASK_PRIORITY,0), OS_ERR_INVALID_PRIORITY); + UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, NULL, 0, 0,0), OS_ERR_NAME_TOO_LONG); } void Test_OS_TaskDelete(void) @@ -122,6 +128,12 @@ void Test_OS_TaskDelete(void) UtAssert_True(actual == expected, "OS_TaskDelete() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(UT_TestHook_Count == 1, "UT_TestHook_Count (%lu) == 1", (unsigned long)UT_TestHook_Count); + + UT_SetForceFail(UT_KEY(OS_TaskDelete_Impl), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete(1), OS_ERROR); + UtAssert_True(UT_TestHook_Count == 1, "UT_TestHook_Count (%lu) == 1", + (unsigned long)UT_TestHook_Count); + OS_task_table[1].delete_hook_pointer = NULL; } @@ -167,6 +179,8 @@ void Test_OS_TaskSetPriority(void) int32 actual = OS_TaskSetPriority(1, 1); UtAssert_True(actual == expected, "OS_TaskSetPriority() (%ld) == OS_SUCCESS", (long)actual); + + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority(1, 10 + OS_MAX_TASK_PRIORITY), OS_ERR_INVALID_PRIORITY); } void Test_OS_TaskRegister(void) { @@ -185,12 +199,13 @@ void Test_OS_TaskGetId(void) * Test Case For: * uint32 OS_TaskGetId (void) */ - uint32 expected = 0; - uint32 actual = OS_TaskGetId(); + UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 5555); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetId(), 5555); - UtAssert_True(actual == expected, "OS_TaskGetId() (%lu) == %lu", - (unsigned long)actual, (unsigned long)expected); + UT_SetForceFail(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetId(), 0); } + void Test_OS_TaskGetIdByName(void) { /* @@ -211,6 +226,8 @@ void Test_OS_TaskGetIdByName(void) actual = OS_TaskGetIdByName(&objid, "NF"); UtAssert_True(actual == expected, "OS_TaskGetIdByName() (%ld) == %ld", (long)actual, (long)expected); + + OSAPI_TEST_FUNCTION_RC(OS_TaskGetIdByName(NULL, NULL), OS_INVALID_POINTER); } void Test_OS_TaskGetInfo(void) @@ -247,6 +264,8 @@ void Test_OS_TaskGetInfo(void) OS_task_table[1].stack_size = 0; OS_task_table[1].priority = 0; + + OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo(0, NULL), OS_INVALID_POINTER); } void Test_OS_TaskInstallDeleteHandler(void) diff --git a/src/unit-test-coverage/shared/src/coveragetest-time.c b/src/unit-test-coverage/shared/src/coveragetest-time.c index e55aaf4ad..25a89d777 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -206,8 +206,17 @@ void Test_OS_TimerDelete(void) actual = OS_TimerDelete(1); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); - memset(OS_timecb_table, 0, sizeof(OS_timecb_table)); + /* verify deletion of the dedicated timebase objects + * these are implicitly created as part of timer creation for API compatibility */ + OS_TimeBaseCreate(&OS_global_timebase_table[0].active_id,"ut",NULL); + OS_timecb_table[1].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; + OS_timecb_table[1].timebase_ref = 0; + actual = OS_TimerDelete(1); + UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(UT_GetStubCount(UT_KEY(OS_TimeBaseDelete)) == 1, "OS_TimerDelete() invoked OS_TimeBaseDelete()"); + memset(OS_timecb_table, 0, sizeof(OS_timecb_table)); + memset(OS_timebase_table, 0, sizeof(OS_timebase_table)); UT_SetForceFail(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index 5874101db..233d0fb15 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -135,7 +135,6 @@ void Test_OS_TimeBaseDelete(void) expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimeBaseDelete(1); UtAssert_True(actual == expected, "OS_TimeBaseDelete() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - } void Test_OS_TimeBaseGetIdByName(void) diff --git a/src/unit-test-coverage/ut-stubs/src/posix-signal-stubs.c b/src/unit-test-coverage/ut-stubs/src/posix-signal-stubs.c index 968710c09..58fbda272 100644 --- a/src/unit-test-coverage/ut-stubs/src/posix-signal-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/posix-signal-stubs.c @@ -98,6 +98,15 @@ int OCS_sigwait (const OCS_sigset_t * set, int * sig) Status = UT_DEFAULT_IMPL(OCS_sigwait); + /* + * The "sig" value is an output, which the UT test + * case may need to control. + */ + if (UT_Stub_CopyToLocal(UT_KEY(OCS_sigwait),sig,sizeof(*sig)) < sizeof(*sig)) + { + *sig = 1; + } + return Status; } diff --git a/src/unit-test-coverage/ut-stubs/src/vxworks-taskLib-stubs.c b/src/unit-test-coverage/ut-stubs/src/vxworks-taskLib-stubs.c index 23c1f1005..9f075b5dc 100644 --- a/src/unit-test-coverage/ut-stubs/src/vxworks-taskLib-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/vxworks-taskLib-stubs.c @@ -123,6 +123,7 @@ OCS_STATUS OCS_taskActivate(OCS_TASK_ID tid) OCS_WIND_TCB *OCS_taskTcb(OCS_TASK_ID tid) { int32 Status; + OCS_WIND_TCB *LocalTcb; Status = UT_DEFAULT_IMPL(OCS_taskTcb); if (Status != 0) @@ -130,12 +131,17 @@ OCS_WIND_TCB *OCS_taskTcb(OCS_TASK_ID tid) return (NULL); } - /* - * On VxWorks the TASK_ID is defined as a direct type cast - * of the TCB address. This is actually documented - * in the API and application code that works with TCBs - * certainly will depend on this being the case. - */ - return ((OCS_WIND_TCB *)tid); + if (UT_Stub_CopyToLocal(UT_KEY(OCS_taskTcb), &LocalTcb, sizeof(LocalTcb)) < sizeof(LocalTcb)) + { + /* + * On VxWorks the TASK_ID is defined as a direct type cast + * of the TCB address. This is actually documented + * in the API and application code that works with TCBs + * certainly will depend on this being the case. + */ + LocalTcb = (OCS_WIND_TCB *)tid; + } + + return LocalTcb; } diff --git a/src/unit-test-coverage/vxworks/modules/inc/ut-osapi.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osapi.h index 9590b0efd..b5af17169 100644 --- a/src/unit-test-coverage/vxworks/modules/inc/ut-osapi.h +++ b/src/unit-test-coverage/vxworks/modules/inc/ut-osapi.h @@ -5,6 +5,7 @@ #include #include +#include /***************************************************** * @@ -36,10 +37,29 @@ void Osapi_Internal_ResetState(void); void Osapi_Internal_SetImplTaskId(uint32 local_id, OCS_TASK_ID TaskId); /** - * Invokes OS_SymTableIterator_Impl() with the given arguments. - * This is normally a static function but exposed via a non-static wrapper for UT purposes. + * Sets the "vxid" field on a global table mutex entry. + */ +void Osapi_Internal_SetImplTableMutex(uint32 idtype, OCS_SEM_ID vxid); + +/** + * Invokes the generic task entry point */ int Osapi_Internal_CallEntryPoint(int arg); +/** + * Invokes the console helper task entry point + */ +void Osapi_Internal_CallConsoleTask_Entry(int arg); + +/** + * Get the (fake) TCB structure for the given id. + */ +OCS_WIND_TCB* Osapi_Internal_GetTaskTcb(uint32 local_id); + +/** + * Force the "is_async" field to a given state for coverage testing + */ +void Osapi_Internal_SetConsoleAsync(uint32 local_id, bool is_async); + #endif /* _OSAL_UT_OSAPI_H_ */ diff --git a/src/unit-test-coverage/vxworks/modules/inc/ut-osfileapi.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osfileapi.h index 1183823c9..68a50bcd8 100644 --- a/src/unit-test-coverage/vxworks/modules/inc/ut-osfileapi.h +++ b/src/unit-test-coverage/vxworks/modules/inc/ut-osfileapi.h @@ -19,6 +19,7 @@ * Prototype for table init function (needs to be called from UT) */ int32 OS_VxWorks_StreamAPI_Impl_Init(void); +int32 OS_VxWorks_DirAPI_Impl_Init(void); /* * Allow UT to get the value of the OS_IMPL_SELF_EUID and diff --git a/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h b/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h index 5037694b1..6e6640a9d 100644 --- a/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h +++ b/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h @@ -5,6 +5,7 @@ #include #include +#include /***************************************************** * @@ -32,8 +33,19 @@ int32 Osapi_Internal_CallSigWaitFunc(uint32 local_id); /* Invokes the static OS_VxWorks_TimeBaseTask() function with given argument */ int Osapi_Internal_CallHelperTaskFunc(int arg); -/* A hook function which sets the timer registration state */ +/* Invokes the static OS_VxWorks_RegisterTimer() function with given argument */ +void Osapi_Internal_CallRegisterTimer(uint32 local_id); + +/* Hook functions which set the timer registration state */ void Osapi_Internal_SetTimeBaseRegState(uint32 local_id, bool is_success); +void Osapi_Internal_ClearTimeBaseRegState(uint32 local_id); + +/* Hook functions which test the timer registration state */ +bool Osapi_Internal_CheckTimeBaseRegisteredState(uint32 local_id); +bool Osapi_Internal_CheckTimeBaseErrorState(uint32 local_id); + +/* Invoke the internal UsecToTimespec API */ +void Osapi_Internal_UsecToTimespec(uint32 usecs, struct OCS_timespec *time_spec); #endif /* _OSAL_UT_OSTIMER_H_ */ diff --git a/src/unit-test-coverage/vxworks/modules/src/ut-osapi.c b/src/unit-test-coverage/vxworks/modules/src/ut-osapi.c index 3d18c30aa..57c0a57b7 100644 --- a/src/unit-test-coverage/vxworks/modules/src/ut-osapi.c +++ b/src/unit-test-coverage/vxworks/modules/src/ut-osapi.c @@ -39,6 +39,11 @@ void Osapi_Internal_ResetState(void) memset(OS_stub_console_table, 0, sizeof(OS_stub_console_table)); } +void Osapi_Internal_SetImplTableMutex(uint32 idtype, OCS_SEM_ID vxid) +{ + VX_MUTEX_TABLE[idtype].vxid = vxid; +} + void Osapi_Internal_SetImplTaskId(uint32 local_id, OCS_TASK_ID TaskId) { OS_impl_task_table[local_id].vxid = TaskId; @@ -54,3 +59,18 @@ int Osapi_Internal_CallEntryPoint(int arg) return OS_VxWorksEntry(arg); } +void Osapi_Internal_CallConsoleTask_Entry(int arg) +{ + OS_ConsoleTask_Entry(arg); +} + +OCS_WIND_TCB* Osapi_Internal_GetTaskTcb(uint32 local_id) +{ + return &OS_impl_task_table[local_id].tcb; +} + +void Osapi_Internal_SetConsoleAsync(uint32 local_id, bool is_async) +{ + OS_impl_console_table[local_id].is_async = is_async; +} + diff --git a/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c b/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c index 8b0d80bbc..261ead83c 100644 --- a/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c +++ b/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c @@ -38,6 +38,26 @@ int Osapi_Internal_CallHelperTaskFunc(int arg) return OS_VxWorks_TimeBaseTask(arg); } +void Osapi_Internal_CallRegisterTimer(uint32 local_id) +{ + OS_VxWorks_RegisterTimer(local_id); +} + +bool Osapi_Internal_CheckTimeBaseRegisteredState(uint32 local_id) +{ + return (OS_impl_timebase_table[local_id].timer_state == OS_TimerRegState_SUCCESS); +} + +bool Osapi_Internal_CheckTimeBaseErrorState(uint32 local_id) +{ + return (OS_impl_timebase_table[local_id].timer_state == OS_TimerRegState_ERROR); +} + +void Osapi_Internal_ClearTimeBaseRegState(uint32 local_id) +{ + OS_impl_timebase_table[local_id].timer_state = OS_TimerRegState_INIT; +} + void Osapi_Internal_SetTimeBaseRegState(uint32 local_id, bool is_success) { /* Mimic the setting of the Reg state global, which @@ -53,6 +73,11 @@ void Osapi_Internal_SetTimeBaseRegState(uint32 local_id, bool is_success) } } +void Osapi_Internal_UsecToTimespec(uint32 usecs, struct OCS_timespec *time_spec) +{ + OS_Impl_UsecToTimespec(usecs, time_spec); +} + void Osapi_Internal_ResetState(void) { memset(OS_timecb_table, 0, sizeof(OS_timecb_table)); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c b/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c index 5ce143ff5..1fc3bf12d 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c @@ -17,14 +17,19 @@ #include #include +#include #include #include +#include #include +#include +#include /* * A chunk of memory usable as a heap for malloc() emulation */ unsigned long TestHeap[4096]; +int TestGlobalSem; void Test_OS_Lock_Global_Impl(void) { @@ -33,8 +38,19 @@ void Test_OS_Lock_Global_Impl(void) * int32 OS_Lock_Global_Impl(uint32 idtype) */ OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(10000), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(0), OS_ERROR); + + /* + * Confirm that if vxid is 0/NULL that the function returns error + * and does not call semTake. + */ + Osapi_Internal_SetImplTableMutex(OS_OBJECT_TYPE_OS_TASK, (OCS_SEM_ID)0); + OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semTake)) == 0, "semTake() NOT called"); + + Osapi_Internal_SetImplTableMutex(OS_OBJECT_TYPE_OS_TASK, (OCS_SEM_ID)&TestGlobalSem); OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semTake)) == 1, "semTake() called"); + UT_SetForceFail(UT_KEY(OCS_semTake), -1); OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); } @@ -199,6 +215,9 @@ void Test_OS_TaskDelay_Impl(void) * int32 OS_TaskDelay_Impl(uint32 millisecond) */ OSAPI_TEST_FUNCTION_RC(OS_TaskDelay_Impl(100), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_taskDelay), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelay_Impl(100), OS_ERROR); } void Test_OS_TaskSetPriority_Impl(void) @@ -208,6 +227,9 @@ void Test_OS_TaskSetPriority_Impl(void) * int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) */ OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(0, 100), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_taskPrioritySet), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(0, 100), OS_ERROR); } void Test_OS_TaskRegister_Impl(void) @@ -225,7 +247,12 @@ void Test_OS_TaskGetId_Impl(void) * Test Case For: * uint32 OS_TaskGetId_Impl (void) */ - OSAPI_TEST_FUNCTION_RC(OS_TaskGetId_Impl(), OS_SUCCESS); + OCS_WIND_TCB *TaskTcb; + + OS_global_task_table[1].active_id = 0x12345; + TaskTcb = Osapi_Internal_GetTaskTcb(1); + UT_SetDataBuffer(UT_KEY(OCS_taskTcb), &TaskTcb, sizeof(TaskTcb), false); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetId_Impl(), 0x12345); } void Test_OS_TaskGetInfo_Impl(void) @@ -255,6 +282,9 @@ void Test_OS_QueueCreate_Impl(void) * int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) */ OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(0,0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_msgQCreate), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(0,0), OS_ERROR); } void Test_OS_QueueDelete_Impl(void) @@ -264,6 +294,9 @@ void Test_OS_QueueDelete_Impl(void) * int32 OS_QueueDelete_Impl (uint32 queue_id) */ OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_msgQDelete), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(0), OS_ERROR); } void Test_OS_QueueGet_Impl(void) @@ -274,7 +307,18 @@ void Test_OS_QueueGet_Impl(void) */ char Data[16]; uint32 ActSz; - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, 0), OS_SUCCESS); + + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_PEND), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, 100), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_msgQReceive), OCS_ERROR); + OCS_errno = OCS_S_objLib_OBJ_TIMEOUT; + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_TIMEOUT); + OCS_errno = OCS_S_objLib_OBJ_UNAVAILABLE; + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_EMPTY); + OCS_errno = 0; + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_ERROR); } void Test_OS_QueuePut_Impl(void) @@ -285,6 +329,12 @@ void Test_OS_QueuePut_Impl(void) */ char Data[16] = "Test"; OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(0, Data, sizeof(Data), 0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_msgQSend), OCS_ERROR); + OCS_errno = OCS_S_objLib_OBJ_UNAVAILABLE; + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(0, Data, sizeof(Data), 0), OS_QUEUE_FULL); + OCS_errno = 0; + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(0, Data, sizeof(Data), 0), OS_ERROR); } void Test_OS_QueueGetInfo_Impl(void) @@ -314,6 +364,9 @@ void Test_OS_BinSemCreate_Impl(void) * int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) */ OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(0,0,0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semBInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(0,0,0), OS_SEM_FAILURE); } void Test_OS_BinSemDelete_Impl(void) @@ -332,6 +385,9 @@ void Test_OS_BinSemGive_Impl(void) * int32 OS_BinSemGive_Impl ( uint32 sem_id ) */ OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semGive), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(0), OS_SEM_FAILURE); } void Test_OS_BinSemFlush_Impl(void) @@ -341,6 +397,9 @@ void Test_OS_BinSemFlush_Impl(void) * int32 OS_BinSemFlush_Impl (uint32 sem_id) */ OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semFlush), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(0), OS_SEM_FAILURE); } void Test_OS_BinSemTake_Impl(void) @@ -359,6 +418,12 @@ void Test_OS_BinSemTimedWait_Impl(void) * int32 OS_BinSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) */ OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0,100), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semTake), OCS_ERROR); + OCS_errno = OCS_S_objLib_OBJ_TIMEOUT; + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0,100), OS_SEM_TIMEOUT); + OCS_errno = 0; + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0,100), OS_SEM_FAILURE); } void Test_OS_BinSemGetInfo_Impl(void) @@ -388,6 +453,9 @@ void Test_OS_CountSemCreate_Impl(void) * int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) */ OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(0,0,0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semCInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(0,0,0), OS_SEM_FAILURE); } void Test_OS_CountSemDelete_Impl(void) @@ -453,6 +521,9 @@ void Test_OS_MutSemCreate_Impl(void) * int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) */ OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(0,0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semMInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(0,0), OS_SEM_FAILURE); } void Test_OS_MutSemDelete_Impl(void) @@ -500,6 +571,9 @@ void Test_OS_IntAttachHandler_Impl(void) * int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter) */ OSAPI_TEST_FUNCTION_RC(OS_IntAttachHandler_Impl(0,NULL,0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_intConnect), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_IntAttachHandler_Impl(0,NULL,0), OS_ERROR); } void Test_OS_IntUnlock_Impl(void) @@ -528,6 +602,9 @@ void Test_OS_IntEnable_Impl(void) * int32 OS_IntEnable_Impl(int32 Level) */ OSAPI_TEST_FUNCTION_RC(OS_IntEnable_Impl(0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_intEnable), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_IntEnable_Impl(0), OS_ERROR); } void Test_OS_IntDisable_Impl(void) @@ -537,6 +614,9 @@ void Test_OS_IntDisable_Impl(void) * int32 OS_IntDisable_Impl(int32 Level) */ OSAPI_TEST_FUNCTION_RC(OS_IntDisable_Impl(0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_intDisable), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_IntDisable_Impl(0), OS_ERROR); } void Test_OS_HeapGetInfo_Impl(void) @@ -549,6 +629,9 @@ void Test_OS_HeapGetInfo_Impl(void) memset(&heap_prop, 0xEE, sizeof(heap_prop)); OSAPI_TEST_FUNCTION_RC(OS_HeapGetInfo_Impl(&heap_prop), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_memPartInfoGet), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_HeapGetInfo_Impl(&heap_prop), OS_ERROR); } void Test_OS_IntSetMask_Impl(void) diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c b/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c index 093d2305e..1ce265e25 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c @@ -17,6 +17,9 @@ #include #include #include +#include +#include +#include #include "ut-osfileapi.h" @@ -30,6 +33,82 @@ void Test_OS_VxWorks_StreamAPI_Impl_Init(void) OSAPI_TEST_FUNCTION_RC(OS_VxWorks_StreamAPI_Impl_Init(), OS_SUCCESS); } +void Test_OS_VxWorks_DirAPI_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_DirAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(OS_VxWorks_DirAPI_Impl_Init(), OS_SUCCESS); +} + +void Test_OS_DirCreate_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirCreate_Impl(const char *local_path, uint32 access) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl("dir", 0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_mkdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl("dir", 0), OS_ERROR); +} + +void Test_OS_DirOpen_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(0, "dir"), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_opendir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(0, "dir"), OS_ERROR); +} + +void Test_OS_DirClose_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirClose_Impl(uint32 local_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirClose_Impl(0), OS_SUCCESS); +} + +void Test_OS_DirRead_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) + */ + os_dirent_t dirent_buff; + + OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(0, &dirent_buff), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_readdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(0, &dirent_buff), OS_ERROR); + +} + +void Test_OS_DirRewind_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirRewind_Impl(uint32 local_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirRewind_Impl(0), OS_SUCCESS); +} + +void Test_OS_DirRemove_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirRemove_Impl(const char *local_path) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirRemove_Impl("dir"), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_rmdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirRemove_Impl("dir"), OS_ERROR); +} void Test_OS_ShellOutputToFile_Impl(void) { @@ -51,6 +130,12 @@ void Test_OS_ShellOutputToFile_Impl(void) UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_shellGenericInit)) == 1, "shellGenericInit() called"); + + /* failure to open the output file */ + UT_SetForceFail(UT_KEY(OS_creat), OS_ERROR); + expected = OS_ERROR; + actual = OS_ShellOutputToFile_Impl(0, "TestCmd"); + UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_ERROR", (long)actual); } @@ -85,8 +170,14 @@ void Osapi_TearDown(void) void OS_Application_Startup(void) { ADD_TEST(OS_VxWorks_StreamAPI_Impl_Init); + ADD_TEST(OS_VxWorks_DirAPI_Impl_Init); + ADD_TEST(OS_DirCreate_Impl); + ADD_TEST(OS_DirOpen_Impl); + ADD_TEST(OS_DirClose_Impl); + ADD_TEST(OS_DirRead_Impl); + ADD_TEST(OS_DirRewind_Impl); + ADD_TEST(OS_DirRemove_Impl); ADD_TEST(OS_ShellOutputToFile_Impl); } - diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c b/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c index 0c0b07038..220f772d0 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c @@ -15,6 +15,13 @@ #include "os-vxworks-coveragetest.h" #include "ut-osloader.h" +#include +#include +#include +#include +#include +#include +#include void Test_OS_VxWorks_ModuleAPI_Impl_Init(void) { @@ -31,6 +38,9 @@ void Test_OS_SymbolLookup_Impl(void) */ cpuaddr SymAddr; OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(NULL, NULL), OS_INVALID_POINTER); + UT_SetForceFail(UT_KEY(OCS_symFindByName), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_ERROR); } void Test_OS_SymTableIterator_Impl(void) @@ -42,6 +52,12 @@ void Test_OS_SymTableIterator_Impl(void) OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallIteratorFunc("ut",&Data,100,1000), true); OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallIteratorFunc("ut",&Data,100,101), false); + UT_SetForceFail(UT_KEY(OCS_strlen), OS_MAX_SYM_LEN + 10); + OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallIteratorFunc("ut",&Data,100,1000), false); + UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_SetForceFail(UT_KEY(OCS_write), -1); + OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallIteratorFunc("ut",&Data,100,1000), false); + UT_ClearForceFail(UT_KEY(OCS_write)); } void Test_OS_ModuleLoad_Impl(void) @@ -50,6 +66,12 @@ void Test_OS_ModuleLoad_Impl(void) * int32 OS_ModuleLoad_Impl ( uint32 module_id, char *translated_path ) */ OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0,"local"), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0,"local"), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_open)); + UT_SetForceFail(UT_KEY(OCS_loadModule), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0,"local"), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_loadModule)); } void Test_OS_ModuleUnload_Impl(void) @@ -58,6 +80,9 @@ void Test_OS_ModuleUnload_Impl(void) * int32 OS_ModuleUnload_Impl ( uint32 module_id ) */ OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_unldByModuleId), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_unldByModuleId)); } void Test_OS_ModuleGetInfo_Impl(void) @@ -66,7 +91,20 @@ void Test_OS_ModuleGetInfo_Impl(void) * int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ) */ OS_module_prop_t module_prop; + + memset(&module_prop, 0, sizeof(module_prop)); + OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(0,&module_prop), OS_SUCCESS); + UtAssert_True(module_prop.addr.valid, "addresses in output valid"); + + /* + * Note this still returns SUCCESS if the underlying call fails, + * but the boolean in the output struct should be false. + */ + memset(&module_prop, 0, sizeof(module_prop)); + UT_SetForceFail(UT_KEY(OCS_moduleInfoGet), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(0,&module_prop), OS_SUCCESS); + UT_ClearForceFail(UT_KEY(OCS_moduleInfoGet)); + UtAssert_True(!module_prop.addr.valid, "addresses in output not valid"); } void Test_OS_SymbolTableDump_Impl(void) @@ -75,6 +113,9 @@ void Test_OS_SymbolTableDump_Impl(void) * int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 SizeLimit ) */ OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file",10000), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file",10000), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_open)); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c b/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c index b63ae102c..13658258f 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c @@ -17,6 +17,9 @@ #include #include +#include +#include +#include void Test_OS_VxWorks_TimeBaseAPI_Impl_Init(void) @@ -25,6 +28,8 @@ void Test_OS_VxWorks_TimeBaseAPI_Impl_Init(void) * int32 OS_VxWorks_TimeBaseAPI_Impl_Init(void) */ OSAPI_TEST_FUNCTION_RC(OS_VxWorks_TimeBaseAPI_Impl_Init(), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_sysClkRateGet), -1); + OSAPI_TEST_FUNCTION_RC(OS_VxWorks_TimeBaseAPI_Impl_Init(), OS_ERROR); } @@ -50,31 +55,92 @@ static int32 Osapi_Internal_TimeBaseRegHook(void *UserObj, int32 StubRetcode, ui return 0; } +void Test_OS_Impl_UsecToTimespec(void) +{ + /* Test Case For: + * static void OS_Impl_UsecToTimespec(uint32 usecs, struct timespec *time_spec) + * + * This is invoked through a wrapper, to get coverage on the function. + * + * Note: For some reason, the vxworks implementation does this differently for intervals + * less than one second vs. one second or more, even though it does not need this + * complexity/special case, because the "one-or-more" code works for all. Nonetheless, + * this needs to exist to test both ways. + */ + + struct OCS_timespec ts; + + memset(&ts, 255, sizeof(ts)); + Osapi_Internal_UsecToTimespec(1, &ts); + UtAssert_True(ts.tv_sec == 0, "ts.tv_sec (%ld) == 0", (long)ts.tv_sec); + UtAssert_True(ts.tv_nsec == 1000, "ts.tv_nsec (%ld) == 1000", (long)ts.tv_sec); + + + memset(&ts, 255, sizeof(ts)); + Osapi_Internal_UsecToTimespec(1000000000, &ts); + UtAssert_True(ts.tv_sec == 1000, "ts.tv_sec (%ld) == 1000", (long)ts.tv_sec); + UtAssert_True(ts.tv_nsec == 0, "ts.tv_nsec (%ld) == 0", (long)ts.tv_sec); +} + void Test_OS_TimeBaseCreate_Impl(void) { /* Test Case For: * int32 OS_TimeBaseCreate_Impl(uint32 timer_id) */ + /* + * Test paths though the signal number assignment. + * + * This should be done first as it will assign the "external_sync" + * and therefore cause future calls to skip this block. + */ + OS_global_timebase_table[1].active_id = 0x1; + Osapi_Internal_Setup(1,OCS_SIGRTMIN); + UT_SetForceFail(UT_KEY(OCS_sigismember), true); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_UNAVAILABLE); + UT_ResetState(UT_KEY(OCS_sigismember)); + + /* fail to initialize the sem */ + UT_SetForceFail(UT_KEY(OCS_semMInitialize), -1); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_INTERNAL); + UT_ClearForceFail(UT_KEY(OCS_semMInitialize)); + /* fail to spawn the task */ UT_SetForceFail(UT_KEY(OCS_taskSpawn), -1); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_INTERNAL); + UT_ClearForceFail(UT_KEY(OCS_taskSpawn)); /* * this call to TimeBaseCreate_Impl should also fail, because * this mimics the situation where the reg global is never * set past OS_TimerRegState_INIT */ - UT_ClearForceFail(UT_KEY(OCS_taskSpawn)); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_INTERNAL); /* + * Do Nominal/success case now. * Using the hook function, this sets the global state to * mimic registration success */ UT_SetHookFunction(UT_KEY(OCS_taskSpawn), Osapi_Internal_TimeBaseRegHook, NULL); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_SUCCESS); + /* + * For coverage, call the OS_VxWorks_TimeBaseTask() function. + */ + Osapi_Internal_CallHelperTaskFunc(0); + + /* + * Check outputs of OS_VxWorks_RegisterTimer() function. + */ + Osapi_Internal_ClearTimeBaseRegState(0); + Osapi_Internal_CallRegisterTimer(0); + UtAssert_True(Osapi_Internal_CheckTimeBaseRegisteredState(0), "timer successfully registered"); + + Osapi_Internal_ClearTimeBaseRegState(0); + UT_SetForceFail(UT_KEY(OCS_timer_create), -1); + Osapi_Internal_CallRegisterTimer(0); + UtAssert_True(Osapi_Internal_CheckTimeBaseErrorState(0), "timer registration failure state"); } void Test_OS_VxWorks_SigWait(void) @@ -83,7 +149,18 @@ void Test_OS_VxWorks_SigWait(void) * static uint32 OS_VxWorks_SigWait(uint32 local_id) * (invocation of static function through a wrapper) */ - OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallSigWaitFunc(0), OS_SUCCESS); + int signo = OCS_SIGRTMIN; + + OS_global_timebase_table[0].active_id = 0x12345; + OS_timebase_table[0].nominal_interval_time = 5555; + + Osapi_Internal_Setup(0, signo); + UT_SetDataBuffer(UT_KEY(OCS_sigwait),&signo,sizeof(signo),false); + OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallSigWaitFunc(0), 5555); + + Osapi_Internal_Setup(0, 0); + OS_global_timebase_table[0].active_id = 0; + OS_timebase_table[0].nominal_interval_time = 0; } void Test_OS_TimeBaseSet_Impl(void) @@ -92,8 +169,12 @@ void Test_OS_TimeBaseSet_Impl(void) * int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time) */ OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0,1,1), OS_ERR_NOT_IMPLEMENTED); + Osapi_Internal_Setup(0, OCS_SIGRTMIN); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0,1,1), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_timer_settime), -1); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0,1,1), OS_TIMER_ERR_INVALID_ARGS); } void Test_OS_TimeBaseDelete_Impl(void) @@ -154,5 +235,6 @@ void OS_Application_Startup(void) ADD_TEST(OS_TimeBaseSet_Impl); ADD_TEST(OS_TimeBaseDelete_Impl); ADD_TEST(OS_TimeBaseGetInfo_Impl); + ADD_TEST(OS_Impl_UsecToTimespec); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-printf.c b/src/unit-test-coverage/vxworks/src/coveragetest-printf.c index 4a105cb52..58dba58f4 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-printf.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-printf.c @@ -12,19 +12,16 @@ * Includes */ -#include -#include -#include - -#include -#include +#include "os-vxworks-coveragetest.h" +#include "ut-osapi.h" #include #include #include +#include #include -char TestConsoleBuffer[256]; +char TestConsoleBuffer[16]; void Test_OS_ConsoleWakeup_Impl(void) { @@ -34,23 +31,51 @@ void Test_OS_ConsoleWakeup_Impl(void) */ /* no return code - check for coverage */ + Osapi_Internal_SetConsoleAsync(0, true); + OS_ConsoleWakeup_Impl(0); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semGive)) == 1, "semGive() called in async mode"); + + UT_SetForceFail(UT_KEY(OCS_semGive), -1); OS_ConsoleWakeup_Impl(0); - UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semGive)) == 1, "semGive() called"); + + Osapi_Internal_SetConsoleAsync(0, false); + OS_console_table[0].WritePos = 1; + OS_ConsoleWakeup_Impl(0); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_putchar)) == 1, "putchar() called in sync mode"); } void Test_OS_ConsoleCreate_Impl(void) { - OS_ConsoleCreate_Impl(0); + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(0), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskSpawn)) == 1, "taskSpawn() called"); + + UT_SetForceFail(UT_KEY(OCS_semCInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(0), OS_SEM_FAILURE); + UT_ClearForceFail(UT_KEY(OCS_semCInitialize)); + + UT_SetForceFail(UT_KEY(OCS_taskSpawn), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(0), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_taskSpawn)); + + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(OS_MAX_CONSOLES + 1), OS_ERR_NOT_IMPLEMENTED); + + /* Also call the actual console task, to get coverage on it. + * This task has an infinite loop, which only exits if semTake fails */ + UT_SetDeferredRetcode(UT_KEY(OCS_semTake), 2, OCS_ERROR); + Osapi_Internal_CallConsoleTask_Entry(0); } void Test_OS_ConsoleOutput_Impl(void) { - strcpy(TestConsoleBuffer, "ABCD"); - OS_console_table[0].WritePos = 4; + memset(TestConsoleBuffer, 'x', sizeof(TestConsoleBuffer)); + OS_console_table[0].WritePos = 4; OS_ConsoleOutput_Impl(0); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_putchar)) == 4, "putchar() called"); + + OS_console_table[0].WritePos = 0; + OS_ConsoleOutput_Impl(0); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_putchar)) == sizeof(TestConsoleBuffer), "putchar() called"); } From 5cdd4035e5cd1e95984ad542d21d80ed960904ee Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 25 Oct 2019 10:37:19 -0400 Subject: [PATCH 3/8] Update #230 to correlate with updated timer code The timer code for VxWorks was fixed in bug #271 and the coverage code test needs a corresponding update to cover the code change. This is kept as a separate update commit as neither changeset is merged to master yet. --- .../ut-stubs/inc/overrides/time.h | 1 + .../ut-stubs/src/posix-time-stubs.c | 14 ++++++++++++++ .../vxworks/modules/inc/ut-ostimer.h | 2 +- .../vxworks/modules/src/stub-map-to-real.h | 1 + .../vxworks/modules/src/ut-ostimer.c | 3 ++- .../vxworks/src/coveragetest-ostimer.c | 15 ++++++++++----- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/unit-test-coverage/ut-stubs/inc/overrides/time.h b/src/unit-test-coverage/ut-stubs/inc/overrides/time.h index 2e40c1d91..118fc8962 100644 --- a/src/unit-test-coverage/ut-stubs/inc/overrides/time.h +++ b/src/unit-test-coverage/ut-stubs/inc/overrides/time.h @@ -44,6 +44,7 @@ extern int OCS_clock_nanosleep (OCS_clockid_t clock_id, int flags, const struct extern int OCS_clock_settime (OCS_clockid_t clock_id, const struct OCS_timespec * tp); extern int OCS_timer_create (OCS_clockid_t clock_id, struct OCS_sigevent * evp, OCS_timer_t * timerid); extern int OCS_timer_delete (OCS_timer_t timerid) ; +extern int OCS_timer_gettime (OCS_timer_t timerid, struct OCS_itimerspec * value); extern int OCS_timer_settime (OCS_timer_t timerid, int flags, const struct OCS_itimerspec * value, struct OCS_itimerspec * ovalue); extern int OCS_timer_connect(OCS_timer_t, OCS_VOIDFUNCPTR, int); diff --git a/src/unit-test-coverage/ut-stubs/src/posix-time-stubs.c b/src/unit-test-coverage/ut-stubs/src/posix-time-stubs.c index d2ad683fb..094afa0a9 100644 --- a/src/unit-test-coverage/ut-stubs/src/posix-time-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/posix-time-stubs.c @@ -75,3 +75,17 @@ int OCS_timer_settime (OCS_timer_t timerid, int flags, const struct OCS_itimersp return Status; } +int OCS_timer_gettime (OCS_timer_t timerid, struct OCS_itimerspec * value) +{ + int32 Status; + + Status = UT_DEFAULT_IMPL(OCS_timer_gettime); + + if (Status == 0 && UT_Stub_CopyToLocal(UT_KEY(OCS_timer_gettime), value, sizeof(*value)) < sizeof(*value)) + { + memset(value, 0, sizeof(*value)); + } + + return Status; +} + diff --git a/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h b/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h index 6e6640a9d..58e2fb7f1 100644 --- a/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h +++ b/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h @@ -22,7 +22,7 @@ int32 OS_VxWorks_TimeBaseAPI_Impl_Init(void); void Osapi_Internal_ResetState(void); -void Osapi_Internal_Setup(uint32 local_id, int signo); +void Osapi_Internal_Setup(uint32 local_id, int signo, bool reset_flag); /** * Invokes OS_VxWorks_SigWait() with the given arguments. diff --git a/src/unit-test-coverage/vxworks/modules/src/stub-map-to-real.h b/src/unit-test-coverage/vxworks/modules/src/stub-map-to-real.h index d9042e6f7..f9761ac4a 100644 --- a/src/unit-test-coverage/vxworks/modules/src/stub-map-to-real.h +++ b/src/unit-test-coverage/vxworks/modules/src/stub-map-to-real.h @@ -238,6 +238,7 @@ #define timer_connect OCS_timer_connect #define timer_create OCS_timer_create #define timer_delete OCS_timer_delete +#define timer_gettime OCS_timer_gettime #define timer_settime OCS_timer_settime #define timer_t OCS_timer_t #define timespec OCS_timespec diff --git a/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c b/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c index 261ead83c..34b8bd86a 100644 --- a/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c +++ b/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c @@ -86,7 +86,7 @@ void Osapi_Internal_ResetState(void) memset(OS_stub_timecb_table, 0, sizeof(OS_stub_timecb_table)); } -void Osapi_Internal_Setup(uint32 local_id, int signo) +void Osapi_Internal_Setup(uint32 local_id, int signo, bool reset_flag) { static int FAKE_TASK; static int FAKE_SEM; @@ -94,5 +94,6 @@ void Osapi_Internal_Setup(uint32 local_id, int signo) OS_impl_timebase_table[local_id].assigned_signal = signo; OS_impl_timebase_table[local_id].handler_task = &FAKE_TASK; OS_impl_timebase_table[local_id].handler_mutex = &FAKE_SEM; + OS_impl_timebase_table[local_id].reset_flag = reset_flag; } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c b/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c index 13658258f..c729379ca 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c @@ -95,7 +95,7 @@ void Test_OS_TimeBaseCreate_Impl(void) * and therefore cause future calls to skip this block. */ OS_global_timebase_table[1].active_id = 0x1; - Osapi_Internal_Setup(1,OCS_SIGRTMIN); + Osapi_Internal_Setup(1,OCS_SIGRTMIN, false); UT_SetForceFail(UT_KEY(OCS_sigismember), true); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_UNAVAILABLE); UT_ResetState(UT_KEY(OCS_sigismember)); @@ -152,13 +152,18 @@ void Test_OS_VxWorks_SigWait(void) int signo = OCS_SIGRTMIN; OS_global_timebase_table[0].active_id = 0x12345; + OS_timebase_table[0].nominal_start_time = 8888; OS_timebase_table[0].nominal_interval_time = 5555; - Osapi_Internal_Setup(0, signo); + Osapi_Internal_Setup(0, signo, true); + UT_SetDataBuffer(UT_KEY(OCS_sigwait),&signo,sizeof(signo),false); + OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallSigWaitFunc(0), 8888); + UT_SetDataBuffer(UT_KEY(OCS_sigwait),&signo,sizeof(signo),false); + OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallSigWaitFunc(0), 5555); UT_SetDataBuffer(UT_KEY(OCS_sigwait),&signo,sizeof(signo),false); OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallSigWaitFunc(0), 5555); - Osapi_Internal_Setup(0, 0); + Osapi_Internal_Setup(0, 0, false); OS_global_timebase_table[0].active_id = 0; OS_timebase_table[0].nominal_interval_time = 0; } @@ -170,7 +175,7 @@ void Test_OS_TimeBaseSet_Impl(void) */ OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0,1,1), OS_ERR_NOT_IMPLEMENTED); - Osapi_Internal_Setup(0, OCS_SIGRTMIN); + Osapi_Internal_Setup(0, OCS_SIGRTMIN, false); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0,1,1), OS_SUCCESS); UT_SetForceFail(UT_KEY(OCS_timer_settime), -1); @@ -182,7 +187,7 @@ void Test_OS_TimeBaseDelete_Impl(void) /* Test Case For: * int32 OS_TimeBaseDelete_Impl(uint32 timer_id) */ - Osapi_Internal_Setup(0, OCS_SIGRTMIN); + Osapi_Internal_Setup(0, OCS_SIGRTMIN, false); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete_Impl(0), OS_SUCCESS); } From 049e1011bc681d21da043de92439f63f5700f139 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 21 Oct 2019 14:36:07 -0400 Subject: [PATCH 4/8] Fix #269: Correct error checking for taskSpawn The test for failure of taskSpawn should be for the value of ERROR, not 0, per the VxWorks API documentation. Found when implementing the unit test improvements in #230. This issue is generally only reproducible in UT where taskSpawn can be made to fail. --- src/os/vxworks/osapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/vxworks/osapi.c b/src/os/vxworks/osapi.c index d1dea6c3b..a7cf8902e 100644 --- a/src/os/vxworks/osapi.c +++ b/src/os/vxworks/osapi.c @@ -1759,7 +1759,7 @@ int32 OS_ConsoleCreate_Impl(uint32 local_id) (FUNCPTR)OS_ConsoleTask_Entry, local_id,0,0,0,0,0,0,0,0,0); - if (local->taskid == (TASK_ID)0) + if (local->taskid == (TASK_ID)ERROR) { OS_DEBUG("taskSpawn() - vxWorks errno %d\n",errno); return_code = OS_ERROR; From 8310170c5c3ae23002ec6f1ec551cb2e3ac8b127 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 22 Oct 2019 23:23:39 -0400 Subject: [PATCH 5/8] Fix #272: use 4K stack for sem-speed-test tasks On VxWorks, no minimum stack size is implemented, and the implementation will create tasks with an extremely small stack if "0" is passed in. This causes the worker tasks to overrun the stack on Vxworks, triggering undefined/inconsistent behavior. --- src/tests/sem-speed-test/sem-speed-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/sem-speed-test/sem-speed-test.c b/src/tests/sem-speed-test/sem-speed-test.c index 6d00ce42c..4e828af77 100644 --- a/src/tests/sem-speed-test/sem-speed-test.c +++ b/src/tests/sem-speed-test/sem-speed-test.c @@ -150,10 +150,10 @@ void SemSetup(void) /* ** Create the tasks */ - status = OS_TaskCreate( &task_1_id, "Task 1", task_1, NULL, 0, TASK_PRIORITY, 0); + status = OS_TaskCreate( &task_1_id, "Task 1", task_1, NULL, 4096, TASK_PRIORITY, 0); UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%u Rc=%d", (unsigned int)task_1_id, (int)status); - status = OS_TaskCreate( &task_2_id, "Task 2", task_2, NULL, 0, TASK_PRIORITY, 0); + status = OS_TaskCreate( &task_2_id, "Task 2", task_2, NULL, 4096, TASK_PRIORITY, 0); UtAssert_True(status == OS_SUCCESS, "Task 2 create Id=%u Rc=%d", (unsigned int)task_2_id, (int)status); /* A small delay just to allow the tasks From c75b38de66369b19bae3e4a464569bc99353ba46 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 22 Oct 2019 23:18:11 -0400 Subject: [PATCH 6/8] Fix #273: Correct format code in debug message Cast the address value so it may be printed as an integer. --- src/os/rtems/osfilesys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/rtems/osfilesys.c b/src/os/rtems/osfilesys.c index f7d46996e..ce34bd0e7 100644 --- a/src/os/rtems/osfilesys.c +++ b/src/os/rtems/osfilesys.c @@ -174,7 +174,7 @@ int32 OS_FileSysStartVolume_Impl (uint32 filesys_id) impl->mount_fstype = RTEMS_FILESYSTEM_TYPE_RFS; OS_DEBUG("OSAL: RAM disk initialized: volume=%s device=%s address=0x%08lX\n", - local->volume_name, impl->blockdev_name, local->address); + local->volume_name, impl->blockdev_name, (unsigned long)local->address); return_code = OS_SUCCESS; break; From f1fcd8d42b946de5782da805e3e75c3695c48006 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 22 Oct 2019 22:52:52 -0400 Subject: [PATCH 7/8] Fix #271: Correct interval time computations In VxWorks, the sigwait routine was not handling the actual time of the first interval, which basically meant that the start_time was elapsed twice before the first callback was generated. This exposed a few other small but significant details regarding how the intervals were dealt with across all operating systems. For VxWorks and RTEMS, where the timer interval is rounded up to an integer number of ticks, compute the actual interval time and write a debug message in case it is different than the intended value. This makes it more obvious to the user that some application/bsp changes might be necessary to get accurate timing. For all operating systems, the "reset" flag needs to be sampled AFTER the sigwait returns, not before it. This flag gets set when the OS_TimeBaseSet() API is called. Removes an unused POSIX delay routine that was intended to support use of clock_nanosleep() in place of the timer signal. This mode was never usable because OS_TimerCreate always allocates a signal and fails if it cannot do so. This code caused problems/incompatibilities for the sigwait model which IS used, so it needed to be removed. --- src/os/posix/ostimer.c | 63 +++++++++------------------- src/os/rtems/ostimer.c | 49 ++++++++++++++++------ src/os/vxworks/ostimer.c | 69 +++++++++++++++++++++++++++++-- src/tests/timer-test/timer-test.c | 45 ++++++++++++++------ 4 files changed, 154 insertions(+), 72 deletions(-) diff --git a/src/os/posix/ostimer.c b/src/os/posix/ostimer.c index d3d5ae4e0..69dd8bfc7 100644 --- a/src/os/posix/ostimer.c +++ b/src/os/posix/ostimer.c @@ -135,7 +135,7 @@ void OS_TimeBaseUnlock_Impl(uint32 local_id) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -static uint32 OS_TimeBase_SoftWaitImpl(uint32 timer_id) +static uint32 OS_TimeBase_SigWaitImpl(uint32 timer_id) { int ret; OS_impl_timebase_internal_record_t *local; @@ -144,57 +144,34 @@ static uint32 OS_TimeBase_SoftWaitImpl(uint32 timer_id) local = &OS_impl_timebase_table[timer_id]; - if (local->reset_flag == 0) - { - interval_time = OS_timebase_table[timer_id].nominal_interval_time; - } - else + ret = sigwait(&local->sigset, &sig); + + if (ret != 0) { - interval_time = OS_timebase_table[timer_id].nominal_start_time; - local->reset_flag = 0; + /* + * the sigwait call failed. + * returning 0 will cause the process to repeat. + */ + interval_time = 0; } - - if (local->assigned_signal == 0) + else if (local->reset_flag == 0) { /* - * If no signal is in use and this function got called, - * just implement it using a software delay. This is the - * least accurate option, but it always works. + * Normal steady-state behavior. + * interval_time reflects the configured interval time. */ - if (interval_time == 0) - { - /* - * Protect against a zero interval time causing a "spin loop" - * In this case sleep for 10ms. - */ - interval_time = 10000; - } - local->softsleep.tv_nsec += 1000 * (interval_time % 1000000); - local->softsleep.tv_sec += interval_time / 1000000; - if (local->softsleep.tv_nsec > 1000000000) - { - local->softsleep.tv_nsec -= 1000000000; - ++local->softsleep.tv_sec; - } + interval_time = OS_timebase_table[timer_id].nominal_interval_time; } - - - do + else { /* - * Note that either of these calls can be interrupted by OTHER signals, - * so it needs to be repeated until it actually returns the proper code. + * Reset/First interval behavior. + * timer_set() was invoked since the previous interval occurred (if any). + * interval_time reflects the configured start time. */ - if (local->assigned_signal == 0) - { - ret = clock_nanosleep(OS_PREFERRED_CLOCK, TIMER_ABSTIME, &local->softsleep, NULL); - } - else - { - ret = sigwait(&local->sigset, &sig); - } + interval_time = OS_timebase_table[timer_id].nominal_start_time; + local->reset_flag = 0; } - while (ret != 0); return interval_time; } /* end OS_TimeBase_SoftWaitImpl */ @@ -453,7 +430,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) break; } - OS_timebase_table[timer_id].external_sync = OS_TimeBase_SoftWaitImpl; + OS_timebase_table[timer_id].external_sync = OS_TimeBase_SigWaitImpl; } while (0); diff --git a/src/os/rtems/ostimer.c b/src/os/rtems/ostimer.c index 05154944a..e966d29f0 100644 --- a/src/os/rtems/ostimer.c +++ b/src/os/rtems/ostimer.c @@ -63,6 +63,8 @@ typedef struct uint8 simulate_flag; uint8 reset_flag; rtems_interval interval_ticks; + uint32 configured_start_time; + uint32 configured_interval_time; } OS_impl_timebase_internal_record_t; /**************************************************************************************** @@ -150,10 +152,15 @@ static rtems_timer_service_routine OS_TimeBase_ISR(rtems_id rtems_timer_id, void static uint32 OS_TimeBase_WaitImpl(uint32 local_id) { OS_impl_timebase_internal_record_t *local; - uint32 interval_time; + uint32 tick_time; local = &OS_impl_timebase_table[local_id]; + /* + * Pend for the tick arrival + */ + rtems_semaphore_obtain(local->tick_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + /* * Determine how long this tick was. * Note that there are plenty of ways this become wrong if the timer @@ -163,21 +170,16 @@ static uint32 OS_TimeBase_WaitImpl(uint32 local_id) */ if (local->reset_flag == 0) { - interval_time = OS_timebase_table[local_id].nominal_interval_time; + tick_time = local->configured_interval_time; } else { - interval_time = OS_timebase_table[local_id].nominal_start_time; + tick_time = local->configured_start_time; local->reset_flag = 0; } - /* - * Pend for the tick arrival - */ - rtems_semaphore_obtain(local->tick_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - - return interval_time; + return tick_time; } /* end OS_TimeBase_WaitImpl */ @@ -469,13 +471,34 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time } else { - if (local->interval_ticks > 0) + local->configured_start_time = (10000 * start_ticks) / OS_SharedGlobalVars.TicksPerSecond; + local->configured_interval_time = (10000 * local->interval_ticks) / OS_SharedGlobalVars.TicksPerSecond; + local->configured_start_time *= 100; + local->configured_interval_time *= 100; + + if (local->configured_start_time != start_time) { - start_ticks = local->interval_ticks; + OS_DEBUG("WARNING: timer %lu start_time requested=%luus, configured=%luus\n", + (unsigned long)timer_id, + (unsigned long)start_time, + (unsigned long)local->configured_start_time); + } + if (local->configured_interval_time != interval_time) + { + OS_DEBUG("WARNING: timer %lu interval_time requested=%luus, configured=%luus\n", + (unsigned long)timer_id, + (unsigned long)interval_time, + (unsigned long)local->configured_interval_time); } - OS_timebase_table[timer_id].accuracy_usec = (start_ticks * 100000) / OS_SharedGlobalVars.TicksPerSecond; - OS_timebase_table[timer_id].accuracy_usec *= 10; + if (local->interval_ticks > 0) + { + OS_timebase_table[timer_id].accuracy_usec = local->configured_interval_time; + } + else + { + OS_timebase_table[timer_id].accuracy_usec = local->configured_start_time; + } } } } diff --git a/src/os/vxworks/ostimer.c b/src/os/vxworks/ostimer.c index ee4b63ac8..9b786ca66 100644 --- a/src/os/vxworks/ostimer.c +++ b/src/os/vxworks/ostimer.c @@ -76,6 +76,9 @@ typedef struct TASK_ID handler_task; timer_t host_timerid; enum OS_TimerState timer_state; + uint32 configured_start_time; + uint32 configured_interval_time; + bool reset_flag; } OS_impl_timebase_internal_record_t; /**************************************************************************************** @@ -153,14 +156,14 @@ static uint32 OS_VxWorks_SigWait(uint32 local_id) OS_impl_timebase_internal_record_t *local; OS_common_record_t *global; uint32 active_id; - uint32 interval_time; + uint32 tick_time; int signo; int ret; local = &OS_impl_timebase_table[local_id]; global = &OS_global_timebase_table[local_id]; active_id = global->active_id; - interval_time = 0; + tick_time = 0; if (active_id != 0 && local->assigned_signal > 0) { @@ -190,11 +193,20 @@ static uint32 OS_VxWorks_SigWait(uint32 local_id) if (ret == OK && signo == local->assigned_signal && global->active_id == active_id) { - interval_time = OS_timebase_table[local_id].nominal_interval_time; + if (local->reset_flag) + { + /* first interval after reset, use start time */ + tick_time = local->configured_start_time; + local->reset_flag = false; + } + else + { + tick_time = local->configured_interval_time; + } } } - return interval_time; + return tick_time; } /* end OS_VxWorks_SigWait */ @@ -354,6 +366,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) local->handler_mutex = (SEM_ID)0; local->host_timerid = 0; local->timer_state = OS_TimerRegState_INIT; + local->reset_flag = false; /* * Set up the necessary OS constructs @@ -543,11 +556,59 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time if (status == OK) { return_code = OS_SUCCESS; + + /* + * VxWorks will round the interval up to the next higher + * system tick interval. Sometimes this can make a substantial + * difference in the actual time, particularly as the error + * accumulates over time. + * + * timer_gettime() will reveal the actual interval programmed, + * after all rounding/adjustments, which can be used to determine + * the actual start_time/interval_time that will be realized. + * + * If this actual interval is different than the intended value, + * it may indicate the need for better tuning on the app/config/bsp + * side, and so a DEBUG message is generated. + */ + status = timer_gettime(local->host_timerid, &timeout); + if (status == OK) + { + local->configured_start_time = + (timeout.it_value.tv_sec * 1000000) + + (timeout.it_value.tv_nsec / 1000); + local->configured_interval_time = + (timeout.it_interval.tv_sec * 1000000) + + (timeout.it_interval.tv_nsec / 1000); + + if (local->configured_start_time != start_time) + { + OS_DEBUG("WARNING: timer %lu start_time requested=%luus, configured=%luus\n", + (unsigned long)timer_id, + (unsigned long)start_time, + (unsigned long)local->configured_start_time); + } + if (local->configured_interval_time != interval_time) + { + OS_DEBUG("WARNING: timer %lu interval_time requested=%luus, configured=%luus\n", + (unsigned long)timer_id, + (unsigned long)interval_time, + (unsigned long)local->configured_interval_time); + } + + } + } else { return_code = OS_TIMER_ERR_INVALID_ARGS; } + + } + + if (!local->reset_flag && return_code == OS_SUCCESS) + { + local->reset_flag = true; } return return_code; diff --git a/src/tests/timer-test/timer-test.c b/src/tests/timer-test/timer-test.c index 89a55dec8..f6cf3d683 100644 --- a/src/tests/timer-test/timer-test.c +++ b/src/tests/timer-test/timer-test.c @@ -92,7 +92,7 @@ void TimerTestTask(void) { int i = 0; - int32 TimerStatus; + int32 TimerStatus[NUMBER_OF_TIMERS]; uint32 TableId; uint32 TimerID[NUMBER_OF_TIMERS]; char TimerName[NUMBER_OF_TIMERS][20] = {"TIMER1","TIMER2","TIMER3","TIMER4"}; @@ -101,25 +101,38 @@ void TimerTestTask(void) for ( i = 0; i < NUMBER_OF_TIMERS; i++ ) { - TimerStatus = OS_TimerCreate(&TimerID[i], TimerName[i], &ClockAccuracy, &(test_func)); - UtAssert_True(TimerStatus == OS_SUCCESS, "Timer %d Created RC=%d ID=%d", i, (int)TimerStatus, (int)TimerID[i]); + TimerStatus[i] = OS_TimerCreate(&TimerID[i], TimerName[i], &ClockAccuracy, &(test_func)); + UtAssert_True(TimerStatus[i] == OS_SUCCESS, "Timer %d Created RC=%d ID=%d", i, (int)TimerStatus[i], (int)TimerID[i]); UtPrintf("Timer %d Accuracy = %d microseconds \n",i ,(int)ClockAccuracy); - TimerStatus = OS_TimerSet(TimerID[i], TimerStart[i], TimerInterval[i]); - UtAssert_True(TimerStatus == OS_SUCCESS, "Timer %d programmed RC=%d", i, (int)TimerStatus); - OS_ConvertToArrayIndex(TimerID[i], &TableId); - timer_idlookup[TableId] = i; } + /* Sample the clock now, before starting any timer */ + OS_GetLocalTime(&StartTime); + for ( i = 0; i < NUMBER_OF_TIMERS; i++ ) + { + /* + * to ensure that all timers are started as closely as possible, + * this just stores the result and does not assert/printf now + */ + TimerStatus[i] = OS_TimerSet(TimerID[i], TimerStart[i], TimerInterval[i]); + } + + /* + * Now the actual OS_TimerSet() return code can be checked. + */ + for ( i = 0; i < NUMBER_OF_TIMERS; i++ ) + { + UtAssert_True(TimerStatus[i] == OS_SUCCESS, "Timer %d programmed RC=%d", i, (int)TimerStatus[i]); + } /* ** Let the main thread sleep */ UtPrintf("Starting Delay loop.\n"); - OS_GetLocalTime(&StartTime); for (i = 0 ; i < 30; i++ ) { /* @@ -134,9 +147,13 @@ void TimerTestTask(void) for ( i = 0; i < NUMBER_OF_TIMERS; i++ ) { - TimerStatus = OS_TimerDelete(TimerID[i]); - UtAssert_True(TimerStatus == OS_SUCCESS, "Timer %d delete RC=%d. Count total = %d", - i, (int)TimerStatus, (int)timer_counter[i]); + TimerStatus[i] = OS_TimerDelete(TimerID[i]); + } + + for ( i = 0; i < NUMBER_OF_TIMERS; i++ ) + { + UtAssert_True(TimerStatus[i] == OS_SUCCESS, "Timer %d delete RC=%d. Count total = %d", + i, (int)TimerStatus[i], (int)timer_counter[i]); } OS_ApplicationShutdown(true); @@ -165,7 +182,11 @@ void TimerTestCheck(void) /* Make sure the ratio of the timers are OK */ for ( i = 0; i < NUMBER_OF_TIMERS; i++ ) { - expected = (microsecs - TimerStart[i]) / TimerInterval[i]; + /* + * Expect one tick after the start time (i.e. first tick) + * Plus one tick for every interval that occurred during the test + */ + expected = 1 + (microsecs - TimerStart[i]) / TimerInterval[i]; UtAssert_True(expected > 0, "Expected ticks = %u", (unsigned int)expected); /* From 6357c2d0e3cd93d6f115ff6a232632d96818deda Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 22 Oct 2019 23:20:06 -0400 Subject: [PATCH 8/8] Fix #274: Avoid possible deadlock of timer callback If the tick_time from the wait routine was perpetually greater than the interval time, eventually the wait_time became such that it was always below zero. Once this occurs, application callbacks would cease entirely. To avoid this, run the callback condition in a loop for periodic timers only (not for one-shot config). --- src/os/shared/osapi-timebase.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/os/shared/osapi-timebase.c b/src/os/shared/osapi-timebase.c index e6cd7cad3..50384b2aa 100644 --- a/src/os/shared/osapi-timebase.c +++ b/src/os/shared/osapi-timebase.c @@ -494,7 +494,7 @@ void OS_TimeBase_CallbackThread(uint32 timebase_id) timecb = &OS_timecb_table[curr_cb_local_id]; saved_wait_time = timecb->wait_time; timecb->wait_time -= tick_time; - if (timecb->wait_time <= 0) + while (timecb->wait_time <= 0) { timecb->wait_time += timecb->interval_time; @@ -519,6 +519,14 @@ void OS_TimeBase_CallbackThread(uint32 timebase_id) { (*timecb->callback_ptr)(curr_cb_public_id, timecb->callback_arg); } + + /* + * Do not repeat the loop unless interval_time is configured. + */ + if (timecb->interval_time <= 0) + { + break; + } } curr_cb_local_id = timecb->next_ref; }