Skip to content

Commit f34de36

Browse files
committed
os/posix: port of the posix implementation to macOS
1 parent 2a2defb commit f34de36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3376
-41
lines changed

.github/workflows/ci-macos.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI macOS
2+
3+
on: push
4+
5+
jobs:
6+
test:
7+
name: Test job
8+
runs-on: macOS-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
with:
12+
submodules: true
13+
14+
- name: "Run CI task"
15+
run: |
16+
make test
17+
18+
# TODO: The timer-add-api-test test is known to fail sometimes on GitHub Actions (both macOS and Linux, but macOS
19+
# is more often). The current hypothesis is that the timer cannot catch up when running on the (elastic) VMs.
20+
# Run tests more than once to increase the reproducibility.
21+
# Revert this change when the macOS branch is ready and create a separate ticket to track this for macOS and
22+
# Linux.
23+
- name: "Run flaky CI task #1"
24+
run: |
25+
make test_flaky
26+
27+
- name: "Run flaky CI task #2"
28+
run: |
29+
make test_flaky
30+
31+
- name: "Run flaky CI task #3"
32+
run: |
33+
make test_flaky
34+
35+
- name: "Run flaky CI task #4"
36+
run: |
37+
make test_flaky
38+
39+
- name: "Run flaky CI task #5"
40+
run: |
41+
make test_flaky
42+
43+
- name: "Run flaky CI task #6"
44+
run: |
45+
make test_flaky
46+
47+
- name: "Run flaky CI task #7"
48+
run: |
49+
make test_flaky
50+
51+
- name: "Run flaky CI task #8"
52+
run: |
53+
make test_flaky
54+
55+
- name: "Run flaky CI task #9"
56+
run: |
57+
make test_flaky
58+
59+
- name: "Run flaky CI task #10"
60+
run: |
61+
make test_flaky

.github/workflows/local_unit_test.yml

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
Local-Unit-Test:
1010
runs-on: ubuntu-18.04
11-
timeout-minutes: 15
11+
timeout-minutes: 30
1212

1313
steps:
1414
- name: Install coverage tools
@@ -26,6 +26,24 @@ jobs:
2626
run: make -j
2727

2828
# Baseline lcov and run all tests
29+
30+
# TODO: The timer-add-api-test test is known to fail sometimes on GitHub Actions (both macOS and Linux, but macOS
31+
# is more often). The current hypothesis is that the timer cannot catch up when running on the (elastic) VMs.
32+
# Run tests more than once to increase the reproducibility.
33+
# Revert this change when the macOS branch is ready and create a separate ticket to track this for macOS and
34+
# Linux.
35+
- name: Test
36+
run: make test
37+
38+
- name: Test
39+
run: make test
40+
41+
- name: Test
42+
run: make test
43+
44+
- name: Test
45+
run: make test
46+
2947
- name: Test
3048
run: make test
3149

CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
cmake_minimum_required(VERSION 2.8.12)
4444
project(OSAL C)
4545

46+
# TODO: Where to integrate this?
47+
if (APPLE)
48+
add_compile_options(
49+
-Wall -Werror
50+
-Wno-non-literal-null-conversion
51+
)
52+
endif ()
53+
4654
# The "OSAL_EXT_SOURCE_DIR" cache variable may be set to a path
4755
# on the host containing extra OS/BSP implementations which are not
4856
# part of the open source release.
@@ -144,7 +152,9 @@ if (DEFINED OSAL_EXPECTED_OSTYPE)
144152
elseif(NOT OSAL_SYSTEM_OSTYPE STREQUAL OSAL_EXPECTED_OSTYPE)
145153
# Generate a warning about the OSTYPE not being expected.
146154
# Not calling this a fatal error because it could possibly be intended during development
147-
message(WARNING "Mismatched BSP/OS: ${OSAL_SYSTEM_BSPTYPE} implies ${OSAL_EXPECTED_OSTYPE}, but ${OSAL_SYSTEM_OSTYPE} is configured")
155+
156+
# TODO: How to integrate -DOSAL_SYSTEM_BSPTYPE=generic-linux -DOSAL_SYSTEM_OSTYPE=posixmacos?
157+
# message(WARNING "Mismatched BSP/OS: ${OSAL_SYSTEM_BSPTYPE} implies ${OSAL_EXPECTED_OSTYPE}, but ${OSAL_SYSTEM_OSTYPE} is configured")
148158
endif(NOT DEFINED OSAL_SYSTEM_OSTYPE)
149159
endif (DEFINED OSAL_EXPECTED_OSTYPE)
150160

Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
default:
3+
mkdir -p build
4+
cd build && cmake -DENABLE_UNIT_TESTS=true -DCMAKE_VERBOSE_MAKEFILE=1 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DOSAL_SYSTEM_BSPTYPE=generic-linux -DOSAL_SYSTEM_OSTYPE=posixmacos --graphviz=test.dot ..
5+
# dot -Tpng build/test.dot -o build/graph.png
6+
cd build && make
7+
8+
test: default
9+
cd build && CTEST_OUTPUT_ON_FAILURE=1 make test
10+
11+
test_flaky: default
12+
cd build && CTEST_OUTPUT_ON_FAILURE=1 ctest --output-on-failure -R timer-add-api-test
13+
cd build && CTEST_OUTPUT_ON_FAILURE=1 ctest --output-on-failure -R queue-test
14+
cd build && CTEST_OUTPUT_ON_FAILURE=1 ctest --output-on-failure -R sem-speed-test

src/bsp/generic-linux/build_options.cmake

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ target_link_libraries(osal_bsp
1818
# Note - although GCC understands the same flags for compile and link here, this may
1919
# not be true on all platforms so the compile and link flags are specified separately.
2020
if (NOT CMAKE_CROSSCOMPILING)
21-
set(UT_COVERAGE_COMPILE_FLAGS -pg --coverage)
22-
set(UT_COVERAGE_LINK_FLAGS -pg --coverage)
21+
if(APPLE)
22+
set(UT_COVERAGE_COMPILE_FLAGS --coverage)
23+
set(UT_COVERAGE_LINK_FLAGS --coverage)
24+
else()
25+
set(UT_COVERAGE_COMPILE_FLAGS -pg --coverage)
26+
set(UT_COVERAGE_LINK_FLAGS -pg --coverage)
27+
endif()
2328
endif()

src/os/inc/common_types.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ extern "C"
6060
** macro to disable this.
6161
*/
6262
#if defined(__GNUC__) && !defined(OSAPI_NO_SPECIAL_ATTRIBS)
63-
#define _EXTENSION_ __extension__
64-
#define OS_USED __attribute__((used))
63+
#define _EXTENSION_ __extension__
64+
#ifndef __APPLE__
65+
#define OS_USED __attribute__((used))
66+
#endif
6567
#define OS_PRINTF(n, m) __attribute__((format(printf, n, m)))
6668
#else
6769
#define _EXTENSION_

src/os/posix/inc/os-impl-console.h

+4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
#include <stdbool.h>
3232
#include "osconfig.h"
3333
#include <unistd.h>
34+
#ifndef __APPLE__
3435
#include <semaphore.h>
36+
#else
37+
#include <posix-macos-semaphore.h>
38+
#endif
3539

3640
/* Console device */
3741
typedef struct

src/os/posix/inc/os-impl-countsem.h

+5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
#define OS_IMPL_COUNTSEM_H
3030

3131
#include "osconfig.h"
32+
33+
#ifndef __APPLE__
3234
#include <semaphore.h>
35+
#else
36+
#include <posix-macos-semaphore.h>
37+
#endif
3338

3439
typedef struct
3540
{

src/os/posix/inc/os-impl-timebase.h

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include "osconfig.h"
3232
#include <pthread.h>
3333
#include <signal.h>
34+
#ifdef __APPLE__
35+
#include <posix-macos-timer.h>
36+
#endif
3437

3538
typedef struct
3639
{

src/os/posix/inc/os-posix.h

+4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@
4545
#include <pthread.h>
4646
#include <mqueue.h>
4747
#include <fcntl.h>
48+
#ifndef __APPLE__
4849
#include <semaphore.h>
50+
#else
51+
#include <posix-macos-semaphore.h>
52+
#endif
4953
#include <sys/types.h>
5054
#include <sys/signal.h>
5155

src/os/posix/src/os-impl-binsem.c

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include "os-shared-binsem.h"
3737
#include "os-impl-binsem.h"
3838

39+
#ifdef __APPLE__
40+
#include <posix-macos-pthread.h>
41+
#endif
42+
3943
/*
4044
* This controls the maximum time that the calling thread will wait to
4145
* acquire the condition mutex before returning an error.

src/os/posix/src/os-impl-filesys.c

+2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
#include <sys/statvfs.h>
4141
#include <sys/stat.h>
4242
#include <sys/mount.h>
43+
#ifndef __APPLE__
4344
#include <sys/vfs.h>
45+
#endif
4446

4547
#include "os-posix.h"
4648
#include "os-shared-filesys.h"

src/os/posixmacos/CMakeLists.txt

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
######################################################################
2+
#
3+
# CMAKE build recipe for POSIX OSAL implementation
4+
#
5+
######################################################################
6+
7+
# This CMake script generates targets specific to the POSIX implementation
8+
set(POSIX_BASE_MAIN_INCLIST_DIR ${CMAKE_SOURCE_DIR}/src/os/posix/inc)
9+
set(POSIX_BASE_MAIN_SRCLIST_DIR ${CMAKE_SOURCE_DIR}/src/os/posix/src)
10+
11+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
12+
include_directories(${POSIX_BASE_MAIN_INCLIST_DIR})
13+
14+
# The basic set of files which are always built
15+
set(POSIX_BASE_SRCLIST
16+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-binsem.c
17+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-common.c
18+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-console.c
19+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-countsem.c
20+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-dirs.c
21+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-errors.c
22+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-files.c
23+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-filesys.c
24+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-heap.c
25+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-idmap.c
26+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-mutex.c
27+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-queues.c
28+
src/os-impl-tasks.c
29+
src/os-impl-timebase.c
30+
)
31+
32+
set(POSIX_MACOS_SRCLIST
33+
src/posix-macos-addons/semaphore/posix-macos-semaphore.c
34+
src/posix-macos-addons/mqueue/mq_internal_fs.c
35+
src/posix-macos-addons/mqueue/mq_notify.c
36+
src/posix-macos-addons/mqueue/mq_open.c
37+
src/posix-macos-addons/mqueue/mq_receive.c
38+
src/posix-macos-addons/mqueue/mq_timedreceive.c
39+
src/posix-macos-addons/mqueue/mq_timedsend.c
40+
src/posix-macos-addons/mqueue/mq_close.c
41+
src/posix-macos-addons/mqueue/mq_unlink.c
42+
src/posix-macos-addons/pthread/posix-macos-pthread.c
43+
src/posix-macos-addons/time/posix-macos-time.c
44+
src/posix-macos-addons/timer/posix-macos-timer.c
45+
)
46+
47+
add_library(rt src/posix-macos-addons/stubs/rt.c)
48+
49+
# Use portable blocks for basic I/O
50+
set(POSIX_IMPL_SRCLIST
51+
../portable/os-impl-posix-gettime.c
52+
../portable/os-impl-console-bsp.c
53+
../portable/os-impl-bsd-select.c
54+
../portable/os-impl-posix-io.c
55+
../portable/os-impl-posix-files.c
56+
../portable/os-impl-posix-dirs.c
57+
)
58+
59+
if (OSAL_CONFIG_INCLUDE_SHELL)
60+
list(APPEND POSIX_IMPL_SRCLIST
61+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-shell.c
62+
)
63+
else ()
64+
list(APPEND POSIX_IMPL_SRCLIST
65+
../portable/os-impl-no-shell.c
66+
)
67+
endif ()
68+
69+
# If some form of module loading is configured,
70+
# then build the module loader
71+
if (OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER)
72+
list(APPEND POSIX_IMPL_SRCLIST
73+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-loader.c
74+
../portable/os-impl-posix-dl-loader.c
75+
../portable/os-impl-posix-dl-symtab.c
76+
)
77+
else ()
78+
list(APPEND POSIX_IMPL_SRCLIST
79+
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-no-module.c
80+
../portable/os-impl-no-loader.c
81+
../portable/os-impl-no-symtab.c
82+
)
83+
endif ()
84+
85+
if (OSAL_CONFIG_INCLUDE_NETWORK)
86+
list(APPEND POSIX_IMPL_SRCLIST
87+
../portable/os-impl-bsd-sockets.c # Use BSD socket layer implementation
88+
../portable/os-impl-posix-network.c # Use POSIX-defined hostname/id implementation
89+
)
90+
else()
91+
list(APPEND POSIX_IMPL_SRCLIST
92+
../portable/os-impl-no-network.c # non-implemented versions of all network APIs
93+
../portable/os-impl-no-sockets.c # non-implemented versions of all socket APIs
94+
)
95+
endif ()
96+
97+
# Defines an OBJECT target named "osal_posix_impl" with selected source files
98+
add_library(osal_posixmacos_impl OBJECT
99+
${POSIX_BASE_SRCLIST}
100+
${POSIX_MACOS_SRCLIST}
101+
${POSIX_IMPL_SRCLIST}
102+
)
103+
104+
target_link_libraries(osal_posixmacos_impl PUBLIC posix-macos-addons)
105+
106+
# TODO: Defining this globally but can be made more focused.
107+
# /usr/include/sys/ucred.h:96:11: error: unknown type name 'u_long'; did you mean 'long'?
108+
# volatile u_long cr_ref; /* reference count */
109+
target_compile_definitions(osal_posixmacos_impl PRIVATE -D_DARWIN_C_SOURCE)

src/os/posixmacos/build_options.cmake

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
##########################################################################
2+
#
3+
# Build options for "posix" implementation layer
4+
#
5+
##########################################################################
6+
7+
# this file is a placeholder for POSIX-specific compile tuning
8+
# currently no extra flags/definitions needed
9+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef _MQUEUE_INTERNAL_H_
2+
#define _MQUEUE_INTERNAL_H_
3+
4+
#include <stddef.h>
5+
6+
#ifdef __cplusplus
7+
extern "C"
8+
{
9+
#endif
10+
11+
extern const size_t MQ_FS_NAME_MAX;
12+
int mq_get_fs_pathname(const char *const pathname, char *const out_pathname);
13+
14+
#ifdef __cplusplus
15+
}
16+
#endif
17+
18+
#endif /* _MQUEUE_INTERNAL_H_ */

0 commit comments

Comments
 (0)