TFTP
Change tests from a copy to using the original with mocs
This commit is contained in:
@@ -6,8 +6,11 @@
|
|||||||
|
|
||||||
#ifndef PROJECT_TFTP_H
|
#ifndef PROJECT_TFTP_H
|
||||||
#define PROJECT_TFTP_H
|
#define PROJECT_TFTP_H
|
||||||
#define LOGGER_LEVEL_ALL
|
|
||||||
#include <tftp_server.h>
|
#include <tftp_server.h>
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#define LOGGER_LEVEL_ALL
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "llfs.h"
|
#include "llfs.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -25,4 +28,11 @@ typedef struct tftp_custom_file_s {
|
|||||||
|
|
||||||
void tftp_server_init(void);
|
void tftp_server_init(void);
|
||||||
void tftp_server_deinit(void);
|
void tftp_server_deinit(void);
|
||||||
|
void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence);
|
||||||
|
size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // PROJECT_TFTP_H
|
#endif // PROJECT_TFTP_H
|
||||||
|
|||||||
@@ -6,8 +6,14 @@ include_directories(${GTEST_INCLUDE_DIR})
|
|||||||
link_directories(${GTEST_LIB_DIR})
|
link_directories(${GTEST_LIB_DIR})
|
||||||
|
|
||||||
# tests
|
# tests
|
||||||
file(GLOB_RECURSE TEST_SOURCES "*.cpp")
|
file(GLOB_RECURSE TEST_SOURCES "*.cpp" "*.c")
|
||||||
add_executable(tests ${TEST_SOURCES})
|
add_executable(tests)
|
||||||
|
|
||||||
|
target_sources(tests
|
||||||
|
PRIVATE
|
||||||
|
${TEST_SOURCES}
|
||||||
|
../project/Core/Src/tftp.c
|
||||||
|
)
|
||||||
|
|
||||||
target_compile_options(tests PRIVATE $<$<CONFIG:Debug>:
|
target_compile_options(tests PRIVATE $<$<CONFIG:Debug>:
|
||||||
-Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion
|
-Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion
|
||||||
@@ -22,6 +28,7 @@ target_include_directories(tests
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${PROJECT_BINARY_DIR}
|
${PROJECT_BINARY_DIR}
|
||||||
|
../project/Core/Inc/
|
||||||
)
|
)
|
||||||
|
|
||||||
include(GoogleTest)
|
include(GoogleTest)
|
||||||
|
|||||||
19
tests/mocs.c
Normal file
19
tests/mocs.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "tftp.h"
|
||||||
|
|
||||||
|
struct llfs_data_file llfs_root = {
|
||||||
|
.data = NULL,
|
||||||
|
.len = 0,
|
||||||
|
.name = "root",
|
||||||
|
.next = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
void tftp_cleanup(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
uint32_t logger_get_timestamp(void) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tftp_init(struct tftp_context* context) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "tftp.hpp"
|
#include "tftp.h"
|
||||||
|
|
||||||
tftp_custom_file_t file = {
|
tftp_custom_file_t file = {
|
||||||
.data = (char*)"1234567890",
|
.data = (char*)"1234567890",
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
#include "tftp.hpp"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief tftp custom file functions to set the offset and read the data
|
|
||||||
* @param[in,out] handle Custom file handles
|
|
||||||
* @param[in] offset The offset to set
|
|
||||||
* @param[in] whence The origin of the offset
|
|
||||||
*/
|
|
||||||
void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence) {
|
|
||||||
switch (whence) {
|
|
||||||
case SEEK_SET:
|
|
||||||
handle->ofset = offset;
|
|
||||||
break;
|
|
||||||
case SEEK_CUR:
|
|
||||||
handle->ofset += offset;
|
|
||||||
break;
|
|
||||||
case SEEK_END:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (handle->ofset > handle->len) {
|
|
||||||
handle->ofset = handle->len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief tftp custom file functions to read the data
|
|
||||||
* auto rolling over the offset
|
|
||||||
* if the bytes to read is bigger than the remaining bytes
|
|
||||||
* it will read the remaining bytes and set the bytes to 0
|
|
||||||
* @param[out] buf The buffer to write the data to
|
|
||||||
* @param[in] bytes The number of bytes to read
|
|
||||||
* @param[in,out] handle Custom file handles
|
|
||||||
*/
|
|
||||||
size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
|
|
||||||
if (handle->ofset + bytes > handle->len) {
|
|
||||||
bytes = handle->len - handle->ofset;
|
|
||||||
}
|
|
||||||
memcpy(buf, handle->data + handle->ofset, bytes);
|
|
||||||
handle->ofset += bytes;
|
|
||||||
((char*)buf)[bytes] = '\0';
|
|
||||||
if (handle->ofset > handle->len) {
|
|
||||||
bytes = 0;
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
typedef struct tftp_custom_file_s {
|
|
||||||
const char* data;
|
|
||||||
size_t len;
|
|
||||||
char*name;
|
|
||||||
size_t ofset;
|
|
||||||
}tftp_custom_file_t;
|
|
||||||
|
|
||||||
void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence);
|
|
||||||
size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle);
|
|
||||||
37
tests/tftp_server.h
Normal file
37
tests/tftp_server.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct pbuf {
|
||||||
|
struct pbuf *next;
|
||||||
|
void *payload;
|
||||||
|
uint16_t tot_len;
|
||||||
|
uint16_t len;
|
||||||
|
uint8_t type_internal;
|
||||||
|
uint8_t flags;
|
||||||
|
//LWIP_PBUF_REF_T ref;
|
||||||
|
|
||||||
|
uint8_t if_idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ERR_OK 0
|
||||||
|
|
||||||
|
struct tftp_context {
|
||||||
|
void* (*open)(const char* fname, const char* mode, uint8_t write);
|
||||||
|
void (*close)(void* handle);
|
||||||
|
int (*read)(void* handle, void* buf, int bytes);
|
||||||
|
int (*write)(void* handle, struct pbuf* p);
|
||||||
|
};
|
||||||
|
|
||||||
|
void tftp_cleanup(void);
|
||||||
|
uint32_t logger_get_timestamp(void);
|
||||||
|
int tftp_init(struct tftp_context* context);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user