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

port for QNX7.1/8.0 #1446

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions asio/include/asio/detail/impl/posix_thread.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2023, BlackBerry Limited. All Rights Reserved.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"All Rights Reserved" isn't going to fly with the Boost Software License.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -47,6 +48,11 @@ std::size_t posix_thread::hardware_concurrency()
{
#if defined(_SC_NPROCESSORS_ONLN)
long result = sysconf(_SC_NPROCESSORS_ONLN);

#if defined(__QNX__)
result &= 0xFFFFFFFF;
#endif //defined(__QNX__)

if (result > 0)
return result;
#endif // defined(_SC_NPROCESSORS_ONLN)
Expand Down
9 changes: 8 additions & 1 deletion asio/include/asio/detail/socket_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2024, BlackBerry Limited. All Rights Reserved.
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -411,7 +412,13 @@ const int max_iov_len = IOV_MAX;
// POSIX platforms are not required to define IOV_MAX.
const int max_iov_len = 16;
# endif
# define ASIO_OS_DEF_SA_RESTART SA_RESTART
// Note: QNX does not support SA_RESTART
// Therefore they are specifically excluded here.
# if defined(__QNX__)
# define ASIO_OS_DEF_SA_RESTART 0
# else
# define ASIO_OS_DEF_SA_RESTART SA_RESTART
# endif
# define ASIO_OS_DEF_SA_NOCLDSTOP SA_NOCLDSTOP
# define ASIO_OS_DEF_SA_NOCLDWAIT SA_NOCLDWAIT
#endif
Expand Down
6 changes: 6 additions & 0 deletions asio/qnx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# QNX Build Files
build/nto-aarch64-le/*
build/nto-x86_64-o/*
!build/Makefile
!build/nto-aarch64-le/GNUmakefile
!build/nto-x86_64-o/GNUmakefile
30 changes: 30 additions & 0 deletions asio/qnx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Compile the port for QNX

**NOTE**: QNX ports are only supported from a **Linux host** operating system

### Install dependencies

`sudo apt install automake`

`sudo apt install pkg-config`

### Switch to asio main folder

`cd asio`

### Generate GNU build tool ./configure and all needed Makefiles

`./autogen.sh`

### Setup QNX SDP environment

`source <path-to-sdp>/qnxsdp-env.sh`

### Build examples and install asio headers into SDP

`JLEVEL=$(nproc) make -C qnx/build install`


**All asio headers have to be installed to SDP**
* $QNX_TARGET/usr/include/asio/
* $QNX_TARGET/usr/include/asio.hpp
3 changes: 3 additions & 0 deletions asio/qnx/build/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LIST=OS CPU VARIANT
MAKEFILE=GNUmakefile
include recurse.mk
160 changes: 160 additions & 0 deletions asio/qnx/build/build-hooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/bin/sh

#
# QNX specific build configuration nested level
#
NESTED_LEVEL="../../.."

#
# Setup of essential configuration parameters
#
function hook_preconfigure {
#
# QNX specific changes are covered by prediefined '__QNX__'
# For examples: "fd_passing_stream_server" and "fd_passing_stream_client"
# For the testsuites: unit/ip/multicast
#
CXXFLAGS="$CXXFLAGS -DASIO_HAS_PTHREADS -DASIO_HAS_STD_STRING_VIEW -DASIO_HAS_CONSTEXPR -DASIO_HAS_STD_FUTURE_CLASS"

#
# Add socket library
#
LDFLAGS="$LDFLAGS -lsocket"

#
# Distributive directory
#
DIST_BASE="${PWD}/${NESTED_LEVEL}"

#
# Setup correct pathes for install and build make commands
#
configure_opts="--srcdir=${DIST_BASE}"
configure_opts="${configure_opts} --prefix=${INSTALL_ROOT_nto}/usr"
configure_opts="${configure_opts} --exec-prefix=${INSTALL_ROOT_nto}/${cpudir}/usr"
}

#
# Adjust relative path to ./configure tool
#
function hook_configure {
${NESTED_LEVEL}/configure \
${ac_host:+"--host=${ac_host}"} \
${ac_build:+"--build=${ac_build}"} \
${configure_opts} \
${ac_params:+${CC:+"CC=${CC}"}} \
${ac_params:+${CFLAGS:+"CFLAGS=-O2 ${CFLAGS}"}} \
${ac_params:+${CPPFLAGS:+"CPPFLAGS=${CPPFLAGS}"}} \
${ac_params:+${LDFLAGS:+"LDFLAGS=${LDFLAGS}"}} \
${ac_params:+${CXX:+"CXX=${CXX}"}} \
${ac_params:+${CXXFLAGS:+"CXXFLAGS=-O2 ${CXXFLAGS}"}} \
${ac_params:+${ac_autotools:+${ac_autotools}}} \
|| Error "configure failed";
}

function hook_premake {
if [ "${make_cmds}" == "check" ] && [ "${TARGET_SYSNAME}" == "nto" ]; then
echo "For target nto suppress tests execution."
echo "All tests have to be run on target system."
make_opts="${make_opts} TESTS=''"
fi
}

function hook_postmake {
red="\033[0;31m"
grn="\033[0;32m"
yel="\033[1;33m"
blu="\033[1;34m"
cls="\033[0m"
base_build=$PWD
base_testsuite="src/tests"
base_script="run_testsuites.sh"
testsuite_log="test-suite.log"
testsuite_script=$base_testsuite/$base_script
testsuite_sdp_bin=${INSTALL_ROOT_nto}/${cpudir}/usr/bin/asio_tests

#
# uninstall all asio test from SDP
#
if [ "${make_cmds}" == "uninstall" ] && [ -d ${testsuite_sdp_bin} ]; then
echo "we have to uninstall all asio tests"
(set -x; rm -rf ${testsuite_sdp_bin})
fi

#
# build and install all asio tests
#
if [ "${make_cmds}" == "check" ] && [ "${TARGET_SYSNAME}" == "nto" ] && [ "${SYSNAME}" == "linux" ]; then
if [ -d ${base_testsuite} ]; then

echo "${blu}=========================================================================${cls}"
echo "${blu}Generate script to run testsuites for the ${cpu}${cls}"
echo "${blu}=========================================================================${cls}"

echo "Remove old testsuite script ..."
#(set -x; <command> - print each command before executing )
(set -x; rm -f "$testsuite_script")

echo "Looking for tests executables..."
testsuite_list=$(find . -type f -executable | sed -n "s/^\.\/src\/tests\/\(\S*\)$/\1/p")

pkg_str=$(grep 'PACKAGE_STRING' Makefile | grep -oP '\d+\.\d+\.\d+' | head -1)

echo "Creating testsuites script..."
echo "#!/bin/sh" > $testsuite_script || Error "Unexpected error during $testsuite_script initialization";
echo "_pass=0" >> $testsuite_script || Error "Unexpected error during $testsuite_script initialization";
echo "_fail=0" >> $testsuite_script || Error "Unexpected error during $testsuite_script initialization";
echo "echo \"### Testsuites log file ###\" > $testsuite_log" >> $testsuite_script || Error "Unexpected error during $testsuite_script initialization";


echo "Adding testsuites to the script:'$testsuite_script'..."
testsuite_number=0
for v in ${testsuite_list}; do
testsuite_number=$((testsuite_number+1));
echo "### Suite number: $testsuite_number" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo "result=\$($v 2>&1)" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo "if [ 0 -eq \$? ]; then" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo " _pass=\$((_pass+1))" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo " echo \"${grn}PASS${cls}:$v\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo "else" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo " _fail=\$((_fail+1))" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo " echo \"${red}FAIL${cls}:$v\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo "fi" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo "echo \"### Testsuite:$v ###\" >> $testsuite_log" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo "echo \"\${result}\" >> $testsuite_log" >> $testsuite_script || Error "Unexpected error during $testsuite_script update by testsuite:'$v'";
echo "${blu}ADDED${cls}:$v";
#
# install testsuite into SDP
#
_dest_folder="${testsuite_sdp_bin}/$(dirname $v)"
_source_test="src/tests/$v"
[ -d "${_dest_folder}" ] || (set -x; mkdir -p ${_dest_folder})
(set -x; cp -f $_source_test $_dest_folder)
done

echo "echo \"${grn}=========================================================================${cls}\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "echo \"${grn}Testsuite summary for asio ${pkg_str}${cls}\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "echo \"${grn}=========================================================================${cls}\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "echo \"# TOTAL: ${testsuite_number}\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "echo \"# ${grn}PASS${cls}: \${_pass}\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "echo \"# ${red}FAIL${cls}: \${_fail}\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "if [ 0 -eq \${_fail} ]; then" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "echo \"${grn}=========================================================================${cls}\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "else" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "echo \"${red}\${_fail} fails see test log:$testsuite_log ${cls}\"" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";
echo "fi" >> $testsuite_script || Error "Unexpected error during $testsuite_script update";

chmod +x $testsuite_script

#(set -x; <command> - print each command before executing )
(set -x; cp -f $testsuite_script $testsuite_sdp_bin)

echo "${blu}For asio ${pkg_str} total ${testsuite_number} testsuites were added into script:${testsuite_script}${cls}";
echo "${blu}All testsuites were installed into '${testsuite_sdp_bin}'${cls}";
echo "${blu}To run all tests please copy '${testsuite_sdp_bin}' to the target system and run test script '${testsuite_script}'${cls}";
else
echo "${red}Error - base testsuite:'${base_build}/${base_testsuite}' for asio ${pkg_str} was not found!${cls}";
exit 1;
fi
fi
}
6 changes: 6 additions & 0 deletions asio/qnx/build/nto-aarch64-le/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)

include $(MKFILES_ROOT)/qmake-cfg.mk
6 changes: 6 additions & 0 deletions asio/qnx/build/nto-x86_64-o/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)

include $(MKFILES_ROOT)/qmake-cfg.mk
60 changes: 60 additions & 0 deletions asio/qnx/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Testing asio lib on QNX

**NOTE**: QNX ports are only supported from a **Linux host** operating system

asio lib normally wants to be tested on the same machine it was built on. This obviously doesn't work when cross-compiling for QNX. The gist is to build, then copy the whole asio lib source tree on a target. This will include all the relevant files and directory structure which asio lib expects when running its test suite.

# Running the Test Suite

### Install dependencies

`sudo apt install automake`

`sudo apt install pkg-config`

### Switch to asio main folder

`cd asio`

### Generate GNU build tool ./configure and all needed Makefiles

`./autogen.sh`

### Setup QNX SDP environment

`source <path-to-sdp>/qnxsdp-env.sh`

### Build and install all asio tests into SDP

`JLEVEL=$(nproc) CPULIST=x86_64 make -C qnx/build check`

### Then build your QNX image using mkqnximage and the following options:

`export ASIO_ROOT=$PWD`

`mkdir test_image && cd test_image`

`mkqnximage --extra-dirs=$ASIO_ROOT/qnx/test/mkqnximage --clean --run --force --test-asio=$QNX_TARGET/x86_64/usr/bin/asio_tests`

### Once the target has booted, the asio tests will be located in /data/asio:

`cd /data/asio`

`./run_testsuites.sh`

### Test execution summary
`...`

`=========================================================================`

`Testsuite summary for asio 1.29.0`

`=========================================================================`

`# TOTAL: 346`

`# PASS: 346`

`# FAIL: 0`

`=========================================================================`
Loading