diff --git a/README.md b/README.md index c7d045d71..c03fabbc4 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,12 @@ The autogenerated OSAL user's guide can be viewed at + ### Development Build: 5.1.0-rc1+dev49 - Adds an event callback mechanism to certain state changes in OSAL. This allows the CFE PSP to be notified at these points, and therefore it can add platform-specific functionality. diff --git a/src/os/inc/osapi-os-filesys.h b/src/os/inc/osapi-os-filesys.h index 6a3264bf8..420ebd45a 100644 --- a/src/os/inc/osapi-os-filesys.h +++ b/src/os/inc/osapi-os-filesys.h @@ -178,6 +178,8 @@ typedef enum * @{ */ +#ifndef OSAL_OMIT_DEPRECATED + /*-------------------------------------------------------------------------------------*/ /** * @brief Creates a file specified by path @@ -199,6 +201,9 @@ typedef enum * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long * @retval #OS_ERROR if permissions are unknown or OS call fails * @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left + * + * @deprecated Replaced by OS_OpenCreate() with flags set to + * OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE. */ int32 OS_creat (const char *path, int32 access); @@ -225,9 +230,14 @@ int32 OS_creat (const char *path, int32 access); * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long * @retval #OS_ERROR if permissions are unknown or OS call fails * @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left + * + * @deprecated Replaced by OS_OpenCreate() with flags set to + * OS_FILE_FLAG_NONE. */ int32 OS_open (const char *path, int32 access, uint32 mode); +#endif + /*-------------------------------------------------------------------------------------*/ /** * @brief Open or create a file diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index 10e713a53..4484223d3 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -30,7 +30,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 49 +#define OS_BUILD_NUMBER 55 #define OS_BUILD_BASELINE "v5.1.0-rc1" /* diff --git a/src/os/rtems/src/os-impl-binsem.c b/src/os/rtems/src/os-impl-binsem.c index cec0b5f1b..38000a4ef 100644 --- a/src/os/rtems/src/os-impl-binsem.c +++ b/src/os/rtems/src/os-impl-binsem.c @@ -104,7 +104,7 @@ int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 opti ** It is convenient to use the OSAL ID in here, as we know it is already unique ** and trying to use the real name would be less than useful (only 4 chars) */ - r_name = OS_global_bin_sem_table[sem_id].active_id; + r_name = OS_ObjectIdToInteger(OS_global_bin_sem_table[sem_id].active_id); /* Check to make sure the sem value is going to be either 0 or 1 */ if (sem_initial_value > 1) diff --git a/src/os/rtems/src/os-impl-console.c b/src/os/rtems/src/os-impl-console.c index 3ffe0f860..5a64f6a39 100644 --- a/src/os/rtems/src/os-impl-console.c +++ b/src/os/rtems/src/os-impl-console.c @@ -156,7 +156,7 @@ int32 OS_ConsoleCreate_Impl(uint32 local_id) ** It is convenient to use the OSAL ID in here, as we know it is already unique ** and trying to use the real name would be less than useful (only 4 chars) */ - r_name = OS_global_console_table[local_id].active_id; + r_name = OS_ObjectIdToInteger(OS_global_console_table[local_id].active_id); status = rtems_semaphore_create( r_name, 0, RTEMS_PRIORITY, 0, diff --git a/src/os/rtems/src/os-impl-countsem.c b/src/os/rtems/src/os-impl-countsem.c index 5fb85aef8..d85837762 100644 --- a/src/os/rtems/src/os-impl-countsem.c +++ b/src/os/rtems/src/os-impl-countsem.c @@ -106,7 +106,7 @@ int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 op ** It is convenient to use the OSAL ID in here, as we know it is already unique ** and trying to use the real name would be less than useful (only 4 chars) */ - r_name = OS_global_count_sem_table[sem_id].active_id; + r_name = OS_ObjectIdToInteger(OS_global_count_sem_table[sem_id].active_id); status = rtems_semaphore_create( r_name, sem_initial_value, OSAL_COUNT_SEM_ATTRIBS, 0, diff --git a/src/os/rtems/src/os-impl-mutex.c b/src/os/rtems/src/os-impl-mutex.c index b9c2158b4..66d4009b7 100644 --- a/src/os/rtems/src/os-impl-mutex.c +++ b/src/os/rtems/src/os-impl-mutex.c @@ -99,7 +99,7 @@ int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) /* ** Try to create the mutex */ - r_name = OS_global_mutex_table[sem_id].active_id; + r_name = OS_ObjectIdToInteger(OS_global_mutex_table[sem_id].active_id); status = rtems_semaphore_create ( r_name, 1, OSAL_MUTEX_ATTRIBS , 0, diff --git a/src/os/rtems/src/os-impl-queues.c b/src/os/rtems/src/os-impl-queues.c index 10cef87f1..24efdb454 100644 --- a/src/os/rtems/src/os-impl-queues.c +++ b/src/os/rtems/src/os-impl-queues.c @@ -94,7 +94,7 @@ int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) ** It is convenient to use the OSAL queue ID in here, as we know it is already unique ** and trying to use the real queue name would be less than useful (only 4 chars) */ - r_name = OS_global_queue_table[queue_id].active_id; + r_name = OS_ObjectIdToInteger(OS_global_queue_table[queue_id].active_id); /* ** Create the message queue. diff --git a/src/os/rtems/src/os-impl-tasks.c b/src/os/rtems/src/os-impl-tasks.c index 3a636ced4..a689aa63f 100644 --- a/src/os/rtems/src/os-impl-tasks.c +++ b/src/os/rtems/src/os-impl-tasks.c @@ -63,7 +63,7 @@ OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; ---------------------------------------------------------------------------------------*/ static rtems_task OS_RtemsEntry(rtems_task_argument arg) { - OS_TaskEntryPoint((uint32)arg); + OS_TaskEntryPoint(OS_ObjectIdFromInteger(arg)); } /* end OS_RtemsEntry */ @@ -107,7 +107,7 @@ int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) ** It is convenient to use the OSAL task ID in here, as we know it is already unique ** and trying to use the real task name would be less than useful (only 4 chars) */ - r_name = OS_global_task_table[task_id].active_id; + r_name = OS_ObjectIdToInteger(OS_global_task_table[task_id].active_id); r_mode = RTEMS_PREEMPT | RTEMS_NO_ASR | RTEMS_NO_TIMESLICE | RTEMS_INTERRUPT_LEVEL(0); /* @@ -139,7 +139,7 @@ int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) /* will place the task in 'ready for scheduling' state */ status = rtems_task_start (OS_impl_task_table[task_id].id, /*rtems task id*/ (rtems_task_entry) OS_RtemsEntry, /* task entry point */ - (rtems_task_argument) OS_global_task_table[task_id].active_id ); /* passed argument */ + (rtems_task_argument) OS_ObjectIdToInteger(OS_global_task_table[task_id].active_id) ); /* passed argument */ if (status != RTEMS_SUCCESSFUL ) { @@ -314,9 +314,9 @@ int32 OS_TaskRegister_Impl (osal_id_t global_task_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -uint32 OS_TaskGetId_Impl (void) +osal_id_t OS_TaskGetId_Impl (void) { - uint32 global_task_id; + osal_id_t global_task_id; rtems_id task_self; rtems_name self_name; rtems_status_code status; @@ -327,11 +327,11 @@ uint32 OS_TaskGetId_Impl (void) status = rtems_object_get_classic_name(task_self, &self_name); if (status == RTEMS_SUCCESSFUL) { - global_task_id = self_name; + global_task_id = OS_ObjectIdFromInteger(self_name); } else { - global_task_id = 0; + global_task_id = OS_OBJECT_ID_UNDEFINED; } return global_task_id; diff --git a/src/os/rtems/src/os-impl-timebase.c b/src/os/rtems/src/os-impl-timebase.c index 919a71ec4..a167ae1ab 100644 --- a/src/os/rtems/src/os-impl-timebase.c +++ b/src/os/rtems/src/os-impl-timebase.c @@ -126,9 +126,9 @@ static rtems_timer_service_routine OS_TimeBase_ISR(rtems_id rtems_timer_id, void OS_impl_timebase_internal_record_t *local; user_data.opaque_arg = arg; - OS_ConvertToArrayIndex(user_data.value, &local_id); + OS_ConvertToArrayIndex(user_data.id, &local_id); local = &OS_impl_timebase_table[local_id]; - if (OS_global_timebase_table[local_id].active_id == user_data.value) + if (OS_ObjectIdEqual(OS_global_timebase_table[local_id].active_id, user_data.id)) { /* * Reset the timer, but only if an interval was selected @@ -299,12 +299,18 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) rtems_status_code rtems_sc; OS_impl_timebase_internal_record_t *local; OS_common_record_t *global; + rtems_name r_name; return_code = OS_SUCCESS; local = &OS_impl_timebase_table[timer_id]; global = &OS_global_timebase_table[timer_id]; + /* + * The RTEMS classic name for dependent resources + */ + r_name = OS_ObjectIdToInteger(global->active_id); + /* * Set up the necessary OS constructs * @@ -323,7 +329,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * The tick_sem is a simple semaphore posted by the ISR and taken by the * timebase helper task (created later). */ - rtems_sc = rtems_semaphore_create (global->active_id, 0, RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_PRIORITY, 0, + rtems_sc = rtems_semaphore_create (r_name, 0, RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_PRIORITY, 0, &local->tick_sem); if ( rtems_sc != RTEMS_SUCCESSFUL ) { @@ -334,7 +340,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) /* * The handler_mutex is deals with access to the callback list for this timebase */ - rtems_sc = rtems_semaphore_create (global->active_id, 1, OSAL_TIMEBASE_MUTEX_ATTRIBS, 0, + rtems_sc = rtems_semaphore_create (r_name, 1, OSAL_TIMEBASE_MUTEX_ATTRIBS, 0, &local->handler_mutex); if ( rtems_sc != RTEMS_SUCCESSFUL ) @@ -344,7 +350,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) return_code = OS_TIMER_ERR_INTERNAL; } - rtems_sc = rtems_timer_create(global->active_id, &local->rtems_timer_id); + rtems_sc = rtems_timer_create(r_name, &local->rtems_timer_id); if ( rtems_sc != RTEMS_SUCCESSFUL ) { OS_DEBUG("Error: Timer object could not be created: %d\n",(int)rtems_sc); @@ -372,7 +378,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * the priority is set to RTEMS_MINIMUM_PRIORITY. */ rtems_sc = rtems_task_create( - global->active_id, + r_name, RTEMS_MINIMUM_PRIORITY + 1, 0, RTEMS_PREEMPT | RTEMS_NO_ASR | RTEMS_NO_TIMESLICE | RTEMS_INTERRUPT_LEVEL(0), @@ -391,7 +397,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) /* will place the task in 'ready for scheduling' state */ rtems_sc = rtems_task_start (local->handler_task, /*rtems task id*/ (rtems_task_entry) OS_TimeBase_CallbackThread, /* task entry point */ - (rtems_task_argument) global->active_id ); /* passed argument */ + (rtems_task_argument) OS_ObjectIdToInteger(global->active_id) ); /* passed argument */ if (rtems_sc != RTEMS_SUCCESSFUL ) { @@ -471,7 +477,7 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time OS_UsecsToTicks(start_time, &start_ticks); user_data.opaque_arg = NULL; - user_data.value = OS_global_timebase_table[timer_id].active_id; + user_data.id = OS_global_timebase_table[timer_id].active_id; status = rtems_timer_fire_after(local->rtems_timer_id, start_ticks, OS_TimeBase_ISR, user_data.opaque_arg ); diff --git a/src/os/shared/src/osapi-file.c b/src/os/shared/src/osapi-file.c index 72b95cf2c..d054696f5 100644 --- a/src/os/shared/src/osapi-file.c +++ b/src/os/shared/src/osapi-file.c @@ -99,6 +99,21 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc OS_common_record_t *record; char local_path[OS_MAX_LOCAL_PATH_LEN]; + if (filedes == NULL) + { + return OS_INVALID_POINTER; + } + + /* + ** Check for a valid access mode + */ + if (access != OS_WRITE_ONLY && + access != OS_READ_ONLY && + access != OS_READ_WRITE) + { + return OS_ERROR; + } + /* * Translate the path */ @@ -127,6 +142,12 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc } /* end OS_OpenCreate */ +/* + * The OS_open and OS_creat functions are deprecated, replaced by + * the generic OS_OpenCreate above + */ +#ifndef OSAL_OMIT_DEPRECATED + /*---------------------------------------------------------------- * * Function: OS_creat @@ -205,7 +226,7 @@ int32 OS_open (const char *path, int32 access, uint32 mode) return return_code; } /* end OS_open */ - +#endif /*---------------------------------------------------------------- * diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index 28d5b27f3..6c9a6ea65 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -147,22 +147,16 @@ void TestCreatRemove(void) } /* create a file with short name */ - status = OS_creat(filename,OS_READ_WRITE); - UtAssert_True(status >= 0, "fd after creat short name length file = %d",(int)status); - - /* conversion to osal_id_t */ - fd = OS_ObjectIdFromInteger(status); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); + UtAssert_True(status == OS_SUCCESS, "fd after creat short name length file = %d",(int)status); /* close the first file */ status = OS_close(fd); UtAssert_True(status == OS_SUCCESS, "status after close short name length file = %d",(int)status); /* create a file with max name size */ - status = OS_creat(maxfilename,OS_READ_WRITE); - UtAssert_True(status >= 0, "fd after creat max name length file = %d",(int)status); - - /* conversion to osal_id_t */ - fd = OS_ObjectIdFromInteger(status); + status = OS_OpenCreate(&fd, maxfilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); + UtAssert_True(status == OS_SUCCESS, "fd after creat max name length file = %d",(int)status); /* close the second file */ status = OS_close(fd); @@ -177,7 +171,7 @@ void TestCreatRemove(void) UtAssert_True(status == OS_SUCCESS, "status after remove max name length file = %d",(int)status); /* try creating with file name too big, should fail */ - status = OS_creat(longfilename,OS_READ_WRITE); + status = OS_OpenCreate(&fd, longfilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status < OS_SUCCESS, "status after create file name too long = %d",(int)status); /* try removing with file name too big. Should Fail */ @@ -207,12 +201,9 @@ void TestOpenClose(void) filename[sizeof(filename) - 1] = 0; /* create a file of reasonable length (but over 8 chars) */ - status = OS_creat(filename,OS_READ_WRITE); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat = %d",(int)status); - /* conversion to osal_id_t */ - fd = OS_ObjectIdFromInteger(status); - /* ** try to close the file */ @@ -220,12 +211,9 @@ void TestOpenClose(void) UtAssert_True(status == OS_SUCCESS, "status after close = %d",(int)status); /* reopen the file */ - status = OS_open(filename,OS_READ_WRITE,0644); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_NONE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after reopen = %d",(int)status); - /* conversion to osal_id_t */ - fd = OS_ObjectIdFromInteger(status); - /* ** try to close the file again */ @@ -243,7 +231,7 @@ void TestOpenClose(void) UtAssert_True(status != OS_SUCCESS, "status after close = %d",(int)status); /* open a file that was never in the system */ - status = OS_open("/drive0/FileNotHere",OS_READ_ONLY,0644); + status = OS_OpenCreate(&fd, "/drive0/FileNotHere", OS_FILE_FLAG_NONE, OS_READ_ONLY); UtAssert_True(status < OS_SUCCESS, "status after open = %d",(int)status); /* try removing the file from the drive to end the function */ @@ -279,11 +267,9 @@ void TestReadWriteLseek(void) /* create a file of reasonable length (but over 8 chars) */ /* Open In R/W mode */ - status = OS_creat(filename,OS_READ_WRITE); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat = %d",(int)status); - /* conversion to osal_id_t */ - fd = OS_ObjectIdFromInteger(status); size = strlen(buffer); /* test write portion of R/W mode */ @@ -310,12 +296,9 @@ void TestReadWriteLseek(void) UtAssert_True(status == OS_SUCCESS, "status after close = %d",(int)status); /* open a file again, but only in READ mode */ - status = OS_open(filename,OS_READ_ONLY,0644); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_NONE, OS_READ_ONLY); UtAssert_True(status >= OS_SUCCESS, "status after reopen = %d",(int)status); - /* conversion to osal_id_t */ - fd = OS_ObjectIdFromInteger(status); - /* test write in READ ONLY mode */ status = OS_write(fd, (void*)buffer, size); UtAssert_True(status < OS_SUCCESS, "status after write = %d",(int)status); @@ -349,12 +332,9 @@ void TestReadWriteLseek(void) UtAssert_True(status == OS_SUCCESS, "status after close = %d",(int)status); /* open a file again, but only in WRITE mode */ - status = OS_open(filename,OS_WRITE_ONLY,0644); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_NONE, OS_WRITE_ONLY); UtAssert_True(status >= OS_SUCCESS, "status after reopen = %d",(int)status); - /* conversion to osal_id_t */ - fd = OS_ObjectIdFromInteger(status); - /* test write in WRITE ONLY mode */ status = OS_write(fd, (void*)buffer, size); UtAssert_True(status == size, "status after write = %d size = %d",(int)status, (int)size); @@ -423,18 +403,12 @@ void TestMkRmDirFreeBytes(void) /* now create two files in the two directories (1 file per directory) */ - status = OS_creat(filename1,OS_READ_WRITE); + status = OS_OpenCreate(&fd1, filename1, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat 1 = %d",(int)status); - /* conversion to osal_id_t */ - fd1 = OS_ObjectIdFromInteger(status); - - status = OS_creat(filename2,OS_READ_WRITE); + status = OS_OpenCreate(&fd2, filename2, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat 2 = %d",(int)status); - /* conversion to osal_id_t */ - fd2 = OS_ObjectIdFromInteger(status); - /* write the propper buffers into each of the files */ size = strlen(buffer1); status = OS_write(fd1, buffer1, size); @@ -537,18 +511,12 @@ void TestOpenReadCloseDir(void) /* now create two files in the two directories (1 file per directory) */ - status = OS_creat(filename1,OS_READ_WRITE); + status = OS_OpenCreate(&fd1, filename1, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat 1 = %d",(int)status); - /* conversion to osal_id_t */ - fd1 = OS_ObjectIdFromInteger(status); - - status = OS_creat(filename2,OS_READ_WRITE); + status = OS_OpenCreate(&fd2, filename2, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat 2 = %d",(int)status); - /* conversion to osal_id_t */ - fd2 = OS_ObjectIdFromInteger(status); - /* write the proper buffers into each of the files */ size = strlen(buffer1); status = OS_write(fd1, buffer1, size); @@ -756,12 +724,9 @@ void TestRename(void) /* now create a file in the directory */ - status = OS_creat(filename1,OS_READ_WRITE); + status = OS_OpenCreate(&fd1, filename1, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat 1 = %d",(int)status); - /* conversion to osal_id_t */ - fd1 = OS_ObjectIdFromInteger(status); - /* write the propper buffes into the file */ size = strlen(buffer1); @@ -787,12 +752,9 @@ void TestRename(void) /* try to read the new file out */ - status = OS_open(newfilename1,OS_READ_ONLY,0644); + status = OS_OpenCreate(&fd1, newfilename1, OS_FILE_FLAG_NONE, OS_READ_ONLY); UtAssert_True(status >= OS_SUCCESS, "status after open 1 = %d",(int)status); - /* conversion to osal_id_t */ - fd1 = OS_ObjectIdFromInteger(status); - size = strlen(copybuffer1); status = OS_read(fd1,buffer1,size); UtAssert_True(status == size, "status after read 1 = %d size = %d",(int)status, (int)size); @@ -838,12 +800,9 @@ void TestStat(void) UtAssert_True(status == OS_SUCCESS, "status after mkdir 1 = %d",(int)status); /* now create a file */ - status = OS_creat(filename1,OS_READ_WRITE); + status = OS_OpenCreate(&fd1, filename1, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat 1 = %d",(int)status); - /* conversion to osal_id_t */ - fd1 = OS_ObjectIdFromInteger(status); - /* Write some data into the file */ size = strlen(buffer1); @@ -887,21 +846,22 @@ void TestOpenFileAPI(void) char filename2 [OS_MAX_PATH_LEN]; char filename3 [OS_MAX_PATH_LEN]; int status; + osal_id_t fd; strcpy(filename1,"/drive0/Filename1"); strcpy(filename2,"/drive0/Filename2"); strcpy(filename3,"/drive0/Filename3"); /* Create/open a file */ - status = OS_creat(filename1,OS_READ_WRITE); + status = OS_OpenCreate(&fd, filename1, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat 1 = %d",(int)status); /* Create/open a file */ - status = OS_creat(filename2,OS_READ_WRITE); + status = OS_OpenCreate(&fd, filename2, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat 2 = %d",(int)status); /* Create/open a file */ - status = OS_creat(filename3,OS_READ_WRITE); + status = OS_OpenCreate(&fd, filename3, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat 3 = %d",(int)status); /* diff --git a/src/unit-test-coverage/shared/src/coveragetest-file.c b/src/unit-test-coverage/shared/src/coveragetest-file.c index ccb8973fd..46071b2ff 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -48,41 +48,45 @@ void Test_OS_FileAPI_Init(void) UtAssert_True(actual == expected, "OS_FileAPI_Init() (%ld) == OS_SUCCESS", (long)actual); } -void Test_OS_creat(void) +void Test_OS_OpenCreate(void) { /* * Test Case For: - * int32 OS_creat (const char *path, int32 access) + * int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access) */ - int32 actual = OS_creat("/cf/file", OS_READ_WRITE); - UtAssert_True(actual >= 0, "OS_creat() (%ld) >= 0", (long)actual); + int32 expected; + int32 actual; + osal_id_t filedes; - actual = OS_creat("/cf/file", OS_READ_ONLY); - UtAssert_True(actual == OS_ERROR, "OS_creat() (%ld) == OS_ERROR", (long)actual); + /* Test in OS_creat mode */ + expected = OS_SUCCESS; + actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); + UtAssert_True(actual == expected, "OS_OpenCreate() (%ld) == OS_SUCCESS (create mode)", (long)actual); - UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_ERROR); - actual = OS_creat(NULL, OS_WRITE_ONLY); - UtAssert_True(actual == OS_ERROR, "OS_creat() (%ld) == OS_ERROR", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TranslatePath)); + /* Test in OS_open mode */ + actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE); + UtAssert_True(actual == expected, "OS_OpenCreate() (%ld) == OS_SUCCESS (open mode)", (long)actual); -} + /* Test with bad descriptor buffer */ + expected = OS_INVALID_POINTER; + actual = OS_OpenCreate(NULL, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE); + UtAssert_True(actual == expected, "OS_OpenCreate() (%ld) == OS_INVALID_POINTER (bad buffer)", (long)actual); -void Test_OS_open(void) -{ - /* - * Test Case For: - * int32 OS_open (const char *path, int32 access, uint32 mode) - */ - int32 actual = OS_open("/cf/file", OS_READ_WRITE, 0); + /* Test with bad access flags */ + expected = OS_ERROR; + actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, 9999); + UtAssert_True(actual == expected, "OS_OpenCreate() (%ld) == OS_ERROR (bad flags)", (long)actual); - UtAssert_True(actual > 0, "OS_open() (%ld) > 0", (long)actual); + /* Test failure to convert path */ + UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_ERROR); + expected = OS_ERROR; + actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE); + UtAssert_True(actual == OS_ERROR, "OS_OpenCreate() (%ld) == OS_ERROR (bad path)", (long)actual); + UT_ClearForceFail(UT_KEY(OS_TranslatePath)); - actual = OS_open("/cf/file", -1, 0); - UtAssert_True(actual < 0, "OS_open() (%ld) < 0", (long)actual); } - void Test_OS_close(void) { /* @@ -344,10 +348,6 @@ void Test_OS_FDGetInfo(void) actual = OS_FDGetInfo(UT_OBJID_1, &file_prop); UtAssert_True(actual == expected, "OS_FDGetInfo() (%ld) == OS_SUCCESS", (long)actual); -#ifdef jphfix - UtAssert_True(file_prop.User == 111, "file_prop.User (%lu) == 111", - (unsigned long)file_prop.User); -#endif UtAssert_True(strcmp(file_prop.Path, "ABC") == 0, "file_prop.Path (%s) == ABC", file_prop.Path); @@ -457,8 +457,7 @@ void Osapi_Test_Teardown(void) void UtTest_Setup(void) { ADD_TEST(OS_FileAPI_Init); - ADD_TEST(OS_creat); - ADD_TEST(OS_open); + ADD_TEST(OS_OpenCreate); ADD_TEST(OS_close); ADD_TEST(OS_TimedRead); ADD_TEST(OS_TimedWrite); diff --git a/src/unit-tests/oscore-test/ut_oscore_select_test.c b/src/unit-tests/oscore-test/ut_oscore_select_test.c index 40ed0fded..9bff0ec39 100644 --- a/src/unit-tests/oscore-test/ut_oscore_select_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_select_test.c @@ -64,11 +64,9 @@ char *fsAddrPtr = NULL; static osal_id_t setup_file(void) { osal_id_t id; - int32 status; UT_SETUP(OS_mkfs(fsAddrPtr, "/ramdev3", "RAM3", 512, 20)); UT_SETUP(OS_mount("/ramdev3", "/drive3")); - status = OS_creat("/drive3/select_test.txt", OS_READ_WRITE); - id = OS_ObjectIdFromInteger(status); + UT_SETUP(OS_OpenCreate(&id, "/drive3/select_test.txt", OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE)); return id; } diff --git a/src/unit-tests/osfile-test/ut_osfile_dirio_test.c b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c index 3f285a3a0..6be06b81d 100644 --- a/src/unit-tests/osfile-test/ut_osfile_dirio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c @@ -176,14 +176,13 @@ void UT_os_makedir_test() memset(g_fileName, '\0', sizeof(g_fileName)); UT_os_sprintf(g_fileName, "%s/mkdir_File.txt", g_dirName); - status = OS_creat(g_fileName, OS_READ_WRITE); + status = OS_OpenCreate(&fileDesc, g_fileName, OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (status >= 0) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); /* Reset test environment */ - fileDesc = OS_ObjectIdFromInteger(status); OS_close(fileDesc); OS_remove(g_fileName); OS_rmdir(g_dirName); @@ -776,7 +775,7 @@ void UT_os_removedir_test() memset(g_fileName, '\0', sizeof(g_fileName)); UT_os_sprintf(g_fileName, "%s/rmdir_File1.txt", g_dirName); - status = OS_creat(g_fileName, OS_READ_WRITE); + status = OS_OpenCreate(&fileDesc, g_fileName, OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (status < 0) { testDesc = "#5 Nominal - File-create failed"; @@ -784,7 +783,6 @@ void UT_os_removedir_test() } /* Must close and remove all files before the directory can be removed */ - fileDesc = OS_ObjectIdFromInteger(status); OS_close(fileDesc); OS_remove(g_fileName); @@ -796,7 +794,7 @@ void UT_os_removedir_test() memset(g_fileName, '\0', sizeof(g_fileName)); UT_os_sprintf(g_fileName, "%s/rmdir_File2.txt", g_dirName); - status = OS_creat(g_fileName, OS_READ_WRITE); + status = OS_OpenCreate(&fileDesc, g_fileName, OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (status < 0) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c index 0d8496acf..01f109f74 100644 --- a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c @@ -212,11 +212,13 @@ void UT_os_createfile_test() { const char* testDesc; int32 res=0, i=0, j=0; + osal_id_t fd; /*-----------------------------------------------------*/ testDesc = "API not implemented"; - if (OS_creat(NULL, OS_READ_WRITE) == OS_ERR_NOT_IMPLEMENTED) + if (OS_OpenCreate(NULL, NULL, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == + OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); goto UT_os_createfile_test_exit_tag; @@ -225,7 +227,14 @@ void UT_os_createfile_test() /*-----------------------------------------------------*/ testDesc = "#1 Null-pointer-arg"; - if (OS_creat(NULL, OS_READ_WRITE) == OS_INVALID_POINTER) + if (OS_OpenCreate(NULL, "file", OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == + OS_INVALID_POINTER) + UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); + else + UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); + + if (OS_OpenCreate(&fd, NULL, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == + OS_INVALID_POINTER) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); @@ -233,7 +242,8 @@ void UT_os_createfile_test() /*-----------------------------------------------------*/ testDesc = "#2 Invalid-path-arg"; - if (OS_creat(g_invalidPath, OS_READ_WRITE) == OS_FS_ERR_PATH_INVALID) + if (OS_OpenCreate(&fd, g_invalidPath, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == + OS_FS_ERR_PATH_INVALID) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); @@ -241,7 +251,8 @@ void UT_os_createfile_test() /*-----------------------------------------------------*/ testDesc = "#3 Path-too-long-arg"; - if (OS_creat(g_longPathName, OS_READ_WRITE) == OS_FS_ERR_PATH_TOO_LONG) + if (OS_OpenCreate(&fd, g_longPathName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == + OS_FS_ERR_PATH_TOO_LONG) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); @@ -249,7 +260,8 @@ void UT_os_createfile_test() /*-----------------------------------------------------*/ testDesc = "#4 Name-too-long-arg"; - if (OS_creat(g_longFileName, OS_READ_WRITE) == OS_FS_ERR_NAME_TOO_LONG) + if (OS_OpenCreate(&fd, g_longFileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == + OS_FS_ERR_NAME_TOO_LONG) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); @@ -259,7 +271,7 @@ void UT_os_createfile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Create_InvPerm.txt", g_mntName); - res = OS_creat(g_fNames[0], 123); + res = OS_OpenCreate(&fd, g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, 123); if (res == OS_ERROR) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -280,11 +292,9 @@ void UT_os_createfile_test() { memset(g_fNames[i], '\0', sizeof(g_fNames[i])); UT_os_sprintf(g_fNames[i], "%s/tmpFile%d.txt", g_mntName, (int)i); - g_fStatus[i] = OS_creat(g_fNames[i], OS_WRITE_ONLY); + g_fStatus[i] = OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); if (g_fStatus[i] < 0) break; - - g_fDescs[i] = OS_ObjectIdFromInteger(g_fStatus[i]); } if ((i == OS_MAX_NUM_OPEN_FILES) && (g_fStatus[i] == OS_ERR_NO_FREE_IDS)) @@ -302,10 +312,8 @@ void UT_os_createfile_test() /*-----------------------------------------------------*/ testDesc = "#8 Nominal"; - g_fStatus[5] = OS_creat(g_fNames[5], OS_WRITE_ONLY); - g_fDescs[5] = OS_ObjectIdFromInteger(g_fStatus[5]); - g_fStatus[6] = OS_creat(g_fNames[6], OS_WRITE_ONLY); - g_fDescs[6] = OS_ObjectIdFromInteger(g_fStatus[6]); + g_fStatus[5] = OS_OpenCreate(&g_fDescs[5], g_fNames[5], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); + g_fStatus[6] = OS_OpenCreate(&g_fDescs[6], g_fNames[6], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); if ((OS_close(g_fDescs[5]) != OS_SUCCESS) || (OS_close(g_fDescs[6]) != OS_SUCCESS) || (OS_remove(g_fNames[5]) != OS_SUCCESS) || (OS_remove(g_fNames[6]) != OS_SUCCESS)) @@ -395,11 +403,13 @@ void UT_os_openfile_test() { const char* testDesc; int32 res=0, i=0, j=0, continueFlg=0; + osal_id_t fd; /*-----------------------------------------------------*/ testDesc = "API not implemented"; - if (OS_open(NULL, OS_READ_WRITE, 0644) == OS_ERR_NOT_IMPLEMENTED) + if (OS_OpenCreate(&fd, NULL, OS_FILE_FLAG_NONE, OS_READ_WRITE) == + OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); goto UT_os_openfile_test_exit_tag; @@ -408,7 +418,14 @@ void UT_os_openfile_test() /*-----------------------------------------------------*/ testDesc = "#1 Null-pointer-arg"; - if (OS_open(NULL, OS_READ_WRITE, 0644) == OS_INVALID_POINTER) + if (OS_OpenCreate(&fd, NULL, OS_FILE_FLAG_NONE, OS_READ_WRITE) == + OS_INVALID_POINTER) + UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); + else + UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); + + if (OS_OpenCreate(NULL, "file", OS_FILE_FLAG_NONE, OS_READ_WRITE) == + OS_INVALID_POINTER) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); @@ -416,7 +433,8 @@ void UT_os_openfile_test() /*-----------------------------------------------------*/ testDesc = "#2 Invalid-path-arg"; - if (OS_open(g_invalidPath, OS_READ_WRITE, 0644) == OS_FS_ERR_PATH_INVALID) + if (OS_OpenCreate(&fd, g_invalidPath, OS_FILE_FLAG_NONE, OS_READ_WRITE) == + OS_FS_ERR_PATH_INVALID) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); @@ -424,7 +442,8 @@ void UT_os_openfile_test() /*-----------------------------------------------------*/ testDesc = "#3 Path-too-long-arg"; - if (OS_open(g_longPathName, OS_READ_WRITE, 0644) == OS_FS_ERR_PATH_TOO_LONG) + if (OS_OpenCreate(&fd, g_longPathName, OS_FILE_FLAG_NONE, OS_READ_WRITE) == + OS_FS_ERR_PATH_TOO_LONG) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); @@ -432,7 +451,8 @@ void UT_os_openfile_test() /*-----------------------------------------------------*/ testDesc = "#4 Name-too-long-arg"; - if (OS_open(g_longFileName, OS_READ_WRITE, 0644) == OS_FS_ERR_NAME_TOO_LONG) + if (OS_OpenCreate(&fd, g_longFileName, OS_FILE_FLAG_NONE, OS_READ_WRITE) == + OS_FS_ERR_NAME_TOO_LONG) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); @@ -442,7 +462,7 @@ void UT_os_openfile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Open_InvPerm.txt", g_mntName); - res = OS_open(g_fNames[0], 123, 0644); + res = OS_OpenCreate(&fd, g_fNames[0], OS_FILE_FLAG_NONE, 123); if (res == OS_ERROR) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -464,7 +484,7 @@ void UT_os_openfile_test() { memset(g_fNames[i], '\0', sizeof(g_fNames[i])); UT_os_sprintf(g_fNames[i], "%s/tmpFile%d.txt", g_mntName, (int)i); - g_fStatus[i] = OS_creat(g_fNames[i], OS_WRITE_ONLY); + g_fStatus[i] = OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); if (g_fStatus[i] < OS_SUCCESS) { testDesc = "#7 File-descriptors-full - File-create failed"; @@ -473,8 +493,6 @@ void UT_os_openfile_test() break; } - g_fDescs[i] = OS_ObjectIdFromInteger(g_fStatus[i]); - if (continueFlg && (OS_close(g_fDescs[i]) != OS_SUCCESS)) { testDesc = "#7 File-descriptors-full - File-close failed"; @@ -488,11 +506,9 @@ void UT_os_openfile_test() { for (i=0; i <= OS_MAX_NUM_OPEN_FILES; i++) { - g_fStatus[i] = OS_open(g_fNames[i], OS_WRITE_ONLY, 0644); + g_fStatus[i] = OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_NONE, OS_WRITE_ONLY); if (g_fStatus[i] < 0) break; - - g_fDescs[i] = OS_ObjectIdFromInteger(g_fStatus[i]); } if ((i == OS_MAX_NUM_OPEN_FILES) && (g_fStatus[i] < OS_SUCCESS)) @@ -511,8 +527,8 @@ void UT_os_openfile_test() /*-----------------------------------------------------*/ testDesc = "#8 Nominal"; - g_fStatus[5] = OS_creat(g_fNames[5], OS_READ_WRITE); - g_fStatus[6] = OS_creat(g_fNames[6], OS_WRITE_ONLY); + g_fStatus[5] = OS_OpenCreate(&g_fDescs[5], g_fNames[5], OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); + g_fStatus[6] = OS_OpenCreate(&g_fDescs[6], g_fNames[6], OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); if ((g_fStatus[5] < OS_SUCCESS) || (g_fStatus[6] < OS_SUCCESS)) { testDesc = "#8 Nominal - File-create failed"; @@ -520,9 +536,6 @@ void UT_os_openfile_test() goto UT_os_openfile_test_exit_tag; } - g_fDescs[5] = OS_ObjectIdFromInteger(g_fStatus[5]); - g_fDescs[6] = OS_ObjectIdFromInteger(g_fStatus[6]); - if ((OS_close(g_fDescs[5]) != OS_SUCCESS) || (OS_close(g_fDescs[6]) != OS_SUCCESS)) { testDesc = "#8 Nominal - File-close failed"; @@ -530,11 +543,8 @@ void UT_os_openfile_test() goto UT_os_openfile_test_exit_tag; } - g_fStatus[5] = OS_open(g_fNames[5], OS_READ_WRITE, 0644); - g_fStatus[6] = OS_open(g_fNames[6], OS_WRITE_ONLY, 0644); - - g_fDescs[5] = OS_ObjectIdFromInteger(g_fStatus[5]); - g_fDescs[6] = OS_ObjectIdFromInteger(g_fStatus[6]); + g_fStatus[5] = OS_OpenCreate(&g_fDescs[5], g_fNames[5], OS_FILE_FLAG_NONE, OS_READ_WRITE); + g_fStatus[6] = OS_OpenCreate(&g_fDescs[6], g_fNames[6], OS_FILE_FLAG_NONE, OS_WRITE_ONLY); if ((OS_close(g_fDescs[5]) != OS_SUCCESS) || (OS_close(g_fDescs[6]) != OS_SUCCESS) || (OS_remove(g_fNames[5]) != OS_SUCCESS) || (OS_remove(g_fNames[6]) != OS_SUCCESS)) @@ -618,7 +628,8 @@ void UT_os_closefile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Close_Nominal.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#3 Nominal - File-create failed"; @@ -626,8 +637,6 @@ void UT_os_closefile_test() goto UT_os_closefile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); - if ((OS_close(g_fDescs[0]) != OS_SUCCESS) || (OS_write(g_fDescs[0], tmpBuff, sizeof(tmpBuff)) != OS_ERR_INVALID_ID) || (OS_read(g_fDescs[0], tmpBuff, sizeof(tmpBuff)) != OS_ERR_INVALID_ID)) @@ -714,7 +723,8 @@ void UT_os_readfile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Read_NullPtr.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#1 Null-pointer-arg - File-create failed"; @@ -722,8 +732,6 @@ void UT_os_readfile_test() } else { - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); - if (OS_read(g_fDescs[0], NULL, sizeof(g_readBuff)) == OS_INVALID_POINTER) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -753,7 +761,8 @@ void UT_os_readfile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Read_Nominal.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#4 Nominal - File-create failed"; @@ -761,7 +770,6 @@ void UT_os_readfile_test() goto UT_os_readfile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); memset(g_writeBuff, '\0', sizeof(g_writeBuff)); strcpy(g_writeBuff, "A HORSE! A HORSE! MY KINGDOM FOR A HORSE!"); if (OS_write(g_fDescs[0], g_writeBuff, strlen(g_writeBuff)) != strlen(g_writeBuff)) @@ -787,7 +795,8 @@ void UT_os_readfile_test() goto UT_os_readfile_test_exit_tag; } - g_fStatus[0] = OS_open(g_fNames[0], OS_READ_WRITE, 0644); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_NONE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#4 Nominal - File-open failed"; @@ -799,7 +808,6 @@ void UT_os_readfile_test() goto UT_os_readfile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); memset(g_readBuff, '\0', sizeof(g_readBuff)); if ((OS_read(g_fDescs[0], g_readBuff, strlen(g_writeBuff)) == strlen(g_writeBuff)) && (strncmp(g_readBuff, g_writeBuff, strlen(g_writeBuff)) == 0)) @@ -889,7 +897,8 @@ void UT_os_writefile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Write_NullPtr.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#1 Null-pointer-arg - File-create failed"; @@ -897,8 +906,6 @@ void UT_os_writefile_test() } else { - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); - if (OS_write(g_fDescs[0], NULL, sizeof(g_writeBuff)) == OS_INVALID_POINTER) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -928,7 +935,8 @@ void UT_os_writefile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Write_Nominal.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < OS_SUCCESS) { testDesc = "#4 Nominal - File-create failed"; @@ -936,7 +944,6 @@ void UT_os_writefile_test() goto UT_os_writefile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); memset(g_writeBuff, '\0', sizeof(g_writeBuff)); strcpy(g_writeBuff, "TO BE OR NOT TO BE, THAT IS A QUESTION."); if (OS_write(g_fDescs[0], g_writeBuff, strlen(g_writeBuff)) != strlen(g_writeBuff)) @@ -961,7 +968,8 @@ void UT_os_writefile_test() goto UT_os_writefile_test_exit_tag; } - g_fStatus[0] = OS_open(g_fNames[0], OS_READ_WRITE, 0644); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_NONE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#4 Nominal - File-open failed"; @@ -973,7 +981,6 @@ void UT_os_writefile_test() goto UT_os_writefile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); memset(g_readBuff, '\0', sizeof(g_readBuff)); if ((OS_read(g_fDescs[0], g_readBuff, strlen(g_writeBuff)) == strlen(g_writeBuff)) && (strncmp(g_readBuff, g_writeBuff, strlen(g_writeBuff)) == 0)) @@ -1070,7 +1077,8 @@ void UT_os_lseekfile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Seek_InvWhence.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#2 Invalid-whence-arg - File-create failed"; @@ -1078,7 +1086,6 @@ void UT_os_lseekfile_test() } else { - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); if (OS_lseek(g_fDescs[0], 0, 123456) == OS_ERROR) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -1101,7 +1108,8 @@ void UT_os_lseekfile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Seek_Nominal.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#4 Nominal - File-create failed"; @@ -1109,7 +1117,6 @@ void UT_os_lseekfile_test() goto UT_os_lseekfile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); memset(g_writeBuff, '\0', sizeof(g_writeBuff)); strcpy(g_writeBuff, "THE BROWN FOX JUMPS OVER THE LAZY DOG."); buffLen = (int32)strlen(g_writeBuff); @@ -1276,7 +1283,8 @@ void UT_os_statfile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Stat_Nominal.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#5 Nominal - File-create failed"; @@ -1290,7 +1298,6 @@ void UT_os_statfile_test() goto UT_os_statfile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); memset(g_writeBuff, '\0', sizeof(g_writeBuff)); strcpy(g_writeBuff, "HOW NOW, BROWN COW?"); if (OS_write(g_fDescs[0], g_writeBuff, strlen(g_writeBuff)) != strlen(g_writeBuff)) @@ -1437,7 +1444,8 @@ void UT_os_removefile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Remove_Nominal.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#6 Nominal - File-create failed"; @@ -1445,8 +1453,6 @@ void UT_os_removefile_test() goto UT_os_removefile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); - /* TODO: Check to see if OS_remove() can delete an opened file. */ OS_close(g_fDescs[0]); if (OS_remove(g_fNames[0]) != OS_SUCCESS) @@ -1584,7 +1590,8 @@ void UT_os_renamefile_test() UT_os_sprintf(g_fNames[0], "%s/Rename_Nom_Old.txt", g_mntName); UT_os_sprintf(g_fNames[1], "%s/Rename_Nom_New.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#6 Nominal - File-create failed"; @@ -1742,7 +1749,8 @@ void UT_os_copyfile_test() goto UT_os_copyfile_test_exit_tag; } - g_fStatus[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#6 Nominal - File-create failed"; @@ -1750,7 +1758,6 @@ void UT_os_copyfile_test() goto UT_os_copyfile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); if (OS_close(g_fDescs[0]) != OS_SUCCESS) { testDesc = "#6 Nominal - File-close failed"; @@ -1911,7 +1918,8 @@ void UT_os_movefile_test() goto UT_os_movefile_test_exit_tag; } - g_fStatus[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#6 Nominal - File-create failed"; @@ -1919,7 +1927,6 @@ void UT_os_movefile_test() goto UT_os_movefile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); /* Close file before moving */ if (OS_close(g_fDescs[0]) != OS_SUCCESS) { @@ -2040,7 +2047,8 @@ void UT_os_outputtofile_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Output_Nominal.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#4 Nominal - File-create failed"; @@ -2048,7 +2056,6 @@ void UT_os_outputtofile_test() goto UT_os_outputtofile_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); cmd = "echo \"UT_os_outputtofile_test\""; res = OS_ShellOutputToFile(cmd, g_fDescs[0]); if (res == OS_ERR_NOT_IMPLEMENTED) @@ -2164,7 +2171,8 @@ void UT_os_getfdinfo_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/GetInfo_Null.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#1 Null-pointer-arg - File-create failed"; @@ -2172,7 +2180,6 @@ void UT_os_getfdinfo_test() } else { - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); if (OS_FDGetInfo(g_fDescs[0], NULL) != OS_INVALID_POINTER) { UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); @@ -2204,7 +2211,8 @@ void UT_os_getfdinfo_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/%s", g_mntName, fileName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_WRITE_ONLY); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); if (g_fStatus[0] < 0) { testDesc = "#4 Nominal - File-create failed"; @@ -2212,7 +2220,6 @@ void UT_os_getfdinfo_test() goto UT_os_getfdinfo_test_exit_tag; } - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); memset(&fdProps, 0x00, sizeof(fdProps)); if (OS_FDGetInfo(g_fDescs[0], &fdProps) != OS_SUCCESS || strcmp(fdProps.Path, g_fNames[0]) != 0) @@ -2301,7 +2308,8 @@ void UT_os_checkfileopen_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/FChk_UnOpened.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#2 File-not-opened - File-create failed"; @@ -2309,8 +2317,6 @@ void UT_os_checkfileopen_test() } else { - g_fDescs[0] = OS_ObjectIdFromInteger(g_fStatus[0]); - if (OS_close(g_fDescs[0]) != OS_SUCCESS) { testDesc = "#2 File-not-opened - File-close failed"; @@ -2335,7 +2341,8 @@ void UT_os_checkfileopen_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/FileChk_Nominal.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#3 Nominal - File-create failed"; @@ -2415,9 +2422,12 @@ void UT_os_closeallfiles_test() UT_os_sprintf(g_fNames[1], "%s/CloseAll_Nom_2.txt", g_mntName); UT_os_sprintf(g_fNames[2], "%s/CloseAll_Nom_3.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); - g_fStatus[1] = OS_creat(g_fNames[1], OS_READ_WRITE); - g_fStatus[2] = OS_creat(g_fNames[2], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); + g_fStatus[1] = OS_OpenCreate(&g_fDescs[1], g_fNames[1], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); + g_fStatus[2] = OS_OpenCreate(&g_fDescs[2], g_fNames[2], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if ((g_fStatus[0] < 0) || (g_fStatus[1] < 0) || (g_fStatus[2] < 0)) { testDesc = "#2 Nominal - File-create failed"; @@ -2529,7 +2539,8 @@ void UT_os_closefilebyname_test() memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Close_Nominal.txt", g_mntName); - g_fStatus[0] = OS_creat(g_fNames[0], OS_READ_WRITE); + g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], + OS_FILE_FLAG_CREATE|OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); if (g_fStatus[0] < 0) { testDesc = "#4 Nominal - File-create failed"; diff --git a/src/ut-stubs/osapi-utstub-file.c b/src/ut-stubs/osapi-utstub-file.c index f9b933c87..845bffd6a 100644 --- a/src/ut-stubs/osapi-utstub-file.c +++ b/src/ut-stubs/osapi-utstub-file.c @@ -107,6 +107,7 @@ static int32 UT_GenericWriteStub(const char *fname, UT_EntryKey_t fkey, const vo return status; } +#ifndef OSAL_OMIT_DEPRECATED /***************************************************************************** * @@ -155,6 +156,8 @@ int32 OS_open(const char *path, int32 access, uint32 mode) return status; } +#endif + /***************************************************************************** * * Stub function for OS_OpenCreate()