Keep UDP framing compatible with the pinned C++11 compiler
This commit is contained in:
1 parent
5e25faa3d0
commit
f4a9a05f75
7 files changed
+47
-18
No files matched your search
@@ -123,7 +123,13 @@ bool UDPBridge::sendFrame(uint8_t peer, udp::Kind kind, uint64_t recipient,
|
||||
if (!_initialized || peer >= udp::MAX_PEERS || !_active.peers[peer].port) return false;
|
||||
if (!sequence) sequence = nextSequence();
|
||||
if (!_initialized || !sequence) return false;
|
||||
const udp::Frame frame{kind, _boot, recipient, sequence, payload, length};
|
||||
udp::Frame frame;
|
||||
frame.kind = kind;
|
||||
frame.sender = _boot;
|
||||
frame.recipient = recipient;
|
||||
frame.sequence = sequence;
|
||||
frame.payload = payload;
|
||||
frame.length = length;
|
||||
uint8_t bytes[udp::MAX_FRAME];
|
||||
const size_t size = udp::encode(bytes, sizeof(bytes), frame, authenticate, this);
|
||||
if (!size) { error(EINVAL); return false; }
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
inline uint32_t test_now = 0;
|
||||
extern uint32_t test_now;
|
||||
inline uint32_t millis() { return test_now; }
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
inline uint32_t random_state = 0x1678abcd;
|
||||
extern uint32_t random_state;
|
||||
inline uint32_t esp_random() { random_state ^= random_state << 13; random_state ^= random_state >> 17; random_state ^= random_state << 5; return random_state; }
|
||||
+2
-2
@@ -15,7 +15,7 @@ struct NodePrefs { uint8_t bridge_pkt_src = 1; uint32_t bridge_delay = 0; char b
|
||||
|
||||
namespace mesh {
|
||||
#if defined(ARDUINO)
|
||||
inline bool logging_enabled = false, debug_enabled = false;
|
||||
extern bool logging_enabled, debug_enabled;
|
||||
class DebugStream : public Stream {
|
||||
public:
|
||||
int capacity = 4096;
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
bytes.insert(bytes.end(), data, data + size); return size;
|
||||
}
|
||||
};
|
||||
inline DebugStream debug_stream;
|
||||
extern DebugStream debug_stream;
|
||||
inline bool isUsbDebugLoggingEnabled() { return logging_enabled && debug_enabled; }
|
||||
inline Stream& usbLoggingPort() { return debug_stream; }
|
||||
inline size_t nrf52DebugPrintf(const char* format, ...) {
|
||||
|
||||
+5
-5
@@ -11,11 +11,11 @@
|
||||
namespace udp_test {
|
||||
struct Datagram { sockaddr_in source{}, target{}; std::vector<uint8_t> bytes; };
|
||||
struct Socket { bool open = false; uint32_t ip = 0; uint16_t port = 0; std::deque<Datagram> rx; };
|
||||
inline Socket sockets[64];
|
||||
inline int next_socket = 0, opens = 0, receives = 0, sends = 0, receive_cap = 0;
|
||||
inline uint32_t creating_ip = 0;
|
||||
inline bool fail_send = false, fail_rcvbuf = false;
|
||||
inline std::vector<Datagram> sent;
|
||||
extern Socket sockets[64];
|
||||
extern int next_socket, opens, receives, sends, receive_cap;
|
||||
extern uint32_t creating_ip;
|
||||
extern bool fail_send, fail_rcvbuf;
|
||||
extern std::vector<Datagram> sent;
|
||||
inline void inject(int index, const Datagram& packet) { sockets[index].rx.push_back(packet); }
|
||||
}
|
||||
inline int udpTestSocket(int, int, int) {
|
||||
|
||||
Vendored
+13
@@ -9,6 +9,19 @@
|
||||
#include "lwip/sockets.h"
|
||||
#include "helpers/bridges/UDPBridge.h"
|
||||
#include <SHA256.h>
|
||||
uint32_t test_now = 0;
|
||||
uint32_t random_state = 0x1678abcd;
|
||||
namespace mesh {
|
||||
bool logging_enabled = false, debug_enabled = false;
|
||||
DebugStream debug_stream;
|
||||
}
|
||||
namespace udp_test {
|
||||
Socket sockets[64];
|
||||
int next_socket = 0, opens = 0, receives = 0, sends = 0, receive_cap = 0;
|
||||
uint32_t creating_ip = 0;
|
||||
bool fail_send = false, fail_rcvbuf = false;
|
||||
std::vector<Datagram> sent;
|
||||
}
|
||||
namespace udp = mesh::bridge::udp;
|
||||
static bool hmac(void* context, const uint8_t* bytes, size_t size, uint8_t digest[32]) {
|
||||
const char* key = static_cast<const char*>(context);
|
||||
|
||||
+18
-8
@@ -21,18 +21,28 @@ class UDPBridgeTests(unittest.TestCase):
|
||||
cls.binaries = []
|
||||
for cooperative in (0, 1):
|
||||
binary = Path(cls.temporary.name) / f'bridge-{cooperative}'
|
||||
built = subprocess.run([
|
||||
compiler, '-std=c++17', '-Wall', '-Wextra', '-Werror', '-O1',
|
||||
flags = [
|
||||
compiler, '-Wall', '-Wextra', '-Werror', '-O1',
|
||||
'-fsanitize=address,undefined', '-fno-sanitize-recover=all',
|
||||
'-fno-pie', '-no-pie', '-DARDUINO=1', '-DESP32=1', '-DWITH_UDP_BRIDGE=1',
|
||||
f'-DMESH_ESP32_USB_CONSOLE_COOPERATIVE={cooperative}',
|
||||
'-I' + str(FIXTURES), '-I' + str(ROOT / 'test/mocks'), '-I' + str(ROOT / 'src'),
|
||||
str(ROOT / 'test/fixtures/udp_bridge_runtime.cpp'),
|
||||
str(ROOT / 'src/helpers/bridges/UDPBridge.cpp'), '-o', str(binary),
|
||||
], capture_output=True, text=True, timeout=60)
|
||||
if built.returncode:
|
||||
cls.temporary.cleanup()
|
||||
raise AssertionError(built.stdout + built.stderr)
|
||||
]
|
||||
core = Path(cls.temporary.name) / f'core-{cooperative}.o'
|
||||
# The pinned ESP32 GCC 8 firmware builds use C++11. Compile the
|
||||
# actual implementation with that language level, even though the
|
||||
# test driver uses C++17 aggregate initialization for test vectors.
|
||||
commands = [
|
||||
flags + ['-std=c++11', '-pedantic-errors', '-c',
|
||||
str(ROOT / 'src/helpers/bridges/UDPBridge.cpp'), '-o', str(core)],
|
||||
flags + ['-std=c++17', str(ROOT / 'test/fixtures/udp_bridge_runtime.cpp'),
|
||||
str(core), '-o', str(binary)],
|
||||
]
|
||||
for command in commands:
|
||||
built = subprocess.run(command, capture_output=True, text=True, timeout=60)
|
||||
if built.returncode:
|
||||
cls.temporary.cleanup()
|
||||
raise AssertionError(built.stdout + built.stderr)
|
||||
cls.binaries.append(binary)
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in new issue
Block a user