From 381fc3d9dfe7d2ff40a075ff8c1f980ae2a62d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Sch=C3=A4fer?= Date: Sun, 9 Jun 2024 17:17:12 -0700 Subject: [PATCH] Restructure package (#622) * Move around * rename messaging to ipc * More renames * refactor visionipc ipc * more movement * compiles * works well * update workflow * Update * test fake * fix names * Fix test * exclude library * exclude from lint too * Rm dir * rm this wayu * Try again * mv logger * delete old * HAX * Move logger down * add warning abck --- .github/workflows/tests.yml | 4 +- .pre-commit-config.yaml | 3 +- Dockerfile | 6 +-- SConscript | 40 ++++++++-------- SConstruct | 3 +- messaging/.gitignore | 1 - msgq/.gitignore | 1 + {messaging => msgq}/__init__.py | 6 +-- {messaging => msgq}/event.cc | 2 +- {messaging => msgq}/event.h | 0 {messaging => msgq}/impl_fake.cc | 2 +- {messaging => msgq}/impl_fake.h | 4 +- {messaging => msgq}/impl_msgq.cc | 2 +- {messaging => msgq}/impl_msgq.h | 4 +- {messaging => msgq}/impl_zmq.cc | 2 +- {messaging => msgq}/impl_zmq.h | 2 +- messaging/messaging.cc => msgq/ipc.cc | 8 ++-- messaging/messaging.h => msgq/ipc.h | 0 messaging/messaging.pxd => msgq/ipc.pxd | 4 +- .../messaging_pyx.pyx => msgq/ipc_pyx.pyx | 26 +++++----- {logger => msgq/logger}/logger.h | 0 {messaging => msgq}/msgq.cc | 2 +- {messaging => msgq}/msgq.h | 0 {messaging => msgq}/msgq_tests.cc | 2 +- {messaging => msgq}/test_runner.cc | 0 {messaging => msgq}/tests/__init__.py | 0 {messaging => msgq}/tests/test_fake.py | 47 +++++++++---------- {messaging => msgq}/tests/test_messaging.py | 15 +++--- {messaging => msgq}/tests/test_poller.py | 40 ++++++++-------- {visionipc => msgq/visionipc}/.gitignore | 0 {visionipc => msgq/visionipc}/__init__.py | 0 {visionipc => msgq/visionipc}/test_runner.cc | 0 .../visionipc}/tests/__init__.py | 0 .../visionipc}/tests/test_visionipc.py | 0 {visionipc => msgq/visionipc}/visionbuf.cc | 0 {visionipc => msgq/visionipc}/visionbuf.h | 0 {visionipc => msgq/visionipc}/visionbuf_cl.cc | 0 .../visionipc}/visionbuf_ion.cc | 0 .../ipc.cc => msgq/visionipc/visionipc.cc | 2 +- {visionipc => msgq/visionipc}/visionipc.h | 6 +++ {visionipc => msgq/visionipc}/visionipc.pxd | 0 .../visionipc}/visionipc_client.cc | 6 +-- .../visionipc}/visionipc_client.h | 2 +- .../visionipc}/visionipc_pyx.pxd | 0 .../visionipc}/visionipc_pyx.pyx | 0 .../visionipc}/visionipc_server.cc | 6 +-- .../visionipc}/visionipc_server.h | 2 +- .../visionipc}/visionipc_tests.cc | 0 visionipc/ipc.h | 7 --- 49 files changed, 128 insertions(+), 129 deletions(-) delete mode 100644 messaging/.gitignore create mode 100644 msgq/.gitignore rename {messaging => msgq}/__init__.py (87%) rename {messaging => msgq}/event.cc (99%) rename {messaging => msgq}/event.h (100%) rename {messaging => msgq}/impl_fake.cc (82%) rename {messaging => msgq}/impl_fake.h (95%) rename {messaging => msgq}/impl_msgq.cc (99%) rename {messaging => msgq}/impl_msgq.h (95%) rename {messaging => msgq}/impl_zmq.cc (98%) rename {messaging => msgq}/impl_zmq.h (97%) rename messaging/messaging.cc => msgq/ipc.cc (94%) rename messaging/messaging.h => msgq/ipc.h (100%) rename messaging/messaging.pxd => msgq/ipc.pxd (93%) rename messaging/messaging_pyx.pyx => msgq/ipc_pyx.pyx (89%) rename {logger => msgq/logger}/logger.h (100%) rename {messaging => msgq}/msgq.cc (99%) rename {messaging => msgq}/msgq.h (100%) rename {messaging => msgq}/msgq_tests.cc (99%) rename {messaging => msgq}/test_runner.cc (100%) rename {messaging => msgq}/tests/__init__.py (100%) rename {messaging => msgq}/tests/test_fake.py (78%) rename {messaging => msgq}/tests/test_messaging.py (83%) rename {messaging => msgq}/tests/test_poller.py (75%) rename {visionipc => msgq/visionipc}/.gitignore (100%) rename {visionipc => msgq/visionipc}/__init__.py (100%) rename {visionipc => msgq/visionipc}/test_runner.cc (100%) rename {visionipc => msgq/visionipc}/tests/__init__.py (100%) rename {visionipc => msgq/visionipc}/tests/test_visionipc.py (100%) rename {visionipc => msgq/visionipc}/visionbuf.cc (100%) rename {visionipc => msgq/visionipc}/visionbuf.h (100%) rename {visionipc => msgq/visionipc}/visionbuf_cl.cc (100%) rename {visionipc => msgq/visionipc}/visionbuf_ion.cc (100%) rename visionipc/ipc.cc => msgq/visionipc/visionipc.cc (98%) rename {visionipc => msgq/visionipc}/visionipc.h (57%) rename {visionipc => msgq/visionipc}/visionipc.pxd (100%) rename {visionipc => msgq/visionipc}/visionipc_client.cc (97%) rename {visionipc => msgq/visionipc}/visionipc_client.h (95%) rename {visionipc => msgq/visionipc}/visionipc_pyx.pxd (100%) rename {visionipc => msgq/visionipc}/visionipc_pyx.pyx (100%) rename {visionipc => msgq/visionipc}/visionipc_server.cc (98%) rename {visionipc => msgq/visionipc}/visionipc_server.h (97%) rename {visionipc => msgq/visionipc}/visionipc_tests.cc (100%) delete mode 100644 visionipc/ipc.h diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2f42fa7de..16219b0bc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,8 +40,8 @@ jobs: run: | $RUN "export ${{ matrix.backend }}=1 && \ scons ${{ matrix.flags }} -j$(nproc) && \ - messaging/test_runner && \ - visionipc/test_runner" + msgq/test_runner && \ + msgq/visionipc/test_runner" - name: python tests run: $RUN_NAMED "${{ matrix.backend }}=1 coverage run -m unittest discover ." - name: Upload coverage diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 03360e0f9..b32abe20c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +files: ^msgq/ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 @@ -21,7 +22,7 @@ repos: entry: cppcheck language: system types: [c++] - exclude: '^(messaging/msgq_tests.cc|messaging/test_runner.cc)' + exclude: '^(msgq/msgq_tests.cc|msgq/test_runner.cc)' args: - --error-exitcode=1 - --inline-suppr diff --git a/Dockerfile b/Dockerfile index 4c1b68256..982d8fa5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,11 +37,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ RUN pip3 install --break-system-packages --no-cache-dir pyyaml Cython scons pycapnp pre-commit ruff parameterized coverage numpy -WORKDIR /project/ +WORKDIR /project/msgq/ RUN cd /tmp/ && \ git clone -b v2.x --depth 1 https://github.com/catchorg/Catch2.git && \ cd Catch2 && \ - mv single_include/catch2/ /project/ && \ + mv single_include/* /project/msgq/ && \ cd .. \ rm -rf Catch2 @@ -50,5 +50,5 @@ WORKDIR /project/msgq ENV PYTHONPATH=/project COPY . . -RUN rm -rf .git && \ +RUN ls && rm -rf .git && \ scons -c && scons -j$(nproc) diff --git a/SConscript b/SConscript index 5c5267cbc..7c0eb5a43 100644 --- a/SConscript +++ b/SConscript @@ -1,27 +1,24 @@ Import('env', 'envCython', 'arch', 'common') -visionipc_dir = Dir('visionipc') +visionipc_dir = Dir('msgq/visionipc') gen_dir = Dir('gen') -# Build messaging - - -messaging_objects = env.SharedObject([ - 'messaging/messaging.cc', - 'messaging/event.cc', - 'messaging/impl_zmq.cc', - 'messaging/impl_msgq.cc', - 'messaging/impl_fake.cc', - 'messaging/msgq.cc', +# Build msgq +msgq_objects = env.SharedObject([ + 'msgq/ipc.cc', + 'msgq/event.cc', + 'msgq/impl_zmq.cc', + 'msgq/impl_msgq.cc', + 'msgq/impl_fake.cc', + 'msgq/msgq.cc', ]) -messaging = env.Library('messaging', messaging_objects) -messaging_python = envCython.Program('messaging/messaging_pyx.so', 'messaging/messaging_pyx.pyx', LIBS=envCython["LIBS"]+[messaging, "zmq", common]) - +msgq = env.Library('msgq', msgq_objects) +msgq_python = envCython.Program('msgq/ipc_pyx.so', 'msgq/ipc_pyx.pyx', LIBS=envCython["LIBS"]+[msgq, "zmq", common]) # Build Vision IPC -vipc_files = ['ipc.cc', 'visionipc_server.cc', 'visionipc_client.cc', 'visionbuf.cc'] +vipc_files = ['visionipc.cc', 'visionipc_server.cc', 'visionipc_client.cc', 'visionbuf.cc'] vipc_sources = [f'{visionipc_dir.abspath}/{f}' for f in vipc_files] if arch == "larch64": @@ -29,12 +26,15 @@ if arch == "larch64": else: vipc_sources += [f'{visionipc_dir.abspath}/visionbuf_cl.cc'] +print(f'Building Vision IPC with {vipc_sources}') vipc_objects = env.SharedObject(vipc_sources) +print(f'Building Vision IPC with {vipc_objects}') + visionipc = env.Library('visionipc', vipc_objects) vipc_frameworks = [] -vipc_libs = envCython["LIBS"] + [visionipc, messaging, common, "zmq"] +vipc_libs = envCython["LIBS"] + [visionipc, msgq, common, "zmq"] if arch == "Darwin": vipc_frameworks.append('OpenCL') else: @@ -43,9 +43,9 @@ envCython.Program(f'{visionipc_dir.abspath}/visionipc_pyx.so', f'{visionipc_dir. LIBS=vipc_libs, FRAMEWORKS=vipc_frameworks) if GetOption('extras'): - env.Program('messaging/test_runner', ['messaging/test_runner.cc', 'messaging/msgq_tests.cc'], LIBS=[messaging, common]) - env.Program('visionipc/test_runner', - ['visionipc/test_runner.cc', 'visionipc/visionipc_tests.cc'], + env.Program('msgq/test_runner', ['msgq/test_runner.cc', 'msgq/msgq_tests.cc'], LIBS=[msgq, common]) + env.Program(f'{visionipc_dir.abspath}/test_runner', + [f'{visionipc_dir.abspath}/test_runner.cc', f'{visionipc_dir.abspath}/visionipc_tests.cc'], LIBS=['pthread'] + vipc_libs, FRAMEWORKS=vipc_frameworks) -Export('visionipc', 'messaging', 'messaging_python') +Export('visionipc', 'msgq', 'msgq_python') diff --git a/SConstruct b/SConstruct index 408c7bfa9..c1e7fc521 100644 --- a/SConstruct +++ b/SConstruct @@ -11,7 +11,8 @@ if platform.system() == "Darwin": common = '' cpppath = [ - f"#/../", + f"#/", + '#msgq/', '/usr/lib/include', '/opt/homebrew/include', sysconfig.get_paths()['include'], diff --git a/messaging/.gitignore b/messaging/.gitignore deleted file mode 100644 index 9f0c6fe7e..000000000 --- a/messaging/.gitignore +++ /dev/null @@ -1 +0,0 @@ -messaging_pyx.cpp diff --git a/msgq/.gitignore b/msgq/.gitignore new file mode 100644 index 000000000..6bd751773 --- /dev/null +++ b/msgq/.gitignore @@ -0,0 +1 @@ +ipc_pyx.cpp diff --git a/messaging/__init__.py b/msgq/__init__.py similarity index 87% rename from messaging/__init__.py rename to msgq/__init__.py index bf6b1e882..340a1254e 100644 --- a/messaging/__init__.py +++ b/msgq/__init__.py @@ -1,12 +1,12 @@ # must be built with scons -from msgq.messaging.messaging_pyx import Context, Poller, SubSocket, PubSocket, SocketEventHandle, toggle_fake_events, \ +from msgq.ipc_pyx import Context, Poller, SubSocket, PubSocket, SocketEventHandle, toggle_fake_events, \ set_fake_prefix, get_fake_prefix, delete_fake_prefix, wait_for_one_event -from msgq.messaging.messaging_pyx import MultiplePublishersError, MessagingError +from msgq.ipc_pyx import MultiplePublishersError, IpcError from typing import Optional, List assert MultiplePublishersError -assert MessagingError +assert IpcError assert toggle_fake_events assert set_fake_prefix assert get_fake_prefix diff --git a/messaging/event.cc b/msgq/event.cc similarity index 99% rename from messaging/event.cc rename to msgq/event.cc index 0c22e7868..be782e3b8 100644 --- a/messaging/event.cc +++ b/msgq/event.cc @@ -13,7 +13,7 @@ #include #include -#include "msgq/messaging/event.h" +#include "msgq/event.h" #ifndef __APPLE__ #include diff --git a/messaging/event.h b/msgq/event.h similarity index 100% rename from messaging/event.h rename to msgq/event.h diff --git a/messaging/impl_fake.cc b/msgq/impl_fake.cc similarity index 82% rename from messaging/impl_fake.cc rename to msgq/impl_fake.cc index 8399ba5f8..a7607206f 100644 --- a/messaging/impl_fake.cc +++ b/msgq/impl_fake.cc @@ -1,4 +1,4 @@ -#include "msgq/messaging/impl_fake.h" +#include "msgq/impl_fake.h" void FakePoller::registerSocket(SubSocket *socket) { this->sockets.push_back(socket); diff --git a/messaging/impl_fake.h b/msgq/impl_fake.h similarity index 95% rename from messaging/impl_fake.h rename to msgq/impl_fake.h index ae40a037f..2c3b74dc9 100644 --- a/messaging/impl_fake.h +++ b/msgq/impl_fake.h @@ -11,8 +11,8 @@ #include #include -#include "msgq/messaging/messaging.h" -#include "msgq/messaging/event.h" +#include "msgq/ipc.h" +#include "msgq/event.h" template class FakeSubSocket: public TSubSocket { diff --git a/messaging/impl_msgq.cc b/msgq/impl_msgq.cc similarity index 99% rename from messaging/impl_msgq.cc rename to msgq/impl_msgq.cc index 429642b87..b23991351 100644 --- a/messaging/impl_msgq.cc +++ b/msgq/impl_msgq.cc @@ -5,7 +5,7 @@ #include #include -#include "msgq/messaging/impl_msgq.h" +#include "msgq/impl_msgq.h" volatile sig_atomic_t msgq_do_exit = 0; diff --git a/messaging/impl_msgq.h b/msgq/impl_msgq.h similarity index 95% rename from messaging/impl_msgq.h rename to msgq/impl_msgq.h index 95f13799b..4d9db1850 100644 --- a/messaging/impl_msgq.h +++ b/msgq/impl_msgq.h @@ -3,8 +3,8 @@ #include #include -#include "msgq/messaging/messaging.h" -#include "msgq/messaging/msgq.h" +#include "msgq/ipc.h" +#include "msgq/msgq.h" #define MAX_POLLERS 128 diff --git a/messaging/impl_zmq.cc b/msgq/impl_zmq.cc similarity index 98% rename from messaging/impl_zmq.cc rename to msgq/impl_zmq.cc index 7e45f2bd9..434888eb8 100644 --- a/messaging/impl_zmq.cc +++ b/msgq/impl_zmq.cc @@ -5,7 +5,7 @@ #include #include -#include "msgq/messaging/impl_zmq.h" +#include "msgq/impl_zmq.h" //FIXME: This is a hack to get the port number from the socket name, might have collisions static int get_port(std::string endpoint) { diff --git a/messaging/impl_zmq.h b/msgq/impl_zmq.h similarity index 97% rename from messaging/impl_zmq.h rename to msgq/impl_zmq.h index 93ebfb5d4..718196e30 100644 --- a/messaging/impl_zmq.h +++ b/msgq/impl_zmq.h @@ -4,7 +4,7 @@ #include #include -#include "msgq/messaging/messaging.h" +#include "msgq/ipc.h" #define MAX_POLLERS 128 diff --git a/messaging/messaging.cc b/msgq/ipc.cc similarity index 94% rename from messaging/messaging.cc rename to msgq/ipc.cc index 5119816b8..f620f46fa 100644 --- a/messaging/messaging.cc +++ b/msgq/ipc.cc @@ -1,10 +1,10 @@ #include #include -#include "msgq/messaging/messaging.h" -#include "msgq/messaging/impl_zmq.h" -#include "msgq/messaging/impl_msgq.h" -#include "msgq/messaging/impl_fake.h" +#include "msgq/ipc.h" +#include "msgq/impl_zmq.h" +#include "msgq/impl_msgq.h" +#include "msgq/impl_fake.h" #ifdef __APPLE__ const bool MUST_USE_ZMQ = true; diff --git a/messaging/messaging.h b/msgq/ipc.h similarity index 100% rename from messaging/messaging.h rename to msgq/ipc.h diff --git a/messaging/messaging.pxd b/msgq/ipc.pxd similarity index 93% rename from messaging/messaging.pxd rename to msgq/ipc.pxd index 420fc09b5..2c7ac963e 100644 --- a/messaging/messaging.pxd +++ b/msgq/ipc.pxd @@ -6,7 +6,7 @@ from libcpp.vector cimport vector from libcpp cimport bool -cdef extern from "msgq/messaging/impl_fake.h": +cdef extern from "msgq/impl_fake.h": cdef cppclass Event: @staticmethod int wait_for_one(vector[Event], int) except + @@ -34,7 +34,7 @@ cdef extern from "msgq/messaging/impl_fake.h": Event recv_ready() -cdef extern from "msgq/messaging/messaging.h": +cdef extern from "msgq/ipc.h": cdef cppclass Context: @staticmethod Context * create() diff --git a/messaging/messaging_pyx.pyx b/msgq/ipc_pyx.pyx similarity index 89% rename from messaging/messaging_pyx.pyx rename to msgq/ipc_pyx.pyx index 8216aeea9..d8797f395 100644 --- a/messaging/messaging_pyx.pyx +++ b/msgq/ipc_pyx.pyx @@ -10,22 +10,22 @@ from libc.string cimport strerror from cython.operator import dereference -from .messaging cimport Context as cppContext -from .messaging cimport SubSocket as cppSubSocket -from .messaging cimport PubSocket as cppPubSocket -from .messaging cimport Poller as cppPoller -from .messaging cimport Message as cppMessage -from .messaging cimport Event as cppEvent, SocketEventHandle as cppSocketEventHandle +from .ipc cimport Context as cppContext +from .ipc cimport SubSocket as cppSubSocket +from .ipc cimport PubSocket as cppPubSocket +from .ipc cimport Poller as cppPoller +from .ipc cimport Message as cppMessage +from .ipc cimport Event as cppEvent, SocketEventHandle as cppSocketEventHandle -class MessagingError(Exception): +class IpcError(Exception): def __init__(self, endpoint=None): suffix = f"with {endpoint.decode('utf-8')}" if endpoint else "" message = f"Messaging failure {suffix}: {strerror(errno.errno).decode('utf-8')}" super().__init__(message) -class MultiplePublishersError(MessagingError): +class MultiplePublishersError(IpcError): pass @@ -170,7 +170,7 @@ cdef class SubSocket: self.is_owner = True if self.socket == NULL: - raise MessagingError + raise IpcError def __dealloc__(self): if self.is_owner: @@ -190,7 +190,7 @@ cdef class SubSocket: if errno.errno == errno.EADDRINUSE: raise MultiplePublishersError(endpoint) else: - raise MessagingError(endpoint) + raise IpcError(endpoint) def setTimeout(self, int timeout): self.socket.setTimeout(timeout) @@ -219,7 +219,7 @@ cdef class PubSocket: def __cinit__(self): self.socket = cppPubSocket.create() if self.socket == NULL: - raise MessagingError + raise IpcError def __dealloc__(self): del self.socket @@ -231,7 +231,7 @@ cdef class PubSocket: if errno.errno == errno.EADDRINUSE: raise MultiplePublishersError(endpoint) else: - raise MessagingError(endpoint) + raise IpcError(endpoint) def send(self, bytes data): length = len(data) @@ -241,7 +241,7 @@ cdef class PubSocket: if errno.errno == errno.EADDRINUSE: raise MultiplePublishersError else: - raise MessagingError + raise IpcError def all_readers_updated(self): return self.socket.all_readers_updated() diff --git a/logger/logger.h b/msgq/logger/logger.h similarity index 100% rename from logger/logger.h rename to msgq/logger/logger.h diff --git a/messaging/msgq.cc b/msgq/msgq.cc similarity index 99% rename from messaging/msgq.cc rename to msgq/msgq.cc index 9344652f0..fed2959bd 100644 --- a/messaging/msgq.cc +++ b/msgq/msgq.cc @@ -23,7 +23,7 @@ #include -#include "msgq/messaging/msgq.h" +#include "msgq/msgq.h" void sigusr2_handler(int signal) { assert(signal == SIGUSR2); diff --git a/messaging/msgq.h b/msgq/msgq.h similarity index 100% rename from messaging/msgq.h rename to msgq/msgq.h diff --git a/messaging/msgq_tests.cc b/msgq/msgq_tests.cc similarity index 99% rename from messaging/msgq_tests.cc rename to msgq/msgq_tests.cc index bc3984e62..02f17917a 100644 --- a/messaging/msgq_tests.cc +++ b/msgq/msgq_tests.cc @@ -1,5 +1,5 @@ #include "catch2/catch.hpp" -#include "msgq/messaging/msgq.h" +#include "msgq/msgq.h" TEST_CASE("ALIGN") { diff --git a/messaging/test_runner.cc b/msgq/test_runner.cc similarity index 100% rename from messaging/test_runner.cc rename to msgq/test_runner.cc diff --git a/messaging/tests/__init__.py b/msgq/tests/__init__.py similarity index 100% rename from messaging/tests/__init__.py rename to msgq/tests/__init__.py diff --git a/messaging/tests/test_fake.py b/msgq/tests/test_fake.py similarity index 78% rename from messaging/tests/test_fake.py rename to msgq/tests/test_fake.py index d17065565..b5ed297ab 100644 --- a/messaging/tests/test_fake.py +++ b/msgq/tests/test_fake.py @@ -2,11 +2,10 @@ import unittest import multiprocessing import platform +import msgq from parameterized import parameterized_class from typing import Optional -import msgq.messaging as messaging - WAIT_TIMEOUT = 5 @@ -14,7 +13,7 @@ class TestEvents(unittest.TestCase): def test_mutation(self): - handle = messaging.fake_event_handle("carState") + handle = msgq.fake_event_handle("carState") event = handle.recv_called_event self.assertFalse(event.peek()) @@ -26,7 +25,7 @@ def test_mutation(self): del event def test_wait(self): - handle = messaging.fake_event_handle("carState") + handle = msgq.fake_event_handle("carState") event = handle.recv_called_event event.set() @@ -37,7 +36,7 @@ def test_wait(self): self.fail("event.wait() timed out") def test_wait_multiprocess(self): - handle = messaging.fake_event_handle("carState") + handle = msgq.fake_event_handle("carState") event = handle.recv_called_event def set_event_run(): @@ -54,7 +53,7 @@ def set_event_run(): p.kill() def test_wait_zero_timeout(self): - handle = messaging.fake_event_handle("carState") + handle = msgq.fake_event_handle("carState") event = handle.recv_called_event try: @@ -71,18 +70,18 @@ class TestFakeSockets(unittest.TestCase): prefix: Optional[str] = None def setUp(self): - messaging.toggle_fake_events(True) + msgq.toggle_fake_events(True) if self.prefix is not None: - messaging.set_fake_prefix(self.prefix) + msgq.set_fake_prefix(self.prefix) else: - messaging.delete_fake_prefix() + msgq.delete_fake_prefix() def tearDown(self): - messaging.toggle_fake_events(False) - messaging.delete_fake_prefix() + msgq.toggle_fake_events(False) + msgq.delete_fake_prefix() def test_event_handle_init(self): - handle = messaging.fake_event_handle("controlsState", override=True) + handle = msgq.fake_event_handle("controlsState", override=True) self.assertFalse(handle.enabled) self.assertGreaterEqual(handle.recv_called_event.fd, 0) @@ -90,9 +89,9 @@ def test_event_handle_init(self): def test_non_managed_socket_state(self): # non managed socket should have zero state - _ = messaging.pub_sock("ubloxGnss") + _ = msgq.pub_sock("ubloxGnss") - handle = messaging.fake_event_handle("ubloxGnss", override=False) + handle = msgq.fake_event_handle("ubloxGnss", override=False) self.assertFalse(handle.enabled) self.assertEqual(handle.recv_called_event.fd, 0) @@ -100,26 +99,26 @@ def test_non_managed_socket_state(self): def test_managed_socket_state(self): # managed socket should not change anything about the state - handle = messaging.fake_event_handle("ubloxGnss") + handle = msgq.fake_event_handle("ubloxGnss") handle.enabled = True expected_enabled = handle.enabled expected_recv_called_fd = handle.recv_called_event.fd expected_recv_ready_fd = handle.recv_ready_event.fd - _ = messaging.pub_sock("ubloxGnss") + _ = msgq.pub_sock("ubloxGnss") self.assertEqual(handle.enabled, expected_enabled) self.assertEqual(handle.recv_called_event.fd, expected_recv_called_fd) self.assertEqual(handle.recv_ready_event.fd, expected_recv_ready_fd) def test_sockets_enable_disable(self): - carState_handle = messaging.fake_event_handle("ubloxGnss", enable=True) + carState_handle = msgq.fake_event_handle("ubloxGnss", enable=True) recv_called = carState_handle.recv_called_event recv_ready = carState_handle.recv_ready_event - pub_sock = messaging.pub_sock("ubloxGnss") - sub_sock = messaging.sub_sock("ubloxGnss") + pub_sock = msgq.pub_sock("ubloxGnss") + sub_sock = msgq.sub_sock("ubloxGnss") try: carState_handle.enabled = True @@ -139,8 +138,8 @@ def test_sockets_enable_disable(self): def test_synced_pub_sub(self): def daemon_repub_process_run(): - pub_sock = messaging.pub_sock("ubloxGnss") - sub_sock = messaging.sub_sock("carState") + pub_sock = msgq.pub_sock("ubloxGnss") + sub_sock = msgq.sub_sock("carState") frame = -1 while True: @@ -153,15 +152,15 @@ def daemon_repub_process_run(): bts = frame.to_bytes(8, 'little') pub_sock.send(bts) - carState_handle = messaging.fake_event_handle("carState", enable=True) + carState_handle = msgq.fake_event_handle("carState", enable=True) recv_called = carState_handle.recv_called_event recv_ready = carState_handle.recv_ready_event p = multiprocessing.Process(target=daemon_repub_process_run) p.start() - pub_sock = messaging.pub_sock("carState") - sub_sock = messaging.sub_sock("ubloxGnss") + pub_sock = msgq.pub_sock("carState") + sub_sock = msgq.sub_sock("ubloxGnss") try: for i in range(10): diff --git a/messaging/tests/test_messaging.py b/msgq/tests/test_messaging.py similarity index 83% rename from messaging/tests/test_messaging.py rename to msgq/tests/test_messaging.py index d2e30b61f..bbeeb3d84 100755 --- a/messaging/tests/test_messaging.py +++ b/msgq/tests/test_messaging.py @@ -5,8 +5,7 @@ import time import string import unittest - -import msgq.messaging as messaging +import msgq def random_sock(): @@ -39,8 +38,8 @@ def setUp(self): def test_pub_sub(self): sock = random_sock() - pub_sock = messaging.pub_sock(sock) - sub_sock = messaging.sub_sock(sock, conflate=False, timeout=None) + pub_sock = msgq.pub_sock(sock) + sub_sock = msgq.sub_sock(sock, conflate=False, timeout=None) zmq_sleep(3) for _ in range(1000): @@ -51,11 +50,11 @@ def test_pub_sub(self): def test_conflate(self): sock = random_sock() - pub_sock = messaging.pub_sock(sock) + pub_sock = msgq.pub_sock(sock) for conflate in [True, False]: for _ in range(10): num_msgs = random.randint(3, 10) - sub_sock = messaging.sub_sock(sock, conflate=conflate, timeout=None) + sub_sock = msgq.sub_sock(sock, conflate=conflate, timeout=None) zmq_sleep() sent_msgs = [] @@ -64,7 +63,7 @@ def test_conflate(self): pub_sock.send(msg) sent_msgs.append(msg) time.sleep(0.1) - recvd_msgs = messaging.drain_sock_raw(sub_sock) + recvd_msgs = msgq.drain_sock_raw(sub_sock) if conflate: self.assertEqual(len(recvd_msgs), 1) else: @@ -75,7 +74,7 @@ def test_receive_timeout(self): sock = random_sock() for _ in range(10): timeout = random.randrange(200) - sub_sock = messaging.sub_sock(sock, timeout=timeout) + sub_sock = msgq.sub_sock(sock, timeout=timeout) zmq_sleep() start_time = time.monotonic() diff --git a/messaging/tests/test_poller.py b/msgq/tests/test_poller.py similarity index 75% rename from messaging/tests/test_poller.py rename to msgq/tests/test_poller.py index 5ac990e31..a68ff4fe7 100644 --- a/messaging/tests/test_poller.py +++ b/msgq/tests/test_poller.py @@ -1,16 +1,16 @@ import unittest import time -import msgq.messaging as messaging +import msgq import concurrent.futures SERVICE_NAME = 'myService' def poller(): - context = messaging.Context() + context = msgq.Context() - p = messaging.Poller() + p = msgq.Poller() - sub = messaging.SubSocket() + sub = msgq.SubSocket() sub.connect(context, SERVICE_NAME) p.registerSocket(sub) @@ -22,9 +22,9 @@ def poller(): class TestPoller(unittest.TestCase): def test_poll_once(self): - context = messaging.Context() + context = msgq.Context() - pub = messaging.PubSocket() + pub = msgq.PubSocket() pub.connect(context, SERVICE_NAME) with concurrent.futures.ThreadPoolExecutor() as e: @@ -44,18 +44,18 @@ def test_poll_once(self): self.assertEqual(result, [b"a"]) def test_poll_and_create_many_subscribers(self): - context = messaging.Context() + context = msgq.Context() - pub = messaging.PubSocket() + pub = msgq.PubSocket() pub.connect(context, SERVICE_NAME) with concurrent.futures.ThreadPoolExecutor() as e: poll = e.submit(poller) time.sleep(0.1) # Slow joiner syndrome - c = messaging.Context() + c = msgq.Context() for _ in range(10): - messaging.SubSocket().connect(c, SERVICE_NAME) + msgq.SubSocket().connect(c, SERVICE_NAME) time.sleep(0.1) @@ -71,13 +71,13 @@ def test_poll_and_create_many_subscribers(self): self.assertEqual(result, [b"a"]) def test_multiple_publishers_exception(self): - context = messaging.Context() + context = msgq.Context() - with self.assertRaises(messaging.MultiplePublishersError): - pub1 = messaging.PubSocket() + with self.assertRaises(msgq.MultiplePublishersError): + pub1 = msgq.PubSocket() pub1.connect(context, SERVICE_NAME) - pub2 = messaging.PubSocket() + pub2 = msgq.PubSocket() pub2.connect(context, SERVICE_NAME) pub1.send(b"a") @@ -87,12 +87,12 @@ def test_multiple_publishers_exception(self): context.term() def test_multiple_messages(self): - context = messaging.Context() + context = msgq.Context() - pub = messaging.PubSocket() + pub = msgq.PubSocket() pub.connect(context, SERVICE_NAME) - sub = messaging.SubSocket() + sub = msgq.SubSocket() sub.connect(context, SERVICE_NAME) time.sleep(0.1) # Slow joiner @@ -119,12 +119,12 @@ def test_multiple_messages(self): context.term() def test_conflate(self): - context = messaging.Context() + context = msgq.Context() - pub = messaging.PubSocket() + pub = msgq.PubSocket() pub.connect(context, SERVICE_NAME) - sub = messaging.SubSocket() + sub = msgq.SubSocket() sub.connect(context, SERVICE_NAME, conflate=True) time.sleep(0.1) # Slow joiner diff --git a/visionipc/.gitignore b/msgq/visionipc/.gitignore similarity index 100% rename from visionipc/.gitignore rename to msgq/visionipc/.gitignore diff --git a/visionipc/__init__.py b/msgq/visionipc/__init__.py similarity index 100% rename from visionipc/__init__.py rename to msgq/visionipc/__init__.py diff --git a/visionipc/test_runner.cc b/msgq/visionipc/test_runner.cc similarity index 100% rename from visionipc/test_runner.cc rename to msgq/visionipc/test_runner.cc diff --git a/visionipc/tests/__init__.py b/msgq/visionipc/tests/__init__.py similarity index 100% rename from visionipc/tests/__init__.py rename to msgq/visionipc/tests/__init__.py diff --git a/visionipc/tests/test_visionipc.py b/msgq/visionipc/tests/test_visionipc.py similarity index 100% rename from visionipc/tests/test_visionipc.py rename to msgq/visionipc/tests/test_visionipc.py diff --git a/visionipc/visionbuf.cc b/msgq/visionipc/visionbuf.cc similarity index 100% rename from visionipc/visionbuf.cc rename to msgq/visionipc/visionbuf.cc diff --git a/visionipc/visionbuf.h b/msgq/visionipc/visionbuf.h similarity index 100% rename from visionipc/visionbuf.h rename to msgq/visionipc/visionbuf.h diff --git a/visionipc/visionbuf_cl.cc b/msgq/visionipc/visionbuf_cl.cc similarity index 100% rename from visionipc/visionbuf_cl.cc rename to msgq/visionipc/visionbuf_cl.cc diff --git a/visionipc/visionbuf_ion.cc b/msgq/visionipc/visionbuf_ion.cc similarity index 100% rename from visionipc/visionbuf_ion.cc rename to msgq/visionipc/visionbuf_ion.cc diff --git a/visionipc/ipc.cc b/msgq/visionipc/visionipc.cc similarity index 98% rename from visionipc/ipc.cc rename to msgq/visionipc/visionipc.cc index 30f7d21d4..48e13c27d 100644 --- a/visionipc/ipc.cc +++ b/msgq/visionipc/visionipc.cc @@ -15,7 +15,7 @@ #define getsocket() socket(AF_UNIX, SOCK_SEQPACKET, 0) #endif -#include "msgq/visionipc/ipc.h" +#include "msgq/visionipc/visionipc.h" int ipc_connect(const char* socket_path) { int err; diff --git a/visionipc/visionipc.h b/msgq/visionipc/visionipc.h similarity index 57% rename from visionipc/visionipc.h rename to msgq/visionipc/visionipc.h index 7489bc958..224f129c9 100644 --- a/visionipc/visionipc.h +++ b/msgq/visionipc/visionipc.h @@ -3,6 +3,12 @@ #include #include + +int ipc_connect(const char* socket_path); +int ipc_bind(const char* socket_path); +int ipc_sendrecv_with_fds(bool send, int fd, void *buf, size_t buf_size, int* fds, int num_fds, + int *out_num_fds); + constexpr int VISIONIPC_MAX_FDS = 128; struct VisionIpcBufExtra { diff --git a/visionipc/visionipc.pxd b/msgq/visionipc/visionipc.pxd similarity index 100% rename from visionipc/visionipc.pxd rename to msgq/visionipc/visionipc.pxd diff --git a/visionipc/visionipc_client.cc b/msgq/visionipc/visionipc_client.cc similarity index 97% rename from visionipc/visionipc_client.cc rename to msgq/visionipc/visionipc_client.cc index ab1bfa3ae..9b24da296 100644 --- a/visionipc/visionipc_client.cc +++ b/msgq/visionipc/visionipc_client.cc @@ -4,11 +4,11 @@ #include #include -#include "msgq/visionipc/ipc.h" +#include "msgq/visionipc/visionipc.h" #include "msgq/visionipc/visionipc_client.h" #include "msgq/visionipc/visionipc_server.h" -#include "msgq/logger/logger.h" -#include "msgq/logger/logger.h" +#include "logger/logger.h" +#include "logger/logger.h" static int connect_to_vipc_server(const std::string &name, bool blocking) { const std::string ipc_path = get_ipc_path(name); diff --git a/visionipc/visionipc_client.h b/msgq/visionipc/visionipc_client.h similarity index 95% rename from visionipc/visionipc_client.h rename to msgq/visionipc/visionipc_client.h index e03677867..e4abdc5de 100644 --- a/visionipc/visionipc_client.h +++ b/msgq/visionipc/visionipc_client.h @@ -3,7 +3,7 @@ #include #include -#include "msgq/messaging/messaging.h" +#include "msgq/ipc.h" #include "msgq/visionipc/visionbuf.h" diff --git a/visionipc/visionipc_pyx.pxd b/msgq/visionipc/visionipc_pyx.pxd similarity index 100% rename from visionipc/visionipc_pyx.pxd rename to msgq/visionipc/visionipc_pyx.pxd diff --git a/visionipc/visionipc_pyx.pyx b/msgq/visionipc/visionipc_pyx.pyx similarity index 100% rename from visionipc/visionipc_pyx.pyx rename to msgq/visionipc/visionipc_pyx.pyx diff --git a/visionipc/visionipc_server.cc b/msgq/visionipc/visionipc_server.cc similarity index 98% rename from visionipc/visionipc_server.cc rename to msgq/visionipc/visionipc_server.cc index e2ac55e64..611d10b20 100644 --- a/visionipc/visionipc_server.cc +++ b/msgq/visionipc/visionipc_server.cc @@ -8,10 +8,10 @@ #include #include -#include "msgq/messaging/messaging.h" -#include "msgq/visionipc/ipc.h" +#include "msgq/ipc.h" +#include "msgq/visionipc/visionipc.h" #include "msgq/visionipc/visionipc_server.h" -#include "msgq/logger/logger.h" +#include "logger/logger.h" std::string get_endpoint_name(std::string name, VisionStreamType type){ if (messaging_use_zmq()){ diff --git a/visionipc/visionipc_server.h b/msgq/visionipc/visionipc_server.h similarity index 97% rename from visionipc/visionipc_server.h rename to msgq/visionipc/visionipc_server.h index 4207f41cd..feacc4d10 100644 --- a/visionipc/visionipc_server.h +++ b/msgq/visionipc/visionipc_server.h @@ -5,7 +5,7 @@ #include #include -#include "msgq/messaging/messaging.h" +#include "msgq/ipc.h" #include "msgq/visionipc/visionbuf.h" std::string get_endpoint_name(std::string name, VisionStreamType type); diff --git a/visionipc/visionipc_tests.cc b/msgq/visionipc/visionipc_tests.cc similarity index 100% rename from visionipc/visionipc_tests.cc rename to msgq/visionipc/visionipc_tests.cc diff --git a/visionipc/ipc.h b/visionipc/ipc.h deleted file mode 100644 index 14bb61a52..000000000 --- a/visionipc/ipc.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include - -int ipc_connect(const char* socket_path); -int ipc_bind(const char* socket_path); -int ipc_sendrecv_with_fds(bool send, int fd, void *buf, size_t buf_size, int* fds, int num_fds, - int *out_num_fds);