From 76227f092eb42ee5ea8c191c588423cc71daf48f Mon Sep 17 00:00:00 2001 From: szc321 <108719242+szc321@users.noreply.github.com> Date: Wed, 7 Jun 2023 13:08:19 +0800 Subject: [PATCH] fix static code analysis (#710) Signed-off-by: szc321 --- prebuild.py | 3 ++- src/lava/magma/runtime/_c_message_infrastructure/README.md | 2 +- .../csrc/channel/dds/cyclone_dds.cc | 4 ++-- .../_c_message_infrastructure/csrc/channel/dds/fast_dds.cc | 5 +++-- .../_c_message_infrastructure/csrc/channel/shmem/shm.cc | 1 - .../csrc/core/message_infrastructure_logging.cc | 1 - .../_c_message_infrastructure/examples/c_pingpong/README.md | 2 +- .../ros_talk_with_dds_py/utils/np_mdata_trans.py | 2 +- .../examples/ros2/test_cyclonedds_from_ros.py | 2 +- .../examples/ros2/test_cyclonedds_to_ros.py | 2 +- .../examples/ros2/test_fastdds_from_ros.py | 2 +- .../examples/ros2/test_fastdds_to_ros.py | 2 +- .../runtime/message_infrastructure/py_multiprocessing.py | 2 +- .../magma/runtime/message_infrastructure/test_channel.py | 1 - .../runtime/message_infrastructure/test_channel_block.py | 4 ++-- .../runtime/message_infrastructure/test_temp_channel.py | 4 ++-- 16 files changed, 19 insertions(+), 20 deletions(-) diff --git a/prebuild.py b/prebuild.py index 12fa327b6..daed5d818 100644 --- a/prebuild.py +++ b/prebuild.py @@ -25,6 +25,8 @@ def __init__(self, sourcedir, targetdir): if self.from_cd_action and self.from_poetry else ["cmake"] self.cmake_args = [] self.build_args = [] + if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ: + self.parallel = multiprocessing.cpu_count() def _check_poetry(self): exec_code = self.env.get('_', "").rsplit('/')[-1] @@ -67,7 +69,6 @@ def _set_cmake_args(self): # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level # across all generators. if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ: - self.parallel = multiprocessing.cpu_count() self.build_args += [f"-j{self.parallel}"] def run(self): diff --git a/src/lava/magma/runtime/_c_message_infrastructure/README.md b/src/lava/magma/runtime/_c_message_infrastructure/README.md index 2f5837154..3541e9701 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/README.md +++ b/src/lava/magma/runtime/_c_message_infrastructure/README.md @@ -80,4 +80,4 @@ Also users could choose to use poetry to enbale the whole environment. $ export CMAKE_ARGS="..." $ poetry install $ source .venv/bin/activate -``` \ No newline at end of file +``` diff --git a/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/dds/cyclone_dds.cc b/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/dds/cyclone_dds.cc index ead66d395..d836831c5 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/dds/cyclone_dds.cc +++ b/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/dds/cyclone_dds.cc @@ -182,11 +182,11 @@ MetaDataPtr CycloneDDSSubscriber::Recv(bool keep) { topic_name_.c_str()); dds::sub::LoanedSamples samples; if (keep) { - while ((samples = selector_->read()).length() <= 0) { + while ((samples = selector_->read()).length() <= 0) { // Flawfinder: ignore helper::Sleep(); } } else { - while ((samples = selector_->take()).length() <= 0) { + while ((samples = selector_->take()).length() <= 0) { // Flawfinder: ignore helper::Sleep(); } } diff --git a/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/dds/fast_dds.cc b/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/dds/fast_dds.cc index cac23302f..216a91fc7 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/dds/fast_dds.cc +++ b/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/dds/fast_dds.cc @@ -259,7 +259,7 @@ MetaDataPtr FastDDSSubscriber::Recv(bool keep) { if (keep) { LAVA_DEBUG(LOG_DDS, "Keep the data recieved\n"); while (ReturnCode_t::RETCODE_OK != - reader_->read(mdata_seq, infos, 1)) { + reader_->read(mdata_seq, infos, 1)) { // Flawfinder: ignore helper::Sleep(); } } else { @@ -307,7 +307,8 @@ bool FastDDSSubscriber::Probe() { MDataSeq mdata_seq; SampleInfoSeq infos; bool res = false; - if (ReturnCode_t::RETCODE_OK == reader_->read(mdata_seq, infos, 1)) { + if (ReturnCode_t::RETCODE_OK == + reader_->read(mdata_seq, infos, 1)) { // Flawfinder: ignore reader_->return_loan(mdata_seq, infos); res = true; } diff --git a/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/shmem/shm.cc b/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/shmem/shm.cc index bcafe35c4..0864da7f0 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/shmem/shm.cc +++ b/src/lava/magma/runtime/_c_message_infrastructure/csrc/channel/shmem/shm.cc @@ -114,7 +114,6 @@ void RwSharedMemory::Close() { void SharedMemManager::DeleteAllSharedMemory() { if (alloc_pid_ != getpid()) return; - int result = 0; LAVA_DEBUG(LOG_SMMP, "Delete: Number of shm to free: %zd.\n", shm_fd_strs_.size()); LAVA_DEBUG(LOG_SMMP, "Delete: Number of sem to free: %zd.\n", diff --git a/src/lava/magma/runtime/_c_message_infrastructure/csrc/core/message_infrastructure_logging.cc b/src/lava/magma/runtime/_c_message_infrastructure/csrc/core/message_infrastructure_logging.cc index cacc0c956..5a544f60b 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/csrc/core/message_infrastructure_logging.cc +++ b/src/lava/magma/runtime/_c_message_infrastructure/csrc/core/message_infrastructure_logging.cc @@ -73,7 +73,6 @@ void MessageInfrastructureLog::Clear() { // multithread unsafe void MessageInfrastructureLog::WriteDown() { if (log_queue_.empty()) return; - int i = 0; signed int pid = GetPid(); std::stringstream log_file_name; log_file_name << log_path_ << "/" << DEBUG_LOG_MODULE << "_pid_" << pid \ diff --git a/src/lava/magma/runtime/_c_message_infrastructure/examples/c_pingpong/README.md b/src/lava/magma/runtime/_c_message_infrastructure/examples/c_pingpong/README.md index 8640c60da..43e22f31a 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/examples/c_pingpong/README.md +++ b/src/lava/magma/runtime/_c_message_infrastructure/examples/c_pingpong/README.md @@ -22,4 +22,4 @@ The Send port will connect to the recv port in initialization and write to the s Therefore, 1. The send port can only be initialized after corresponding Recv port called `start()` -2. In each round, the send port is used one-off. One needs to create a new `TempChannel()` and get the send port from it each time. (The send port will be initialized when accessing the .dst_port property at the first time) \ No newline at end of file +2. In each round, the send port is used one-off. One needs to create a new `TempChannel()` and get the send port from it each time. (The send port will be initialized when accessing the .dst_port property at the first time) diff --git a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/ros_talk_with_dds_py/ros_talk_with_dds_py/utils/np_mdata_trans.py b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/ros_talk_with_dds_py/ros_talk_with_dds_py/utils/np_mdata_trans.py index 235f07faf..8629f1446 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/ros_talk_with_dds_py/ros_talk_with_dds_py/utils/np_mdata_trans.py +++ b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/ros_talk_with_dds_py/ros_talk_with_dds_py/utils/np_mdata_trans.py @@ -46,7 +46,7 @@ def nparray_to_metadata(np_array): metadata.elsize = np_array.itemsize metadata.total_size = np_array.size shape_list = list(np_array.shape) - for i in range(5 - len(shape_list)): + for _ in range(5 - len(shape_list)): shape_list.append(0) metadata.dims = shape_list strides_list = list(np_array.strides) diff --git a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_cyclonedds_from_ros.py b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_cyclonedds_from_ros.py index 69d127f8d..f31294dd4 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_cyclonedds_from_ros.py +++ b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_cyclonedds_from_ros.py @@ -21,7 +21,7 @@ def test_ddschannel(): recv_port = dds_channel.dst_port recv_port.start() - for i in range(100): + for _ in range(100): res = recv_port.recv() print(res) recv_port.join() diff --git a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_cyclonedds_to_ros.py b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_cyclonedds_to_ros.py index cc77b7814..08910420c 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_cyclonedds_to_ros.py +++ b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_cyclonedds_to_ros.py @@ -28,7 +28,7 @@ def test_ddschannel(): send_port = dds_channel.src_port send_port.start() - for i in range(100): + for _ in range(100): send_port.send(prepare_data()) time.sleep(0.1) send_port.join() diff --git a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_fastdds_from_ros.py b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_fastdds_from_ros.py index 15930266f..f6951b345 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_fastdds_from_ros.py +++ b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_fastdds_from_ros.py @@ -22,7 +22,7 @@ def test_ddschannel(): recv_port = dds_channel.dst_port recv_port.start() - for i in range(100): + for _ in range(100): res = recv_port.recv() print(res) recv_port.join() diff --git a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_fastdds_to_ros.py b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_fastdds_to_ros.py index 93365c85f..824309556 100644 --- a/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_fastdds_to_ros.py +++ b/src/lava/magma/runtime/_c_message_infrastructure/examples/ros2/test_fastdds_to_ros.py @@ -28,7 +28,7 @@ def test_ddschannel(): send_port = dds_channel.src_port send_port.start() - for i in range(100): + for _ in range(100): send_port.send(prepare_data()) time.sleep(0.1) send_port.join() diff --git a/src/lava/magma/runtime/message_infrastructure/py_multiprocessing.py b/src/lava/magma/runtime/message_infrastructure/py_multiprocessing.py index 12042a803..ad7a5c2e2 100644 --- a/src/lava/magma/runtime/message_infrastructure/py_multiprocessing.py +++ b/src/lava/magma/runtime/message_infrastructure/py_multiprocessing.py @@ -58,7 +58,7 @@ def run(self): tb = traceback.format_exc() self._cconn.send((e, tb)) - def join(self): + def join(self, timeout=None): if not self._is_done: super().join() super().close() diff --git a/tests/lava/magma/runtime/message_infrastructure/test_channel.py b/tests/lava/magma/runtime/message_infrastructure/test_channel.py index d5caa13ed..8850d692f 100644 --- a/tests/lava/magma/runtime/message_infrastructure/test_channel.py +++ b/tests/lava/magma/runtime/message_infrastructure/test_channel.py @@ -53,7 +53,6 @@ def build(self): def ddschannel_protocol(transfer_type, backend, topic_name): from lava.magma.runtime.message_infrastructure import ( GetDDSChannel, - DDSBackendType, ChannelQueueSize) from lava.magma.runtime.message_infrastructure \ .multiprocessing import MultiProcessing diff --git a/tests/lava/magma/runtime/message_infrastructure/test_channel_block.py b/tests/lava/magma/runtime/message_infrastructure/test_channel_block.py index 187605d35..dfa0d4a07 100644 --- a/tests/lava/magma/runtime/message_infrastructure/test_channel_block.py +++ b/tests/lava/magma/runtime/message_infrastructure/test_channel_block.py @@ -27,7 +27,7 @@ def send_proc(*args, **kwargs): if not isinstance(port, SendPort): raise AssertionError() port.start() - for i in range(QUEUE_SIZE + 1): + for _ in range(QUEUE_SIZE + 1): data = generate_data() port.send(data) @@ -38,7 +38,7 @@ def recv_proc(*args, **kwargs): if not isinstance(port, RecvPort): raise AssertionError() time.sleep(1) - for i in range(QUEUE_SIZE + 1): + for _ in range(QUEUE_SIZE + 1): port.recv() diff --git a/tests/lava/magma/runtime/message_infrastructure/test_temp_channel.py b/tests/lava/magma/runtime/message_infrastructure/test_temp_channel.py index ba8e3c266..b22094990 100644 --- a/tests/lava/magma/runtime/message_infrastructure/test_temp_channel.py +++ b/tests/lava/magma/runtime/message_infrastructure/test_temp_channel.py @@ -32,7 +32,7 @@ def actor_stop(name): def recv_proc(*args, **kwargs): port = kwargs.pop("port") port.start() - for i in range(loop_number): + for _ in range(loop_number): path, recv_port = getTempRecvPort() recv_port.start() port.send(np.array([path])) @@ -46,7 +46,7 @@ def recv_proc(*args, **kwargs): def send_proc(*args, **kwargs): port = kwargs.pop("port") port.start() - for i in range(loop_number): + for _ in range(loop_number): path = port.recv() send_port = getTempSendPort(str(path[0])) send_port.start()