Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/posix: port of the posix implementation to macOS (take 2) #1161

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CI macOS

on: push

jobs:
test:
name: Test job
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: "Run CI task"
run: |
make test

# TODO: The timer-add-api-test test is known to fail sometimes on GitHub Actions (both macOS and Linux, but macOS
# is more often). The current hypothesis is that the timer cannot catch up when running on the (elastic) VMs.
# Run tests more than once to increase the reproducibility.
# Revert this change when the macOS branch is ready and create a separate ticket to track this for macOS and
# Linux.
- name: "Run flaky CI task #1"
run: |
make test_flaky

- name: "Run flaky CI task #2"
run: |
make test_flaky

- name: "Run flaky CI task #3"
run: |
make test_flaky

- name: "Run flaky CI task #4"
run: |
make test_flaky

- name: "Run flaky CI task #5"
run: |
make test_flaky

- name: "Run flaky CI task #6"
run: |
make test_flaky

- name: "Run flaky CI task #7"
run: |
make test_flaky

- name: "Run flaky CI task #8"
run: |
make test_flaky

- name: "Run flaky CI task #9"
run: |
make test_flaky

- name: "Run flaky CI task #10"
run: |
make test_flaky
20 changes: 19 additions & 1 deletion .github/workflows/local_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

Local-Unit-Test:
runs-on: ubuntu-18.04
timeout-minutes: 15
timeout-minutes: 30

steps:
- name: Install coverage tools
Expand All @@ -26,6 +26,24 @@ jobs:
run: make -j

# Baseline lcov and run all tests

# TODO: The timer-add-api-test test is known to fail sometimes on GitHub Actions (both macOS and Linux, but macOS
# is more often). The current hypothesis is that the timer cannot catch up when running on the (elastic) VMs.
# Run tests more than once to increase the reproducibility.
# Revert this change when the macOS branch is ready and create a separate ticket to track this for macOS and
# Linux.
- name: Test
run: make test

- name: Test
run: make test

- name: Test
run: make test

- name: Test
run: make test

- name: Test
run: make test

Expand Down
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
cmake_minimum_required(VERSION 2.8.12)
project(OSAL C)

# TODO: Where to integrate this?
if (APPLE)
add_compile_options(
-Wall -Werror
-Wno-non-literal-null-conversion
)
endif ()

# The "OSAL_EXT_SOURCE_DIR" cache variable may be set to a path
# on the host containing extra OS/BSP implementations which are not
# part of the open source release.
Expand Down Expand Up @@ -144,7 +152,9 @@ if (DEFINED OSAL_EXPECTED_OSTYPE)
elseif(NOT OSAL_SYSTEM_OSTYPE STREQUAL OSAL_EXPECTED_OSTYPE)
# Generate a warning about the OSTYPE not being expected.
# Not calling this a fatal error because it could possibly be intended during development
message(WARNING "Mismatched BSP/OS: ${OSAL_SYSTEM_BSPTYPE} implies ${OSAL_EXPECTED_OSTYPE}, but ${OSAL_SYSTEM_OSTYPE} is configured")

# TODO: How to integrate -DOSAL_SYSTEM_BSPTYPE=generic-linux -DOSAL_SYSTEM_OSTYPE=posixmacos?
# message(WARNING "Mismatched BSP/OS: ${OSAL_SYSTEM_BSPTYPE} implies ${OSAL_EXPECTED_OSTYPE}, but ${OSAL_SYSTEM_OSTYPE} is configured")
endif(NOT DEFINED OSAL_SYSTEM_OSTYPE)
endif (DEFINED OSAL_EXPECTED_OSTYPE)

Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

default:
mkdir -p build
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 ..
# dot -Tpng build/test.dot -o build/graph.png
cd build && make

test: default
cd build && CTEST_OUTPUT_ON_FAILURE=1 make test

test_flaky: default
cd build && CTEST_OUTPUT_ON_FAILURE=1 ctest --output-on-failure -R timer-add-api-test
cd build && CTEST_OUTPUT_ON_FAILURE=1 ctest --output-on-failure -R queue-test
cd build && CTEST_OUTPUT_ON_FAILURE=1 ctest --output-on-failure -R sem-speed-test
9 changes: 7 additions & 2 deletions src/bsp/generic-linux/build_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ target_link_libraries(osal_bsp
# Note - although GCC understands the same flags for compile and link here, this may
# not be true on all platforms so the compile and link flags are specified separately.
if (NOT CMAKE_CROSSCOMPILING)
set(UT_COVERAGE_COMPILE_FLAGS -pg --coverage)
set(UT_COVERAGE_LINK_FLAGS -pg --coverage)
if(APPLE)
set(UT_COVERAGE_COMPILE_FLAGS --coverage)
set(UT_COVERAGE_LINK_FLAGS --coverage)
else()
set(UT_COVERAGE_COMPILE_FLAGS -pg --coverage)
set(UT_COVERAGE_LINK_FLAGS -pg --coverage)
endif()
endif()
6 changes: 4 additions & 2 deletions src/os/inc/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ extern "C"
** macro to disable this.
*/
#if defined(__GNUC__) && !defined(OSAPI_NO_SPECIAL_ATTRIBS)
#define _EXTENSION_ __extension__
#define OS_USED __attribute__((used))
#define _EXTENSION_ __extension__
#ifndef __APPLE__
#define OS_USED __attribute__((used))
#endif
#define OS_PRINTF(n, m) __attribute__((format(printf, n, m)))
#else
#define _EXTENSION_
Expand Down
4 changes: 4 additions & 0 deletions src/os/posix/inc/os-impl-console.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
#include <stdbool.h>
#include "osconfig.h"
#include <unistd.h>
#ifndef __APPLE__
#include <semaphore.h>
#else
#include <posix-macos-semaphore.h>
#endif

/* Console device */
typedef struct
Expand Down
5 changes: 5 additions & 0 deletions src/os/posix/inc/os-impl-countsem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
#define OS_IMPL_COUNTSEM_H

#include "osconfig.h"

#ifndef __APPLE__
#include <semaphore.h>
#else
#include <posix-macos-semaphore.h>
#endif

typedef struct
{
Expand Down
3 changes: 3 additions & 0 deletions src/os/posix/inc/os-impl-timebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "osconfig.h"
#include <pthread.h>
#include <signal.h>
#ifdef __APPLE__
#include <posix-macos-timer.h>
#endif

typedef struct
{
Expand Down
4 changes: 4 additions & 0 deletions src/os/posix/inc/os-posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
#include <pthread.h>
#include <mqueue.h>
#include <fcntl.h>
#ifndef __APPLE__
#include <semaphore.h>
#else
#include <posix-macos-semaphore.h>
#endif
#include <sys/types.h>
#include <sys/signal.h>

Expand Down
4 changes: 4 additions & 0 deletions src/os/posix/src/os-impl-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include "os-shared-binsem.h"
#include "os-impl-binsem.h"

#ifdef __APPLE__
#include <posix-macos-pthread.h>
#endif

/*
* This controls the maximum time that the calling thread will wait to
* acquire the condition mutex before returning an error.
Expand Down
2 changes: 2 additions & 0 deletions src/os/posix/src/os-impl-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
#include <sys/statvfs.h>
#include <sys/stat.h>
#include <sys/mount.h>
#ifndef __APPLE__
#include <sys/vfs.h>
#endif

#include "os-posix.h"
#include "os-shared-filesys.h"
Expand Down
109 changes: 109 additions & 0 deletions src/os/posixmacos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
######################################################################
#
# CMAKE build recipe for POSIX OSAL implementation
#
######################################################################

# This CMake script generates targets specific to the POSIX implementation
set(POSIX_BASE_MAIN_INCLIST_DIR ${CMAKE_SOURCE_DIR}/src/os/posix/inc)
set(POSIX_BASE_MAIN_SRCLIST_DIR ${CMAKE_SOURCE_DIR}/src/os/posix/src)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
include_directories(${POSIX_BASE_MAIN_INCLIST_DIR})

# The basic set of files which are always built
set(POSIX_BASE_SRCLIST
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-binsem.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-common.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-console.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-countsem.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-dirs.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-errors.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-files.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-filesys.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-heap.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-idmap.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-mutex.c
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-queues.c
src/os-impl-tasks.c
src/os-impl-timebase.c
)

set(POSIX_MACOS_SRCLIST
src/posix-macos-addons/semaphore/posix-macos-semaphore.c
src/posix-macos-addons/mqueue/mq_internal_fs.c
src/posix-macos-addons/mqueue/mq_notify.c
src/posix-macos-addons/mqueue/mq_open.c
src/posix-macos-addons/mqueue/mq_receive.c
src/posix-macos-addons/mqueue/mq_timedreceive.c
src/posix-macos-addons/mqueue/mq_timedsend.c
src/posix-macos-addons/mqueue/mq_close.c
src/posix-macos-addons/mqueue/mq_unlink.c
src/posix-macos-addons/pthread/posix-macos-pthread.c
src/posix-macos-addons/time/posix-macos-time.c
src/posix-macos-addons/timer/posix-macos-timer.c
)

add_library(rt src/posix-macos-addons/stubs/rt.c)

# Use portable blocks for basic I/O
set(POSIX_IMPL_SRCLIST
../portable/os-impl-posix-gettime.c
../portable/os-impl-console-bsp.c
../portable/os-impl-bsd-select.c
../portable/os-impl-posix-io.c
../portable/os-impl-posix-files.c
../portable/os-impl-posix-dirs.c
)

if (OSAL_CONFIG_INCLUDE_SHELL)
list(APPEND POSIX_IMPL_SRCLIST
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-shell.c
)
else ()
list(APPEND POSIX_IMPL_SRCLIST
../portable/os-impl-no-shell.c
)
endif ()

# If some form of module loading is configured,
# then build the module loader
if (OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER)
list(APPEND POSIX_IMPL_SRCLIST
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-loader.c
../portable/os-impl-posix-dl-loader.c
../portable/os-impl-posix-dl-symtab.c
)
else ()
list(APPEND POSIX_IMPL_SRCLIST
${POSIX_BASE_MAIN_SRCLIST_DIR}/os-impl-no-module.c
../portable/os-impl-no-loader.c
../portable/os-impl-no-symtab.c
)
endif ()

if (OSAL_CONFIG_INCLUDE_NETWORK)
list(APPEND POSIX_IMPL_SRCLIST
../portable/os-impl-bsd-sockets.c # Use BSD socket layer implementation
../portable/os-impl-posix-network.c # Use POSIX-defined hostname/id implementation
)
else()
list(APPEND POSIX_IMPL_SRCLIST
../portable/os-impl-no-network.c # non-implemented versions of all network APIs
../portable/os-impl-no-sockets.c # non-implemented versions of all socket APIs
)
endif ()

# Defines an OBJECT target named "osal_posix_impl" with selected source files
add_library(osal_posixmacos_impl OBJECT
${POSIX_BASE_SRCLIST}
${POSIX_MACOS_SRCLIST}
${POSIX_IMPL_SRCLIST}
)

target_link_libraries(osal_posixmacos_impl PUBLIC posix-macos-addons)

# TODO: Defining this globally but can be made more focused.
# /usr/include/sys/ucred.h:96:11: error: unknown type name 'u_long'; did you mean 'long'?
# volatile u_long cr_ref; /* reference count */
target_compile_definitions(osal_posixmacos_impl PRIVATE -D_DARWIN_C_SOURCE)
9 changes: 9 additions & 0 deletions src/os/posixmacos/build_options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
##########################################################################
#
# Build options for "posix" implementation layer
#
##########################################################################

# this file is a placeholder for POSIX-specific compile tuning
# currently no extra flags/definitions needed

18 changes: 18 additions & 0 deletions src/os/posixmacos/inc/mqueue-internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _MQUEUE_INTERNAL_H_
#define _MQUEUE_INTERNAL_H_

#include <stddef.h>

#ifdef __cplusplus
extern "C"
{
#endif

extern const size_t MQ_FS_NAME_MAX;
int mq_get_fs_pathname(const char *const pathname, char *const out_pathname);

#ifdef __cplusplus
}
#endif

#endif /* _MQUEUE_INTERNAL_H_ */
Loading