Implemented TactilityKernel and DevicetreeCompiler, updated licenses & copyrights (#452)
**New features** - Created a devicetree DTS and YAML parser in Python - Created new modules: - TactilityKernel (LGPL v3.0 license) - Platforms/PlatformEsp32 (LGPL v3.0 license) - Platforms/PlatformPosix (LGPL v3.0 license) - Tests/TactilityKernelTests Most boards have a placeholder DTS file, while T-Lora Pager has a few devices attached. **Licenses** Clarified licenses and copyrights better. - Add explanation about the intent behind them. - Added explanation about licenses for past and future subprojects - Added more details explanations with regards to the logo usage - Copied licenses to subprojects to make it more explicit
This commit is contained in:
committed by
GitHub
parent
0d16eb606f
commit
4b6ed871a9
@@ -0,0 +1,14 @@
|
||||
project(TactilityCoreTests)
|
||||
|
||||
enable_language(C CXX ASM)
|
||||
|
||||
set(CMAKE_CXX_COMPILER g++)
|
||||
|
||||
file(GLOB_RECURSE TEST_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
|
||||
add_executable(TactilityKernelTests EXCLUDE_FROM_ALL ${TEST_SOURCES})
|
||||
|
||||
target_include_directories(TactilityKernelTests PRIVATE ${DOCTESTINC})
|
||||
|
||||
add_test(NAME TactilityKernelTests COMMAND TactilityKernelTests)
|
||||
|
||||
target_link_libraries(TactilityKernelTests PUBLIC TactilityKernel)
|
||||
@@ -0,0 +1,190 @@
|
||||
#include "doctest.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include <Tactility/Device.h>
|
||||
|
||||
TEST_CASE("device_construct and device_destruct should set and unset the correct fields") {
|
||||
Device device = { 0 };
|
||||
|
||||
int error = device_construct(&device);
|
||||
CHECK_EQ(error, 0);
|
||||
|
||||
CHECK_NE(device.internal.data, nullptr);
|
||||
CHECK_NE(device.internal.mutex.handle, nullptr);
|
||||
|
||||
error = device_destruct(&device);
|
||||
CHECK_EQ(error, 0);
|
||||
|
||||
CHECK_EQ(device.internal.data, nullptr);
|
||||
CHECK_EQ(device.internal.mutex.handle, nullptr);
|
||||
|
||||
Device comparison_device = { 0 };
|
||||
comparison_device.internal.data = device.internal.data;
|
||||
comparison_device.internal.mutex.handle = device.internal.mutex.handle;
|
||||
|
||||
// Check that no other data was set
|
||||
CHECK_EQ(memcmp(&device, &comparison_device, sizeof(Device)), 0);
|
||||
}
|
||||
|
||||
TEST_CASE("device_add should add the device to the list of all devices") {
|
||||
Device device = { 0 };
|
||||
CHECK_EQ(device_construct(&device), 0);
|
||||
CHECK_EQ(device_add(&device), 0);
|
||||
|
||||
// Gather all devices
|
||||
std::vector<Device*> devices;
|
||||
for_each_device(&devices, [](auto* device, auto* context) {
|
||||
auto* devices_ptr = (std::vector<Device*>*)context;
|
||||
devices_ptr->push_back(device);
|
||||
return true;
|
||||
});
|
||||
|
||||
CHECK_EQ(devices.size(), 1);
|
||||
CHECK_EQ(devices[0], &device);
|
||||
|
||||
CHECK_EQ(device_remove(&device), 0);
|
||||
CHECK_EQ(device_destruct(&device), 0);
|
||||
}
|
||||
|
||||
TEST_CASE("device_add should add the device to its parent") {
|
||||
Device parent = { 0 };
|
||||
|
||||
Device child = {
|
||||
.name = nullptr,
|
||||
.config = nullptr,
|
||||
.parent = &parent
|
||||
};
|
||||
|
||||
CHECK_EQ(device_construct(&parent), 0);
|
||||
CHECK_EQ(device_add(&parent), 0);
|
||||
|
||||
CHECK_EQ(device_construct(&child), 0);
|
||||
CHECK_EQ(device_add(&child), 0);
|
||||
|
||||
// Gather all child devices
|
||||
std::vector<Device*> children;
|
||||
for_each_device_child(&parent, &children, [](auto* child_device, auto* context) {
|
||||
auto* children_ptr = (std::vector<Device*>*)context;
|
||||
children_ptr->push_back(child_device);
|
||||
return true;
|
||||
});
|
||||
|
||||
CHECK_EQ(children.size(), 1);
|
||||
CHECK_EQ(children[0], &child);
|
||||
|
||||
CHECK_EQ(device_remove(&child), 0);
|
||||
CHECK_EQ(device_destruct(&child), 0);
|
||||
|
||||
CHECK_EQ(device_remove(&parent), 0);
|
||||
CHECK_EQ(device_destruct(&parent), 0);
|
||||
}
|
||||
|
||||
TEST_CASE("device_add should set the state to 'added'") {
|
||||
Device device = { 0 };
|
||||
CHECK_EQ(device_construct(&device), 0);
|
||||
|
||||
CHECK_EQ(device.internal.state.added, false);
|
||||
CHECK_EQ(device_add(&device), 0);
|
||||
CHECK_EQ(device.internal.state.added, true);
|
||||
|
||||
CHECK_EQ(device_remove(&device), 0);
|
||||
CHECK_EQ(device_destruct(&device), 0);
|
||||
}
|
||||
|
||||
TEST_CASE("device_remove should remove it from the list of all devices") {
|
||||
Device device = { 0 };
|
||||
CHECK_EQ(device_construct(&device), 0);
|
||||
CHECK_EQ(device_add(&device), 0);
|
||||
CHECK_EQ(device_remove(&device), 0);
|
||||
|
||||
// Gather all devices
|
||||
std::vector<Device*> devices;
|
||||
for_each_device(&devices, [](auto* device, auto* context) {
|
||||
auto* devices_ptr = (std::vector<Device*>*)context;
|
||||
devices_ptr->push_back(device);
|
||||
return true;
|
||||
});
|
||||
|
||||
CHECK_EQ(devices.size(), 0);
|
||||
|
||||
CHECK_EQ(device_destruct(&device), 0);
|
||||
}
|
||||
|
||||
TEST_CASE("device_remove should remove the device from its parent") {
|
||||
Device parent = { 0 };
|
||||
|
||||
Device child = {
|
||||
.name = nullptr,
|
||||
.config = nullptr,
|
||||
.parent = &parent
|
||||
};
|
||||
|
||||
CHECK_EQ(device_construct(&parent), 0);
|
||||
CHECK_EQ(device_add(&parent), 0);
|
||||
|
||||
CHECK_EQ(device_construct(&child), 0);
|
||||
CHECK_EQ(device_add(&child), 0);
|
||||
CHECK_EQ(device_remove(&child), 0);
|
||||
|
||||
// Gather all child devices
|
||||
std::vector<Device*> children;
|
||||
for_each_device_child(&parent, &children, [](auto* child_device, auto* context) {
|
||||
auto* children_ptr = (std::vector<Device*>*)context;
|
||||
children_ptr->push_back(child_device);
|
||||
return true;
|
||||
});
|
||||
|
||||
CHECK_EQ(children.size(), 0);
|
||||
|
||||
CHECK_EQ(device_destruct(&child), 0);
|
||||
|
||||
CHECK_EQ(device_remove(&parent), 0);
|
||||
CHECK_EQ(device_destruct(&parent), 0);
|
||||
}
|
||||
|
||||
TEST_CASE("device_remove should clear the state 'added'") {
|
||||
Device device = { 0 };
|
||||
CHECK_EQ(device_construct(&device), 0);
|
||||
|
||||
CHECK_EQ(device_add(&device), 0);
|
||||
CHECK_EQ(device.internal.state.added, true);
|
||||
CHECK_EQ(device_remove(&device), 0);
|
||||
CHECK_EQ(device.internal.state.added, false);
|
||||
|
||||
CHECK_EQ(device_destruct(&device), 0);
|
||||
}
|
||||
|
||||
TEST_CASE("device_is_ready should return true only when it is started") {
|
||||
const char* compatible[] = { "test_compatible", nullptr };
|
||||
Driver driver = {
|
||||
.name = "test_driver",
|
||||
.compatible = compatible,
|
||||
.start_device = nullptr,
|
||||
.stop_device = nullptr,
|
||||
.api = nullptr,
|
||||
.device_type = nullptr,
|
||||
.internal = { 0 }
|
||||
};
|
||||
|
||||
Device device = { 0 };
|
||||
|
||||
CHECK_EQ(driver_construct(&driver), 0);
|
||||
CHECK_EQ(device_construct(&device), 0);
|
||||
|
||||
CHECK_EQ(device.internal.state.started, false);
|
||||
device_set_driver(&device, &driver);
|
||||
CHECK_EQ(device.internal.state.started, false);
|
||||
CHECK_EQ(device_add(&device), 0);
|
||||
CHECK_EQ(device.internal.state.started, false);
|
||||
CHECK_EQ(device_start(&device), 0);
|
||||
CHECK_EQ(device.internal.state.started, true);
|
||||
CHECK_EQ(device_stop(&device), 0);
|
||||
CHECK_EQ(device.internal.state.started, false);
|
||||
CHECK_EQ(device_remove(&device), 0);
|
||||
CHECK_EQ(device.internal.state.started, false);
|
||||
|
||||
CHECK_EQ(driver_destruct(&driver), 0);
|
||||
CHECK_EQ(device_destruct(&device), 0);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "doctest.h"
|
||||
#include <Tactility/Device.h>
|
||||
#include <Tactility/Driver.h>
|
||||
|
||||
struct IntegrationDriverConfig {
|
||||
int startResult;
|
||||
int stopResult;
|
||||
};
|
||||
|
||||
static int startCalled = 0;
|
||||
static int stopCalled = 0;
|
||||
|
||||
#define integration_data(device) static_cast<IntegrationDriverData*>(device_get_driver_data(device))
|
||||
#define integration_config(device) static_cast<const IntegrationDriverConfig*>(device->config)
|
||||
|
||||
static int start(Device* device) {
|
||||
startCalled++;
|
||||
return integration_config(device)->startResult;
|
||||
}
|
||||
|
||||
static int stop(Device* device) {
|
||||
stopCalled++;
|
||||
return integration_config(device)->stopResult;
|
||||
}
|
||||
|
||||
static Driver integration_driver = {
|
||||
.name = "integration_test_driver",
|
||||
.compatible = (const char*[]) { "integration", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = nullptr,
|
||||
.device_type = nullptr,
|
||||
.internal = { 0 }
|
||||
};
|
||||
|
||||
TEST_CASE("driver with with start success and stop success should start and stop a device") {
|
||||
startCalled = 0;
|
||||
stopCalled = 0;
|
||||
static const IntegrationDriverConfig config {
|
||||
.startResult = 0,
|
||||
.stopResult = 0
|
||||
};
|
||||
|
||||
static Device integration_device {
|
||||
.name = "integration_device",
|
||||
.config = &config,
|
||||
.parent = nullptr,
|
||||
};
|
||||
|
||||
CHECK_EQ(driver_construct(&integration_driver), 0);
|
||||
|
||||
CHECK_EQ(device_construct(&integration_device), 0);
|
||||
device_add(&integration_device);
|
||||
CHECK_EQ(startCalled, 0);
|
||||
CHECK_EQ(driver_bind(&integration_driver, &integration_device), 0);
|
||||
CHECK_EQ(startCalled, 1);
|
||||
CHECK_EQ(stopCalled, 0);
|
||||
CHECK_EQ(driver_unbind(&integration_driver, &integration_device), 0);
|
||||
CHECK_EQ(stopCalled, 1);
|
||||
CHECK_EQ(device_remove(&integration_device), 0);
|
||||
CHECK_EQ(device_destruct(&integration_device), 0);
|
||||
|
||||
CHECK_EQ(driver_destruct(&integration_driver), 0);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "doctest.h"
|
||||
#include <Tactility/Driver.h>
|
||||
|
||||
TEST_CASE("driver_construct and driver_destruct should set and unset the correct fields") {
|
||||
Driver driver = { 0 };
|
||||
|
||||
int error = driver_construct(&driver);
|
||||
CHECK_EQ(error, 0);
|
||||
CHECK_NE(driver.internal.data, nullptr);
|
||||
|
||||
error = driver_destruct(&driver);
|
||||
CHECK_EQ(error, 0);
|
||||
CHECK_EQ(driver.internal.data, nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("driver_is_compatible should return true if a compatible value is found") {
|
||||
const char* compatible[] = { "test_compatible", nullptr };
|
||||
Driver driver = {
|
||||
.name = "test_driver",
|
||||
.compatible = compatible,
|
||||
.start_device = nullptr,
|
||||
.stop_device = nullptr,
|
||||
.api = nullptr,
|
||||
.device_type = nullptr,
|
||||
.internal = { 0 }
|
||||
};
|
||||
CHECK_EQ(driver_is_compatible(&driver, "test_compatible"), true);
|
||||
CHECK_EQ(driver_is_compatible(&driver, "nope"), false);
|
||||
CHECK_EQ(driver_is_compatible(&driver, nullptr), false);
|
||||
}
|
||||
|
||||
TEST_CASE("driver_find should only find a compatible driver when the driver was constructed") {
|
||||
const char* compatible[] = { "test_compatible", nullptr };
|
||||
Driver driver = {
|
||||
.name = "test_driver",
|
||||
.compatible = compatible,
|
||||
.start_device = nullptr,
|
||||
.stop_device = nullptr,
|
||||
.api = nullptr,
|
||||
.device_type = nullptr,
|
||||
.internal = { 0 }
|
||||
};
|
||||
|
||||
Driver* found_driver = driver_find_compatible("test_compatible");
|
||||
CHECK_EQ(found_driver, nullptr);
|
||||
|
||||
int error = driver_construct(&driver);
|
||||
CHECK_EQ(error, 0);
|
||||
|
||||
found_driver = driver_find_compatible("test_compatible");
|
||||
CHECK_EQ(found_driver, &driver);
|
||||
|
||||
error = driver_destruct(&driver);
|
||||
CHECK_EQ(error, 0);
|
||||
|
||||
found_driver = driver_find_compatible("test_compatible");
|
||||
CHECK_EQ(found_driver, nullptr);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT
|
||||
#include "doctest.h"
|
||||
#include <cassert>
|
||||
|
||||
#include <Tactility/FreeRTOS/task.h>
|
||||
|
||||
typedef struct {
|
||||
int argc;
|
||||
char** argv;
|
||||
int result;
|
||||
} TestTaskData;
|
||||
|
||||
void test_task(void* parameter) {
|
||||
auto* data = (TestTaskData*)parameter;
|
||||
|
||||
doctest::Context context;
|
||||
|
||||
context.applyCommandLine(data->argc, data->argv);
|
||||
|
||||
// overrides
|
||||
context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
|
||||
|
||||
data->result = context.run();
|
||||
|
||||
vTaskEndScheduler();
|
||||
|
||||
vTaskDelete(nullptr);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
TestTaskData data = {
|
||||
.argc = argc,
|
||||
.argv = argv,
|
||||
.result = 0
|
||||
};
|
||||
|
||||
BaseType_t task_result = xTaskCreate(
|
||||
test_task,
|
||||
"test_task",
|
||||
8192,
|
||||
&data,
|
||||
1,
|
||||
nullptr
|
||||
);
|
||||
assert(task_result == pdPASS);
|
||||
|
||||
vTaskStartScheduler();
|
||||
|
||||
return data.result;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
// Required for FreeRTOS
|
||||
void vAssertCalled(unsigned long line, const char* const file) {
|
||||
__assert_fail("assert failed", file, line, "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user