Remove unnecessary CMake modules and fixup os/CMakeLists.txt

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2018-12-20 16:26:15 +01:00
parent 1990007614
commit e25656a4c5
39 changed files with 406 additions and 210 deletions

View file

@ -25,8 +25,9 @@ set(sources
"thread.c"
"thread_cleanup.c"
"strcasecmp.c"
"log.c")
"log.c"
"strlcpy.c")
add_cunit_executable(abstraction ${sources})
target_link_libraries(abstraction OSAPI)
add_cunit_executable(cunit_abstraction ${sources})
target_link_libraries(cunit_abstraction OSAPI)

View file

@ -81,6 +81,7 @@ FILE *fmemopen(void *buf, size_t size, const char *mode)
if (err) {
errno = err;
} else {
OS_WARNING_MSVC_OFF(4996);
if ((fd = _open_osfhandle((intptr_t)hdl, _O_APPEND)) == -1) {
/* errno set by _open_osfhandle. */
CloseHandle(hdl);
@ -90,6 +91,7 @@ FILE *fmemopen(void *buf, size_t size, const char *mode)
} else {
return fh;
}
OS_WARNING_MSVC_ON(4996);
}
return NULL;

View file

@ -355,7 +355,7 @@ CU_Test(os_rwlock, read, false)
printf ("concurrent_tryread_access = %d\n", sd.concurrent_tryread_access);
printf ("concurrent_trywrite_access = %d\n", sd.concurrent_trywrite_access);
sprintf (buffer, "Corrupt counter = %d, Loop counter is %d",
snprintf (buffer, sizeof(buffer), "Corrupt counter = %d, Loop counter is %d",
sd.read_corrupt_count + sd.write_corrupt_count + sd.tryread_corrupt_count + sd.trywrite_corrupt_count,
sd.concurrent_read_access + sd.concurrent_write_access + sd.concurrent_tryread_access + sd.concurrent_trywrite_access);
@ -419,7 +419,7 @@ CU_Test(os_rwlock, read, false)
par[i].read_access, par[i].concurrent_read_access, i);
}
sprintf (buffer, "Corrupt read counter = %d, Read loop counter is %d", sd.read_corrupt_count, sd.concurrent_read_access);
snprintf (buffer, sizeof(buffer), "Corrupt read counter = %d, Read loop counter is %d", sd.read_corrupt_count, sd.concurrent_read_access);
CU_ASSERT (sd.read_corrupt_count == 0 && sd.concurrent_read_access > 0);
/* Test read on rwlock with PRIVATE scope and Success result & not locked */
@ -443,7 +443,7 @@ CU_Test(os_rwlock, write, false)
/* Test critical section WRITE access with locking and PRIVATE scope */
printf ("Starting os_rwlock_write_001\n");
sprintf (buffer, "Corrupt write counter = %d, Write loop counter is %d", sd.write_corrupt_count, sd.concurrent_write_access);
snprintf (buffer, sizeof(buffer), "Corrupt write counter = %d, Write loop counter is %d", sd.write_corrupt_count, sd.concurrent_write_access);
CU_ASSERT (sd.write_corrupt_count == 0 && sd.concurrent_write_access > 0);
/* Test write on rwlock with PRIVATE scope and Success result */
@ -464,7 +464,7 @@ CU_Test(rwlock, tryread, false)
/* Test critical section READ access with trylocking and PRIVATE scope */
printf ("Starting os_rwlock_tryread_001\n");
sprintf (buffer, "Corrupt tryread counter = %d, Tryread loop counter is %d, Busy counter = %d", sd.tryread_corrupt_count, sd.concurrent_tryread_access, sd.tryread_busy_count);
snprintf (buffer, sizeof(buffer), "Corrupt tryread counter = %d, Tryread loop counter is %d, Busy counter = %d", sd.tryread_corrupt_count, sd.concurrent_tryread_access, sd.tryread_busy_count);
CU_ASSERT (sd.tryread_corrupt_count == 0 && sd.concurrent_tryread_access > 0);
/* Test try read on rwlock with PRIVATE scope and Success result & not locked */
@ -494,7 +494,7 @@ CU_Test(os_rwlock, trywrite, false)
/* Test critical section WRITE access with trylocking and PRIVATE scope */
printf ("Starting os_rwlock_trywrite_001\n");
sprintf (buffer, "Corrupt trywrite counter = %d, Trywrite loop counter is %d, Busy counter = %d", sd.trywrite_corrupt_count, sd.concurrent_trywrite_access, sd.trywrite_busy_count);
snprintf (buffer, sizeof(buffer), "Corrupt trywrite counter = %d, Trywrite loop counter is %d, Busy counter = %d", sd.trywrite_corrupt_count, sd.concurrent_trywrite_access, sd.trywrite_busy_count);
CU_ASSERT (sd.trywrite_corrupt_count == 0 && sd.concurrent_trywrite_access > 0);
/* Test try write on rwlock with PRIVATE scope and Success result */

80
src/os/tests/strlcpy.c Normal file
View file

@ -0,0 +1,80 @@
/*
* 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 <stdio.h>
#include <string.h>
#include "os/os.h"
#include "CUnit/Theory.h"
CU_TheoryDataPoints(os_strlcpy, dest_size) = {
CU_DataPoints(char *, "foo", "foo", "foo", "foo", "foo", "", "", ""),
CU_DataPoints(size_t, 0, 1, 3, 4, 5, 0, 1, 2)
};
CU_Theory((char *src, size_t size), os_strlcpy, dest_size)
{
char dest[] = "................";
size_t len, srclen;
srclen = strlen(src);
len = os_strlcpy(dest, src, size);
CU_ASSERT_EQUAL(len, srclen);
if (size > 0) {
if ((size - 1) < len) {
len = size - 1;
}
CU_ASSERT_EQUAL(dest[len], '\0');
CU_ASSERT_EQUAL(dest[len+1], '.');
CU_ASSERT((strncmp(dest, src, len) == 0));
} else {
CU_ASSERT_EQUAL(dest[0], '.');
}
}
CU_TheoryDataPoints(os_strlcat, dest_size) = {
CU_DataPoints(char *, "", "", "", "", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "", "", "foo", "foo", "foo"),
CU_DataPoints(char *, "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "", "", "", "", ""),
CU_DataPoints(size_t, 0, 1, 3, 4, 0, 1, 3, 4, 5, 6, 7, 0, 1, 3, 4, 5)
};
CU_Theory((char *seed, char *src, size_t size), os_strlcat, dest_size)
{
char dest[] = "................";
size_t len, seedlen, srclen;
seedlen = strlen(seed);
srclen = strlen(src);
memcpy(dest, seed, seedlen);
dest[seedlen] = '\0';
len = os_strlcat(dest, src, size);
CU_ASSERT_EQUAL(len, (seedlen + srclen));
if (size > 0) {
char foobar[sizeof(dest)];
if ((size - 1) <= seedlen) {
len = seedlen;
} else if ((size - 1) <= len) {
len = size - 1;
}
CU_ASSERT_EQUAL(dest[len], '\0');
if (seedlen < (size - 1)) {
CU_ASSERT_EQUAL(dest[len+1], '.');
}
(void)snprintf(foobar, len+1, "%s%s", seed, src);
CU_ASSERT((strncmp(dest, foobar, len) == 0));
} else {
CU_ASSERT((strcmp(dest, seed) == 0));
}
}