Simplify logging and remove unwanted functions from abstraction layer

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2018-11-26 19:10:09 +01:00
parent ac020f62f7
commit 1cf03332ca
97 changed files with 2819 additions and 5361 deletions

View file

@ -19,7 +19,6 @@ set(sources
"iter.c"
"mutex.c"
"once.c"
"report.c"
"rwlock.c"
"stdlib.c"
"strtoll.c"

View file

@ -1,404 +0,0 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#include "CUnit/Test.h"
#include "os/os.h"
#include "os/os_project.h"
#include <stdio.h>
CU_Init(os_report)
{
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_ERRORFILE=vdds_test_error");
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_INFOFILE=vdds_test_info");
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_LOGAPPEND=TRUE");
return 0;
}
void remove_logs()
{
const char * error_file_name = os_getenv(OS_PROJECT_NAME_NOSPACE_CAPS"_ERRORFILE");
const char * info_file_name = os_getenv(OS_PROJECT_NAME_NOSPACE_CAPS"_INFOFILE");
os_remove(error_file_name);
os_remove(info_file_name);
}
void check_existence(os_result error_log_existence, os_result info_log_existence)
{
const char * error_file_name = os_getenv(OS_PROJECT_NAME_NOSPACE_CAPS"_ERRORFILE");
const char * info_file_name = os_getenv(OS_PROJECT_NAME_NOSPACE_CAPS"_INFOFILE");
CU_ASSERT(os_access(error_file_name, OS_ROK) == error_log_existence);
CU_ASSERT(os_access(info_file_name, OS_ROK) == info_log_existence);
}
CU_Clean(os_report)
{
remove_logs();
return 0;
}
CU_Test(os_report, re_init)
{
os_reportInit(true);
OS_INFO(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
OS_ERROR(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
check_existence(os_resultSuccess, os_resultSuccess);
os_reportExit();
os_reportInit(true);
check_existence(os_resultSuccess, os_resultSuccess);
OS_INFO(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
os_reportExit();
remove_logs();
}
CU_Test(os_report, stack_critical)
{
os_reportInit(true);
OS_REPORT_STACK();
OS_CRITICAL(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
check_existence(os_resultFail, os_resultFail);
OS_REPORT_FLUSH(false);
// Since a critical is logged, the error log should be created
check_existence(os_resultSuccess, os_resultFail);
os_reportExit();
remove_logs();
}
CU_Test(os_report, stack_non_critical)
{
os_reportInit(true);
OS_REPORT_STACK();
OS_ERROR(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
check_existence(os_resultFail, os_resultFail);
OS_REPORT_FLUSH(false);
// Since a non critical is logged, the error log should not be created
check_existence(os_resultFail, os_resultFail);
os_reportExit();
remove_logs();
}
CU_Test(os_report, error_file_creation_critical)
{
os_reportInit(true);
OS_CRITICAL(OS_FUNCTION, 0, "os_report-critical-test %d", __LINE__);
check_existence(os_resultSuccess, os_resultFail);
os_reportExit();
remove_logs();
}
CU_Test(os_report, error_file_creation_fatal)
{
os_reportInit(true);
OS_FATAL(OS_FUNCTION, 0, "os_report-fatal-test %d", __LINE__);
check_existence(os_resultSuccess, os_resultFail);
os_reportExit();
remove_logs();
}
CU_Test(os_report, info_file_creation_warning)
{
os_reportInit(true);
OS_WARNING(OS_FUNCTION, 0, "os_report-warning-test %d", __LINE__);
check_existence(os_resultFail, os_resultSuccess);
os_reportExit();
remove_logs();
}
CU_Test(os_report, info_file_creation_info)
{
os_reportInit(true);
OS_INFO(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
check_existence(os_resultFail, os_resultSuccess);
os_reportExit();
remove_logs();
}
CU_Test(os_report, verbosity_low)
{
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
os_reportVerbosity = OS_REPORT_ERROR;
OS_WARNING(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
check_existence(os_resultFail, os_resultFail);
os_reportExit();
remove_logs();
}
CU_Test(os_report, verbosity_high)
{
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
os_reportVerbosity = OS_REPORT_DEBUG;
OS_WARNING(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
check_existence(os_resultFail, os_resultSuccess);
os_reportExit();
remove_logs();
}
CU_Test(os_report, verbosity_equal)
{
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
os_reportVerbosity = OS_REPORT_WARNING;
OS_WARNING(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
check_existence(os_resultFail, os_resultSuccess);
os_reportExit();
remove_logs();
}
CU_Test(os_report, stack_verbosity_low)
{
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
os_reportVerbosity = OS_REPORT_ERROR;
OS_REPORT_STACK();
OS_WARNING(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
OS_REPORT_FLUSH(true);
check_existence(os_resultFail, os_resultFail);
os_reportExit();
remove_logs();
}
CU_Test(os_report, stack_verbosity_high)
{
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
os_reportVerbosity = OS_REPORT_DEBUG;
OS_REPORT_STACK();
OS_WARNING(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
OS_REPORT_FLUSH(true);
check_existence(os_resultFail, os_resultSuccess);
os_reportExit();
remove_logs();
}
CU_Test(os_report, stack_verbosity_equal)
{
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
os_reportVerbosity = OS_REPORT_WARNING;
OS_REPORT_STACK();
OS_WARNING(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
OS_REPORT_FLUSH(true);
check_existence(os_resultFail, os_resultSuccess);
os_reportExit();
remove_logs();
}
CU_Test(os_report, no_log_append)
{
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
OS_ERROR(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
OS_INFO(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
check_existence(os_resultSuccess, os_resultSuccess);
os_reportExit();
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_LOGAPPEND=FALSE");
os_reportInit(true);
// Both logs should be deleted
check_existence(os_resultFail, os_resultFail);
os_reportExit();
remove_logs();
}
CU_Test(os_report, log_dir)
{
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_LOGPATH=.");
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
OS_ERROR(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
OS_INFO(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
check_existence(os_resultSuccess, os_resultSuccess);
os_reportExit();
remove_logs();
}
CU_Test(os_report, verbosity_env_value_info)
{
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=0");
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
OS_ERROR(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
OS_INFO(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
check_existence(os_resultSuccess, os_resultSuccess);
os_reportExit();
remove_logs();
//reset for other tests.
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=");
}
CU_Test(os_report, verbosity_env_value_error)
{
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=3");
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
OS_ERROR(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
OS_INFO(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
check_existence(os_resultSuccess, os_resultFail);
os_reportExit();
remove_logs();
//reset for other tests.
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=");
}
CU_Test(os_report, verbosity_env_value_error_as_string)
{
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=ERROR");
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
OS_ERROR(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
OS_DEBUG(OS_FUNCTION, 0, "os_report-info-test %d", __LINE__);
check_existence(os_resultSuccess, os_resultFail);
os_reportExit();
remove_logs();
//reset for other tests.
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=");
}
CU_Test(os_report, verbosity_wrong_env_value)
{
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=WRONG");
os_reportInit(true);
check_existence(os_resultFail, os_resultFail);
OS_ERROR(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
OS_DEBUG(OS_FUNCTION, 0, "os_report-error-test %d", __LINE__);
check_existence(os_resultSuccess, os_resultFail);
os_reportExit();
remove_logs();
//reset for other tests.
os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=");
}

View file

@ -12,261 +12,8 @@
#include "CUnit/Test.h"
#include "os/os.h"
#ifndef WINCE
#include <fcntl.h>
#endif
#if (defined WIN32 || defined WIN64)
#include <direct.h>
#include <Windows.h>
#endif
static const os_time wait_time_out = { 1, 0 };
static FILE *file;
#define ENABLE_TRACING 0
#define FLOCKFILE_THREAD1_INPUT1 "thread1_flockfile_proc: *** input 1 ***"
#define FLOCKFILE_THREAD1_INPUT3 "thread1_flockfile_proc: *** input 3 ***"
#define FLOCKFILE_THREAD2_INPUT2 "thread2_flockfile_proc: *** input 2 ***"
#define defSignal(signal) \
static os_cond signal;\
static bool signal##_set = false;
#define initSignal(signal, mutex) \
os_condInit(&signal, &mutex);\
signal##_set = false;
#define sendSignal(signal, mutex) \
os_mutexLock(&mutex);\
/* signaling */ \
signal##_set = true; \
os_condSignal(&signal);\
os_mutexUnlock(&mutex);
#define waitForSignal(signal, mutex) \
os_mutexLock(&mutex);\
while(!signal##_set) { \
/* waiting for signal */ \
os_condWait(&signal, &mutex);\
/* received */ \
} /* else already signal received */ \
os_mutexUnlock(&mutex);
#define timedWaitSignal(signal, mutex, time) \
{ \
os_time duration = time; \
os_time startTime, currentTime; \
os_result rc; \
os_mutexLock(&mutex); \
startTime = os_timeGetElapsed(); \
while(!signal##_set) { \
/* waiting for signal */ \
rc = os_condTimedWait(&signal, &mutex, &duration); \
/* signal received or timeout */ \
if(rc == os_resultTimeout) { \
break; \
} else { \
currentTime = os_timeGetElapsed(); \
if(os_timeCompare(os_timeSub(currentTime, startTime), wait_time_out) >= 0) { \
break; \
} \
duration = os_timeSub(wait_time_out, os_timeSub(currentTime, startTime)); \
} \
} /* else already signal received */ \
os_mutexUnlock(&mutex);\
}
static os_mutex mutex;
static bool do_locking;
/* signals set by threads */
defSignal(thread1_started);
defSignal(thread2_started);
defSignal(action1_done);
defSignal(action2_done);
/* signals set by the test orchestrator (doFlockfileTest) */
defSignal(do_action1);
defSignal(do_action2);
defSignal(do_action3);
static uint32_t thread1_flockfile_proc(void* args) {
int result = 0;
(void)args;
/* thread1: start */
sendSignal(thread1_started, mutex);
waitForSignal(do_action1, mutex);
if(do_locking) os_flockfile(file);
/* Thread1: writing input 1 to the file */
result = fputs(FLOCKFILE_THREAD1_INPUT1, file);
CU_ASSERT(result >= 0);
sendSignal(action1_done, mutex);
waitForSignal(do_action3, mutex);
/* Thread1: writing input 3 to the file */
result = fputs(FLOCKFILE_THREAD1_INPUT3, file);
CU_ASSERT(result >= 0);
if(do_locking) os_funlockfile(file);
/* thread1: end */
return 0;
}
static uint32_t thread2_flockfile_proc(void* args) {
int result = 0;
(void)args;
/* thread2: start */
sendSignal(thread2_started, mutex);
waitForSignal(do_action2, mutex);
/* Thread2: writing input 2 to the file */
result = fputs(FLOCKFILE_THREAD2_INPUT2, file);
CU_ASSERT(result >= 0);
sendSignal(action2_done, mutex);
/* thread2: end */
return 0;
}
bool doFlockfileTest(bool lock) {
bool testPassed = true;
bool strcmpResult = true;
os_result result;
os_threadAttr threadAttr;
os_threadId thread1;
os_threadId thread2;
int FLOCKFILE_INPUT_MAX = sizeof(FLOCKFILE_THREAD1_INPUT1);
do_locking = lock;
char *buffer = os_malloc(sizeof(char) * (unsigned)FLOCKFILE_INPUT_MAX);
file = tmpfile();
os_mutexInit(&mutex);
/* initialize all signal conditions */
os_mutexLock(&mutex);
initSignal(thread1_started, mutex);
initSignal(thread2_started, mutex);
initSignal(action1_done, mutex);
initSignal(action2_done, mutex);
initSignal(do_action1, mutex);
initSignal(do_action2, mutex);
initSignal(do_action3, mutex);
os_mutexUnlock(&mutex);
/* create threads... */
os_threadAttrInit(&threadAttr);
result = os_threadCreate(
&thread1,
"thread 1",
&threadAttr,
thread1_flockfile_proc,
NULL);
CU_ASSERT(result == os_resultSuccess);
result = os_threadCreate(
&thread2,
"thread 2",
&threadAttr,
thread2_flockfile_proc,
NULL);
CU_ASSERT(result == os_resultSuccess);
/* wait for threads to start */
waitForSignal(thread1_started, mutex);
waitForSignal(thread2_started, mutex);
/* get thread one to do its first thing */
sendSignal(do_action1, mutex);
/* wait for thread 1 to acknowledge */
timedWaitSignal(action1_done, mutex, wait_time_out);
/* kick thead 2 */
sendSignal(do_action2, mutex);
/* wait for thread 2 to acknowledge */
timedWaitSignal(action2_done, mutex, wait_time_out);
/* kick thread 1, again */
sendSignal(do_action3, mutex);
/* wait for threads to shutdown */
result = os_threadWaitExit(thread1,NULL);
CU_ASSERT(result == os_resultSuccess);
result = os_threadWaitExit(thread2,NULL);
CU_ASSERT(result == os_resultSuccess);
/* if lock then Expected action order: 1 3 2
* else Expected action order: 1 2 3 */
rewind(file);
if(lock) {
if(fgets(buffer, FLOCKFILE_INPUT_MAX, file) > (char*)0) {
strcmpResult = (strcmp(buffer, FLOCKFILE_THREAD1_INPUT1) == 0);
CU_ASSERT(strcmpResult);
testPassed = testPassed && strcmpResult; /* update flag indicating overall test state */
}
if(fgets(buffer, FLOCKFILE_INPUT_MAX, file) > (char*)0) {
strcmpResult = (strcmp(buffer, FLOCKFILE_THREAD1_INPUT3) == 0);
CU_ASSERT(strcmpResult);
testPassed = testPassed && strcmpResult; /* update flag indicating overall test state */
}
if(fgets(buffer, FLOCKFILE_INPUT_MAX, file) > (char*)0) {
strcmpResult = (strcmp(buffer, FLOCKFILE_THREAD2_INPUT2) == 0);
CU_ASSERT(strcmpResult);
testPassed = testPassed && strcmpResult; /* update flag indicating overall test state */
}
} else {
if(fgets(buffer, FLOCKFILE_INPUT_MAX, file) > (char*)0) {
strcmpResult = (strcmp(buffer, FLOCKFILE_THREAD1_INPUT1) == 0);
CU_ASSERT(strcmpResult);
testPassed = testPassed && strcmpResult; /* update flag indicating overall test state */
}
if(fgets(buffer, FLOCKFILE_INPUT_MAX, file) > (char*)0) {
strcmpResult = (strcmp(buffer, FLOCKFILE_THREAD2_INPUT2) == 0);
CU_ASSERT(strcmpResult);
testPassed = testPassed && strcmpResult; /* update flag indicating overall test state */
}
if(fgets(buffer, FLOCKFILE_INPUT_MAX, file) > (char*)0) {
strcmpResult = (strcmp(buffer, FLOCKFILE_THREAD1_INPUT3) == 0);
CU_ASSERT(strcmpResult);
testPassed = testPassed && strcmpResult; /* update flag indicating overall test state */
}
}
/* cleanup */
os_free(buffer);
fclose(file);
os_mutexLock(&mutex);
os_condDestroy(&do_action1);
os_condDestroy(&do_action2);
os_condDestroy(&do_action3);
os_condDestroy(&thread1_started);
os_condDestroy(&thread2_started);
os_condDestroy(&action1_done);
os_condDestroy(&action2_done);
os_mutexUnlock(&mutex);
os_mutexDestroy(&mutex);
/* doFlockfileTest */
return testPassed;
}
static int
vsnprintfTest(
const char *format,
@ -292,15 +39,8 @@ CU_Init(os_stdlib)
CU_Clean(os_stdlib)
{
/* Remove files used to test permissions */
remove ("exec_only");
remove ("read_exec");
remove ("read_only");
remove ("read_write_exec");
remove ("write_only");
remove ("existing_file");
os_osExit();
return 0;
os_osExit();
return 0;
}
CU_Test(os_stdlib, gethostname)
@ -356,254 +96,6 @@ CU_Test(os_stdlib, getenv)
printf ("Ending os_stdlib_getenv\n");
}
CU_Test(os_stdlib, fileSep)
{
#if defined WIN32
const char *wanted= "\\";
#else
const char *wanted= "/";
#endif
printf ("Starting os_stdlib_fileSep_001\n");
CU_ASSERT (strcmp(os_fileSep(), wanted) == 0);
printf ("Ending os_stdlib_fileSep\n");
}
CU_Test(os_stdlib, access)
{
os_result os_res;
os_result wanted;
int fh;
/* Check correct functioning of os_access, non existing file read access */
printf ("Starting os_stdlib_access_001\n");
#if defined VXWORKS_RTP || defined _WRS_KERNEL
printf ("N.A - Not tested for vxworks.\n");
#else
os_res = os_access("non_existing_file", OS_ROK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access, non existing file write access */
printf ("Starting os_stdlib_access_002\n");
os_res = os_access("non_existing_file", OS_WOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access, non existing file execute access */
printf ("Starting os_stdlib_access_003\n");
os_res = os_access("non_existing_file", OS_XOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access, non existing file existence */
printf ("Starting os_stdlib_access_004\n");
os_res = os_access("non_existing_file", OS_FOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access, existing file with no
permissions read access */
printf ("Starting os_stdlib_access_005\n");
#ifdef WIN32
fh= _creat("existing_file", 0000); /* Note always has read & execute */
if (fh != -1)
_close(fh);
wanted = os_resultSuccess;
#else
fh= creat("existing_file", 0000);
if (fh != -1)
close(fh);
wanted = os_resultFail;
#endif /* WIN32 */
os_res = os_access("existing_file", OS_ROK);
CU_ASSERT (os_res == wanted);
/* Check correct functioning of os_access, existing file with no
permissions write access */
printf ("Starting os_stdlib_access_006\n");
os_res = os_access("existing_file", OS_WOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access, existing file with no
permissions execute access */
printf ("Starting os_stdlib_access_007\n");
os_res = os_access("existing_file", OS_XOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access, existing file with no permissions existence */
printf ("Starting os_stdlib_access_008\n");
os_res = os_access("existing_file", OS_FOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with read permissions read access */
printf ("Starting os_stdlib_access_009\n");
#ifdef WIN32
fh= _creat("read_only", _S_IREAD); /* Note always has read & execute */
if (fh != -1)
_close(fh);
#else
fh= creat("read_only", S_IRUSR);
if (fh != -1)
close(fh);
#endif /* WIN32 */
os_res = os_access("read_only", OS_ROK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with read permissions write access */
printf ("Starting os_stdlib_access_010\n");
os_res = os_access("read_only", OS_WOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access,
existing file with read permissions execute access */
printf ("Starting os_stdlib_access_011\n");
os_res = os_access("read_only", OS_XOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access,
existing file with read permissions existence */
printf ("Starting os_stdlib_access_012\n");
os_res = os_access("read_only", OS_FOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with write permissions read access */
printf ("Starting os_stdlib_access_013\n");
#ifdef WIN32
fh= _creat("write_only", _S_IWRITE); /* Note windows automatically has read access can't have write only */
if (fh != -1)
_close(fh);
wanted = os_resultSuccess;
#else
fh= creat("write_only", S_IWUSR);
if (fh != -1)
close(fh);
wanted = os_resultFail;
#endif /* WIN32 */
os_res = os_access("write_only", OS_ROK);
CU_ASSERT (os_res == wanted);
/* Check correct functioning of os_access,
existing file with write permissions write access */
printf ("Starting os_stdlib_access_014\n");
os_res = os_access("write_only", OS_WOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with write permissions execute access */
printf ("Starting os_stdlib_access_015\n");
os_res = os_access("write_only", OS_XOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access,
existing file with write permissions existence */
printf ("Starting os_stdlib_access_016\n");
os_res = os_access("write_only", OS_FOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with exec permissions read access */
printf ("Starting os_stdlib_access_017\n");
#ifdef WIN32
fh= _creat("exec_only" OS_OS_EXESUFFIX, _S_IREAD); /* Windows always has read and can't do execute (that's based upon filename ext only) */
if (fh != -1)
_close(fh);
wanted = os_resultSuccess;
#else
fh= creat("exec_only" OS_OS_EXESUFFIX, S_IXUSR);
if (fh != -1)
close(fh);
wanted = os_resultFail;
#endif /* WIN32 */
os_res = os_access("exec_only" OS_OS_EXESUFFIX, OS_ROK);
CU_ASSERT (os_res == wanted);
/* Check correct functioning of os_access,
existing file with exec permissions write access */
printf ("Starting os_stdlib_access_018\n");
os_res = os_access("exec_only" OS_OS_EXESUFFIX, OS_WOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access,
existing file with exec permissions execute access */
printf ("Starting os_stdlib_access_019\n");
os_res = os_access("exec_only" OS_OS_EXESUFFIX, OS_XOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with exec permissions existence */
printf ("Starting os_stdlib_access_020\n");
os_res = os_access("exec_only" OS_OS_EXESUFFIX, OS_FOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with read/write/exec permissions read access */
printf ("Starting os_stdlib_access_021\n");
#ifdef WIN32
fh= _creat("read_write_exec" OS_OS_EXESUFFIX, _S_IREAD | _S_IWRITE); /* Windows always has read and can't do execute (that's based upon filename ext only) */
if (fh != -1)
_close(fh);
#else
fh= creat("read_write_exec" OS_OS_EXESUFFIX, S_IRUSR | S_IWUSR | S_IXUSR);
if (fh != -1)
close(fh);
#endif /* WIN32 */
os_res = os_access("read_write_exec" OS_OS_EXESUFFIX, OS_ROK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with read/write/exec permissions write access */
printf ("Starting os_stdlib_access_022\n");
os_res = os_access("read_write_exec" OS_OS_EXESUFFIX, OS_WOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with read/write/exec permissions execute access */
printf ("Starting os_stdlib_access_023\n");
os_res = os_access("read_write_exec" OS_OS_EXESUFFIX, OS_XOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with read/write/exec permissions existence */
printf ("Starting os_stdlib_access_024\n");
os_res = os_access("read_write_exec" OS_OS_EXESUFFIX, OS_FOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with read/exec permissions read+write access */
printf ("Starting os_stdlib_access_025\n");
#ifdef WIN32
fh= _creat("read_exec" OS_OS_EXESUFFIX, _S_IREAD); /* Windows always has read and can't do execute (that's based upon filename ext only) */
if (fh != -1)
_close(fh);
#else
fh= creat("read_exec" OS_OS_EXESUFFIX, S_IRUSR | S_IXUSR);
if (fh != -1)
close(fh);
#endif /* WIN32 */
os_res = os_access("read_exec" OS_OS_EXESUFFIX, OS_ROK|OS_WOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access,
existing file with read/exec permissions write+exec access */
printf ("Starting os_stdlib_access_026\n");
os_res = os_access("read_exec" OS_OS_EXESUFFIX, OS_WOK|OS_XOK);
CU_ASSERT (os_res == os_resultFail);
/* Check correct functioning of os_access,
existing file with read/exec permissions read+exec access */
printf ("Starting os_stdlib_access_027\n");
os_res = os_access("read_exec" OS_OS_EXESUFFIX, OS_ROK|OS_XOK);
CU_ASSERT (os_res == os_resultSuccess);
/* Check correct functioning of os_access,
existing file with read/exec permissions read+exec+existence */
printf ("Starting os_stdlib_access_028\n");
os_res = os_access("read_exec" OS_OS_EXESUFFIX, OS_ROK|OS_XOK|OS_FOK);
CU_ASSERT (os_res == os_resultSuccess);
#endif /* VXWORKS */
printf ("Ending stdlib_os_access\n");
}
CU_Test(os_stdlib, vsnprintf)
{
printf ("Starting os_stdlib_vsnprintf_001\n");
@ -694,27 +186,6 @@ CU_Test(os_stdlib, index)
printf ("Ending os_stdlib_index\n");
}
CU_Test(os_stdlib, flockfile)
{
bool result = false;
os_osInit();
/* Check writing in a FILE from multiple threads without using os_flockfile. */
printf ("Starting os_stdlib_flockfile_001\n");
result = doFlockfileTest(false);
CU_ASSERT (result);
/* Check writing in a FILE from multiple threads using os_flockfile in the first thread. */
printf ("Starting os_stdlib_flockfile_002\n");
result = doFlockfileTest(true);
CU_ASSERT (result);
printf ("Ending os_stdlib_flockfile\n");
os_osExit();
}
CU_Test(os_stdlib, getopt)
{
int c = 0;