commit
4fd5ac8326
@ -0,0 +1,57 @@
|
|||||||
|
ifndef VERBOSE
|
||||||
|
.SILENT:
|
||||||
|
endif
|
||||||
|
|
||||||
|
.DEFAULT_GOAL := all
|
||||||
|
|
||||||
|
include common.mk
|
||||||
|
|
||||||
|
TARGET=test/$(TEST)
|
||||||
|
|
||||||
|
GTEST_OUTPUT = $(BUILD_DIR)/gtest
|
||||||
|
|
||||||
|
TEST_OBJ = $(BUILD_DIR)/test_obj
|
||||||
|
|
||||||
|
OUTPUTS := $(TEST_OBJ)/$(TEST) $(GTEST_OUTPUT)
|
||||||
|
|
||||||
|
GTEST_INC := \
|
||||||
|
$(LIB_PATH)/googletest/googletest/include\
|
||||||
|
$(LIB_PATH)/googletest/googlemock/include\
|
||||||
|
|
||||||
|
GTEST_INTERNAL_INC :=\
|
||||||
|
$(LIB_PATH)/googletest/googletest\
|
||||||
|
$(LIB_PATH)/googletest/googlemock
|
||||||
|
|
||||||
|
$(GTEST_OUTPUT)_SRC :=\
|
||||||
|
googletest/src/gtest-all.cc\
|
||||||
|
googletest/src/gtest_main.cc\
|
||||||
|
googlemock/src/gmock-all.cc
|
||||||
|
|
||||||
|
$(GTEST_OUTPUT)_DEFS :=
|
||||||
|
$(GTEST_OUTPUT)_INC := $(GTEST_INC) $(GTEST_INTERNAL_INC)
|
||||||
|
|
||||||
|
LDFLAGS += -lstdc++ -lpthread -shared-libgcc
|
||||||
|
CREATE_MAP := no
|
||||||
|
|
||||||
|
VPATH +=\
|
||||||
|
$(LIB_PATH)/googletest\
|
||||||
|
$(LIB_PATH)/googlemock
|
||||||
|
|
||||||
|
all: elf
|
||||||
|
|
||||||
|
VPATH += $(COMMON_VPATH)
|
||||||
|
|
||||||
|
include $(TMK_PATH)/common.mk
|
||||||
|
include $(QUANTUM_PATH)/serial_link/tests/rules.mk
|
||||||
|
|
||||||
|
$(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC)
|
||||||
|
$(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC)
|
||||||
|
$(TEST_OBJ)/$(TEST)_DEFS := $($(TEST)_DEFS)
|
||||||
|
|
||||||
|
include $(TMK_PATH)/native.mk
|
||||||
|
include $(TMK_PATH)/rules.mk
|
||||||
|
|
||||||
|
|
||||||
|
$(shell mkdir -p $(BUILD_DIR)/test 2>/dev/null)
|
||||||
|
$(shell mkdir -p $(TEST_OBJ) 2>/dev/null)
|
||||||
|
|
@ -0,0 +1,26 @@
|
|||||||
|
include message.mk
|
||||||
|
|
||||||
|
# Directory common source files exist
|
||||||
|
TOP_DIR = .
|
||||||
|
TMK_DIR = tmk_core
|
||||||
|
TMK_PATH = $(TOP_DIR)/$(TMK_DIR)
|
||||||
|
LIB_PATH = $(TOP_DIR)/lib
|
||||||
|
|
||||||
|
QUANTUM_DIR = quantum
|
||||||
|
QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR)
|
||||||
|
|
||||||
|
BUILD_DIR := $(TOP_DIR)/.build
|
||||||
|
|
||||||
|
SERIAL_DIR := $(QUANTUM_DIR)/serial_link
|
||||||
|
SERIAL_PATH := $(QUANTUM_PATH)/serial_link
|
||||||
|
SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c)
|
||||||
|
SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c)
|
||||||
|
SERIAL_DEFS += -DSERIAL_LINK_ENABLE
|
||||||
|
|
||||||
|
COMMON_VPATH := $(TOP_DIR)
|
||||||
|
COMMON_VPATH += $(TMK_PATH)
|
||||||
|
COMMON_VPATH += $(QUANTUM_PATH)
|
||||||
|
COMMON_VPATH += $(QUANTUM_PATH)/keymap_extras
|
||||||
|
COMMON_VPATH += $(QUANTUM_PATH)/audio
|
||||||
|
COMMON_VPATH += $(QUANTUM_PATH)/process_keycode
|
||||||
|
COMMON_VPATH += $(SERIAL_PATH)
|
@ -0,0 +1 @@
|
|||||||
|
Subproject commit ec44c6c1675c25b9827aacd08c02433cccde7780
|
@ -1,231 +0,0 @@
|
|||||||
/*
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2016 Fred Sundvik
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <cgreen/cgreen.h>
|
|
||||||
#include <cgreen/mocks.h>
|
|
||||||
#include "serial_link/protocol/byte_stuffer.c"
|
|
||||||
#include "serial_link/protocol/frame_validator.c"
|
|
||||||
#include "serial_link/protocol/frame_router.c"
|
|
||||||
#include "serial_link/protocol/transport.h"
|
|
||||||
|
|
||||||
static uint8_t received_data[256];
|
|
||||||
static uint16_t received_data_size;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t sent_data[256];
|
|
||||||
uint16_t sent_data_size;
|
|
||||||
} receive_buffer_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
receive_buffer_t send_buffers[2];
|
|
||||||
} router_buffer_t;
|
|
||||||
|
|
||||||
router_buffer_t router_buffers[8];
|
|
||||||
|
|
||||||
router_buffer_t* current_router_buffer;
|
|
||||||
|
|
||||||
|
|
||||||
Describe(FrameRouter);
|
|
||||||
BeforeEach(FrameRouter) {
|
|
||||||
init_byte_stuffer();
|
|
||||||
memset(router_buffers, 0, sizeof(router_buffers));
|
|
||||||
current_router_buffer = 0;
|
|
||||||
}
|
|
||||||
AfterEach(FrameRouter) {}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t data;
|
|
||||||
uint8_t extra[16];
|
|
||||||
} frame_buffer_t;
|
|
||||||
|
|
||||||
|
|
||||||
void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
|
|
||||||
receive_buffer_t* buffer = ¤t_router_buffer->send_buffers[link];
|
|
||||||
memcpy(buffer->sent_data + buffer->sent_data_size, data, size);
|
|
||||||
buffer->sent_data_size += size;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void receive_data(uint8_t link, uint8_t* data, uint16_t size) {
|
|
||||||
int i;
|
|
||||||
for(i=0;i<size;i++) {
|
|
||||||
byte_stuffer_recv_byte(link, data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void activate_router(uint8_t num) {
|
|
||||||
current_router_buffer = router_buffers + num;
|
|
||||||
router_set_master(num==0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void simulate_transport(uint8_t from, uint8_t to) {
|
|
||||||
activate_router(to);
|
|
||||||
if (from > to) {
|
|
||||||
receive_data(DOWN_LINK,
|
|
||||||
router_buffers[from].send_buffers[UP_LINK].sent_data,
|
|
||||||
router_buffers[from].send_buffers[UP_LINK].sent_data_size);
|
|
||||||
}
|
|
||||||
else if(to > from) {
|
|
||||||
receive_data(UP_LINK,
|
|
||||||
router_buffers[from].send_buffers[DOWN_LINK].sent_data,
|
|
||||||
router_buffers[from].send_buffers[DOWN_LINK].sent_data_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) {
|
|
||||||
mock(from, data, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Ensure(FrameRouter, master_broadcast_is_received_by_everyone) {
|
|
||||||
frame_buffer_t data;
|
|
||||||
data.data = 0xAB7055BB;
|
|
||||||
activate_router(0);
|
|
||||||
router_send_frame(0xFF, (uint8_t*)&data, 4);
|
|
||||||
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
|
|
||||||
expect(transport_recv_frame,
|
|
||||||
when(from, is_equal_to(0)),
|
|
||||||
when(size, is_equal_to(4)),
|
|
||||||
when(data, is_equal_to_contents_of(&data.data, 4))
|
|
||||||
);
|
|
||||||
simulate_transport(0, 1);
|
|
||||||
assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
|
|
||||||
expect(transport_recv_frame,
|
|
||||||
when(from, is_equal_to(0)),
|
|
||||||
when(size, is_equal_to(4)),
|
|
||||||
when(data, is_equal_to_contents_of(&data.data, 4))
|
|
||||||
);
|
|
||||||
simulate_transport(1, 2);
|
|
||||||
assert_that(router_buffers[2].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[2].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(FrameRouter, master_send_is_received_by_targets) {
|
|
||||||
frame_buffer_t data;
|
|
||||||
data.data = 0xAB7055BB;
|
|
||||||
activate_router(0);
|
|
||||||
router_send_frame((1 << 1) | (1 << 2), (uint8_t*)&data, 4);
|
|
||||||
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
|
|
||||||
simulate_transport(0, 1);
|
|
||||||
assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
|
|
||||||
expect(transport_recv_frame,
|
|
||||||
when(from, is_equal_to(0)),
|
|
||||||
when(size, is_equal_to(4)),
|
|
||||||
when(data, is_equal_to_contents_of(&data.data, 4))
|
|
||||||
);
|
|
||||||
simulate_transport(1, 2);
|
|
||||||
assert_that(router_buffers[2].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[2].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
|
|
||||||
expect(transport_recv_frame,
|
|
||||||
when(from, is_equal_to(0)),
|
|
||||||
when(size, is_equal_to(4)),
|
|
||||||
when(data, is_equal_to_contents_of(&data.data, 4))
|
|
||||||
);
|
|
||||||
simulate_transport(2, 3);
|
|
||||||
assert_that(router_buffers[3].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[3].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(FrameRouter, first_link_sends_to_master) {
|
|
||||||
frame_buffer_t data;
|
|
||||||
data.data = 0xAB7055BB;
|
|
||||||
activate_router(1);
|
|
||||||
router_send_frame(0, (uint8_t*)&data, 4);
|
|
||||||
assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
|
|
||||||
expect(transport_recv_frame,
|
|
||||||
when(from, is_equal_to(1)),
|
|
||||||
when(size, is_equal_to(4)),
|
|
||||||
when(data, is_equal_to_contents_of(&data.data, 4))
|
|
||||||
);
|
|
||||||
simulate_transport(1, 0);
|
|
||||||
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(FrameRouter, second_link_sends_to_master) {
|
|
||||||
frame_buffer_t data;
|
|
||||||
data.data = 0xAB7055BB;
|
|
||||||
activate_router(2);
|
|
||||||
router_send_frame(0, (uint8_t*)&data, 4);
|
|
||||||
assert_that(router_buffers[2].send_buffers[UP_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[2].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
|
|
||||||
simulate_transport(2, 1);
|
|
||||||
assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
|
|
||||||
expect(transport_recv_frame,
|
|
||||||
when(from, is_equal_to(2)),
|
|
||||||
when(size, is_equal_to(4)),
|
|
||||||
when(data, is_equal_to_contents_of(&data.data, 4))
|
|
||||||
);
|
|
||||||
simulate_transport(1, 0);
|
|
||||||
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(FrameRouter, master_sends_to_master_does_nothing) {
|
|
||||||
frame_buffer_t data;
|
|
||||||
data.data = 0xAB7055BB;
|
|
||||||
activate_router(0);
|
|
||||||
router_send_frame(0, (uint8_t*)&data, 4);
|
|
||||||
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(FrameRouter, link_sends_to_other_link_does_nothing) {
|
|
||||||
frame_buffer_t data;
|
|
||||||
data.data = 0xAB7055BB;
|
|
||||||
activate_router(1);
|
|
||||||
router_send_frame(2, (uint8_t*)&data, 4);
|
|
||||||
assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(FrameRouter, master_receives_on_uplink_does_nothing) {
|
|
||||||
frame_buffer_t data;
|
|
||||||
data.data = 0xAB7055BB;
|
|
||||||
activate_router(1);
|
|
||||||
router_send_frame(0, (uint8_t*)&data, 4);
|
|
||||||
assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_greater_than(0));
|
|
||||||
assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
|
|
||||||
never_expect(transport_recv_frame);
|
|
||||||
activate_router(0);
|
|
||||||
receive_data(UP_LINK,
|
|
||||||
router_buffers[1].send_buffers[UP_LINK].sent_data,
|
|
||||||
router_buffers[1].send_buffers[UP_LINK].sent_data_size);
|
|
||||||
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
|
|
||||||
}
|
|
@ -0,0 +1,229 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Fred Sundvik
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
#include <array>
|
||||||
|
extern "C" {
|
||||||
|
#include "serial_link/protocol/transport.h"
|
||||||
|
#include "serial_link/protocol/byte_stuffer.h"
|
||||||
|
#include "serial_link/protocol/frame_router.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
using testing::_;
|
||||||
|
using testing::ElementsAreArray;
|
||||||
|
using testing::Args;
|
||||||
|
|
||||||
|
class FrameRouter : public testing::Test {
|
||||||
|
public:
|
||||||
|
FrameRouter() :
|
||||||
|
current_router_buffer(nullptr)
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
init_byte_stuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
~FrameRouter() {
|
||||||
|
Instance = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
|
||||||
|
auto& buffer = current_router_buffer->send_buffers[link];
|
||||||
|
std::copy(data, data + size, std::back_inserter(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
void receive_data(uint8_t link, uint8_t* data, uint16_t size) {
|
||||||
|
int i;
|
||||||
|
for(i=0;i<size;i++) {
|
||||||
|
byte_stuffer_recv_byte(link, data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void activate_router(uint8_t num) {
|
||||||
|
current_router_buffer = router_buffers + num;
|
||||||
|
router_set_master(num==0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void simulate_transport(uint8_t from, uint8_t to) {
|
||||||
|
activate_router(to);
|
||||||
|
if (from > to) {
|
||||||
|
receive_data(DOWN_LINK,
|
||||||
|
router_buffers[from].send_buffers[UP_LINK].data(),
|
||||||
|
router_buffers[from].send_buffers[UP_LINK].size());
|
||||||
|
}
|
||||||
|
else if(to > from) {
|
||||||
|
receive_data(UP_LINK,
|
||||||
|
router_buffers[from].send_buffers[DOWN_LINK].data(),
|
||||||
|
router_buffers[from].send_buffers[DOWN_LINK].size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MOCK_METHOD3(transport_recv_frame, void (uint8_t from, uint8_t* data, uint16_t size));
|
||||||
|
|
||||||
|
std::vector<uint8_t> received_data;
|
||||||
|
|
||||||
|
struct router_buffer {
|
||||||
|
std::vector<uint8_t> send_buffers[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
router_buffer router_buffers[8];
|
||||||
|
router_buffer* current_router_buffer;
|
||||||
|
|
||||||
|
static FrameRouter* Instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
FrameRouter* FrameRouter::Instance = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
std::array<uint8_t, 4> data;
|
||||||
|
uint8_t extra[16];
|
||||||
|
} frame_buffer_t;
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
|
||||||
|
FrameRouter::Instance->send_data(link, data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) {
|
||||||
|
FrameRouter::Instance->transport_recv_frame(from, data, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FrameRouter, master_broadcast_is_received_by_everyone) {
|
||||||
|
frame_buffer_t data;
|
||||||
|
data.data = {0xAB, 0x70, 0x55, 0xBB};
|
||||||
|
activate_router(0);
|
||||||
|
router_send_frame(0xFF, (uint8_t*)&data, 4);
|
||||||
|
EXPECT_GT(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
|
||||||
|
EXPECT_CALL(*this, transport_recv_frame(0, _, _))
|
||||||
|
.With(Args<1, 2>(ElementsAreArray(data.data)));
|
||||||
|
simulate_transport(0, 1);
|
||||||
|
EXPECT_GT(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[1].send_buffers[UP_LINK].size(), 0);
|
||||||
|
|
||||||
|
EXPECT_CALL(*this, transport_recv_frame(0, _, _))
|
||||||
|
.With(Args<1, 2>(ElementsAreArray(data.data)));
|
||||||
|
simulate_transport(1, 2);
|
||||||
|
EXPECT_GT(router_buffers[2].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[2].send_buffers[UP_LINK].size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FrameRouter, master_send_is_received_by_targets) {
|
||||||
|
frame_buffer_t data;
|
||||||
|
data.data = {0xAB, 0x70, 0x55, 0xBB};
|
||||||
|
activate_router(0);
|
||||||
|
router_send_frame((1 << 1) | (1 << 2), (uint8_t*)&data, 4);
|
||||||
|
EXPECT_GT(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
|
||||||
|
|
||||||
|
simulate_transport(0, 1);
|
||||||
|
EXPECT_GT(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[1].send_buffers[UP_LINK].size(), 0);
|
||||||
|
|
||||||
|
EXPECT_CALL(*this, transport_recv_frame(0, _, _))
|
||||||
|
.With(Args<1, 2>(ElementsAreArray(data.data)));
|
||||||
|
simulate_transport(1, 2);
|
||||||
|
EXPECT_GT(router_buffers[2].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[2].send_buffers[UP_LINK].size(), 0);
|
||||||
|
|
||||||
|
EXPECT_CALL(*this, transport_recv_frame(0, _, _))
|
||||||
|
.With(Args<1, 2>(ElementsAreArray(data.data)));
|
||||||
|
simulate_transport(2, 3);
|
||||||
|
EXPECT_GT(router_buffers[3].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[3].send_buffers[UP_LINK].size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FrameRouter, first_link_sends_to_master) {
|
||||||
|
frame_buffer_t data;
|
||||||
|
data.data = {0xAB, 0x70, 0x55, 0xBB};
|
||||||
|
activate_router(1);
|
||||||
|
router_send_frame(0, (uint8_t*)&data, 4);
|
||||||
|
EXPECT_GT(router_buffers[1].send_buffers[UP_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
|
||||||
|
EXPECT_CALL(*this, transport_recv_frame(1, _, _))
|
||||||
|
.With(Args<1, 2>(ElementsAreArray(data.data)));
|
||||||
|
simulate_transport(1, 0);
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FrameRouter, second_link_sends_to_master) {
|
||||||
|
frame_buffer_t data;
|
||||||
|
data.data = {0xAB, 0x70, 0x55, 0xBB};
|
||||||
|
activate_router(2);
|
||||||
|
router_send_frame(0, (uint8_t*)&data, 4);
|
||||||
|
EXPECT_GT(router_buffers[2].send_buffers[UP_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[2].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
|
||||||
|
simulate_transport(2, 1);
|
||||||
|
EXPECT_GT(router_buffers[1].send_buffers[UP_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
|
||||||
|
EXPECT_CALL(*this, transport_recv_frame(2, _, _))
|
||||||
|
.With(Args<1, 2>(ElementsAreArray(data.data)));
|
||||||
|
simulate_transport(1, 0);
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FrameRouter, master_sends_to_master_does_nothing) {
|
||||||
|
frame_buffer_t data;
|
||||||
|
data.data = {0xAB, 0x70, 0x55, 0xBB};
|
||||||
|
activate_router(0);
|
||||||
|
router_send_frame(0, (uint8_t*)&data, 4);
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FrameRouter, link_sends_to_other_link_does_nothing) {
|
||||||
|
frame_buffer_t data;
|
||||||
|
data.data = {0xAB, 0x70, 0x55, 0xBB};
|
||||||
|
activate_router(1);
|
||||||
|
router_send_frame(2, (uint8_t*)&data, 4);
|
||||||
|
EXPECT_EQ(router_buffers[1].send_buffers[UP_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FrameRouter, master_receives_on_uplink_does_nothing) {
|
||||||
|
frame_buffer_t data;
|
||||||
|
data.data = {0xAB, 0x70, 0x55, 0xBB};
|
||||||
|
activate_router(1);
|
||||||
|
router_send_frame(0, (uint8_t*)&data, 4);
|
||||||
|
EXPECT_GT(router_buffers[1].send_buffers[UP_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
|
||||||
|
EXPECT_CALL(*this, transport_recv_frame(_, _, _))
|
||||||
|
.Times(0);
|
||||||
|
activate_router(0);
|
||||||
|
receive_data(UP_LINK,
|
||||||
|
router_buffers[1].send_buffers[UP_LINK].data(),
|
||||||
|
router_buffers[1].send_buffers[UP_LINK].size());
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0);
|
||||||
|
EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0);
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
serial_link_byte_stuffer_SRC :=\
|
||||||
|
$(SERIAL_PATH)/tests/byte_stuffer_tests.cpp \
|
||||||
|
$(SERIAL_PATH)/protocol/byte_stuffer.c
|
||||||
|
|
||||||
|
serial_link_frame_validator_SRC := \
|
||||||
|
$(SERIAL_PATH)/tests/frame_validator_tests.cpp \
|
||||||
|
$(SERIAL_PATH)/protocol/frame_validator.c
|
||||||
|
|
||||||
|
serial_link_frame_router_SRC := \
|
||||||
|
$(SERIAL_PATH)/tests/frame_router_tests.cpp \
|
||||||
|
$(SERIAL_PATH)/protocol/byte_stuffer.c \
|
||||||
|
$(SERIAL_PATH)/protocol/frame_validator.c \
|
||||||
|
$(SERIAL_PATH)/protocol/frame_router.c
|
||||||
|
|
||||||
|
serial_link_triple_buffered_object_SRC := \
|
||||||
|
$(SERIAL_PATH)/tests/triple_buffered_object_tests.cpp \
|
||||||
|
$(SERIAL_PATH)/protocol/triple_buffered_object.c
|
||||||
|
|
||||||
|
serial_link_transport_SRC := \
|
||||||
|
$(SERIAL_PATH)/tests/transport_tests.cpp \
|
||||||
|
$(SERIAL_PATH)/protocol/transport.c \
|
||||||
|
$(SERIAL_PATH)/protocol/triple_buffered_object.c
|
@ -0,0 +1,6 @@
|
|||||||
|
TEST_LIST +=\
|
||||||
|
serial_link_byte_stuffer\
|
||||||
|
serial_link_frame_validator\
|
||||||
|
serial_link_frame_router\
|
||||||
|
serial_link_triple_buffered_object\
|
||||||
|
serial_link_transport
|
@ -1,168 +0,0 @@
|
|||||||
/*
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2016 Fred Sundvik
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <cgreen/cgreen.h>
|
|
||||||
#include <cgreen/mocks.h>
|
|
||||||
#include "serial_link/protocol/transport.c"
|
|
||||||
#include "serial_link/protocol/triple_buffered_object.c"
|
|
||||||
|
|
||||||
void signal_data_written(void) {
|
|
||||||
mock();
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t sent_data[2048];
|
|
||||||
static uint16_t sent_data_size;
|
|
||||||
|
|
||||||
void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
|
|
||||||
mock(destination);
|
|
||||||
memcpy(sent_data + sent_data_size, data, size);
|
|
||||||
sent_data_size += size;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t test;
|
|
||||||
} test_object1_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t test1;
|
|
||||||
uint32_t test2;
|
|
||||||
} test_object2_t;
|
|
||||||
|
|
||||||
MASTER_TO_ALL_SLAVES_OBJECT(master_to_slave, test_object1_t);
|
|
||||||
MASTER_TO_SINGLE_SLAVE_OBJECT(master_to_single_slave, test_object1_t);
|
|
||||||
SLAVE_TO_MASTER_OBJECT(slave_to_master, test_object1_t);
|
|
||||||
|
|
||||||
static remote_object_t* test_remote_objects[] = {
|
|
||||||
REMOTE_OBJECT(master_to_slave),
|
|
||||||
REMOTE_OBJECT(master_to_single_slave),
|
|
||||||
REMOTE_OBJECT(slave_to_master),
|
|
||||||
};
|
|
||||||
|
|
||||||
Describe(Transport);
|
|
||||||
BeforeEach(Transport) {
|
|
||||||
add_remote_objects(test_remote_objects, sizeof(test_remote_objects) / sizeof(remote_object_t*));
|
|
||||||
sent_data_size = 0;
|
|
||||||
}
|
|
||||||
AfterEach(Transport) {}
|
|
||||||
|
|
||||||
Ensure(Transport, write_to_local_signals_an_event) {
|
|
||||||
begin_write_master_to_slave();
|
|
||||||
expect(signal_data_written);
|
|
||||||
end_write_master_to_slave();
|
|
||||||
begin_write_slave_to_master();
|
|
||||||
expect(signal_data_written);
|
|
||||||
end_write_slave_to_master();
|
|
||||||
begin_write_master_to_single_slave(1);
|
|
||||||
expect(signal_data_written);
|
|
||||||
end_write_master_to_single_slave(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(Transport, writes_from_master_to_all_slaves) {
|
|
||||||
update_transport();
|
|
||||||
test_object1_t* obj = begin_write_master_to_slave();
|
|
||||||
obj->test = 5;
|
|
||||||
expect(signal_data_written);
|
|
||||||
end_write_master_to_slave();
|
|
||||||
expect(router_send_frame,
|
|
||||||
when(destination, is_equal_to(0xFF)));
|
|
||||||
update_transport();
|
|
||||||
transport_recv_frame(0, sent_data, sent_data_size);
|
|
||||||
test_object1_t* obj2 = read_master_to_slave();
|
|
||||||
assert_that(obj2, is_not_equal_to(NULL));
|
|
||||||
assert_that(obj2->test, is_equal_to(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(Transport, writes_from_slave_to_master) {
|
|
||||||
update_transport();
|
|
||||||
test_object1_t* obj = begin_write_slave_to_master();
|
|
||||||
obj->test = 7;
|
|
||||||
expect(signal_data_written);
|
|
||||||
end_write_slave_to_master();
|
|
||||||
expect(router_send_frame,
|
|
||||||
when(destination, is_equal_to(0)));
|
|
||||||
update_transport();
|
|
||||||
transport_recv_frame(3, sent_data, sent_data_size);
|
|
||||||
test_object1_t* obj2 = read_slave_to_master(2);
|
|
||||||
assert_that(read_slave_to_master(0), is_equal_to(NULL));
|
|
||||||
assert_that(obj2, is_not_equal_to(NULL));
|
|
||||||
assert_that(obj2->test, is_equal_to(7));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(Transport, writes_from_master_to_single_slave) {
|
|
||||||
update_transport();
|
|
||||||
test_object1_t* obj = begin_write_master_to_single_slave(3);
|
|
||||||
obj->test = 7;
|
|
||||||
expect(signal_data_written);
|
|
||||||
end_write_master_to_single_slave(3);
|
|
||||||
expect(router_send_frame,
|
|
||||||
when(destination, is_equal_to(4)));
|
|
||||||
update_transport();
|
|
||||||
transport_recv_frame(0, sent_data, sent_data_size);
|
|
||||||
test_object1_t* obj2 = read_master_to_single_slave();
|
|
||||||
assert_that(obj2, is_not_equal_to(NULL));
|
|
||||||
assert_that(obj2->test, is_equal_to(7));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(Transport, ignores_object_with_invalid_id) {
|
|
||||||
update_transport();
|
|
||||||
test_object1_t* obj = begin_write_master_to_single_slave(3);
|
|
||||||
obj->test = 7;
|
|
||||||
expect(signal_data_written);
|
|
||||||
end_write_master_to_single_slave(3);
|
|
||||||
expect(router_send_frame,
|
|
||||||
when(destination, is_equal_to(4)));
|
|
||||||
update_transport();
|
|
||||||
sent_data[sent_data_size - 1] = 44;
|
|
||||||
transport_recv_frame(0, sent_data, sent_data_size);
|
|
||||||
test_object1_t* obj2 = read_master_to_single_slave();
|
|
||||||
assert_that(obj2, is_equal_to(NULL));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(Transport, ignores_object_with_size_too_small) {
|
|
||||||
update_transport();
|
|
||||||
test_object1_t* obj = begin_write_master_to_slave();
|
|
||||||
obj->test = 7;
|
|
||||||
expect(signal_data_written);
|
|
||||||
end_write_master_to_slave();
|
|
||||||
expect(router_send_frame);
|
|
||||||
update_transport();
|
|
||||||
sent_data[sent_data_size - 2] = 0;
|
|
||||||
transport_recv_frame(0, sent_data, sent_data_size - 1);
|
|
||||||
test_object1_t* obj2 = read_master_to_slave();
|
|
||||||
assert_that(obj2, is_equal_to(NULL));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure(Transport, ignores_object_with_size_too_big) {
|
|
||||||
update_transport();
|
|
||||||
test_object1_t* obj = begin_write_master_to_slave();
|
|
||||||
obj->test = 7;
|
|
||||||
expect(signal_data_written);
|
|
||||||
end_write_master_to_slave();
|
|
||||||
expect(router_send_frame);
|
|
||||||
update_transport();
|
|
||||||
sent_data[sent_data_size + 21] = 0;
|
|
||||||
transport_recv_frame(0, sent_data, sent_data_size + 22);
|
|
||||||
test_object1_t* obj2 = read_master_to_slave();
|
|
||||||
assert_that(obj2, is_equal_to(NULL));
|
|
||||||
}
|
|
@ -0,0 +1,188 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Fred Sundvik
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
|
using testing::_;
|
||||||
|
using testing::ElementsAreArray;
|
||||||
|
using testing::Args;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "serial_link/protocol/transport.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
struct test_object1 {
|
||||||
|
uint32_t test;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct test_object2 {
|
||||||
|
uint32_t test1;
|
||||||
|
uint32_t test2;
|
||||||
|
};
|
||||||
|
|
||||||
|
MASTER_TO_ALL_SLAVES_OBJECT(master_to_slave, test_object1);
|
||||||
|
MASTER_TO_SINGLE_SLAVE_OBJECT(master_to_single_slave, test_object1);
|
||||||
|
SLAVE_TO_MASTER_OBJECT(slave_to_master, test_object1);
|
||||||
|
|
||||||
|
static remote_object_t* test_remote_objects[] = {
|
||||||
|
REMOTE_OBJECT(master_to_slave),
|
||||||
|
REMOTE_OBJECT(master_to_single_slave),
|
||||||
|
REMOTE_OBJECT(slave_to_master),
|
||||||
|
};
|
||||||
|
|
||||||
|
class Transport : public testing::Test {
|
||||||
|
public:
|
||||||
|
Transport() {
|
||||||
|
Instance = this;
|
||||||
|
add_remote_objects(test_remote_objects, sizeof(test_remote_objects) / sizeof(remote_object_t*));
|
||||||
|
}
|
||||||
|
|
||||||
|
~Transport() {
|
||||||
|
Instance = nullptr;
|
||||||
|
reinitialize_serial_link_transport();
|
||||||
|
}
|
||||||
|
|
||||||
|
MOCK_METHOD0(signal_data_written, void ());
|
||||||
|
MOCK_METHOD1(router_send_frame, void (uint8_t destination));
|
||||||
|
|
||||||
|
void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
|
||||||
|
router_send_frame(destination);
|
||||||
|
std::copy(data, data + size, std::back_inserter(sent_data));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Transport* Instance;
|
||||||
|
|
||||||
|
std::vector<uint8_t> sent_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
Transport* Transport::Instance = nullptr;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
void signal_data_written(void) {
|
||||||
|
Transport::Instance->signal_data_written();
|
||||||
|
}
|
||||||
|
|
||||||
|
void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
|
||||||
|
Transport::Instance->router_send_frame(destination, data, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Transport, write_to_local_signals_an_event) {
|
||||||
|
begin_write_master_to_slave();
|
||||||
|
EXPECT_CALL(*this, signal_data_written());
|
||||||
|
end_write_master_to_slave();
|
||||||
|
begin_write_slave_to_master();
|
||||||
|
EXPECT_CALL(*this, signal_data_written());
|
||||||
|
end_write_slave_to_master();
|
||||||
|
begin_write_master_to_single_slave(1);
|
||||||
|
EXPECT_CALL(*this, signal_data_written());
|
||||||
|
end_write_master_to_single_slave(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Transport, writes_from_master_to_all_slaves) {
|
||||||
|
update_transport();
|
||||||
|
test_object1* obj = begin_write_master_to_slave();
|
||||||
|
obj->test = 5;
|
||||||
|
EXPECT_CALL(*this, signal_data_written());
|
||||||
|
end_write_master_to_slave();
|
||||||
|
EXPECT_CALL(*this, router_send_frame(0xFF));
|
||||||
|
update_transport();
|
||||||
|
transport_recv_frame(0, sent_data.data(), sent_data.size());
|
||||||
|
test_object1* obj2 = read_master_to_slave();
|
||||||
|
EXPECT_NE(obj2, nullptr);
|
||||||
|
EXPECT_EQ(obj2->test, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Transport, writes_from_slave_to_master) {
|
||||||
|
update_transport();
|
||||||
|
test_object1* obj = begin_write_slave_to_master();
|
||||||
|
obj->test = 7;
|
||||||
|
EXPECT_CALL(*this, signal_data_written());
|
||||||
|
end_write_slave_to_master();
|
||||||
|
EXPECT_CALL(*this, router_send_frame(0));
|
||||||
|
update_transport();
|
||||||
|
transport_recv_frame(3, sent_data.data(), sent_data.size());
|
||||||
|
test_object1* obj2 = read_slave_to_master(2);
|
||||||
|
EXPECT_EQ(read_slave_to_master(0), nullptr);
|
||||||
|
EXPECT_NE(obj2, nullptr);
|
||||||
|
EXPECT_EQ(obj2->test, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Transport, writes_from_master_to_single_slave) {
|
||||||
|
update_transport();
|
||||||
|
test_object1* obj = begin_write_master_to_single_slave(3);
|
||||||
|
obj->test = 7;
|
||||||
|
EXPECT_CALL(*this, signal_data_written());
|
||||||
|
end_write_master_to_single_slave(3);
|
||||||
|
EXPECT_CALL(*this, router_send_frame(4));
|
||||||
|
update_transport();
|
||||||
|
transport_recv_frame(0, sent_data.data(), sent_data.size());
|
||||||
|
test_object1* obj2 = read_master_to_single_slave();
|
||||||
|
EXPECT_NE(obj2, nullptr);
|
||||||
|
EXPECT_EQ(obj2->test, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Transport, ignores_object_with_invalid_id) {
|
||||||
|
update_transport();
|
||||||
|
test_object1* obj = begin_write_master_to_single_slave(3);
|
||||||
|
obj->test = 7;
|
||||||
|
EXPECT_CALL(*this, signal_data_written());
|
||||||
|
end_write_master_to_single_slave(3);
|
||||||
|
EXPECT_CALL(*this, router_send_frame(4));
|
||||||
|
update_transport();
|
||||||
|
sent_data[sent_data.size() - 1] = 44;
|
||||||
|
transport_recv_frame(0, sent_data.data(), sent_data.size());
|
||||||
|
test_object1* obj2 = read_master_to_single_slave();
|
||||||
|
EXPECT_EQ(obj2, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Transport, ignores_object_with_size_too_small) {
|
||||||
|
update_transport();
|
||||||
|
test_object1* obj = begin_write_master_to_slave();
|
||||||
|
obj->test = 7;
|
||||||
|
EXPECT_CALL(*this, signal_data_written());
|
||||||
|
end_write_master_to_slave();
|
||||||
|
EXPECT_CALL(*this, router_send_frame(_));
|
||||||
|
update_transport();
|
||||||
|
sent_data[sent_data.size() - 2] = 0;
|
||||||
|
transport_recv_frame(0, sent_data.data(), sent_data.size() - 1);
|
||||||
|
test_object1* obj2 = read_master_to_slave();
|
||||||
|
EXPECT_EQ(obj2, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Transport, ignores_object_with_size_too_big) {
|
||||||
|
update_transport();
|
||||||
|
test_object1* obj = begin_write_master_to_slave();
|
||||||
|
obj->test = 7;
|
||||||
|
EXPECT_CALL(*this, signal_data_written());
|
||||||
|
end_write_master_to_slave();
|
||||||
|
EXPECT_CALL(*this, router_send_frame(_));
|
||||||
|
update_transport();
|
||||||
|
sent_data.resize(sent_data.size() + 22);
|
||||||
|
sent_data[sent_data.size() - 1] = 0;
|
||||||
|
transport_recv_frame(0, sent_data.data(), sent_data.size());
|
||||||
|
test_object1* obj2 = read_master_to_slave();
|
||||||
|
EXPECT_EQ(obj2, nullptr);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
include $(ROOT_DIR)/quantum/serial_link/tests/testlist.mk
|
||||||
|
|
||||||
|
define VALIDATE_TEST_LIST
|
||||||
|
ifneq ($1,)
|
||||||
|
ifeq ($$(findstring -,$1),-)
|
||||||
|
$$(error Test names can't contain '-', but '$1' does)
|
||||||
|
else
|
||||||
|
$$(eval $$(call VALIDATE_TEST_LIST,$$(firstword $2),$$(wordlist 2,9999,$2)))
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(call VALIDATE_TEST_LIST,$(firstword $(TEST_LIST)),$(wordlist 2,9999,$(TEST_LIST))))
|
@ -0,0 +1,24 @@
|
|||||||
|
CC = gcc
|
||||||
|
OBJCOPY =
|
||||||
|
OBJDUMP =
|
||||||
|
SIZE =
|
||||||
|
AR =
|
||||||
|
NM =
|
||||||
|
HEX =
|
||||||
|
EEP =
|
||||||
|
BIN =
|
||||||
|
|
||||||
|
|
||||||
|
COMPILEFLAGS += -funsigned-char
|
||||||
|
COMPILEFLAGS += -funsigned-bitfields
|
||||||
|
COMPILEFLAGS += -ffunction-sections
|
||||||
|
COMPILEFLAGS += -fdata-sections
|
||||||
|
COMPILEFLAGS += -fshort-enums
|
||||||
|
|
||||||
|
CFLAGS += $(COMPILEFLAGS)
|
||||||
|
CFLAGS += -fno-inline-small-functions
|
||||||
|
CFLAGS += -fno-strict-aliasing
|
||||||
|
|
||||||
|
CPPFLAGS += $(COMPILEFLAGS)
|
||||||
|
CPPFLAGS += -fno-exceptions
|
||||||
|
CPPFLAGS += -std=gnu++11
|
Loading…
Reference in new issue