From 58197d25c7fa5aea332f46c8575dc6d20958ea84 Mon Sep 17 00:00:00 2001 From: koonpeng Date: Tue, 8 Dec 2020 13:15:06 +0800 Subject: [PATCH 1/8] simplify building tests --- package.json | 2 +- scripts/compile_tests.js | 109 ++++----------------------------------- scripts/run_test.js | 8 --- scripts/test.js | 36 +++++++++++++ 4 files changed, 46 insertions(+), 109 deletions(-) create mode 100644 scripts/test.js diff --git a/package.json b/package.json index 5e08bc2e..cca2daac 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "scripts": { "install": "node-gyp rebuild", "docs": "cd docs && make", - "test": "node ./scripts/compile_tests.js && node --expose-gc ./scripts/run_test.js && npm run dtslint", + "test": "node ./scripts/compile_tests.js && node ./scripts/test.js && npm run dtslint", "dtslint": "node ./scripts/generate_tsd.js && dtslint test/types", "lint": "eslint --max-warnings=0 --ext js,ts index.js types scripts lib example rosidl_gen rosidl_parser test benchmark/rclnodejs && node ./scripts/cpplint.js", "postinstall": "node scripts/generate_messages.js", diff --git a/scripts/compile_tests.js b/scripts/compile_tests.js index 3be62e02..68f90c74 100644 --- a/scripts/compile_tests.js +++ b/scripts/compile_tests.js @@ -14,111 +14,20 @@ 'use strict'; -/* eslint-disable */ -const fs = require('fs-extra'); -const os = require('os'); const path = require('path'); const child = require('child_process'); var rootDir = path.dirname(__dirname); var testCppDir = path.join(rootDir, 'test', 'cpp'); -function getExecutable(input) { - if (os.platform() === 'win32') return input + '.exe'; - - return input; -} - -var publisher = getExecutable('publisher_msg'); -var subscription = getExecutable('subscription_msg'); -var listener = getExecutable('listener'); -var client = getExecutable('add_two_ints_client'); - -function getExecutablePath(input) { - var releaseDir = ''; - if (os.platform() === 'win32') releaseDir = 'Release'; - - return path.join(rootDir, 'build', 'cpp_nodes', releaseDir, input); -} - -var publisherPath = getExecutablePath(publisher); -var subscriptionPath = getExecutablePath(subscription); -var listenerPath = getExecutablePath(listener); -var clientPath = getExecutablePath(client); - -function copyFile(platform, srcFile, destFile) { - if (!fs.existsSync(destFile)) { - if (os.platform() === 'win32') { - child.spawn('cmd.exe', ['/c', `copy ${srcFile} ${destFile}`]); - } else { - child.spawn('sh', ['-c', `cp ${srcFile} ${destFile}`]); - } - } -} - -function copyAll(fileList, dest) { - fileList.forEach((file) => { - copyFile(os.platform(), file, path.join(dest, path.basename(file))); - console.log(`cpp executables ${file} is copied to test/cpp.`); - }); -} - -function copyPkgToRos2(pkgName) { - let srcDir = path.join(rootDir, 'install', pkgName); - let destDir = process.env.COLCON_PREFIX_PATH; - if (os.platform() === 'win32') { - child.spawn('cmd.exe', ['/c', `xcopy ${srcDir} ${destDir} /O /X /E /K`]); - } else { - child.spawn('sh', ['-c ', '"' + `cp -fr ${srcDir}/. ${destDir}` + '"'], { - shell: true, - }); - } -} - -var subProcess = child.spawn('colcon', [ - 'build', - '--event-handlers', - 'console_cohesion+', - '--base-paths', +const basePaths = [ path.join(rootDir, 'test', 'rclnodejs_test_msgs'), -]); -subProcess.on('close', (code) => { - copyPkgToRos2('rclnodejs_test_msgs'); + testCppDir, +]; + +// foxy has a bug where fastRTPS can't be found, a workaround is to add +// AMENT_PREFIX_PATH to CMAKE_PREFIX_PATH +process.env.CMAKE_PREFIX_PATH = `${process.env.CMAKE_PREFIX_PATH}:${process.env.AMENT_PREFIX_PATH}`; +child.spawnSync('colcon', ['build', '--base-paths', ...basePaths], { + stdio: 'inherit', }); -subProcess.stdout.on('data', (data) => { - console.log(`${data}`); -}); -subProcess.stderr.on('data', (data) => { - console.log(`${data}`); -}); - -if ( - !fs.existsSync(publisherPath) && - !fs.existsSync(subscriptionPath) && - !fs.existsSync(listenerPath) && - !fs.existsSync(clientPath) -) { - var compileProcess = child.spawn('colcon', [ - 'build', - '--base-paths', - testCppDir, - ]); - compileProcess.on('close', (code) => { - copyAll( - [publisherPath, subscriptionPath, listenerPath, clientPath], - testCppDir - ); - }); - compileProcess.stdout.on('data', (data) => { - console.log(`${data}`); - }); - compileProcess.stderr.on('data', (data) => { - console.log(`${data}`); - }); -} else { - copyAll( - [publisherPath, subscriptionPath, , listenerPath, clientPath], - testCppDir - ); -} -/* eslint-enable */ diff --git a/scripts/run_test.js b/scripts/run_test.js index ac123e6a..0eca595c 100644 --- a/scripts/run_test.js +++ b/scripts/run_test.js @@ -19,14 +19,6 @@ const Mocha = require('mocha'); const os = require('os'); const path = require('path'); -let rootDir = path.dirname(__dirname); -let actionPath = path.join(rootDir, 'test', 'ros1_actions'); -process.env.AMENT_PREFIX_PATH = - process.env.AMENT_PREFIX_PATH + path.delimiter + actionPath; -let msgPath = path.join(rootDir, 'test', 'rclnodejs_test_msgs'); -process.env.AMENT_PREFIX_PATH = - process.env.AMENT_PREFIX_PATH + path.delimiter + msgPath; - fs.remove(path.join(path.dirname(__dirname), 'generated'), (err) => { if (!err) { let mocha = new Mocha(); diff --git a/scripts/test.js b/scripts/test.js new file mode 100644 index 00000000..0664072b --- /dev/null +++ b/scripts/test.js @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2020 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +'use strict'; + +const os = require('os'); +const childprocess = require('child_process'); +const path = require('path'); + +const rootDir = path.dirname(__dirname); + +if (os.platform === 'win32') { + childprocess.execSync( + `. ${rootDir}\\install\\setup.ps1 && node --expose-gc ${rootDir}\\scripts\\run_test.js`, + { stdio: 'inherit', shell: 'powershell' } + ); +} else { + childprocess.execSync( + `. ${rootDir}/install/setup.bash && node --expose-gc ${rootDir}/scripts/run_test.js`, + { stdio: 'inherit', shell: 'bash' } + ); +} From 2691b04106eb71d772fb37ef9f37aaddd6fbb86f Mon Sep 17 00:00:00 2001 From: koonpeng Date: Tue, 8 Dec 2020 14:23:22 +0800 Subject: [PATCH 2/8] maybe fix mac test --- .circleci/config.yml | 2 +- .../rclcpp/service/client-stress-test.cpp | 20 ++++----- test/cpp/add_two_ints_client.cpp | 41 +++++++++---------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c8c98f8a..bcf99e22 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,7 +38,7 @@ jobs: - ./node_modules # Test - run: npm install istanbul coveralls - - run: source ~/ros2_install/ros2-osx/local_setup.bash && export OPENSSL_ROOT_DIR="/usr/local/opt/openssl" && node scripts/compile_tests.js && node --expose-gc ./node_modules/.bin/istanbul cover ./scripts/run_test.js --report lcovonly && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage + - run: source ~/ros2_install/ros2-osx/local_setup.bash && export OPENSSL_ROOT_DIR="/usr/local/opt/openssl" && node scripts/compile_tests.js && . install/setup.bash && node --expose-gc ./node_modules/.bin/istanbul cover ./scripts/run_test.js --report lcovonly && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage # Teardown - run: find $HOME/Library/Developer/Xcode/DerivedData -name '*.xcactivitylog' -exec cp {} $CIRCLE_ARTIFACTS/xcactivitylog \; || true # Save test results diff --git a/benchmark/rclcpp/service/client-stress-test.cpp b/benchmark/rclcpp/service/client-stress-test.cpp index 14719f51..98246df3 100644 --- a/benchmark/rclcpp/service/client-stress-test.cpp +++ b/benchmark/rclcpp/service/client-stress-test.cpp @@ -22,11 +22,10 @@ #include "utilities.hpp" void ShowUsage(const std::string name) { - std::cerr << "Usage: " << name << " [options]\n" - << "\nOptions:\n" - << "\n--run \tHow many times to run\n" - << "--help \toutput usage information" - << std::endl; + std::cerr << "Usage: " << name << " [options]\n" + << "\nOptions:\n" + << "\n--run \tHow many times to run\n" + << "--help \toutput usage information" << std::endl; } int main(int argc, char* argv[]) { @@ -36,15 +35,16 @@ int main(int argc, char* argv[]) { for (int i = 1; i < argc; i++) { std::string arg = argv[i]; if ((arg == "-h") || (arg == "--help")) { - ShowUsage(argv[0]); - return 0; + ShowUsage(argv[0]); + return 0; } else if (arg.find("--run=") != std::string::npos) { - total_times = std::stoi(arg.substr(arg.find("=") + 1)); + total_times = std::stoi(arg.substr(arg.find("=") + 1)); } } printf( "The client will send a GetMap request continuously until receiving " - "response %d times.\n", total_times); + "response %d times.\n", + total_times); auto start = std::chrono::high_resolution_clock::now(); auto node = rclcpp::Node::make_shared("stress_client_rclcpp"); @@ -60,7 +60,7 @@ int main(int argc, char* argv[]) { } else { auto result_future = client->async_send_request(request); if (rclcpp::spin_until_future_complete(node, result_future) != - rclcpp::executor::FutureReturnCode::SUCCESS) { + rclcpp::FutureReturnCode::SUCCESS) { RCLCPP_ERROR(node->get_logger(), "service call failed."); return 1; } diff --git a/test/cpp/add_two_ints_client.cpp b/test/cpp/add_two_ints_client.cpp index 241ec46e..0571e912 100644 --- a/test/cpp/add_two_ints_client.cpp +++ b/test/cpp/add_two_ints_client.cpp @@ -17,47 +17,45 @@ #include #include +#include "example_interfaces/srv/add_two_ints.hpp" #include "rclcpp/rclcpp.hpp" #include "rcutils/cmdline_parser.h" - #include "std_msgs/msg/int8.hpp" -#include "example_interfaces/srv/add_two_ints.hpp" using namespace std::chrono_literals; rclcpp::Publisher::SharedPtr publisher = nullptr; -void print_usage() -{ +void print_usage() { printf("Usage for add_two_ints_client app:\n"); printf("add_two_ints_client [-t topic_name] [-h]\n"); printf("options:\n"); printf("-h : Print this help function.\n"); - printf("-s service_name : Specify the service name for this client. Defaults to add_two_ints.\n"); + printf( + "-s service_name : Specify the service name for this client. Defaults to " + "add_two_ints.\n"); } // TODO(wjwwood): make this into a method of rclcpp::client::Client. example_interfaces::srv::AddTwoInts_Response::SharedPtr send_request( - rclcpp::Node::SharedPtr node, - rclcpp::Client::SharedPtr client, - example_interfaces::srv::AddTwoInts_Request::SharedPtr request) -{ + rclcpp::Node::SharedPtr node, + rclcpp::Client::SharedPtr client, + example_interfaces::srv::AddTwoInts_Request::SharedPtr request) { auto result = client->async_send_request(request); // Wait for the result. if (rclcpp::spin_until_future_complete(node, result) == - rclcpp::executor::FutureReturnCode::SUCCESS) - { + rclcpp::FutureReturnCode::SUCCESS) { return result.get(); } else { return NULL; } } -int main(int argc, char ** argv) -{ +int main(int argc, char** argv) { rclcpp::init(argc, argv); - auto node = rclcpp::Node::make_shared("add_two_ints_client", rclcpp::NodeOptions()); + auto node = + rclcpp::Node::make_shared("add_two_ints_client", rclcpp::NodeOptions()); if (rcutils_cli_option_exist(argv, argv + argc, "-h")) { print_usage(); @@ -70,13 +68,16 @@ int main(int argc, char ** argv) } auto client = node->create_client(topic); - auto request = std::make_shared(); + auto request = + std::make_shared(); request->a = 2; request->b = 3; while (!client->wait_for_service(1s)) { if (!rclcpp::ok()) { - printf("add_two_ints_client was interrupted while waiting for the service. Exiting.\n"); + printf( + "add_two_ints_client was interrupted while waiting for the service. " + "Exiting.\n"); return 0; } printf("service not available, waiting again...\n"); @@ -84,21 +85,19 @@ int main(int argc, char ** argv) auto msg = std::make_shared(); publisher = node->create_publisher( - std::string("back_") + topic, 7); - + std::string("back_") + topic, 7); auto future_result = client->async_send_request(request); // Wait for the result. if (rclcpp::spin_until_future_complete(node, future_result) == - rclcpp::executor::FutureReturnCode::SUCCESS) - { + rclcpp::FutureReturnCode::SUCCESS) { // printf("Result of add_two_ints: %zd\n", future_result.get()->sum); msg->data = future_result.get()->sum; publisher->publish(*msg); } else { printf("add_two_ints_client_async was interrupted. Exiting.\n"); - } + } rclcpp::spin(node); return 0; From 706562854befb420b5c55e2604ba1743b8af418c Mon Sep 17 00:00:00 2001 From: koonpeng Date: Tue, 8 Dec 2020 15:12:43 +0800 Subject: [PATCH 3/8] try using ros2 release --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 4650f4be..4bf06095 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -28,7 +28,7 @@ before_build: - appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/tinyxml2.6.0.0.nupkg - appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/log4cxx.0.10.0.nupkg - choco install -y -s c:\download\ asio bullet cunit eigen tinyxml-usestl tinyxml2 log4cxx - - appveyor DownloadFile https://ci.ros2.org/view/packaging/job/packaging_windows/lastSuccessfulBuild/artifact/ws/ros2-package-windows-AMD64.zip + - appveyor DownloadFile https://github.com/ros2/ros2/releases/download/release-foxy-20201009/ros2-foxy-20201009-windows-release-amd64.zip - 7z x -y "c:\download\ros2-package-windows-AMD64.zip" -o"c:\" > nul - setx -m OPENSSL_CONF C:\OpenSSL-Win64\bin\openssl.cfg - set PATH=C:\OpenSSL-Win64\bin;%PATH% From ebf2df0679e99843befa5abd38e171733ab76422 Mon Sep 17 00:00:00 2001 From: koonpeng Date: Tue, 8 Dec 2020 15:18:31 +0800 Subject: [PATCH 4/8] downloaded file name --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 4bf06095..865af339 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -29,7 +29,7 @@ before_build: - appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/log4cxx.0.10.0.nupkg - choco install -y -s c:\download\ asio bullet cunit eigen tinyxml-usestl tinyxml2 log4cxx - appveyor DownloadFile https://github.com/ros2/ros2/releases/download/release-foxy-20201009/ros2-foxy-20201009-windows-release-amd64.zip - - 7z x -y "c:\download\ros2-package-windows-AMD64.zip" -o"c:\" > nul + - 7z x -y "c:\download\ros2-foxy-20201009-windows-release-amd64.zip" -o"c:\" > nul - setx -m OPENSSL_CONF C:\OpenSSL-Win64\bin\openssl.cfg - set PATH=C:\OpenSSL-Win64\bin;%PATH% - setx AMENT_PYTHON_EXECUTABLE "c:\Python37" From 8b7ab324a56c32248ba36ab02ac3bf95bdfb0570 Mon Sep 17 00:00:00 2001 From: koonpeng Date: Tue, 8 Dec 2020 17:20:21 +0800 Subject: [PATCH 5/8] call platform() --- scripts/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.js b/scripts/test.js index 0664072b..99bffd3f 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -23,7 +23,7 @@ const path = require('path'); const rootDir = path.dirname(__dirname); -if (os.platform === 'win32') { +if (os.platform() === 'win32') { childprocess.execSync( `. ${rootDir}\\install\\setup.ps1 && node --expose-gc ${rootDir}\\scripts\\run_test.js`, { stdio: 'inherit', shell: 'powershell' } From 4eadbec4dcd4715362d50bbc48acdfd8da38cf1e Mon Sep 17 00:00:00 2001 From: koonpeng Date: Tue, 8 Dec 2020 17:34:14 +0800 Subject: [PATCH 6/8] try cmd --- scripts/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test.js b/scripts/test.js index 99bffd3f..d70fe5f2 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -25,8 +25,8 @@ const rootDir = path.dirname(__dirname); if (os.platform() === 'win32') { childprocess.execSync( - `. ${rootDir}\\install\\setup.ps1 && node --expose-gc ${rootDir}\\scripts\\run_test.js`, - { stdio: 'inherit', shell: 'powershell' } + `dir ${rootDir}\\install && call ${rootDir}\\install\\setup.bat && node --expose-gc ${rootDir}\\scripts\\run_test.js`, + { stdio: 'inherit' } ); } else { childprocess.execSync( From ec1e4fa6c3e86ed08c6f984dabef3b2e85f4673d Mon Sep 17 00:00:00 2001 From: koonpeng Date: Tue, 8 Dec 2020 17:43:13 +0800 Subject: [PATCH 7/8] cleanup --- scripts/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.js b/scripts/test.js index d70fe5f2..e3e5e2d9 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -25,7 +25,7 @@ const rootDir = path.dirname(__dirname); if (os.platform() === 'win32') { childprocess.execSync( - `dir ${rootDir}\\install && call ${rootDir}\\install\\setup.bat && node --expose-gc ${rootDir}\\scripts\\run_test.js`, + `call ${rootDir}\\install\\setup.bat && node --expose-gc ${rootDir}\\scripts\\run_test.js`, { stdio: 'inherit' } ); } else { From c78abbdb5c5c0dbefb39de2822de2f356765de29 Mon Sep 17 00:00:00 2001 From: koonpeng Date: Thu, 7 Jan 2021 14:29:27 +0800 Subject: [PATCH 8/8] Revert "try using ros2 release" This reverts commit 706562854befb420b5c55e2604ba1743b8af418c. --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 865af339..4650f4be 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -28,8 +28,8 @@ before_build: - appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/tinyxml2.6.0.0.nupkg - appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/log4cxx.0.10.0.nupkg - choco install -y -s c:\download\ asio bullet cunit eigen tinyxml-usestl tinyxml2 log4cxx - - appveyor DownloadFile https://github.com/ros2/ros2/releases/download/release-foxy-20201009/ros2-foxy-20201009-windows-release-amd64.zip - - 7z x -y "c:\download\ros2-foxy-20201009-windows-release-amd64.zip" -o"c:\" > nul + - appveyor DownloadFile https://ci.ros2.org/view/packaging/job/packaging_windows/lastSuccessfulBuild/artifact/ws/ros2-package-windows-AMD64.zip + - 7z x -y "c:\download\ros2-package-windows-AMD64.zip" -o"c:\" > nul - setx -m OPENSSL_CONF C:\OpenSSL-Win64\bin\openssl.cfg - set PATH=C:\OpenSSL-Win64\bin;%PATH% - setx AMENT_PYTHON_EXECUTABLE "c:\Python37"