<commit_before>// Copyright (c) 2019 - for information on the respective copyright owner
// see the NOTICE file and/or the repository https://github.com/ros2/rclc.
// Copyright 2014 Open Source Robotics Foundation, Inc.
//
// 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.
#include <std_msgs/msg/int32.h>
#include <gtest/gtest.h>

#include <chrono>
#include <thread>
#include <vector>

#include "rclc/executor.h"
#include "osrf_testing_tools_cpp/scope_exit.hpp"
#include "rcutils/time.h"

// Include backport of function 'rcl_wait_set_is_valid' introduced in Foxy
// in case of building for Dashing and Eloquent. This pre-processor macro
// is defined in CMakeLists.txt.
#if defined (USE_RCL_WAIT_SET_IS_VALID_BACKPORT)
#include "rclc/rcl_wait_set_is_valid_backport.h"
#endif


// 27.06.2019, unit test adapted from ros2/rcl/rcl_lifecycle/test/test_default_state_machine.cpp
// by <NAME>, under Apache 2.0 License

/******************************* CALLBACKS for subscriptions ************************/

// some variables for testing the LET-semantics
// array holds the msg_id in the order as they are received
// the callback calls the function _results_add(msg_id)
// at the end the array contains the order of received events.
#define TC_SPIN_SOME_NUM_PUBLISHER 3
#define TC_SPIN_SOME_PUBLISHED_MSGS 3
#define TC_SPIN_SOME_MAX_MSGS \
  (TC_SPIN_SOME_NUM_PUBLISHER * TC_SPIN_SOME_PUBLISHED_MSGS)
static unsigned int _executor_results[TC_SPIN_SOME_MAX_MSGS];
static unsigned int _executor_results_i;

// callback for topic "chatter1"
static unsigned int _cb1_cnt = 0;
static unsigned int _cb1_int_value = 0;
// callback for topic "chatter2"
static unsigned int _cb2_cnt = 0;
static unsigned int _cb2_int_value = 0;
// callback for topic "chatter3"
static unsigned int _cb3_cnt = 0;
static unsigned int _cb3_int_value = 0;
// callback for testing data communication semantics
static unsigned int _cb5_cnt = 0;
static unsigned int _cb5_int_value = 0;
rcl_publisher_t * _pub_int_ptr;
std_msgs__msg__Int32 * _pub_int_msg_ptr;

// sleep time beween publish and receive in DDS middleware
// to allow enough time on CI jobs (in milliseconds)
#define RCLC_UNIT_TEST_SLEEP_TIME_MS 500
const std::chrono::milliseconds rclc_test_sleep_time =
  std::chrono::milliseconds(RCLC_UNIT_TEST_SLEEP_TIME_MS);

// timeout for rcl_wait() when calling spin_some API of executor
const uint64_t rclc_test_timeout_ns = 1000000000;  // 1s

static
void
_results_callback_counters_init()<commit_msg>Increased waiting time to 2ms for executor unit tests.<commit_after>// Copyright (c) 2019 - for information on the respective copyright owner
// see the NOTICE file and/or the repository https://github.com/ros2/rclc.
// Copyright 2014 Open Source Robotics Foundation, Inc.
//
// 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.
#include <std_msgs/msg/int32.h>
#include <gtest/gtest.h>

#include <chrono>
#include <thread>
#include <vector>

#include "rclc/executor.h"
#include "osrf_testing_tools_cpp/scope_exit.hpp"
#include "rcutils/time.h"

// Include backport of function 'rcl_wait_set_is_valid' introduced in Foxy
// in case of building for Dashing and Eloquent. This pre-processor macro
// is defined in CMakeLists.txt.
#if defined (USE_RCL_WAIT_SET_IS_VALID_BACKPORT)
#include "rclc/rcl_wait_set_is_valid_backport.h"
#endif


// 27.06.2019, unit test adapted from ros2/rcl/rcl_lifecycle/test/test_default_state_machine.cpp
// by <NAME>, under Apache 2.0 License

/******************************* CALLBACKS for subscriptions ************************/

// some variables for testing the LET-semantics
// array holds the msg_id in the order as they are received
// the callback calls the function _results_add(msg_id)
// at the end the array contains the order of received events.
#define TC_SPIN_SOME_NUM_PUBLISHER 3
#define TC_SPIN_SOME_PUBLISHED_MSGS 3
#define TC_SPIN_SOME_MAX_MSGS \
  (TC_SPIN_SOME_NUM_PUBLISHER * TC_SPIN_SOME_PUBLISHED_MSGS)
static unsigned int _executor_results[TC_SPIN_SOME_MAX_MSGS];
static unsigned int _executor_results_i;

// callback for topic "chatter1"
static unsigned int _cb1_cnt = 0;
static unsigned int _cb1_int_value = 0;
// callback for topic "chatter2"
static unsigned int _cb2_cnt = 0;
static unsigned int _cb2_int_value = 0;
// callback for topic "chatter3"
static unsigned int _cb3_cnt = 0;
static unsigned int _cb3_int_value = 0;
// callback for testing data communication semantics
static unsigned int _cb5_cnt = 0;
static unsigned int _cb5_int_value = 0;
rcl_publisher_t * _pub_int_ptr;
std_msgs__msg__Int32 * _pub_int_msg_ptr;

// sleep time beween publish and receive in DDS middleware
// to allow enough time on CI jobs (in milliseconds)
#define RCLC_UNIT_TEST_SLEEP_TIME_MS 2000
const std::chrono::milliseconds rclc_test_sleep_time =
  std::chrono::milliseconds(RCLC_UNIT_TEST_SLEEP_TIME_MS);

// timeout for rcl_wait() when calling spin_some API of executor
const uint64_t rclc_test_timeout_ns = 1000000000;  // 1s

static
void
_results_callback_counters_init()
{'fraction_non_alphanumeric': 0.09523015343562374, 'fraction_numerical': 0.022014676450967312, 'mean_word_length': 4.914201183431953, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1057671', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1905, 'n_words': 647}