RTEMS 6.1-rc4
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Typedefs | Enumerations | Functions
Test suite for libtftpsfs tests

This test suite provides a tests for libtftpfs. More...

Files

file  init.c
 This source file contains the implementation of tests for libtftpfs.
 
file  tftpfs_interactions.c
 This source file contains the implementation of network interaction functions related to the UDP network fake for tftpfs testing.
 
file  tftpfs_interactions.h
 This header file provides functions used to implement network interactions of the UDP network fake for tftpfs tests.
 
file  tftpfs_udp_network_fake.c
 This source file contains the implementation of UDP network fake functions related to tftpfs testing.
 
file  tftpfs_udp_network_fake.h
 This header file provides interfaces and functions used to implement the UDP network fake for tftpfs tests.
 

Data Structures

struct  Tftp_Action
 
struct  Tftp_Interaction
 
struct  Tftp_Packet
 

Macros

#define TFTP_STD_PORT   69
 
#define TFTP_MAX_IP_ADDR_STRLEN   (16 * 2 + 7 + 1)
 
#define TFTP_MAX_ERROR_STRLEN   20
 
#define TFTP_MAX_OPTIONS_SIZE   40
 
#define TFTP_KNOWN_IPV4_ADDR0_STR   "127.0.0.1"
 IP address strings and server names resolved by network fake functions like inet_aton() and gethostbyname().
 
#define TFTP_KNOWN_IPV4_ADDR0_ARRAY   127, 0, 0, 1
 
#define TFTP_KNOWN_SERVER0_NAME   "server.tftp"
 
#define TFTP_KNOWN_SERVER0_IPV4   "10.7.0.2"
 
#define TFTP_KNOWN_SERVER0_ARRAY   10, 7, 0, 2
 
#define TFTP_FIRST_FD   33333
 The faked socket() function (i.e. socket interaction) must return a file descriptor equal or larger than TFTP_FIRST_FD or -1.
 
#define TFTP_MODE_NETASCII   "netascii"
 
#define TFTP_MODE_OCTET   "octet"
 
#define TFTP_OPTION_BLKSIZE   "blksize"
 
#define TFTP_OPTION_TIMEOUT   "timeout"
 
#define TFTP_OPTION_TSIZE   "tsize"
 
#define TFTP_OPTION_WINDOWSIZE   "windowsize"
 
#define TFTP_WINDOW_SIZE_MIN   1
 
#define TFTP_BLOCK_SIZE_MIN   8
 
#define TFTP_BLOCK_SIZE_MAX   65464
 

Typedefs

typedef enum Tftp_Action_kind Tftp_Action_kind
 
typedef struct Tftp_Action Tftp_Action
 
typedef bool(* Tftp_Interaction_fn) (Tftp_Action *act, void *data)
 Carry out interactions with TFTP client.
 
typedef struct Tftp_Interaction Tftp_Interaction
 
typedef enum Tftp_Opcode Tftp_Opcode
 
typedef enum Tftp_Error_code Tftp_Error_code
 
typedef struct Tftp_Packet Tftp_Packet
 

Enumerations

enum  Tftp_Action_kind {
  TFTP_IA_KIND_SOCKET , TFTP_IA_KIND_CLOSE , TFTP_IA_KIND_BIND , TFTP_IA_KIND_SENDTO ,
  TFTP_IA_KIND_RECVFROM
}
 
enum  Tftp_Opcode {
  TFTP_OPCODE_RRQ = 1 , TFTP_OPCODE_WRQ = 2 , TFTP_OPCODE_DATA = 3 , TFTP_OPCODE_ACK = 4 ,
  TFTP_OPCODE_ERROR = 5 , TFTP_OPCODE_OACK = 6
}
 
enum  Tftp_Error_code {
  TFTP_ERROR_CODE_NOT_DEFINED = 0 , TFTP_ERROR_CODE_NOT_FOUND = 1 , TFTP_ERROR_CODE_NO_ACCESS = 2 , TFTP_ERROR_CODE_DISK_FULL = 3 ,
  TFTP_ERROR_CODE_ILLEGAL = 4 , TFTP_ERROR_CODE_UNKNOWN_ID = 5 , TFTP_ERROR_CODE_FILE_EXISTS = 6 , TFTP_ERROR_CODE_NO_USER = 7 ,
  TFTP_ERROR_CODE_OPTION_NEGO = 8
}
 

Functions

void _Tftp_Add_interaction_socket (int domain, int type, int protocol, int result)
 
void _Tftp_Add_interaction_close (int fd, int result)
 
void _Tftp_Add_interaction_bind (int fd, int family, int result)
 
void _Tftp_Add_interaction_send_rrq (int fd, const char *filename, uint16_t dest_port, const char *dest_addr_str, uint16_t block_size, uint16_t window_size, bool result)
 
void _Tftp_Add_interaction_send_wrq (int fd, const char *filename, uint16_t dest_port, const char *dest_addr_str, uint16_t block_size, uint16_t window_size, bool result)
 
void _Tftp_Add_interaction_send_ack (int fd, uint16_t block_num, uint16_t dest_port, const char *dest_addr_str, bool result)
 
void _Tftp_Add_interaction_send_data (int fd, uint16_t block_num, size_t start, size_t len, uint8_t(*get_data)(size_t pos), uint16_t dest_port, const char *dest_addr_str, bool result)
 
void _Tftp_Add_interaction_send_error (int fd, uint16_t error_code, uint16_t dest_port, const char *dest_addr_str, bool result)
 
void _Tftp_Add_interaction_recv_data (int fd, uint32_t timeout_ms, uint16_t src_port, const char *src_addr_str, uint16_t block_num, size_t start, size_t len, uint8_t(*get_data)(size_t pos), bool result)
 
void _Tftp_Add_interaction_recv_ack (int fd, uint32_t timeout_ms, uint16_t src_port, const char *src_addr_str, uint16_t block_num, bool result)
 
void _Tftp_Add_interaction_recv_oack (int fd, uint32_t timeout_ms, uint16_t src_port, const char *src_addr_str, const char *options, size_t options_size, bool result)
 
void _Tftp_Add_interaction_recv_error (int fd, uint32_t timeout_ms, uint16_t src_port, const char *src_addr_str, uint16_t error_code, const char *err_msg, bool result)
 
void _Tftp_Add_interaction_recv_raw (int fd, uint32_t timeout_ms, uint16_t src_port, const char *src_addr_str, size_t len, const uint8_t *bytes, bool result)
 
void _Tftp_Add_interaction_recv_nothing (int fd, uint32_t timeout_ms)
 
void _Tftp_Reset (void)
 Initialize and free the singleton control object.
 
void * _Tftp_Append_interaction (Tftp_Action_kind kind, Tftp_Interaction_fn fn, size_t size)
 Create an interaction and append it to the sequence of expected interactions.
 
bool _Tftp_Has_no_more_interactions (void)
 Have all queued interactions been processed?
 
const char * _Tftp_Get_error_str (uint16_t error_code)
 Provides a human readable description for an error code from an TFTP error packet.
 

Detailed Description

This test suite provides a tests for libtftpfs.

There are some additional files relevant for the TFTP test suite:

See also the RTEMS Filesystem Design Guide Chapter Trivial FTP Client Filesystem.

Typedef Documentation

◆ Tftp_Interaction_fn

typedef bool(* Tftp_Interaction_fn) (Tftp_Action *act, void *data)

Carry out interactions with TFTP client.

Tftp_Interaction_fn() is called to

  • check that the fake network function has been called with the expected arguments (in act)
  • define values which shall be returned (to be stored in act)

The function should not call T_assert_*() but use T_*(). Otherwise, it is unlikely that the test can terminate the client in teardown().

Parameters
[in,out]actThe actual arguments provided by the TFTP client to the network function. Moreover, storage to store the results to be returned to the TFTP client.
dataArbitrary data area allocated when the interaction is created by _Tftp_Append_interaction()
Return values
trueif the client behaved as expected.
falseif the test shall fail.

Function Documentation

◆ _Tftp_Append_interaction()

void * _Tftp_Append_interaction ( Tftp_Action_kind  kind,
Tftp_Interaction_fn  fn,
size_t  size 
)

Create an interaction and append it to the sequence of expected interactions.

This allocates memory for an interaction and additional specific data for the function fn() parameter data. The interaction is initialized and appended at the end of the sequence of expected interactions. If an error occurs a T_assert_*() macro is called. Hence, this function never returns NULL.

Parameters
kindDefines which interaction is expected. Note that it cannot happen that fn is called for a different network function.
fnA function which is called to handle the interaction. See Tftp_Interaction_fn()
sizeThe size of a memory area which is given to fn() as data argument when it is invoked. This can be used to provide private data to the function.
Returns
A pointer to a memory area of size size. The same pointer will be provided to fn as argument data when invoked.

◆ _Tftp_Get_error_str()

const char * _Tftp_Get_error_str ( uint16_t  error_code)

Provides a human readable description for an error code from an TFTP error packet.

Parameters
error_codeThe error code from the TFTP error packet in host byte order.
Returns
A pointer to a string describing the error. If the error code is unknown, a pointer to "Unknown error code" is returned. Do not change the the string as a pointer to the very same string will be returned by future calls.

◆ _Tftp_Has_no_more_interactions()

bool _Tftp_Has_no_more_interactions ( void  )

Have all queued interactions been processed?

At the end of a test, it should be checked whether all queued interactions have been consumed by the TFTP client.

Return values
trueAll queued interactions have been processed.
falseAt least one queued interactions has not yet been processed.

◆ _Tftp_Reset()

void _Tftp_Reset ( void  )

Initialize and free the singleton control object.

Invoke _Tftp_Reset() in setup() and teardown() of the test.