File indexing completed on 2025-05-11 08:24:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 #ifdef HAVE_CONFIG_H
0042 #include "config.h"
0043 #endif
0044
0045 #include <stdio.h>
0046 #include <stdlib.h> /* malloc(), free() */
0047 #include <ctype.h> /* isprint() */
0048 #include <errno.h>
0049 #include <sys/stat.h> /* mkdir(), open() */
0050 #include <sys/types.h> /* mkdir(), open() */
0051 #include <sys/socket.h> /* AF_INET, SOCK_DGRAM */
0052 #include <fcntl.h> /* open() */
0053 #include <unistd.h> /* read(), close(), rmdir() */
0054
0055 #include <rtems/tftp.h>
0056 #include <rtems/libio.h> /* mount(), RTEMS_FILESYSTEM_TYPE_TFTPFS */
0057 #include <rtems/test.h>
0058 #include <rtems/test-info.h>
0059 #include <rtems/testopts.h> /* RTEMS_TEST_VERBOSITY */
0060 #include <rtems.h>
0061
0062 #include "tftpfs_udp_network_fake.h"
0063 #include "tftpfs_interactions.h"
0064 #include "tftp_driver.h"
0065
0066 #define SERV_PORT 12345
0067 #define FIRST_TIMEOUT_MILLISECONDS 400
0068 #define TIMEOUT_MILLISECONDS 1000
0069 #define LARGE_BLOCK_SIZE TFTP_BLOCK_SIZE_MAX
0070 #define SMALL_BLOCK_SIZE 12
0071 #define SMALL_WINDOW_SIZE 4
0072 #define T_no_more_interactions() T_assert_true( \
0073 _Tftp_Has_no_more_interactions(), \
0074 "The TFTP client skiped some final network interactions." \
0075 )
0076
0077
0078
0079
0080
0081 typedef struct tftp_test_context {
0082 int fd0;
0083 void *tftp_handle;
0084 } tftp_test_context;
0085
0086 static const char *tftpfs_mount_point = "/tftp";
0087 static const char *tftpfs_ipv4_loopback = TFTP_KNOWN_IPV4_ADDR0_STR;
0088 static const char *tftpfs_server0_name = TFTP_KNOWN_SERVER0_NAME;
0089 static const char *tftpfs_server0_ipv4 = TFTP_KNOWN_SERVER0_IPV4;
0090 static const char *tftpfs_file = "file.txt";
0091 static tftp_test_context tftp_context;
0092
0093 static void mount_tftp_fs( const char *mount_point, const char *options )
0094 {
0095 int result;
0096
0097 result = mkdir( mount_point, S_IRWXU | S_IRWXG | S_IRWXO );
0098 T_assert_eq_int( result, 0 );
0099
0100 result = mount(
0101 "",
0102 mount_point,
0103 RTEMS_FILESYSTEM_TYPE_TFTPFS,
0104 RTEMS_FILESYSTEM_READ_WRITE,
0105 options
0106 );
0107 T_assert_eq_int( result, 0 );
0108 }
0109
0110 static void umount_tftp_fs( const char *mount_point )
0111 {
0112 int result;
0113
0114 result = unmount( mount_point );
0115 T_assert_eq_int( result, 0 );
0116
0117 result = rmdir( mount_point );
0118 T_assert_eq_int( result, 0 );
0119 }
0120
0121 static void setup_rfc1350( void *context )
0122 {
0123 tftp_test_context *ctx = context;
0124 _Tftp_Reset();
0125 ctx->fd0 = -1;
0126 ctx->tftp_handle = NULL;
0127 mount_tftp_fs( tftpfs_mount_point, "verbose,rfc1350" );
0128 }
0129
0130 static void teardown( void *context )
0131 {
0132 tftp_test_context *ctx = context;
0133 if ( ctx->fd0 >= 0 ) {
0134 close( ctx->fd0 );
0135 }
0136 tftp_close( ctx->tftp_handle );
0137 umount_tftp_fs( tftpfs_mount_point );
0138 _Tftp_Reset();
0139 }
0140
0141 static const T_fixture fixture_rfc1350 = {
0142 .setup = setup_rfc1350,
0143 .stop = NULL,
0144 .teardown = teardown,
0145 .scope = NULL,
0146 .initial_context = &tftp_context
0147 };
0148
0149 static void setup_default_options( void *context )
0150 {
0151 tftp_test_context *ctx = context;
0152 _Tftp_Reset();
0153 ctx->fd0 = -1;
0154 ctx->tftp_handle = NULL;
0155 mount_tftp_fs( tftpfs_mount_point, NULL );
0156 }
0157
0158 static const T_fixture fixture_default_options = {
0159 .setup = setup_default_options,
0160 .stop = NULL,
0161 .teardown = teardown,
0162 .scope = NULL,
0163 .initial_context = &tftp_context
0164 };
0165
0166 static void setup_large_blocksize( void *context )
0167 {
0168 tftp_test_context *ctx = context;
0169 _Tftp_Reset();
0170 ctx->fd0 = -1;
0171 ctx->tftp_handle = NULL;
0172 mount_tftp_fs(
0173 tftpfs_mount_point,
0174 "verbose,blocksize=" RTEMS_XSTRING(LARGE_BLOCK_SIZE) ",windowsize=1"
0175 );
0176 }
0177
0178 static const T_fixture fixture_large_blocksize = {
0179 .setup = setup_large_blocksize,
0180 .stop = NULL,
0181 .teardown = teardown,
0182 .scope = NULL,
0183 .initial_context = &tftp_context
0184 };
0185
0186 static void setup_small_opt_size( void *context )
0187 {
0188 tftp_test_context *ctx = context;
0189 _Tftp_Reset();
0190 ctx->fd0 = -1;
0191 ctx->tftp_handle = NULL;
0192 mount_tftp_fs(
0193 tftpfs_mount_point,
0194 "blocksize=" RTEMS_XSTRING(SMALL_BLOCK_SIZE)
0195 ",windowsize=" RTEMS_XSTRING(SMALL_WINDOW_SIZE)
0196 );
0197 }
0198
0199 static const T_fixture fixture_small_opt_size = {
0200 .setup = setup_small_opt_size,
0201 .stop = NULL,
0202 .teardown = teardown,
0203 .scope = NULL,
0204 .initial_context = &tftp_context
0205 };
0206
0207 static void setup_mount_point( void *context )
0208 {
0209 int result;
0210
0211 _Tftp_Reset();
0212 result = mkdir( tftpfs_mount_point, S_IRWXU | S_IRWXG | S_IRWXO );
0213 T_assert_eq_int( result, 0 );
0214 }
0215
0216 static void teardown_mount_point( void *context )
0217 {
0218 int result;
0219
0220 result = rmdir( tftpfs_mount_point );
0221 T_assert_eq_int( result, 0 );
0222 _Tftp_Reset();
0223 }
0224
0225 static const T_fixture fixture_mount_point = {
0226 .setup = setup_mount_point,
0227 .stop = NULL,
0228 .teardown = teardown_mount_point,
0229 .scope = NULL,
0230 .initial_context = &tftp_context
0231 };
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241 static uint8_t get_file_content( size_t pos )
0242 {
0243 static const size_t frame_size = 100;
0244 static const size_t num_size = 11;
0245 static const size_t alpha_size = 53;
0246 char buf[10];
0247 size_t remainder = pos % frame_size;
0248
0249 switch ( remainder ) {
0250 case 0:
0251 case 1:
0252 case 2:
0253 sprintf( buf, "%9zu", pos - remainder );
0254 return buf[remainder];
0255 case 3:
0256 case 7:
0257 return '\'';
0258 case 4:
0259 case 5:
0260 case 6:
0261 sprintf( buf, "%9zu", pos - remainder );
0262 return buf[remainder-1];
0263 case 8:
0264 case 9:
0265 case 10:
0266 sprintf( buf, "%9zu", pos - remainder );
0267 return buf[remainder-2];
0268 default:
0269 pos -= ( pos / frame_size + 1 ) * num_size;
0270 remainder = pos % alpha_size;
0271 return ( remainder <= 'Z' - '@' ) ?
0272 remainder + '@' : remainder - ( 'Z' - '@' + 1) + 'a';
0273 }
0274 }
0275
0276
0277
0278
0279 static uint8_t get_bad_file_content( size_t pos )
0280 {
0281 static const char buf[] = "BAD!";
0282 return (uint8_t) buf[ pos % strlen( buf ) ];
0283 }
0284
0285 static const char *create_tftpfs_path(
0286 const char *sever_addr,
0287 const char *file_name
0288 )
0289 {
0290 static char buffer[100];
0291 int len;
0292
0293 len = snprintf(
0294 buffer,
0295 sizeof( buffer ),
0296 "%s/%s:%s",
0297 tftpfs_mount_point,
0298 sever_addr,
0299 file_name
0300 );
0301
0302 T_quiet_gt_int( len, 0 );
0303 T_quiet_lt_int( len, (int) sizeof( buffer ) );
0304 return buffer;
0305 }
0306
0307 static int read_tftp_file(
0308 const char *path,
0309 size_t buffer_size,
0310 size_t max_bytes,
0311 int *fd
0312 )
0313 {
0314 char *data_buffer;
0315 int result = 0;
0316 int res;
0317 ssize_t i;
0318 ssize_t bytes = 1;
0319 ssize_t bytes_total = 0;
0320 int errno_store;
0321
0322 T_log( T_VERBOSE, "File system: open( %s, O_RDONLY )", path );
0323 errno = 0;
0324 *fd = open( path, O_RDONLY );
0325 errno_store = errno;
0326 T_log(
0327 T_VERBOSE,
0328 "File system: [open( %s, O_RDONLY )] = fd:%d (errno = %d)",
0329 path,
0330 *fd,
0331 errno
0332 );
0333
0334 if ( *fd < 0 ) {
0335
0336 T_log( T_VERBOSE, "File system: cannot open \"%s\" for reading", path );
0337 errno = errno_store;
0338 result = -1;
0339 }
0340
0341 if ( *fd >= 0 ) {
0342 data_buffer = malloc( buffer_size );
0343
0344 while ( bytes > 0 && max_bytes >= bytes ) {
0345 errno = 0;
0346 bytes = read(
0347 *fd,
0348 data_buffer,
0349 ( max_bytes > buffer_size ) ? buffer_size : max_bytes
0350 );
0351 errno_store = errno;
0352 T_log(
0353 T_VERBOSE,
0354 "File system: [read( fd:%d, size=%zu )] = %zd (errno = %d)",
0355 *fd,
0356 ( max_bytes > buffer_size ) ? buffer_size : max_bytes,
0357 bytes,
0358 errno
0359 );
0360
0361 if ( bytes > 0 ) {
0362 max_bytes -= bytes;
0363 for ( i = 0; i < bytes; ++i ) {
0364 if ( data_buffer[i] != get_file_content( bytes_total + i ) ) {
0365 T_true(
0366 false,
0367 "File system: wrong file content '%c' (expected '%c') "
0368 "at position %zd",
0369 (int) ( isprint( (int) data_buffer[i] ) ? data_buffer[i] : '?' ),
0370 (int) get_file_content( bytes_total + i ),
0371 bytes_total + i
0372 );
0373 bytes = 0;
0374 break;
0375 }
0376 }
0377 bytes_total += bytes;
0378 }
0379 if ( bytes == 0 ) {
0380 result = (int) bytes_total;
0381 }
0382 if ( bytes < 0 ) {
0383
0384 T_log(
0385 T_VERBOSE,
0386 "File system: error reading from \"%s\" after %zd bytes",
0387 path,
0388 bytes_total
0389 );
0390 result = (int) bytes_total;
0391 }
0392 }
0393
0394 free( data_buffer );
0395 }
0396
0397 if ( bytes > 0 ) {
0398 T_log(
0399 T_VERBOSE,
0400 "File system: reader closes \"%s\" after %zd bytes",
0401 path,
0402 bytes_total
0403 );
0404 result = (int) bytes_total;
0405 }
0406
0407 if ( *fd >= 0 ) {
0408 res = close( *fd );
0409 T_log(
0410 T_VERBOSE,
0411 "File system: [close( %s (fd:%d) )] = %d",
0412 path,
0413 *fd,
0414 res
0415 );
0416 *fd = -1;
0417 T_eq_int( res, 0 );
0418 }
0419
0420 errno = errno_store;
0421 return result;
0422 }
0423
0424 static int write_tftp_file(
0425 const char *path,
0426 size_t file_size,
0427 size_t buffer_size,
0428 int *fd )
0429 {
0430 char *data_buffer;
0431 int result = 0;
0432 int res;
0433 ssize_t i;
0434 ssize_t bytes;
0435 ssize_t bytes_total = 0;
0436 int errno_store;
0437
0438 errno = 0;
0439 T_log( T_VERBOSE, "File system: open( %s, O_WRONLY )", path );
0440 *fd = open( path, O_WRONLY );
0441 errno_store = errno;
0442 T_log(
0443 T_VERBOSE,
0444 "File system: [open( %s, O_WRONLY )] = fd:%d (errno = %d)",
0445 path,
0446 *fd,
0447 errno
0448 );
0449 if ( *fd < 0 ) {
0450
0451 T_log( T_VERBOSE, "File system: cannot open \"%s\" for writing", path );
0452 errno = errno_store;
0453 result = -1;
0454 }
0455
0456 if ( *fd >= 0 ) {
0457 data_buffer = malloc( buffer_size );
0458
0459 do {
0460 bytes = ( file_size - bytes_total >= buffer_size ) ?
0461 buffer_size : file_size - bytes_total;
0462 for ( i = 0; i < bytes; ++i ) {
0463 data_buffer[i] = get_file_content( bytes_total + i );
0464 }
0465 errno = 0;
0466 bytes = write( *fd, data_buffer, i );
0467 errno_store = errno;
0468 T_log(
0469 T_VERBOSE,
0470 "File system: [write( fd:%d, size=%zd )] = %zd (errno = %d)",
0471 *fd,
0472 i,
0473 bytes,
0474 errno
0475 );
0476 if ( bytes > 0 ) {
0477 bytes_total += bytes;
0478 result = (int) bytes_total;
0479 }
0480 if ( bytes != i ) {
0481
0482 T_log(
0483 T_VERBOSE,
0484 "File system: error writing to \"%s\" after %zd bytes",
0485 path,
0486 bytes_total
0487 );
0488 break;
0489 }
0490 } while( bytes_total < file_size );
0491
0492 free( data_buffer );
0493 }
0494
0495 if ( *fd >= 0 ) {
0496 res = close( *fd );
0497 if (res != 0) {
0498 errno_store = errno;
0499 result = res;
0500 }
0501 T_log(
0502 T_VERBOSE,
0503 "File system: [close( %s (fd:%d) )] = %d",
0504 path,
0505 *fd,
0506 res
0507 );
0508 *fd = -1;
0509 }
0510
0511 errno = errno_store;
0512 return result;
0513 }
0514
0515 static int rdwt_tftp_client_file(
0516 const char *hostname,
0517 const char *filename,
0518 bool is_for_reading,
0519 ssize_t file_size,
0520 const tftp_net_config *config,
0521 void **tftp_handle
0522 )
0523 {
0524 const static size_t buffer_size = 4001;
0525 char *data_buffer;
0526 int res = 0;
0527 ssize_t i;
0528 ssize_t bytes = 1;
0529 ssize_t bytes_total = 0;
0530 int errno_store = 0;
0531
0532 if ( *tftp_handle == NULL ) {
0533 T_log(
0534 T_VERBOSE,
0535 "TFTP Client: tftp_open( \"%s\", \"%s\", %s, ... )",
0536 hostname,
0537 filename,
0538 is_for_reading ? "read" : "write"
0539 );
0540 res = tftp_open(
0541 hostname,
0542 filename,
0543 is_for_reading,
0544 config,
0545 tftp_handle
0546 );
0547 T_log(
0548 T_VERBOSE,
0549 "TFTP Client: [tftp_open( \"%s\", \"%s\", %s, ... )] = %d (handle:%p)",
0550 hostname,
0551 filename,
0552 is_for_reading ? "read" : "write",
0553 res,
0554 *tftp_handle
0555 );
0556 } else {
0557 T_log(
0558 T_VERBOSE,
0559 "TFTP Client: \"%s\":\"%s\" already open for %s, handle: %p ",
0560 hostname,
0561 filename,
0562 is_for_reading ? "read" : "write",
0563 *tftp_handle
0564 );
0565 }
0566
0567 if ( res != 0 ) {
0568
0569 T_log(
0570 T_VERBOSE,
0571 "TFTP client: cannot open \"%s\":\"%s\" for %s",
0572 hostname,
0573 filename,
0574 is_for_reading ? "reading" : "writing"
0575 );
0576 errno_store = res;
0577 } else {
0578 T_assert_not_null( *tftp_handle );
0579 }
0580
0581 if ( *tftp_handle != NULL ) {
0582 data_buffer = malloc( buffer_size );
0583
0584 if ( is_for_reading ) {
0585
0586
0587 while ( bytes > 0 ) {
0588 errno = 0;
0589 bytes = tftp_read(
0590 *tftp_handle,
0591 data_buffer,
0592 buffer_size
0593 );
0594 T_log(
0595 T_VERBOSE,
0596 "TFTP Client: [tftp_read( %p, size=%zu )] = %zd",
0597 *tftp_handle,
0598 buffer_size,
0599 bytes
0600 );
0601
0602 if ( bytes > 0 ) {
0603 for ( i = 0; i < bytes; ++i ) {
0604 if ( data_buffer[i] != get_file_content( bytes_total + i ) ) {
0605 T_true(
0606 false,
0607 "FTP Client: wrong file content '%c' (expected '%c') at positon %zd",
0608 (int) ( isprint( (int) data_buffer[i] ) ? data_buffer[i] : '?' ),
0609 (int) get_file_content( bytes_total + i ),
0610 bytes_total + i
0611 );
0612 bytes = 0;
0613 break;
0614 }
0615 }
0616 bytes_total += bytes;
0617 }
0618 if ( bytes < 0 ) {
0619
0620 T_log(
0621 T_VERBOSE,
0622 "TFTP Client: error reading from \"%s\":\"%s\" after %zd bytes",
0623 hostname,
0624 filename,
0625 bytes_total
0626 );
0627 errno_store = -bytes;
0628 }
0629 }
0630 } else {
0631
0632
0633 do {
0634 bytes = ( file_size - bytes_total >= buffer_size ) ?
0635 buffer_size : file_size - bytes_total;
0636 for ( i = 0; i < bytes; ++i ) {
0637 data_buffer[i] = get_file_content( bytes_total + i );
0638 }
0639 errno = 0;
0640 bytes = tftp_write( *tftp_handle, data_buffer, i );
0641 T_log(
0642 T_VERBOSE,
0643 "TFTP Client: [tftp_write( %p, size=%zd )] = %zd",
0644 *tftp_handle,
0645 i,
0646 bytes
0647 );
0648 if ( bytes > 0 ) {
0649 bytes_total += bytes;
0650 } else {
0651 errno_store = -bytes;
0652 }
0653 if ( bytes != i ) {
0654
0655 T_log(
0656 T_VERBOSE,
0657 "TFTP Client: error writing to \"%s\":\"%s\" after %zd bytes",
0658 hostname,
0659 filename,
0660 bytes_total
0661 );
0662 break;
0663 }
0664 } while( bytes_total < file_size );
0665 }
0666
0667 free( data_buffer );
0668 }
0669
0670 if ( *tftp_handle != NULL ) {
0671 res = tftp_close( *tftp_handle );
0672 T_log(
0673 T_VERBOSE,
0674 "TFTP Client: [tftp_close( \"%s\":\"%s\" (handle:%p) )] = %d",
0675 hostname,
0676 filename,
0677 *tftp_handle,
0678 res
0679 );
0680 *tftp_handle = NULL;
0681 T_eq_int( res, 0 );
0682 }
0683
0684 errno = errno_store;
0685 return (int) bytes_total;
0686 }
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699 T_TEST_CASE( tftp_initialize_net_config )
0700 {
0701 tftp_net_config config;
0702 memset( &config, 0, sizeof( config ) );
0703 tftp_initialize_net_config( &config );
0704 T_eq_u16( config.retransmissions, 6 );
0705 T_eq_u16( config.server_port, 69 );
0706 T_eq_u32( config.timeout, 1000 );
0707 T_eq_u32( config.first_timeout, 400 );
0708 T_eq_u16( config.options.block_size, 1456 );
0709 T_eq_u16( config.options.window_size, 8 );
0710 }
0711
0712
0713
0714
0715
0716
0717
0718 T_TEST_CASE( tftp_initialize_net_config_null )
0719 {
0720 tftp_initialize_net_config( NULL );
0721 }
0722
0723
0724
0725
0726
0727
0728
0729 T_TEST_CASE_FIXTURE( tftp_open_null_hostname, &fixture_rfc1350 )
0730 {
0731 tftp_test_context *ctx = T_fixture_context();
0732 int res;
0733
0734 res = tftp_open(
0735 NULL,
0736 tftpfs_file,
0737 true,
0738 NULL,
0739 &ctx->tftp_handle
0740 );
0741 T_eq_int( res, EINVAL );
0742 T_null( ctx->tftp_handle );
0743 }
0744
0745
0746
0747
0748
0749
0750
0751 T_TEST_CASE_FIXTURE( tftp_open_null_filename, &fixture_rfc1350 )
0752 {
0753 tftp_test_context *ctx = T_fixture_context();
0754 int res;
0755
0756 res = tftp_open(
0757 tftpfs_ipv4_loopback,
0758 NULL,
0759 true,
0760 NULL,
0761 &ctx->tftp_handle
0762 );
0763 T_eq_int( res, EINVAL );
0764 T_null( ctx->tftp_handle );
0765 }
0766
0767
0768
0769
0770
0771
0772
0773 T_TEST_CASE( tftp_open_null_tftp_handle )
0774 {
0775 int res;
0776
0777 res = tftp_open(
0778 tftpfs_ipv4_loopback,
0779 tftpfs_file,
0780 true,
0781 NULL,
0782 NULL
0783 );
0784 T_eq_int( res, EINVAL );
0785 }
0786
0787
0788
0789
0790
0791
0792
0793 T_TEST_CASE_FIXTURE( tftp_open_illegal_window_size, &fixture_rfc1350 )
0794 {
0795 tftp_test_context *ctx = T_fixture_context();
0796 tftp_net_config config;
0797 int res;
0798
0799 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
0800 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
0801
0802 tftp_initialize_net_config( &config );
0803 config.options.window_size = 1 - 1;
0804
0805 res = tftp_open(
0806 tftpfs_ipv4_loopback,
0807 tftpfs_file,
0808 true,
0809 &config,
0810 &ctx->tftp_handle
0811 );
0812 T_eq_int( res, EINVAL );
0813 T_null( ctx->tftp_handle );
0814 T_no_more_interactions();
0815 }
0816
0817
0818
0819
0820
0821
0822
0823 T_TEST_CASE_FIXTURE( tftp_open_block_size_too_small, &fixture_rfc1350 )
0824 {
0825 tftp_test_context *ctx = T_fixture_context();
0826 tftp_net_config config;
0827 int res;
0828
0829 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
0830 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
0831
0832 tftp_initialize_net_config( &config );
0833 config.options.block_size = 8 - 1;
0834
0835 res = tftp_open(
0836 tftpfs_ipv4_loopback,
0837 tftpfs_file,
0838 true,
0839 &config,
0840 &ctx->tftp_handle
0841 );
0842 T_eq_int( res, EINVAL );
0843 T_null( ctx->tftp_handle );
0844 T_no_more_interactions();
0845 }
0846
0847
0848
0849
0850
0851
0852
0853 T_TEST_CASE_FIXTURE( tftp_open_block_size_too_large, &fixture_rfc1350 )
0854 {
0855 tftp_test_context *ctx = T_fixture_context();
0856 tftp_net_config config;
0857 int res;
0858
0859 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
0860 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
0861
0862 tftp_initialize_net_config( &config );
0863 config.options.block_size = 65464 + 1;
0864
0865 res = tftp_open(
0866 tftpfs_ipv4_loopback,
0867 tftpfs_file,
0868 false,
0869 &config,
0870 &ctx->tftp_handle
0871 );
0872 T_eq_int( res, EINVAL );
0873 T_null( ctx->tftp_handle );
0874 T_no_more_interactions();
0875 }
0876
0877
0878
0879
0880
0881
0882
0883 T_TEST_CASE( tftp_read_null_tftp_handle )
0884 {
0885 char data_buffer[10];
0886 ssize_t res;
0887
0888 res = tftp_read(
0889 NULL,
0890 data_buffer,
0891 sizeof( data_buffer)
0892 );
0893 T_eq_int( res, -EIO );
0894 }
0895
0896
0897
0898
0899
0900
0901
0902 T_TEST_CASE( tftp_read_null_buffer )
0903 {
0904 int tftp_handle;
0905 ssize_t res;
0906
0907 res = tftp_read(
0908 &tftp_handle,
0909 NULL,
0910 8
0911 );
0912 T_eq_int( res, -EIO );
0913 }
0914
0915
0916
0917
0918
0919
0920
0921 T_TEST_CASE( tftp_write_null_tftp_handle )
0922 {
0923 char data_buffer[10] = { 0 };
0924 ssize_t res;
0925
0926 res = tftp_write(
0927 NULL,
0928 data_buffer,
0929 sizeof( data_buffer)
0930 );
0931 T_eq_int( res, -EIO );
0932 }
0933
0934
0935
0936
0937
0938
0939
0940 T_TEST_CASE( tftp_write_null_buffer )
0941 {
0942 int tftp_handle;
0943 ssize_t res;
0944
0945 res = tftp_write(
0946 &tftp_handle,
0947 NULL,
0948 8
0949 );
0950 T_eq_int( res, -EIO );
0951 }
0952
0953
0954
0955
0956
0957
0958 T_TEST_CASE( tftp_close_null )
0959 {
0960 T_eq_int( tftp_close( NULL ), 0 );
0961 }
0962
0963
0964
0965
0966
0967
0968 T_TEST_CASE( _Tftpfs_Parse_options_empty )
0969 {
0970 size_t err_pos;
0971 uint32_t flags = 0;
0972 tftp_net_config config;
0973
0974 tftp_initialize_net_config( &config );
0975 err_pos = _Tftpfs_Parse_options( "", &config, &flags );
0976 T_eq_sz( err_pos, 0 );
0977 T_eq_u16( config.options.block_size, TFTP_DEFAULT_BLOCK_SIZE );
0978 T_eq_u16( config.options.window_size, TFTP_DEFAULT_WINDOW_SIZE );
0979 T_eq_u32( flags, 0 );
0980 }
0981
0982
0983
0984
0985
0986
0987 T_TEST_CASE( _Tftpfs_Parse_options_null )
0988 {
0989 size_t err_pos;
0990 uint32_t flags = 0;
0991 tftp_net_config config;
0992
0993 tftp_initialize_net_config( &config );
0994 err_pos = _Tftpfs_Parse_options( NULL, &config, &flags );
0995 T_eq_sz( err_pos, 0 );
0996 T_eq_u16( config.options.block_size, TFTP_DEFAULT_BLOCK_SIZE );
0997 T_eq_u16( config.options.window_size, TFTP_DEFAULT_WINDOW_SIZE );
0998 T_eq_u32( flags, 0 );
0999 }
1000
1001
1002
1003
1004
1005
1006 T_TEST_CASE( _Tftpfs_Parse_options_verbose )
1007 {
1008 size_t err_pos;
1009 uint32_t flags = 0;
1010 tftp_net_config config;
1011
1012 tftp_initialize_net_config( &config );
1013 err_pos = _Tftpfs_Parse_options( "verbose", &config, &flags );
1014 T_eq_sz( err_pos, 0 );
1015 T_eq_u16( config.options.block_size, TFTP_DEFAULT_BLOCK_SIZE );
1016 T_eq_u16( config.options.window_size, TFTP_DEFAULT_WINDOW_SIZE );
1017 T_gt_u32( flags, 0 );
1018 }
1019
1020
1021
1022
1023
1024
1025 T_TEST_CASE( _Tftpfs_Parse_options_rfc1350 )
1026 {
1027 size_t err_pos;
1028 uint32_t flags = 0;
1029 tftp_net_config config;
1030
1031 tftp_initialize_net_config( &config );
1032 err_pos = _Tftpfs_Parse_options( "rfc1350", &config, &flags );
1033 T_eq_sz( err_pos, 0 );
1034 T_eq_u16( config.options.block_size, TFTP_RFC1350_BLOCK_SIZE );
1035 T_eq_u16( config.options.window_size, TFTP_RFC1350_WINDOW_SIZE );
1036 T_eq_u32( flags, 0 );
1037 }
1038
1039
1040
1041
1042
1043
1044 T_TEST_CASE( _Tftpfs_Parse_options_blocksize )
1045 {
1046 size_t err_pos;
1047 uint32_t flags = 0;
1048 tftp_net_config config;
1049
1050 tftp_initialize_net_config( &config );
1051 err_pos = _Tftpfs_Parse_options( "blocksize=21", &config, &flags );
1052 T_eq_sz( err_pos, 0 );
1053 T_eq_u16( config.options.block_size, 21 );
1054 T_eq_u16( config.options.window_size, TFTP_DEFAULT_WINDOW_SIZE );
1055 T_eq_u32( flags, 0 );
1056 }
1057
1058
1059
1060
1061
1062
1063 T_TEST_CASE( _Tftpfs_Parse_options_windowsize )
1064 {
1065 size_t err_pos;
1066 uint32_t flags = 0;
1067 tftp_net_config config;
1068
1069 tftp_initialize_net_config( &config );
1070 err_pos = _Tftpfs_Parse_options( "windowsize=13", &config, &flags );
1071 T_eq_sz( err_pos, 0 );
1072 T_eq_u16( config.options.block_size, TFTP_DEFAULT_BLOCK_SIZE );
1073 T_eq_u16( config.options.window_size, 13 );
1074 T_eq_u32( flags, 0 );
1075 }
1076
1077
1078
1079
1080
1081
1082 T_TEST_CASE( _Tftpfs_Parse_options_all )
1083 {
1084 size_t err_pos;
1085 uint32_t flags = 0;
1086 tftp_net_config config;
1087
1088 tftp_initialize_net_config( &config );
1089 err_pos = _Tftpfs_Parse_options( "rfc1350,blocksize=1234,windowsize=4567,verbose", &config, &flags );
1090 T_eq_sz( err_pos, 0 );
1091 T_eq_u16( config.options.block_size, 1234 );
1092 T_eq_u16( config.options.window_size, 4567 );
1093 T_gt_u32( flags, 0 );
1094 }
1095
1096
1097
1098
1099
1100
1101 T_TEST_CASE( _Tftpfs_Parse_options_surplus_comma )
1102 {
1103 size_t err_pos;
1104 uint32_t flags = 0;
1105 tftp_net_config config;
1106
1107 tftp_initialize_net_config( &config );
1108 err_pos = _Tftpfs_Parse_options( ",blocksize=1234,,,,windowsize=4567,,", &config, &flags );
1109 T_eq_sz( err_pos, 0 );
1110 T_eq_u16( config.options.block_size, 1234 );
1111 T_eq_u16( config.options.window_size, 4567 );
1112 T_eq_u32( flags, 0 );
1113 }
1114
1115
1116
1117
1118
1119
1120 T_TEST_CASE( _Tftpfs_Parse_options_bad_value )
1121 {
1122 size_t err_pos;
1123 uint32_t flags = 0;
1124 tftp_net_config config;
1125
1126 tftp_initialize_net_config( &config );
1127 err_pos = _Tftpfs_Parse_options( "blocksize=123.4,windowsize=4567", &config, &flags );
1128 T_eq_sz( err_pos, 14 );
1129 }
1130
1131
1132
1133
1134
1135
1136 T_TEST_CASE( _Tftpfs_Parse_options_illegal_option )
1137 {
1138 size_t err_pos;
1139 uint32_t flags = 0;
1140 tftp_net_config config;
1141
1142 tftp_initialize_net_config( &config );
1143 err_pos = _Tftpfs_Parse_options( "blocksize=123,illegal", &config, &flags );
1144 T_eq_sz( err_pos, 15 );
1145 }
1146
1147
1148
1149
1150
1151
1152 T_TEST_CASE( _Tftpfs_Parse_options_truncated_option )
1153 {
1154 size_t err_pos;
1155 uint32_t flags = 0;
1156 tftp_net_config config;
1157
1158 tftp_initialize_net_config( &config );
1159 err_pos = _Tftpfs_Parse_options( "blocksize", &config, &flags );
1160 T_eq_sz( err_pos, 1 );
1161 }
1162
1163
1164
1165
1166
1167
1168 T_TEST_CASE_FIXTURE( mount_with_bad_options, &fixture_mount_point )
1169 {
1170 int result;
1171
1172 result = mount(
1173 "",
1174 tftpfs_mount_point,
1175 RTEMS_FILESYSTEM_TYPE_TFTPFS,
1176 RTEMS_FILESYSTEM_READ_WRITE,
1177 "windowsize=4567,blocksize=123bad"
1178 );
1179 T_assert_le_int( result, -1 );
1180 T_assert_eq_int( errno, EINVAL );
1181 }
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202 T_TEST_CASE_FIXTURE( client_open_with_NULL_config, &fixture_rfc1350 )
1203 {
1204 tftp_test_context *ctx = T_fixture_context();
1205 int bytes_read;
1206 uint16_t block_num = 1;
1207 size_t pos_in_file = 0;
1208
1209
1210 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
1211 _Tftp_Add_interaction_send_rrq(
1212 TFTP_FIRST_FD,
1213 tftpfs_file,
1214 TFTP_STD_PORT,
1215 tftpfs_ipv4_loopback,
1216 TFTP_DEFAULT_BLOCK_SIZE,
1217 TFTP_DEFAULT_WINDOW_SIZE,
1218 true
1219 );
1220 _Tftp_Add_interaction_recv_data(
1221 TFTP_FIRST_FD,
1222 FIRST_TIMEOUT_MILLISECONDS,
1223 SERV_PORT,
1224 tftpfs_ipv4_loopback,
1225 block_num,
1226 pos_in_file,
1227 1,
1228 get_file_content,
1229 true
1230 );
1231 pos_in_file += 1;
1232 _Tftp_Add_interaction_send_ack(
1233 TFTP_FIRST_FD,
1234 block_num++,
1235 SERV_PORT,
1236 tftpfs_ipv4_loopback,
1237 true
1238 );
1239 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
1240
1241 bytes_read = rdwt_tftp_client_file(
1242 tftpfs_ipv4_loopback,
1243 tftpfs_file,
1244 true,
1245 -1,
1246 NULL,
1247 &ctx->tftp_handle
1248 );
1249 T_eq_sz( bytes_read, pos_in_file );
1250 T_eq_int( errno, 0 );
1251 T_no_more_interactions();
1252 }
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276 T_TEST_CASE_FIXTURE( client_open_with_none_default_config, &fixture_rfc1350 )
1277 {
1278 tftp_test_context *ctx = T_fixture_context();
1279 tftp_net_config config;
1280 int bytes_read;
1281 uint16_t block_num = 0;
1282 size_t pos_in_file = 0;
1283 uint16_t retransmissions = 2;
1284 uint16_t server_port = 3456;
1285 uint32_t timeout = 300;
1286 uint32_t first_timeout = 200;
1287 uint16_t block_size = 8;
1288 uint16_t window_size = 2;
1289 const char options[] =
1290 "WINDOWSIZE" "\0" "2\0"
1291 TFTP_OPTION_BLKSIZE "\0" "8";
1292
1293
1294 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
1295 _Tftp_Add_interaction_send_rrq(
1296 TFTP_FIRST_FD,
1297 tftpfs_file,
1298 server_port,
1299 tftpfs_ipv4_loopback,
1300 block_size,
1301 window_size,
1302 true
1303 );
1304 _Tftp_Add_interaction_recv_oack(
1305 TFTP_FIRST_FD,
1306 first_timeout,
1307 SERV_PORT,
1308 tftpfs_ipv4_loopback,
1309 options,
1310 sizeof( options ),
1311 true
1312 );
1313 _Tftp_Add_interaction_send_ack(
1314 TFTP_FIRST_FD,
1315 block_num++,
1316 SERV_PORT,
1317 tftpfs_ipv4_loopback,
1318 true
1319 );
1320 _Tftp_Add_interaction_recv_data(
1321 TFTP_FIRST_FD,
1322 first_timeout,
1323 SERV_PORT,
1324 tftpfs_ipv4_loopback,
1325 block_num++,
1326 pos_in_file,
1327 block_size,
1328 get_file_content,
1329 true
1330 );
1331 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
1332 _Tftp_Add_interaction_recv_data(
1333 TFTP_FIRST_FD,
1334 first_timeout,
1335 SERV_PORT,
1336 tftpfs_ipv4_loopback,
1337 block_num,
1338 pos_in_file,
1339 block_size,
1340 get_file_content,
1341 true
1342 );
1343 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
1344 _Tftp_Add_interaction_send_ack(
1345 TFTP_FIRST_FD,
1346 block_num++,
1347 SERV_PORT,
1348 tftpfs_ipv4_loopback,
1349 true
1350 );
1351 _Tftp_Add_interaction_recv_nothing(
1352 TFTP_FIRST_FD,
1353 first_timeout
1354 );
1355 _Tftp_Add_interaction_send_ack(
1356 TFTP_FIRST_FD,
1357 block_num - 1,
1358 SERV_PORT,
1359 tftpfs_ipv4_loopback,
1360 true
1361 );
1362 _Tftp_Add_interaction_recv_nothing(
1363 TFTP_FIRST_FD,
1364 timeout
1365 );
1366 _Tftp_Add_interaction_send_error(
1367 TFTP_FIRST_FD,
1368 TFTP_ERROR_CODE_NO_USER,
1369 SERV_PORT,
1370 tftpfs_ipv4_loopback,
1371 true
1372 );
1373 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
1374
1375 tftp_initialize_net_config( &config );
1376 config.retransmissions = retransmissions;
1377 config.server_port = server_port;
1378 config.timeout = timeout;
1379 config.first_timeout = first_timeout;
1380 config.options.block_size = block_size;
1381 config.options.window_size = window_size;
1382
1383 bytes_read = rdwt_tftp_client_file(
1384 tftpfs_ipv4_loopback,
1385 tftpfs_file,
1386 true,
1387 -1,
1388 &config,
1389 &ctx->tftp_handle
1390 );
1391
1392
1393
1394
1395
1396
1397 T_eq_sz( bytes_read, 0 );
1398 T_eq_int( errno, EIO );
1399 T_no_more_interactions();
1400 }
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414 T_TEST_CASE_FIXTURE( client_write_to_file_opened_for_reading, &fixture_rfc1350 )
1415 {
1416 tftp_test_context *ctx = T_fixture_context();
1417 int res = 0;
1418 const char options[] =
1419 TFTP_OPTION_BLKSIZE "\0"
1420 RTEMS_XSTRING( TFTP_DEFAULT_BLOCK_SIZE ) "\0"
1421 TFTP_OPTION_WINDOWSIZE"\0"
1422 RTEMS_XSTRING( TFTP_DEFAULT_WINDOW_SIZE );
1423
1424
1425 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
1426 _Tftp_Add_interaction_send_rrq(
1427 TFTP_FIRST_FD,
1428 tftpfs_file,
1429 TFTP_STD_PORT,
1430 tftpfs_ipv4_loopback,
1431 TFTP_DEFAULT_BLOCK_SIZE,
1432 TFTP_DEFAULT_WINDOW_SIZE,
1433 true
1434 );
1435 _Tftp_Add_interaction_recv_oack(
1436 TFTP_FIRST_FD,
1437 FIRST_TIMEOUT_MILLISECONDS,
1438 SERV_PORT,
1439 tftpfs_ipv4_loopback,
1440 options,
1441 sizeof( options ),
1442 true
1443 );
1444
1445 _Tftp_Add_interaction_send_error(
1446 TFTP_FIRST_FD,
1447 TFTP_ERROR_CODE_NO_USER,
1448 SERV_PORT,
1449 tftpfs_ipv4_loopback,
1450 true
1451 );
1452 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
1453
1454 res = tftp_open(
1455 tftpfs_ipv4_loopback,
1456 tftpfs_file,
1457 true,
1458 NULL,
1459 &ctx->tftp_handle
1460 );
1461 T_eq_int( res, 0 );
1462 T_assert_not_null( ctx->tftp_handle );
1463
1464 res = (int) tftp_write( ctx->tftp_handle, &res, 1 );
1465 T_eq_int( res, -EIO );
1466
1467 res = tftp_close( ctx->tftp_handle );
1468 ctx->tftp_handle = NULL;
1469 T_eq_int( res, 0 );
1470 T_no_more_interactions();
1471 }
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483 T_TEST_CASE_FIXTURE( client_read_to_file_opened_for_writing, &fixture_rfc1350 )
1484 {
1485 tftp_test_context *ctx = T_fixture_context();
1486 int res = 0;
1487 uint16_t block_num = 1;
1488 size_t pos_in_file = 0;
1489 const char options[] =
1490 TFTP_OPTION_BLKSIZE "\0"
1491 RTEMS_XSTRING( TFTP_DEFAULT_BLOCK_SIZE ) "\0"
1492 TFTP_OPTION_WINDOWSIZE"\0"
1493 RTEMS_XSTRING( TFTP_DEFAULT_WINDOW_SIZE );
1494
1495
1496 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
1497 _Tftp_Add_interaction_send_wrq(
1498 TFTP_FIRST_FD,
1499 tftpfs_file,
1500 TFTP_STD_PORT,
1501 tftpfs_ipv4_loopback,
1502 TFTP_DEFAULT_BLOCK_SIZE,
1503 TFTP_DEFAULT_WINDOW_SIZE,
1504 true
1505 );
1506 _Tftp_Add_interaction_recv_oack(
1507 TFTP_FIRST_FD,
1508 FIRST_TIMEOUT_MILLISECONDS,
1509 SERV_PORT,
1510 tftpfs_ipv4_loopback,
1511 options,
1512 sizeof( options ),
1513 true
1514 );
1515 _Tftp_Add_interaction_send_data(
1516 TFTP_FIRST_FD,
1517 block_num,
1518 pos_in_file,
1519 0,
1520 get_file_content,
1521 SERV_PORT,
1522 tftpfs_ipv4_loopback,
1523 true
1524 );
1525 pos_in_file += 0;
1526 _Tftp_Add_interaction_recv_ack(
1527 TFTP_FIRST_FD,
1528 FIRST_TIMEOUT_MILLISECONDS,
1529 SERV_PORT,
1530 tftpfs_ipv4_loopback,
1531 block_num++,
1532 true
1533 );
1534 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
1535
1536 res = tftp_open(
1537 tftpfs_ipv4_loopback,
1538 tftpfs_file,
1539 false,
1540 NULL,
1541 &ctx->tftp_handle
1542 );
1543 T_eq_int( res, 0 );
1544 T_assert_not_null( ctx->tftp_handle );
1545
1546 res = (int) tftp_read( ctx->tftp_handle, &res, 1 );
1547 T_eq_int( res, -EIO );
1548
1549 res = tftp_close( ctx->tftp_handle );
1550 ctx->tftp_handle = NULL;
1551 T_eq_int( res, 0 );
1552 T_no_more_interactions();
1553 }
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571 T_TEST_CASE_FIXTURE( client_write_simple_file, &fixture_default_options )
1572 {
1573 tftp_test_context *ctx = T_fixture_context();
1574 tftp_net_config config;
1575 int bytes_written;
1576 uint16_t block_num = 1;
1577 size_t pos_in_file = 0;
1578 const char options[] =
1579 TFTP_OPTION_BLKSIZE "\0"
1580 RTEMS_XSTRING( TFTP_DEFAULT_BLOCK_SIZE ) "\0"
1581 TFTP_OPTION_WINDOWSIZE "\0"
1582 RTEMS_XSTRING( TFTP_DEFAULT_WINDOW_SIZE );
1583
1584
1585 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
1586 _Tftp_Add_interaction_send_wrq(
1587 TFTP_FIRST_FD,
1588 tftpfs_file,
1589 TFTP_STD_PORT,
1590 tftpfs_server0_ipv4,
1591 TFTP_DEFAULT_BLOCK_SIZE,
1592 TFTP_DEFAULT_WINDOW_SIZE,
1593 true
1594 );
1595 _Tftp_Add_interaction_recv_oack(
1596 TFTP_FIRST_FD,
1597 FIRST_TIMEOUT_MILLISECONDS,
1598 SERV_PORT,
1599 tftpfs_server0_ipv4,
1600 options,
1601 sizeof( options ),
1602 true
1603 );
1604 _Tftp_Add_interaction_send_data(
1605 TFTP_FIRST_FD,
1606 block_num++,
1607 pos_in_file,
1608 TFTP_DEFAULT_BLOCK_SIZE,
1609 get_file_content,
1610 SERV_PORT,
1611 tftpfs_server0_ipv4,
1612 true
1613 );
1614 pos_in_file += TFTP_DEFAULT_BLOCK_SIZE;
1615 _Tftp_Add_interaction_recv_nothing(
1616 TFTP_FIRST_FD,
1617 DO_NOT_WAIT_FOR_ANY_TIMEOUT
1618 );
1619 _Tftp_Add_interaction_send_data(
1620 TFTP_FIRST_FD,
1621 block_num++,
1622 pos_in_file,
1623 TFTP_DEFAULT_BLOCK_SIZE,
1624 get_file_content,
1625 SERV_PORT,
1626 tftpfs_server0_ipv4,
1627 true
1628 );
1629 pos_in_file += TFTP_DEFAULT_BLOCK_SIZE;
1630 _Tftp_Add_interaction_recv_nothing(
1631 TFTP_FIRST_FD,
1632 DO_NOT_WAIT_FOR_ANY_TIMEOUT
1633 );
1634 _Tftp_Add_interaction_send_data(
1635 TFTP_FIRST_FD,
1636 block_num,
1637 pos_in_file,
1638 TFTP_DEFAULT_BLOCK_SIZE / 2,
1639 get_file_content,
1640 SERV_PORT,
1641 tftpfs_server0_ipv4,
1642 true
1643 );
1644 pos_in_file += TFTP_DEFAULT_BLOCK_SIZE / 2;
1645 _Tftp_Add_interaction_recv_ack(
1646 TFTP_FIRST_FD,
1647 FIRST_TIMEOUT_MILLISECONDS,
1648 SERV_PORT,
1649 tftpfs_server0_ipv4,
1650 block_num++,
1651 true
1652 );
1653 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
1654
1655 tftp_initialize_net_config( &config );
1656 bytes_written = rdwt_tftp_client_file(
1657 tftpfs_server0_name,
1658 tftpfs_file,
1659 false,
1660 pos_in_file,
1661 &config,
1662 &ctx->tftp_handle
1663 );
1664 T_eq_sz( bytes_written, pos_in_file );
1665 T_eq_int( errno, 0 );
1666 T_no_more_interactions();
1667 }
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686 T_TEST_CASE_FIXTURE( read_simple_file, &fixture_rfc1350 )
1687 {
1688 tftp_test_context *ctx = T_fixture_context();
1689 int bytes_read;
1690 uint16_t block_num = 1;
1691 size_t pos_in_file = 0;
1692
1693
1694 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
1695 _Tftp_Add_interaction_send_rrq(
1696 TFTP_FIRST_FD,
1697 tftpfs_file,
1698 TFTP_STD_PORT,
1699 tftpfs_ipv4_loopback,
1700 NO_BLOCK_SIZE_OPTION,
1701 NO_WINDOW_SIZE_OPTION,
1702 true
1703 );
1704 _Tftp_Add_interaction_recv_data(
1705 TFTP_FIRST_FD,
1706 FIRST_TIMEOUT_MILLISECONDS,
1707 SERV_PORT,
1708 tftpfs_ipv4_loopback,
1709 block_num,
1710 pos_in_file,
1711 TFTP_RFC1350_BLOCK_SIZE,
1712 get_file_content,
1713 true
1714 );
1715 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
1716 _Tftp_Add_interaction_send_ack(
1717 TFTP_FIRST_FD,
1718 block_num++,
1719 SERV_PORT,
1720 tftpfs_ipv4_loopback,
1721 true
1722 );
1723 _Tftp_Add_interaction_recv_data(
1724 TFTP_FIRST_FD,
1725 FIRST_TIMEOUT_MILLISECONDS,
1726 SERV_PORT,
1727 tftpfs_ipv4_loopback,
1728 block_num,
1729 pos_in_file,
1730 TFTP_RFC1350_BLOCK_SIZE,
1731 get_file_content,
1732 true
1733 );
1734 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
1735 _Tftp_Add_interaction_send_ack(
1736 TFTP_FIRST_FD,
1737 block_num++,
1738 SERV_PORT,
1739 tftpfs_ipv4_loopback,
1740 true
1741 );
1742 _Tftp_Add_interaction_recv_data(
1743 TFTP_FIRST_FD,
1744 FIRST_TIMEOUT_MILLISECONDS,
1745 SERV_PORT,
1746 tftpfs_ipv4_loopback,
1747 block_num,
1748 pos_in_file,
1749 TFTP_RFC1350_BLOCK_SIZE / 2,
1750 get_file_content,
1751 true
1752 );
1753 pos_in_file += TFTP_RFC1350_BLOCK_SIZE / 2;
1754 _Tftp_Add_interaction_send_ack(
1755 TFTP_FIRST_FD,
1756 block_num++,
1757 SERV_PORT,
1758 tftpfs_ipv4_loopback,
1759 true
1760 );
1761 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
1762
1763 bytes_read = read_tftp_file(
1764 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
1765
1766 2 * TFTP_RFC1350_BLOCK_SIZE + TFTP_RFC1350_BLOCK_SIZE / 2,
1767 SIZE_MAX,
1768 &ctx->fd0
1769 );
1770 T_eq_int( bytes_read, pos_in_file );
1771 T_no_more_interactions();
1772 }
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785 T_TEST_CASE_FIXTURE( read_tiny_file, &fixture_rfc1350 )
1786 {
1787 tftp_test_context *ctx = T_fixture_context();
1788 int bytes_read;
1789 uint16_t block_num = 1;
1790 size_t pos_in_file = 0;
1791
1792
1793 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
1794 _Tftp_Add_interaction_send_rrq(
1795 TFTP_FIRST_FD,
1796 tftpfs_file,
1797 TFTP_STD_PORT,
1798 tftpfs_ipv4_loopback,
1799 NO_BLOCK_SIZE_OPTION,
1800 NO_WINDOW_SIZE_OPTION,
1801 true
1802 );
1803 _Tftp_Add_interaction_recv_data(
1804 TFTP_FIRST_FD,
1805 FIRST_TIMEOUT_MILLISECONDS,
1806 SERV_PORT,
1807 tftpfs_ipv4_loopback,
1808 block_num,
1809 pos_in_file,
1810 1,
1811 get_file_content,
1812 true
1813 );
1814 pos_in_file += 1;
1815 _Tftp_Add_interaction_send_ack(
1816 TFTP_FIRST_FD,
1817 block_num++,
1818 SERV_PORT,
1819 tftpfs_ipv4_loopback,
1820 true
1821 );
1822 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
1823
1824 bytes_read = read_tftp_file(
1825 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
1826 1,
1827 SIZE_MAX,
1828 &ctx->fd0
1829 );
1830 T_eq_int( bytes_read, pos_in_file );
1831 T_no_more_interactions();
1832 }
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849 T_TEST_CASE_FIXTURE( read_one_block_file, &fixture_rfc1350 )
1850 {
1851 tftp_test_context *ctx = T_fixture_context();
1852 int bytes_read;
1853 uint16_t block_num = 1;
1854 size_t pos_in_file = 0;
1855
1856
1857 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
1858 _Tftp_Add_interaction_send_rrq(
1859 TFTP_FIRST_FD,
1860 tftpfs_file,
1861 TFTP_STD_PORT,
1862 tftpfs_ipv4_loopback,
1863 NO_BLOCK_SIZE_OPTION,
1864 NO_WINDOW_SIZE_OPTION,
1865 true
1866 );
1867 _Tftp_Add_interaction_recv_data(
1868 TFTP_FIRST_FD,
1869 FIRST_TIMEOUT_MILLISECONDS,
1870 SERV_PORT,
1871 tftpfs_ipv4_loopback,
1872 block_num,
1873 pos_in_file,
1874 TFTP_RFC1350_BLOCK_SIZE,
1875 get_file_content,
1876 true
1877 );
1878 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
1879 _Tftp_Add_interaction_send_ack(
1880 TFTP_FIRST_FD,
1881 block_num++,
1882 SERV_PORT,
1883 tftpfs_ipv4_loopback,
1884 true
1885 );
1886 _Tftp_Add_interaction_recv_data(
1887 TFTP_FIRST_FD,
1888 FIRST_TIMEOUT_MILLISECONDS,
1889 SERV_PORT,
1890 tftpfs_ipv4_loopback,
1891 block_num,
1892 pos_in_file,
1893 0,
1894 get_file_content,
1895 true
1896 );
1897 _Tftp_Add_interaction_send_ack(
1898 TFTP_FIRST_FD,
1899 block_num++,
1900 SERV_PORT,
1901 tftpfs_ipv4_loopback,
1902 true
1903 );
1904 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
1905
1906 bytes_read = read_tftp_file(
1907 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
1908
1909 TFTP_RFC1350_BLOCK_SIZE / 4 * 3,
1910 SIZE_MAX,
1911 &ctx->fd0
1912 );
1913 T_eq_int( bytes_read, pos_in_file );
1914 T_no_more_interactions();
1915 }
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939 T_TEST_CASE_FIXTURE( read_file_stray_packets, &fixture_rfc1350 )
1940 {
1941 tftp_test_context *ctx = T_fixture_context();
1942 int bytes_read;
1943 uint16_t block_num = 1;
1944 size_t pos_in_file = 0;
1945
1946
1947 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
1948 _Tftp_Add_interaction_send_rrq(
1949 TFTP_FIRST_FD,
1950 tftpfs_file,
1951 TFTP_STD_PORT,
1952 tftpfs_ipv4_loopback,
1953 NO_BLOCK_SIZE_OPTION,
1954 NO_WINDOW_SIZE_OPTION,
1955 true
1956 );
1957 _Tftp_Add_interaction_recv_data(
1958 TFTP_FIRST_FD,
1959 FIRST_TIMEOUT_MILLISECONDS,
1960 SERV_PORT,
1961 tftpfs_ipv4_loopback,
1962 block_num,
1963 pos_in_file,
1964 TFTP_RFC1350_BLOCK_SIZE,
1965 get_file_content,
1966 true
1967 );
1968 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
1969 _Tftp_Add_interaction_send_ack(
1970 TFTP_FIRST_FD,
1971 block_num++,
1972 SERV_PORT,
1973 tftpfs_ipv4_loopback,
1974 true
1975 );
1976 _Tftp_Add_interaction_recv_data(
1977 TFTP_FIRST_FD,
1978 FIRST_TIMEOUT_MILLISECONDS,
1979 SERV_PORT + 1,
1980 tftpfs_ipv4_loopback,
1981 block_num,
1982 pos_in_file,
1983 TFTP_RFC1350_BLOCK_SIZE,
1984 get_file_content,
1985 true
1986 );
1987 _Tftp_Add_interaction_send_error(
1988 TFTP_FIRST_FD,
1989 TFTP_ERROR_CODE_UNKNOWN_ID,
1990 SERV_PORT + 1,
1991 tftpfs_ipv4_loopback,
1992 true
1993 );
1994 _Tftp_Add_interaction_recv_ack(
1995 TFTP_FIRST_FD,
1996 FIRST_TIMEOUT_MILLISECONDS,
1997 SERV_PORT,
1998 tftpfs_ipv4_loopback,
1999 block_num - 1,
2000 true
2001 );
2002 _Tftp_Add_interaction_send_error(
2003 TFTP_FIRST_FD,
2004 TFTP_ERROR_CODE_ILLEGAL,
2005 SERV_PORT,
2006 tftpfs_ipv4_loopback,
2007 true
2008 );
2009 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2010
2011 bytes_read = read_tftp_file(
2012 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2013
2014 TFTP_RFC1350_BLOCK_SIZE / 4 * 3,
2015 SIZE_MAX,
2016 &ctx->fd0
2017 );
2018 T_eq_int( errno, EPROTO );
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028 T_eq_int( bytes_read, TFTP_RFC1350_BLOCK_SIZE / 4 * 3 );
2029 T_no_more_interactions();
2030 }
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047 T_TEST_CASE_FIXTURE( read_one_block_file_server_error, &fixture_rfc1350 )
2048 {
2049 tftp_test_context *ctx = T_fixture_context();
2050 int bytes_read;
2051 uint16_t block_num = 1;
2052 size_t pos_in_file = 0;
2053
2054
2055 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2056 _Tftp_Add_interaction_send_rrq(
2057 TFTP_FIRST_FD,
2058 tftpfs_file,
2059 TFTP_STD_PORT,
2060 tftpfs_ipv4_loopback,
2061 NO_BLOCK_SIZE_OPTION,
2062 NO_WINDOW_SIZE_OPTION,
2063 true
2064 );
2065 _Tftp_Add_interaction_recv_data(
2066 TFTP_FIRST_FD,
2067 FIRST_TIMEOUT_MILLISECONDS,
2068 SERV_PORT,
2069 tftpfs_ipv4_loopback,
2070 block_num,
2071 pos_in_file,
2072 TFTP_RFC1350_BLOCK_SIZE,
2073 get_file_content,
2074 true
2075 );
2076 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
2077 _Tftp_Add_interaction_send_ack(
2078 TFTP_FIRST_FD,
2079 block_num++,
2080 SERV_PORT,
2081 tftpfs_ipv4_loopback,
2082 true
2083 );
2084 _Tftp_Add_interaction_recv_error(
2085 TFTP_FIRST_FD,
2086 FIRST_TIMEOUT_MILLISECONDS,
2087 SERV_PORT,
2088 tftpfs_ipv4_loopback,
2089 TFTP_ERROR_CODE_NO_ACCESS,
2090 "Cannot read more",
2091 true
2092 );
2093 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2094
2095 bytes_read = read_tftp_file(
2096 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2097
2098 TFTP_RFC1350_BLOCK_SIZE / 4 * 3,
2099 SIZE_MAX,
2100 &ctx->fd0
2101 );
2102 T_eq_int( bytes_read, TFTP_RFC1350_BLOCK_SIZE / 4 * 3 );
2103 T_eq_int( errno, EPERM );
2104 T_no_more_interactions();
2105 }
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121 T_TEST_CASE_FIXTURE( read_one_block_file_malformed_server_error, &fixture_rfc1350 )
2122 {
2123 tftp_test_context *ctx = T_fixture_context();
2124 int bytes_read;
2125 uint16_t block_num = 1;
2126 size_t pos_in_file = 0;
2127 static const uint8_t packet_malformed_error[] = {
2128 0x00, 0x05,
2129 0x00, 0x02,
2130 'n', 'o', ' ', 'a', 'c', 'c', 'e', 's', 's'
2131 };
2132
2133
2134 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2135 _Tftp_Add_interaction_send_rrq(
2136 TFTP_FIRST_FD,
2137 tftpfs_file,
2138 TFTP_STD_PORT,
2139 tftpfs_ipv4_loopback,
2140 NO_BLOCK_SIZE_OPTION,
2141 NO_WINDOW_SIZE_OPTION,
2142 true
2143 );
2144 _Tftp_Add_interaction_recv_data(
2145 TFTP_FIRST_FD,
2146 FIRST_TIMEOUT_MILLISECONDS,
2147 SERV_PORT,
2148 tftpfs_ipv4_loopback,
2149 block_num,
2150 pos_in_file,
2151 TFTP_RFC1350_BLOCK_SIZE,
2152 get_file_content,
2153 true
2154 );
2155 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
2156 _Tftp_Add_interaction_send_ack(
2157 TFTP_FIRST_FD,
2158 block_num++,
2159 SERV_PORT,
2160 tftpfs_ipv4_loopback,
2161 true
2162 );
2163 _Tftp_Add_interaction_recv_raw(
2164 TFTP_FIRST_FD,
2165 FIRST_TIMEOUT_MILLISECONDS,
2166 SERV_PORT,
2167 tftpfs_ipv4_loopback,
2168 sizeof( packet_malformed_error ),
2169 packet_malformed_error,
2170 true
2171 );
2172 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2173
2174 bytes_read = read_tftp_file(
2175 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2176
2177 TFTP_RFC1350_BLOCK_SIZE / 4 * 3,
2178 SIZE_MAX,
2179 &ctx->fd0
2180 );
2181 T_eq_int( bytes_read, TFTP_RFC1350_BLOCK_SIZE / 4 * 3 );
2182 T_eq_int( errno, EPERM );
2183 T_no_more_interactions();
2184 }
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201 T_TEST_CASE_FIXTURE( read_one_block_close_file, &fixture_rfc1350 )
2202 {
2203 tftp_test_context *ctx = T_fixture_context();
2204 int bytes_read;
2205 uint16_t block_num = 1;
2206 size_t pos_in_file = 0;
2207
2208
2209 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2210 _Tftp_Add_interaction_send_rrq(
2211 TFTP_FIRST_FD,
2212 tftpfs_file,
2213 TFTP_STD_PORT,
2214 tftpfs_ipv4_loopback,
2215 NO_BLOCK_SIZE_OPTION,
2216 NO_WINDOW_SIZE_OPTION,
2217 true
2218 );
2219 _Tftp_Add_interaction_recv_data(
2220 TFTP_FIRST_FD,
2221 FIRST_TIMEOUT_MILLISECONDS,
2222 SERV_PORT,
2223 tftpfs_ipv4_loopback,
2224 block_num,
2225 pos_in_file,
2226 TFTP_RFC1350_BLOCK_SIZE,
2227 get_file_content,
2228 true
2229 );
2230
2231 _Tftp_Add_interaction_send_error(
2232 TFTP_FIRST_FD,
2233 TFTP_ERROR_CODE_NO_USER,
2234 SERV_PORT,
2235 tftpfs_ipv4_loopback,
2236 true
2237 );
2238 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2239
2240 bytes_read = read_tftp_file(
2241 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2242 TFTP_RFC1350_BLOCK_SIZE / 4,
2243 TFTP_RFC1350_BLOCK_SIZE / 2,
2244 &ctx->fd0
2245 );
2246 T_eq_int( bytes_read, TFTP_RFC1350_BLOCK_SIZE / 2 );
2247 T_no_more_interactions();
2248 }
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263 T_TEST_CASE_FIXTURE( read_close_file_immediately, &fixture_rfc1350 )
2264 {
2265 tftp_test_context *ctx = T_fixture_context();
2266 int bytes_read;
2267 uint16_t block_num = 1;
2268 size_t pos_in_file = 0;
2269
2270
2271 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2272 _Tftp_Add_interaction_send_rrq(
2273 TFTP_FIRST_FD,
2274 tftpfs_file,
2275 TFTP_STD_PORT,
2276 tftpfs_ipv4_loopback,
2277 NO_BLOCK_SIZE_OPTION,
2278 NO_WINDOW_SIZE_OPTION,
2279 true
2280 );
2281 _Tftp_Add_interaction_recv_data(
2282 TFTP_FIRST_FD,
2283 FIRST_TIMEOUT_MILLISECONDS,
2284 SERV_PORT,
2285 tftpfs_ipv4_loopback,
2286 block_num,
2287 pos_in_file,
2288 TFTP_RFC1350_BLOCK_SIZE,
2289 get_file_content,
2290 true
2291 );
2292
2293 _Tftp_Add_interaction_send_error(
2294 TFTP_FIRST_FD,
2295 TFTP_ERROR_CODE_NO_USER,
2296 SERV_PORT,
2297 tftpfs_ipv4_loopback,
2298 true
2299 );
2300 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2301
2302 bytes_read = read_tftp_file(
2303 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2304 TFTP_RFC1350_BLOCK_SIZE / 4,
2305 0,
2306 &ctx->fd0
2307 );
2308 T_eq_int( bytes_read, 0 );
2309 T_no_more_interactions();
2310 }
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326 T_TEST_CASE_FIXTURE( read_empty_file, &fixture_rfc1350 )
2327 {
2328 tftp_test_context *ctx = T_fixture_context();
2329 int bytes_read;
2330 uint16_t block_num = 1;
2331 size_t pos_in_file = 0;
2332
2333
2334 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2335 _Tftp_Add_interaction_send_rrq(
2336 TFTP_FIRST_FD,
2337 tftpfs_file,
2338 TFTP_STD_PORT,
2339 tftpfs_server0_ipv4,
2340 NO_BLOCK_SIZE_OPTION,
2341 NO_WINDOW_SIZE_OPTION,
2342 true
2343 );
2344 _Tftp_Add_interaction_recv_data(
2345 TFTP_FIRST_FD,
2346 FIRST_TIMEOUT_MILLISECONDS,
2347 SERV_PORT,
2348 tftpfs_server0_ipv4,
2349 block_num,
2350 pos_in_file,
2351 0,
2352 get_file_content,
2353 true
2354 );
2355 _Tftp_Add_interaction_send_ack(
2356 TFTP_FIRST_FD,
2357 block_num++,
2358 SERV_PORT,
2359 tftpfs_server0_ipv4,
2360 true
2361 );
2362 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2363
2364 bytes_read = read_tftp_file(
2365 create_tftpfs_path( tftpfs_server0_name, tftpfs_file ),
2366
2367 TFTP_RFC1350_BLOCK_SIZE,
2368 SIZE_MAX,
2369 &ctx->fd0
2370 );
2371 T_assert_eq_int( bytes_read, pos_in_file );
2372 T_no_more_interactions();
2373 }
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391 T_TEST_CASE_FIXTURE( read_empty_file_looing_rrq, &fixture_rfc1350 )
2392 {
2393 tftp_test_context *ctx = T_fixture_context();
2394 int bytes_read;
2395 uint16_t block_num = 1;
2396 size_t pos_in_file = 0;
2397
2398
2399 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2400 _Tftp_Add_interaction_send_rrq(
2401 TFTP_FIRST_FD,
2402 tftpfs_file,
2403 TFTP_STD_PORT,
2404 tftpfs_server0_ipv4,
2405 NO_BLOCK_SIZE_OPTION,
2406 NO_WINDOW_SIZE_OPTION,
2407 true
2408 );
2409 _Tftp_Add_interaction_recv_nothing(
2410 TFTP_FIRST_FD,
2411 FIRST_TIMEOUT_MILLISECONDS
2412 );
2413 _Tftp_Add_interaction_send_rrq(
2414 TFTP_FIRST_FD,
2415 tftpfs_file,
2416 TFTP_STD_PORT,
2417 tftpfs_server0_ipv4,
2418 NO_BLOCK_SIZE_OPTION,
2419 NO_WINDOW_SIZE_OPTION,
2420 true
2421 );
2422 _Tftp_Add_interaction_recv_nothing(
2423 TFTP_FIRST_FD,
2424 TIMEOUT_MILLISECONDS
2425 );
2426 _Tftp_Add_interaction_send_rrq(
2427 TFTP_FIRST_FD,
2428 tftpfs_file,
2429 TFTP_STD_PORT,
2430 tftpfs_server0_ipv4,
2431 NO_BLOCK_SIZE_OPTION,
2432 NO_WINDOW_SIZE_OPTION,
2433 true
2434 );
2435 _Tftp_Add_interaction_recv_data(
2436 TFTP_FIRST_FD,
2437 TIMEOUT_MILLISECONDS,
2438 SERV_PORT,
2439 tftpfs_server0_ipv4,
2440 block_num,
2441 pos_in_file,
2442 0,
2443 get_file_content,
2444 true
2445 );
2446 _Tftp_Add_interaction_send_ack(
2447 TFTP_FIRST_FD,
2448 block_num++,
2449 SERV_PORT,
2450 tftpfs_server0_ipv4,
2451 true
2452 );
2453 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2454
2455 bytes_read = read_tftp_file(
2456 create_tftpfs_path( tftpfs_server0_name, tftpfs_file ),
2457
2458 TFTP_RFC1350_BLOCK_SIZE,
2459 SIZE_MAX,
2460 &ctx->fd0
2461 );
2462 T_assert_eq_int( bytes_read, pos_in_file );
2463 T_no_more_interactions();
2464 }
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482 T_TEST_CASE_FIXTURE( read_small_file_lost_packets, &fixture_rfc1350 )
2483 {
2484 tftp_test_context *ctx = T_fixture_context();
2485 int bytes_read;
2486 uint16_t block_num = 1;
2487 size_t pos_in_file = 0;
2488
2489
2490 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2491 _Tftp_Add_interaction_send_rrq(
2492 TFTP_FIRST_FD,
2493 tftpfs_file,
2494 TFTP_STD_PORT,
2495 tftpfs_ipv4_loopback,
2496 NO_BLOCK_SIZE_OPTION,
2497 NO_WINDOW_SIZE_OPTION,
2498 true
2499 );
2500 _Tftp_Add_interaction_recv_data(
2501 TFTP_FIRST_FD,
2502 FIRST_TIMEOUT_MILLISECONDS,
2503 SERV_PORT,
2504 tftpfs_ipv4_loopback,
2505 block_num,
2506 pos_in_file,
2507 TFTP_RFC1350_BLOCK_SIZE,
2508 get_file_content,
2509 true
2510 );
2511 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
2512 _Tftp_Add_interaction_send_ack(
2513 TFTP_FIRST_FD,
2514 block_num,
2515 SERV_PORT,
2516 tftpfs_ipv4_loopback,
2517 true
2518 );
2519 _Tftp_Add_interaction_recv_nothing(
2520 TFTP_FIRST_FD,
2521 FIRST_TIMEOUT_MILLISECONDS
2522 );
2523 _Tftp_Add_interaction_send_ack(
2524 TFTP_FIRST_FD,
2525 block_num,
2526 SERV_PORT,
2527 tftpfs_ipv4_loopback,
2528 true
2529 );
2530 _Tftp_Add_interaction_recv_nothing(
2531 TFTP_FIRST_FD,
2532 TIMEOUT_MILLISECONDS
2533 );
2534 _Tftp_Add_interaction_send_ack(
2535 TFTP_FIRST_FD,
2536 block_num++,
2537 SERV_PORT,
2538 tftpfs_ipv4_loopback,
2539 true
2540 );
2541 _Tftp_Add_interaction_recv_data(
2542 TFTP_FIRST_FD,
2543 TIMEOUT_MILLISECONDS,
2544 SERV_PORT,
2545 tftpfs_ipv4_loopback,
2546 block_num,
2547 pos_in_file,
2548 TFTP_RFC1350_BLOCK_SIZE / 2,
2549 get_file_content,
2550 true
2551 );
2552 pos_in_file += TFTP_RFC1350_BLOCK_SIZE / 2;
2553 _Tftp_Add_interaction_send_ack(
2554 TFTP_FIRST_FD,
2555 block_num++,
2556 SERV_PORT,
2557 tftpfs_ipv4_loopback,
2558 true
2559 );
2560 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2561
2562 bytes_read = read_tftp_file(
2563 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2564 17,
2565 SIZE_MAX,
2566 &ctx->fd0
2567 );
2568 T_eq_int( bytes_read, pos_in_file );
2569 T_no_more_interactions();
2570 }
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586 T_TEST_CASE_FIXTURE( read_small_file_malformed_packet_1, &fixture_rfc1350 )
2587 {
2588 tftp_test_context *ctx = T_fixture_context();
2589 int bytes_read;
2590 uint16_t block_num = 1;
2591 size_t pos_in_file = 0;
2592 static const uint8_t packet_illegal_opcode_1[] = { 0x00, 0xFF, 0x00, 0x00 };
2593
2594
2595 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2596 _Tftp_Add_interaction_send_rrq(
2597 TFTP_FIRST_FD,
2598 tftpfs_file,
2599 TFTP_STD_PORT,
2600 tftpfs_ipv4_loopback,
2601 NO_BLOCK_SIZE_OPTION,
2602 NO_WINDOW_SIZE_OPTION,
2603 true
2604 );
2605 _Tftp_Add_interaction_recv_data(
2606 TFTP_FIRST_FD,
2607 FIRST_TIMEOUT_MILLISECONDS,
2608 SERV_PORT,
2609 tftpfs_ipv4_loopback,
2610 block_num,
2611 pos_in_file,
2612 TFTP_RFC1350_BLOCK_SIZE,
2613 get_file_content,
2614 true
2615 );
2616 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
2617 _Tftp_Add_interaction_send_ack(
2618 TFTP_FIRST_FD,
2619 block_num,
2620 SERV_PORT,
2621 tftpfs_ipv4_loopback,
2622 true
2623 );
2624 _Tftp_Add_interaction_recv_raw(
2625 TFTP_FIRST_FD,
2626 FIRST_TIMEOUT_MILLISECONDS,
2627 SERV_PORT,
2628 tftpfs_ipv4_loopback,
2629 sizeof( packet_illegal_opcode_1 ),
2630 packet_illegal_opcode_1,
2631 true
2632 );
2633 _Tftp_Add_interaction_send_error(
2634 TFTP_FIRST_FD,
2635 TFTP_ERROR_CODE_ILLEGAL,
2636 SERV_PORT,
2637 tftpfs_ipv4_loopback,
2638 true
2639 );
2640 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2641
2642 bytes_read = read_tftp_file(
2643 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2644 TFTP_RFC1350_BLOCK_SIZE / 4,
2645 SIZE_MAX,
2646 &ctx->fd0
2647 );
2648 T_eq_int( bytes_read, pos_in_file );
2649 T_eq_int( errno, EPROTO );
2650 T_no_more_interactions();
2651 }
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667 T_TEST_CASE_FIXTURE( read_small_file_malformed_packet_2, &fixture_rfc1350 )
2668 {
2669 tftp_test_context *ctx = T_fixture_context();
2670 int bytes_read;
2671 uint16_t block_num = 1;
2672 size_t pos_in_file = 0;
2673 static const uint8_t packet_illegal_opcode_2[] = { 0x03, 0x00, 0x00, 0x01 };
2674
2675
2676 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2677 _Tftp_Add_interaction_send_rrq(
2678 TFTP_FIRST_FD,
2679 tftpfs_file,
2680 TFTP_STD_PORT,
2681 tftpfs_ipv4_loopback,
2682 NO_BLOCK_SIZE_OPTION,
2683 NO_WINDOW_SIZE_OPTION,
2684 true
2685 );
2686 _Tftp_Add_interaction_recv_data(
2687 TFTP_FIRST_FD,
2688 FIRST_TIMEOUT_MILLISECONDS,
2689 SERV_PORT,
2690 tftpfs_ipv4_loopback,
2691 block_num,
2692 pos_in_file,
2693 TFTP_RFC1350_BLOCK_SIZE,
2694 get_file_content,
2695 true
2696 );
2697 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
2698 _Tftp_Add_interaction_send_ack(
2699 TFTP_FIRST_FD,
2700 block_num,
2701 SERV_PORT,
2702 tftpfs_ipv4_loopback,
2703 true
2704 );
2705 _Tftp_Add_interaction_recv_raw(
2706 TFTP_FIRST_FD,
2707 FIRST_TIMEOUT_MILLISECONDS,
2708 SERV_PORT,
2709 tftpfs_ipv4_loopback,
2710 sizeof( packet_illegal_opcode_2 ),
2711 packet_illegal_opcode_2,
2712 true
2713 );
2714 _Tftp_Add_interaction_send_error(
2715 TFTP_FIRST_FD,
2716 TFTP_ERROR_CODE_ILLEGAL,
2717 SERV_PORT,
2718 tftpfs_ipv4_loopback,
2719 true
2720 );
2721 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2722
2723 bytes_read = read_tftp_file(
2724 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2725 TFTP_RFC1350_BLOCK_SIZE / 4,
2726 SIZE_MAX,
2727 &ctx->fd0
2728 );
2729 T_eq_int( bytes_read, pos_in_file );
2730 T_eq_int( errno, EPROTO );
2731 T_no_more_interactions();
2732 }
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748 T_TEST_CASE_FIXTURE( read_file_malformed_ack_1, &fixture_rfc1350 )
2749 {
2750 tftp_test_context *ctx = T_fixture_context();
2751 int bytes_read;
2752 size_t pos_in_file = 0;
2753 static const uint8_t packet_too_short_1[] = { 0x03 };
2754
2755
2756 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2757 _Tftp_Add_interaction_send_rrq(
2758 TFTP_FIRST_FD,
2759 tftpfs_file,
2760 TFTP_STD_PORT,
2761 tftpfs_ipv4_loopback,
2762 NO_BLOCK_SIZE_OPTION,
2763 NO_WINDOW_SIZE_OPTION,
2764 true
2765 );
2766 _Tftp_Add_interaction_recv_raw(
2767 TFTP_FIRST_FD,
2768 FIRST_TIMEOUT_MILLISECONDS,
2769 SERV_PORT,
2770 tftpfs_ipv4_loopback,
2771 sizeof( packet_too_short_1 ),
2772 packet_too_short_1,
2773 true
2774 );
2775 _Tftp_Add_interaction_send_error(
2776 TFTP_FIRST_FD,
2777 TFTP_ERROR_CODE_ILLEGAL,
2778 SERV_PORT,
2779 tftpfs_ipv4_loopback,
2780 true
2781 );
2782 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2783
2784 bytes_read = read_tftp_file(
2785 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2786 TFTP_RFC1350_BLOCK_SIZE / 4,
2787 SIZE_MAX,
2788 &ctx->fd0
2789 );
2790 T_eq_int( bytes_read, pos_in_file );
2791 T_eq_int( errno, EPROTO );
2792 T_no_more_interactions();
2793 }
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809 T_TEST_CASE_FIXTURE( read_file_malformed_ack_2, &fixture_rfc1350 )
2810 {
2811 tftp_test_context *ctx = T_fixture_context();
2812 int bytes_read;
2813 size_t pos_in_file = 0;
2814 static const uint8_t packet_too_short_2[] = { 0x00, 0x03 };
2815
2816
2817 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2818 _Tftp_Add_interaction_send_rrq(
2819 TFTP_FIRST_FD,
2820 tftpfs_file,
2821 TFTP_STD_PORT,
2822 tftpfs_ipv4_loopback,
2823 NO_BLOCK_SIZE_OPTION,
2824 NO_WINDOW_SIZE_OPTION,
2825 true
2826 );
2827 _Tftp_Add_interaction_recv_raw(
2828 TFTP_FIRST_FD,
2829 FIRST_TIMEOUT_MILLISECONDS,
2830 SERV_PORT,
2831 tftpfs_ipv4_loopback,
2832 sizeof( packet_too_short_2 ),
2833 packet_too_short_2,
2834 true
2835 );
2836 _Tftp_Add_interaction_send_error(
2837 TFTP_FIRST_FD,
2838 TFTP_ERROR_CODE_ILLEGAL,
2839 SERV_PORT,
2840 tftpfs_ipv4_loopback,
2841 true
2842 );
2843 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2844
2845 bytes_read = read_tftp_file(
2846 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2847 TFTP_RFC1350_BLOCK_SIZE / 4,
2848 SIZE_MAX,
2849 &ctx->fd0
2850 );
2851 T_eq_int( bytes_read, pos_in_file );
2852 T_eq_int( errno, EPROTO );
2853 T_no_more_interactions();
2854 }
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870 T_TEST_CASE_FIXTURE( read_file_malformed_ack_3, &fixture_rfc1350 )
2871 {
2872 tftp_test_context *ctx = T_fixture_context();
2873 int bytes_read;
2874 size_t pos_in_file = 0;
2875 static const uint8_t packet_too_short_3[] = { 0x00, 0x03, 0x00 };
2876
2877
2878 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2879 _Tftp_Add_interaction_send_rrq(
2880 TFTP_FIRST_FD,
2881 tftpfs_file,
2882 TFTP_STD_PORT,
2883 tftpfs_ipv4_loopback,
2884 NO_BLOCK_SIZE_OPTION,
2885 NO_WINDOW_SIZE_OPTION,
2886 true
2887 );
2888 _Tftp_Add_interaction_recv_raw(
2889 TFTP_FIRST_FD,
2890 FIRST_TIMEOUT_MILLISECONDS,
2891 SERV_PORT,
2892 tftpfs_ipv4_loopback,
2893 sizeof( packet_too_short_3 ),
2894 packet_too_short_3,
2895 true
2896 );
2897 _Tftp_Add_interaction_send_error(
2898 TFTP_FIRST_FD,
2899 TFTP_ERROR_CODE_ILLEGAL,
2900 SERV_PORT,
2901 tftpfs_ipv4_loopback,
2902 true
2903 );
2904 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2905
2906 bytes_read = read_tftp_file(
2907 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2908 TFTP_RFC1350_BLOCK_SIZE / 4,
2909 SIZE_MAX,
2910 &ctx->fd0
2911 );
2912 T_eq_int( bytes_read, pos_in_file );
2913 T_eq_int( errno, EPROTO );
2914 T_no_more_interactions();
2915 }
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931 T_TEST_CASE_FIXTURE( read_file_block_number_0, &fixture_rfc1350 )
2932 {
2933 tftp_test_context *ctx = T_fixture_context();
2934 int bytes_read;
2935 size_t pos_in_file = 0;
2936
2937
2938 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
2939 _Tftp_Add_interaction_send_rrq(
2940 TFTP_FIRST_FD,
2941 tftpfs_file,
2942 TFTP_STD_PORT,
2943 tftpfs_ipv4_loopback,
2944 NO_BLOCK_SIZE_OPTION,
2945 NO_WINDOW_SIZE_OPTION,
2946 true
2947 );
2948 _Tftp_Add_interaction_recv_data(
2949 TFTP_FIRST_FD,
2950 FIRST_TIMEOUT_MILLISECONDS,
2951 SERV_PORT,
2952 tftpfs_ipv4_loopback,
2953 0,
2954 pos_in_file,
2955 TFTP_RFC1350_BLOCK_SIZE,
2956 get_file_content,
2957 true
2958 );
2959 _Tftp_Add_interaction_send_error(
2960 TFTP_FIRST_FD,
2961 TFTP_ERROR_CODE_ILLEGAL,
2962 SERV_PORT,
2963 tftpfs_ipv4_loopback,
2964 true
2965 );
2966 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
2967
2968 bytes_read = read_tftp_file(
2969 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
2970 TFTP_RFC1350_BLOCK_SIZE / 4,
2971 SIZE_MAX,
2972 &ctx->fd0
2973 );
2974 T_eq_int( bytes_read, pos_in_file );
2975 T_eq_int( errno, EPROTO );
2976 T_no_more_interactions();
2977 }
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993 T_TEST_CASE_FIXTURE( read_file_illegal_opcode_1, &fixture_rfc1350 )
2994 {
2995 tftp_test_context *ctx = T_fixture_context();
2996 int bytes_read;
2997 size_t pos_in_file = 0;
2998 static const uint8_t packet_illegal_opcode_1[] = { 0x00, 0xFF, 0x00, 0x00 };
2999
3000
3001 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3002 _Tftp_Add_interaction_send_rrq(
3003 TFTP_FIRST_FD,
3004 tftpfs_file,
3005 TFTP_STD_PORT,
3006 tftpfs_ipv4_loopback,
3007 NO_BLOCK_SIZE_OPTION,
3008 NO_WINDOW_SIZE_OPTION,
3009 true
3010 );
3011 _Tftp_Add_interaction_recv_raw(
3012 TFTP_FIRST_FD,
3013 FIRST_TIMEOUT_MILLISECONDS,
3014 SERV_PORT,
3015 tftpfs_ipv4_loopback,
3016 sizeof( packet_illegal_opcode_1 ),
3017 packet_illegal_opcode_1,
3018 true
3019 );
3020 _Tftp_Add_interaction_send_error(
3021 TFTP_FIRST_FD,
3022 TFTP_ERROR_CODE_ILLEGAL,
3023 SERV_PORT,
3024 tftpfs_ipv4_loopback,
3025 true
3026 );
3027 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3028
3029 bytes_read = read_tftp_file(
3030 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
3031 TFTP_RFC1350_BLOCK_SIZE / 4,
3032 SIZE_MAX,
3033 &ctx->fd0
3034 );
3035 T_eq_int( bytes_read, pos_in_file );
3036 T_eq_int( errno, EPROTO );
3037 T_no_more_interactions();
3038 }
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064 T_TEST_CASE_FIXTURE( read_two_block_file_wrong_block_numbers, &fixture_rfc1350 )
3065 {
3066 tftp_test_context *ctx = T_fixture_context();
3067 int bytes_read;
3068 uint16_t block_num = 1;
3069 size_t pos_in_file = 0;
3070
3071
3072 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3073 _Tftp_Add_interaction_send_rrq(
3074 TFTP_FIRST_FD,
3075 tftpfs_file,
3076 TFTP_STD_PORT,
3077 tftpfs_ipv4_loopback,
3078 NO_BLOCK_SIZE_OPTION,
3079 NO_WINDOW_SIZE_OPTION,
3080 true
3081 );
3082 _Tftp_Add_interaction_recv_data(
3083 TFTP_FIRST_FD,
3084 FIRST_TIMEOUT_MILLISECONDS,
3085 SERV_PORT,
3086 tftpfs_ipv4_loopback,
3087 block_num + 1,
3088 pos_in_file,
3089 TFTP_RFC1350_BLOCK_SIZE,
3090 get_file_content,
3091 true
3092 );
3093 _Tftp_Add_interaction_send_rrq(
3094 TFTP_FIRST_FD,
3095 tftpfs_file,
3096 TFTP_STD_PORT,
3097 tftpfs_ipv4_loopback,
3098 NO_BLOCK_SIZE_OPTION,
3099 NO_WINDOW_SIZE_OPTION,
3100 true
3101 );
3102 _Tftp_Add_interaction_recv_data(
3103 TFTP_FIRST_FD,
3104 FIRST_TIMEOUT_MILLISECONDS,
3105 SERV_PORT,
3106 tftpfs_ipv4_loopback,
3107 block_num + 1,
3108 pos_in_file,
3109 TFTP_RFC1350_BLOCK_SIZE,
3110 get_file_content,
3111 true
3112 );
3113 _Tftp_Add_interaction_recv_data(
3114 TFTP_FIRST_FD,
3115 FIRST_TIMEOUT_MILLISECONDS,
3116 SERV_PORT,
3117 tftpfs_ipv4_loopback,
3118 block_num,
3119 pos_in_file,
3120 TFTP_RFC1350_BLOCK_SIZE,
3121 get_file_content,
3122 true
3123 );
3124 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
3125 _Tftp_Add_interaction_send_ack(
3126 TFTP_FIRST_FD,
3127 block_num++,
3128 SERV_PORT,
3129 tftpfs_ipv4_loopback,
3130 true
3131 );
3132 _Tftp_Add_interaction_recv_data(
3133 TFTP_FIRST_FD,
3134 FIRST_TIMEOUT_MILLISECONDS,
3135 SERV_PORT,
3136 tftpfs_ipv4_loopback,
3137 block_num - 1,
3138 pos_in_file,
3139 TFTP_RFC1350_BLOCK_SIZE,
3140 get_file_content,
3141 true
3142 );
3143 _Tftp_Add_interaction_send_ack(
3144 TFTP_FIRST_FD,
3145 block_num - 1,
3146 SERV_PORT,
3147 tftpfs_ipv4_loopback,
3148 true
3149 );
3150 _Tftp_Add_interaction_recv_data(
3151 TFTP_FIRST_FD,
3152 FIRST_TIMEOUT_MILLISECONDS,
3153 SERV_PORT,
3154 tftpfs_ipv4_loopback,
3155 block_num + 1,
3156 pos_in_file,
3157 TFTP_RFC1350_BLOCK_SIZE,
3158 get_file_content,
3159 true
3160 );
3161 _Tftp_Add_interaction_send_ack(
3162 TFTP_FIRST_FD,
3163 block_num - 1,
3164 SERV_PORT,
3165 tftpfs_ipv4_loopback,
3166 true
3167 );
3168 _Tftp_Add_interaction_recv_data(
3169 TFTP_FIRST_FD,
3170 FIRST_TIMEOUT_MILLISECONDS,
3171 SERV_PORT,
3172 tftpfs_ipv4_loopback,
3173 block_num + 1,
3174 pos_in_file,
3175 TFTP_RFC1350_BLOCK_SIZE,
3176 get_file_content,
3177 true
3178 );
3179 _Tftp_Add_interaction_recv_data(
3180 TFTP_FIRST_FD,
3181 FIRST_TIMEOUT_MILLISECONDS,
3182 SERV_PORT,
3183 tftpfs_ipv4_loopback,
3184 block_num,
3185 pos_in_file,
3186 TFTP_RFC1350_BLOCK_SIZE,
3187 get_file_content,
3188 true
3189 );
3190 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
3191 _Tftp_Add_interaction_send_ack(
3192 TFTP_FIRST_FD,
3193 block_num++,
3194 SERV_PORT,
3195 tftpfs_ipv4_loopback,
3196 true
3197 );
3198 _Tftp_Add_interaction_recv_data(
3199 TFTP_FIRST_FD,
3200 FIRST_TIMEOUT_MILLISECONDS,
3201 SERV_PORT,
3202 tftpfs_ipv4_loopback,
3203 block_num - 2,
3204 pos_in_file,
3205 TFTP_RFC1350_BLOCK_SIZE,
3206 get_file_content,
3207 true
3208 );
3209 _Tftp_Add_interaction_recv_data(
3210 TFTP_FIRST_FD,
3211 FIRST_TIMEOUT_MILLISECONDS,
3212 SERV_PORT,
3213 tftpfs_ipv4_loopback,
3214 block_num + 1,
3215 pos_in_file,
3216 TFTP_RFC1350_BLOCK_SIZE,
3217 get_file_content,
3218 true
3219 );
3220 _Tftp_Add_interaction_send_ack(
3221 TFTP_FIRST_FD,
3222 block_num - 1,
3223 SERV_PORT,
3224 tftpfs_ipv4_loopback,
3225 true
3226 );
3227 _Tftp_Add_interaction_recv_data(
3228 TFTP_FIRST_FD,
3229 FIRST_TIMEOUT_MILLISECONDS,
3230 SERV_PORT,
3231 tftpfs_ipv4_loopback,
3232 block_num,
3233 pos_in_file,
3234 0,
3235 get_file_content,
3236 true
3237 );
3238 _Tftp_Add_interaction_send_ack(
3239 TFTP_FIRST_FD,
3240 block_num++,
3241 SERV_PORT,
3242 tftpfs_ipv4_loopback,
3243 true
3244 );
3245 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3246
3247 bytes_read = read_tftp_file(
3248 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
3249
3250 3 * TFTP_RFC1350_BLOCK_SIZE,
3251 SIZE_MAX,
3252 &ctx->fd0
3253 );
3254 T_eq_int( bytes_read, pos_in_file );
3255 T_no_more_interactions();
3256 }
3257
3258
3259
3260
3261
3262
3263 T_TEST_CASE_FIXTURE( read_malformed_filename, &fixture_rfc1350 )
3264 {
3265 tftp_test_context *ctx = T_fixture_context();
3266 int bytes_read;
3267 char buffer[100];
3268 int len;
3269
3270 len = snprintf(
3271 buffer,
3272 sizeof( buffer ),
3273 "%s/%s",
3274 tftpfs_mount_point,
3275 tftpfs_server0_name
3276 );
3277
3278 T_quiet_gt_int( len, 0 );
3279 T_quiet_lt_int( len, (int) sizeof( buffer ) );
3280
3281 bytes_read = read_tftp_file(
3282 buffer,
3283
3284 TFTP_RFC1350_BLOCK_SIZE,
3285 SIZE_MAX,
3286 &ctx->fd0
3287 );
3288 T_assert_eq_int( bytes_read, 0 );
3289 T_assert_eq_int( errno, EINVAL );
3290 }
3291
3292
3293
3294
3295
3296
3297 T_TEST_CASE_FIXTURE( read_from_unknown_ip_address, &fixture_rfc1350 )
3298 {
3299 tftp_test_context *ctx = T_fixture_context();
3300 int bytes_read;
3301
3302 bytes_read = read_tftp_file(
3303 create_tftpfs_path( "not-existing-server-address", tftpfs_file ),
3304
3305 TFTP_RFC1350_BLOCK_SIZE,
3306 SIZE_MAX,
3307 &ctx->fd0
3308 );
3309 T_assert_eq_int( bytes_read, 0 );
3310 T_assert_eq_int( errno, ENOENT );
3311 }
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323 T_TEST_CASE_FIXTURE( read_not_existing_file, &fixture_rfc1350 )
3324 {
3325 tftp_test_context *ctx = T_fixture_context();
3326 int bytes_read;
3327
3328
3329 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3330 _Tftp_Add_interaction_send_rrq(
3331 TFTP_FIRST_FD,
3332 tftpfs_file,
3333 TFTP_STD_PORT,
3334 tftpfs_server0_ipv4,
3335 NO_BLOCK_SIZE_OPTION,
3336 NO_WINDOW_SIZE_OPTION,
3337 true
3338 );
3339 _Tftp_Add_interaction_recv_error(
3340 TFTP_FIRST_FD,
3341 FIRST_TIMEOUT_MILLISECONDS,
3342 SERV_PORT,
3343 tftpfs_server0_ipv4,
3344 TFTP_ERROR_CODE_NOT_FOUND,
3345 "No such file",
3346 true
3347 );
3348 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3349
3350 bytes_read = read_tftp_file(
3351 create_tftpfs_path( tftpfs_server0_name, tftpfs_file ),
3352
3353 TFTP_RFC1350_BLOCK_SIZE,
3354 SIZE_MAX,
3355 &ctx->fd0
3356 );
3357 T_assert_eq_int( bytes_read, 0 );
3358 T_assert_eq_int( errno, ENOENT );
3359 T_no_more_interactions();
3360 }
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378 T_TEST_CASE_FIXTURE( write_empty_file_packet_losts, &fixture_rfc1350 )
3379 {
3380 tftp_test_context *ctx = T_fixture_context();
3381 int bytes_written;
3382 uint16_t block_num = 0;
3383 size_t pos_in_file = 0;
3384
3385
3386 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3387 _Tftp_Add_interaction_send_wrq(
3388 TFTP_FIRST_FD,
3389 tftpfs_file,
3390 TFTP_STD_PORT,
3391 tftpfs_server0_ipv4,
3392 NO_BLOCK_SIZE_OPTION,
3393 NO_WINDOW_SIZE_OPTION,
3394 true
3395 );
3396 _Tftp_Add_interaction_recv_nothing(
3397 TFTP_FIRST_FD,
3398 FIRST_TIMEOUT_MILLISECONDS
3399 );
3400 _Tftp_Add_interaction_send_wrq(
3401 TFTP_FIRST_FD,
3402 tftpfs_file,
3403 TFTP_STD_PORT,
3404 tftpfs_server0_ipv4,
3405 NO_BLOCK_SIZE_OPTION,
3406 NO_WINDOW_SIZE_OPTION,
3407 true
3408 );
3409 _Tftp_Add_interaction_recv_nothing(
3410 TFTP_FIRST_FD,
3411 TIMEOUT_MILLISECONDS
3412 );
3413 _Tftp_Add_interaction_send_wrq(
3414 TFTP_FIRST_FD,
3415 tftpfs_file,
3416 TFTP_STD_PORT,
3417 tftpfs_server0_ipv4,
3418 NO_BLOCK_SIZE_OPTION,
3419 NO_WINDOW_SIZE_OPTION,
3420 true
3421 );
3422 _Tftp_Add_interaction_recv_ack(
3423 TFTP_FIRST_FD,
3424 TIMEOUT_MILLISECONDS,
3425 SERV_PORT,
3426 tftpfs_server0_ipv4,
3427 block_num++,
3428 true
3429 );
3430 _Tftp_Add_interaction_send_data(
3431 TFTP_FIRST_FD,
3432 block_num,
3433 pos_in_file,
3434 0,
3435 get_file_content,
3436 SERV_PORT,
3437 tftpfs_server0_ipv4,
3438 true
3439 );
3440 _Tftp_Add_interaction_recv_nothing(
3441 TFTP_FIRST_FD,
3442 FIRST_TIMEOUT_MILLISECONDS
3443 );
3444 _Tftp_Add_interaction_send_data(
3445 TFTP_FIRST_FD,
3446 block_num,
3447 pos_in_file,
3448 0,
3449 get_file_content,
3450 SERV_PORT,
3451 tftpfs_server0_ipv4,
3452 true
3453 );
3454 _Tftp_Add_interaction_recv_nothing(
3455 TFTP_FIRST_FD,
3456 TIMEOUT_MILLISECONDS
3457 );
3458 _Tftp_Add_interaction_send_data(
3459 TFTP_FIRST_FD,
3460 block_num,
3461 pos_in_file,
3462 0,
3463 get_file_content,
3464 SERV_PORT,
3465 tftpfs_server0_ipv4,
3466 true
3467 );
3468 _Tftp_Add_interaction_recv_ack(
3469 TFTP_FIRST_FD,
3470 TIMEOUT_MILLISECONDS,
3471 SERV_PORT,
3472 tftpfs_server0_ipv4,
3473 block_num++,
3474 true
3475 );
3476 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3477
3478 bytes_written = write_tftp_file(
3479 create_tftpfs_path( tftpfs_server0_name, tftpfs_file ),
3480 0,
3481 4,
3482 &ctx->fd0
3483 );
3484 T_eq_int( bytes_written, pos_in_file );
3485 T_no_more_interactions();
3486 }
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507 T_TEST_CASE_FIXTURE( write_tiny_file_packet_losts, &fixture_rfc1350 )
3508 {
3509 tftp_test_context *ctx = T_fixture_context();
3510 int bytes_written;
3511 uint16_t block_num = 0;
3512 size_t pos_in_file = 0;
3513
3514
3515 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3516 _Tftp_Add_interaction_send_wrq(
3517 TFTP_FIRST_FD,
3518 tftpfs_file,
3519 TFTP_STD_PORT,
3520 tftpfs_server0_ipv4,
3521 NO_BLOCK_SIZE_OPTION,
3522 NO_WINDOW_SIZE_OPTION,
3523 true
3524 );
3525 _Tftp_Add_interaction_recv_ack(
3526 TFTP_FIRST_FD,
3527 FIRST_TIMEOUT_MILLISECONDS,
3528 SERV_PORT,
3529 tftpfs_server0_ipv4,
3530 block_num++,
3531 true
3532 );
3533 _Tftp_Add_interaction_send_data(
3534 TFTP_FIRST_FD,
3535 block_num,
3536 pos_in_file,
3537 TFTP_RFC1350_BLOCK_SIZE,
3538 get_file_content,
3539 SERV_PORT,
3540 tftpfs_server0_ipv4,
3541 true
3542 );
3543 _Tftp_Add_interaction_recv_nothing(
3544 TFTP_FIRST_FD,
3545 FIRST_TIMEOUT_MILLISECONDS
3546 );
3547 _Tftp_Add_interaction_send_data(
3548 TFTP_FIRST_FD,
3549 block_num,
3550 pos_in_file,
3551 TFTP_RFC1350_BLOCK_SIZE,
3552 get_file_content,
3553 SERV_PORT,
3554 tftpfs_server0_ipv4,
3555 true
3556 );
3557 _Tftp_Add_interaction_recv_nothing(
3558 TFTP_FIRST_FD,
3559 TIMEOUT_MILLISECONDS
3560 );
3561 _Tftp_Add_interaction_send_data(
3562 TFTP_FIRST_FD,
3563 block_num,
3564 pos_in_file,
3565 TFTP_RFC1350_BLOCK_SIZE,
3566 get_file_content,
3567 SERV_PORT,
3568 tftpfs_server0_ipv4,
3569 true
3570 );
3571 _Tftp_Add_interaction_recv_ack(
3572 TFTP_FIRST_FD,
3573 TIMEOUT_MILLISECONDS,
3574 SERV_PORT,
3575 tftpfs_server0_ipv4,
3576 block_num++,
3577 true
3578 );
3579 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
3580 _Tftp_Add_interaction_send_data(
3581 TFTP_FIRST_FD,
3582 block_num,
3583 pos_in_file,
3584 TFTP_RFC1350_BLOCK_SIZE / 2,
3585 get_file_content,
3586 SERV_PORT,
3587 tftpfs_server0_ipv4,
3588 true
3589 );
3590 _Tftp_Add_interaction_recv_ack(
3591 TFTP_FIRST_FD,
3592 FIRST_TIMEOUT_MILLISECONDS,
3593 SERV_PORT,
3594 tftpfs_server0_ipv4,
3595 block_num - 1,
3596 true
3597 );
3598 _Tftp_Add_interaction_send_data(
3599 TFTP_FIRST_FD,
3600 block_num,
3601 pos_in_file,
3602 TFTP_RFC1350_BLOCK_SIZE / 2,
3603 get_file_content,
3604 SERV_PORT,
3605 tftpfs_server0_ipv4,
3606 true
3607 );
3608 pos_in_file += TFTP_RFC1350_BLOCK_SIZE / 2;
3609 _Tftp_Add_interaction_recv_ack(
3610 TFTP_FIRST_FD,
3611 FIRST_TIMEOUT_MILLISECONDS,
3612 SERV_PORT,
3613 tftpfs_server0_ipv4,
3614 block_num++,
3615 true
3616 );
3617 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3618
3619 bytes_written = write_tftp_file(
3620 create_tftpfs_path( tftpfs_server0_name, tftpfs_file ),
3621 TFTP_RFC1350_BLOCK_SIZE / 2 * 3,
3622 TFTP_RFC1350_BLOCK_SIZE / 4,
3623 &ctx->fd0
3624 );
3625 T_eq_int( bytes_written, pos_in_file );
3626 T_no_more_interactions();
3627 }
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642 T_TEST_CASE_FIXTURE( write_simple_file, &fixture_rfc1350 )
3643 {
3644 tftp_test_context *ctx = T_fixture_context();
3645 int bytes_written;
3646 uint16_t block_num = 0;
3647 size_t pos_in_file = 0;
3648
3649
3650 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3651 _Tftp_Add_interaction_send_wrq(
3652 TFTP_FIRST_FD,
3653 tftpfs_file,
3654 TFTP_STD_PORT,
3655 tftpfs_ipv4_loopback,
3656 NO_BLOCK_SIZE_OPTION,
3657 NO_WINDOW_SIZE_OPTION,
3658 true
3659 );
3660 _Tftp_Add_interaction_recv_ack(
3661 TFTP_FIRST_FD,
3662 FIRST_TIMEOUT_MILLISECONDS,
3663 SERV_PORT,
3664 tftpfs_ipv4_loopback,
3665 block_num++,
3666 true
3667 );
3668 _Tftp_Add_interaction_send_data(
3669 TFTP_FIRST_FD,
3670 block_num,
3671 pos_in_file,
3672 TFTP_RFC1350_BLOCK_SIZE,
3673 get_file_content,
3674 SERV_PORT,
3675 tftpfs_ipv4_loopback,
3676 true
3677 );
3678 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
3679 _Tftp_Add_interaction_recv_ack(
3680 TFTP_FIRST_FD,
3681 FIRST_TIMEOUT_MILLISECONDS,
3682 SERV_PORT,
3683 tftpfs_ipv4_loopback,
3684 block_num++,
3685 true
3686 );
3687 _Tftp_Add_interaction_send_data(
3688 TFTP_FIRST_FD,
3689 block_num,
3690 pos_in_file,
3691 TFTP_RFC1350_BLOCK_SIZE,
3692 get_file_content,
3693 SERV_PORT,
3694 tftpfs_ipv4_loopback,
3695 true
3696 );
3697 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
3698 _Tftp_Add_interaction_recv_ack(
3699 TFTP_FIRST_FD,
3700 FIRST_TIMEOUT_MILLISECONDS,
3701 SERV_PORT,
3702 tftpfs_ipv4_loopback,
3703 block_num++,
3704 true
3705 );
3706 _Tftp_Add_interaction_send_data(
3707 TFTP_FIRST_FD,
3708 block_num,
3709 pos_in_file,
3710 1,
3711 get_file_content,
3712 SERV_PORT,
3713 tftpfs_ipv4_loopback,
3714 true
3715 );
3716 pos_in_file += 1;
3717 _Tftp_Add_interaction_recv_ack(
3718 TFTP_FIRST_FD,
3719 FIRST_TIMEOUT_MILLISECONDS,
3720 SERV_PORT,
3721 tftpfs_ipv4_loopback,
3722 block_num++,
3723 true
3724 );
3725 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3726
3727 bytes_written = write_tftp_file(
3728 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
3729 pos_in_file,
3730 pos_in_file,
3731 &ctx->fd0
3732 );
3733 T_eq_int( bytes_written, pos_in_file );
3734 T_no_more_interactions();
3735 }
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751 T_TEST_CASE_FIXTURE( write_simple_file_disk_full, &fixture_rfc1350 )
3752 {
3753 tftp_test_context *ctx = T_fixture_context();
3754 int bytes_written;
3755 uint16_t block_num = 0;
3756 size_t pos_in_file = 0;
3757
3758
3759 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3760 _Tftp_Add_interaction_send_wrq(
3761 TFTP_FIRST_FD,
3762 tftpfs_file,
3763 TFTP_STD_PORT,
3764 tftpfs_ipv4_loopback,
3765 NO_BLOCK_SIZE_OPTION,
3766 NO_WINDOW_SIZE_OPTION,
3767 true
3768 );
3769 _Tftp_Add_interaction_recv_ack(
3770 TFTP_FIRST_FD,
3771 FIRST_TIMEOUT_MILLISECONDS,
3772 SERV_PORT,
3773 tftpfs_ipv4_loopback,
3774 block_num++,
3775 true
3776 );
3777 _Tftp_Add_interaction_send_data(
3778 TFTP_FIRST_FD,
3779 block_num,
3780 pos_in_file,
3781 TFTP_RFC1350_BLOCK_SIZE,
3782 get_file_content,
3783 SERV_PORT,
3784 tftpfs_ipv4_loopback,
3785 true
3786 );
3787 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
3788 _Tftp_Add_interaction_recv_error(
3789 TFTP_FIRST_FD,
3790 FIRST_TIMEOUT_MILLISECONDS,
3791 SERV_PORT,
3792 tftpfs_ipv4_loopback,
3793 TFTP_ERROR_CODE_DISK_FULL,
3794 "disk full",
3795 true
3796 );
3797 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3798
3799 bytes_written = write_tftp_file(
3800 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
3801 pos_in_file,
3802 1,
3803 &ctx->fd0
3804 );
3805 T_eq_int( errno, ENOSPC );
3806 T_eq_int( bytes_written, pos_in_file - 1 );
3807 T_no_more_interactions();
3808 }
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824 T_TEST_CASE_FIXTURE( write_file_malformed_ack_1, &fixture_rfc1350 )
3825 {
3826 tftp_test_context *ctx = T_fixture_context();
3827 int bytes_written;
3828 size_t pos_in_file = 0;
3829 static const uint8_t packet_too_short_1[] = { 0x04 };
3830
3831
3832 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3833 _Tftp_Add_interaction_send_wrq(
3834 TFTP_FIRST_FD,
3835 tftpfs_file,
3836 TFTP_STD_PORT,
3837 tftpfs_ipv4_loopback,
3838 NO_BLOCK_SIZE_OPTION,
3839 NO_WINDOW_SIZE_OPTION,
3840 true
3841 );
3842 _Tftp_Add_interaction_recv_raw(
3843 TFTP_FIRST_FD,
3844 FIRST_TIMEOUT_MILLISECONDS,
3845 SERV_PORT,
3846 tftpfs_ipv4_loopback,
3847 sizeof( packet_too_short_1 ),
3848 packet_too_short_1,
3849 true
3850 );
3851 _Tftp_Add_interaction_send_error(
3852 TFTP_FIRST_FD,
3853 TFTP_ERROR_CODE_ILLEGAL,
3854 SERV_PORT,
3855 tftpfs_ipv4_loopback,
3856 true
3857 );
3858 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3859
3860 bytes_written = write_tftp_file(
3861 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
3862 pos_in_file,
3863 17,
3864 &ctx->fd0
3865 );
3866 T_eq_int( bytes_written, -1 );
3867 T_eq_int( errno, EPROTO );
3868 T_no_more_interactions();
3869 }
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885 T_TEST_CASE_FIXTURE( write_file_malformed_ack_2, &fixture_rfc1350 )
3886 {
3887 tftp_test_context *ctx = T_fixture_context();
3888 int bytes_written;
3889 size_t pos_in_file = 0;
3890 static const uint8_t packet_too_short_2[] = { 0x00, 0x04 };
3891
3892
3893 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3894 _Tftp_Add_interaction_send_wrq(
3895 TFTP_FIRST_FD,
3896 tftpfs_file,
3897 TFTP_STD_PORT,
3898 tftpfs_ipv4_loopback,
3899 NO_BLOCK_SIZE_OPTION,
3900 NO_WINDOW_SIZE_OPTION,
3901 true
3902 );
3903 _Tftp_Add_interaction_recv_raw(
3904 TFTP_FIRST_FD,
3905 FIRST_TIMEOUT_MILLISECONDS,
3906 SERV_PORT,
3907 tftpfs_ipv4_loopback,
3908 sizeof( packet_too_short_2 ),
3909 packet_too_short_2,
3910 true
3911 );
3912 _Tftp_Add_interaction_send_error(
3913 TFTP_FIRST_FD,
3914 TFTP_ERROR_CODE_ILLEGAL,
3915 SERV_PORT,
3916 tftpfs_ipv4_loopback,
3917 true
3918 );
3919 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3920
3921 bytes_written = write_tftp_file(
3922 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
3923 pos_in_file,
3924 17,
3925 &ctx->fd0
3926 );
3927 T_eq_int( bytes_written, -1 );
3928 T_eq_int( errno, EPROTO );
3929 T_no_more_interactions();
3930 }
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946 T_TEST_CASE_FIXTURE( write_file_malformed_ack_3, &fixture_rfc1350 )
3947 {
3948 tftp_test_context *ctx = T_fixture_context();
3949 int bytes_written;
3950 size_t pos_in_file = 0;
3951 static const uint8_t packet_too_short_3[] = { 0x00, 0x04, 0x00 };
3952
3953
3954 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
3955 _Tftp_Add_interaction_send_wrq(
3956 TFTP_FIRST_FD,
3957 tftpfs_file,
3958 TFTP_STD_PORT,
3959 tftpfs_ipv4_loopback,
3960 NO_BLOCK_SIZE_OPTION,
3961 NO_WINDOW_SIZE_OPTION,
3962 true
3963 );
3964 _Tftp_Add_interaction_recv_raw(
3965 TFTP_FIRST_FD,
3966 FIRST_TIMEOUT_MILLISECONDS,
3967 SERV_PORT,
3968 tftpfs_ipv4_loopback,
3969 sizeof( packet_too_short_3 ),
3970 packet_too_short_3,
3971 true
3972 );
3973 _Tftp_Add_interaction_send_error(
3974 TFTP_FIRST_FD,
3975 TFTP_ERROR_CODE_ILLEGAL,
3976 SERV_PORT,
3977 tftpfs_ipv4_loopback,
3978 true
3979 );
3980 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
3981
3982 bytes_written = write_tftp_file(
3983 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
3984 pos_in_file,
3985 17,
3986 &ctx->fd0
3987 );
3988 T_eq_int( bytes_written, -1 );
3989 T_eq_int( errno, EPROTO );
3990 T_no_more_interactions();
3991 }
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007 T_TEST_CASE_FIXTURE( write_file_illegal_opcode_1, &fixture_rfc1350 )
4008 {
4009 tftp_test_context *ctx = T_fixture_context();
4010 int bytes_written;
4011 size_t pos_in_file = 0;
4012 static const uint8_t packet_illegal_opcode_1[] = { 0x00, 0xFF, 0x00, 0x00 };
4013
4014
4015 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4016 _Tftp_Add_interaction_send_wrq(
4017 TFTP_FIRST_FD,
4018 tftpfs_file,
4019 TFTP_STD_PORT,
4020 tftpfs_ipv4_loopback,
4021 NO_BLOCK_SIZE_OPTION,
4022 NO_WINDOW_SIZE_OPTION,
4023 true
4024 );
4025 _Tftp_Add_interaction_recv_raw(
4026 TFTP_FIRST_FD,
4027 FIRST_TIMEOUT_MILLISECONDS,
4028 SERV_PORT,
4029 tftpfs_ipv4_loopback,
4030 sizeof( packet_illegal_opcode_1 ),
4031 packet_illegal_opcode_1,
4032 true
4033 );
4034 _Tftp_Add_interaction_send_error(
4035 TFTP_FIRST_FD,
4036 TFTP_ERROR_CODE_ILLEGAL,
4037 SERV_PORT,
4038 tftpfs_ipv4_loopback,
4039 true
4040 );
4041 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4042
4043 bytes_written = write_tftp_file(
4044 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4045 pos_in_file,
4046 17,
4047 &ctx->fd0
4048 );
4049 T_eq_int( bytes_written, -1 );
4050 T_eq_int( errno, EPROTO );
4051 T_no_more_interactions();
4052 }
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067 T_TEST_CASE_FIXTURE( write_short_file_malformed_ACK_1, &fixture_rfc1350 )
4068 {
4069 tftp_test_context *ctx = T_fixture_context();
4070 int bytes_written;
4071 uint16_t block_num = 0;
4072 size_t pos_in_file = 0;
4073 static const uint8_t packet_too_short_3[] = { 0x00, 0x04, 0x00 };
4074
4075
4076 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4077 _Tftp_Add_interaction_send_wrq(
4078 TFTP_FIRST_FD,
4079 tftpfs_file,
4080 TFTP_STD_PORT,
4081 tftpfs_ipv4_loopback,
4082 NO_BLOCK_SIZE_OPTION,
4083 NO_WINDOW_SIZE_OPTION,
4084 true
4085 );
4086 _Tftp_Add_interaction_recv_ack(
4087 TFTP_FIRST_FD,
4088 FIRST_TIMEOUT_MILLISECONDS,
4089 SERV_PORT,
4090 tftpfs_ipv4_loopback,
4091 block_num++,
4092 true
4093 );
4094 _Tftp_Add_interaction_send_data(
4095 TFTP_FIRST_FD,
4096 block_num,
4097 pos_in_file,
4098 TFTP_RFC1350_BLOCK_SIZE,
4099 get_file_content,
4100 SERV_PORT,
4101 tftpfs_ipv4_loopback,
4102 true
4103 );
4104 _Tftp_Add_interaction_recv_raw(
4105 TFTP_FIRST_FD,
4106 FIRST_TIMEOUT_MILLISECONDS,
4107 SERV_PORT,
4108 tftpfs_ipv4_loopback,
4109 sizeof( packet_too_short_3 ),
4110 packet_too_short_3,
4111 true
4112 );
4113 _Tftp_Add_interaction_send_error(
4114 TFTP_FIRST_FD,
4115 TFTP_ERROR_CODE_ILLEGAL,
4116 SERV_PORT,
4117 tftpfs_ipv4_loopback,
4118 true
4119 );
4120 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4121
4122 bytes_written = write_tftp_file(
4123 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4124 2 * TFTP_RFC1350_BLOCK_SIZE,
4125 17,
4126 &ctx->fd0
4127 );
4128 T_eq_int( errno, EPROTO );
4129 T_eq_int( bytes_written, 510 );
4130 T_no_more_interactions();
4131 }
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147 T_TEST_CASE_FIXTURE( write_short_file_malformed_ACK_2, &fixture_rfc1350 )
4148 {
4149 tftp_test_context *ctx = T_fixture_context();
4150 int bytes_written;
4151 uint16_t block_num = 0;
4152 size_t pos_in_file = 0;
4153 static const uint8_t packet_too_short_1[] = { 0x04 };
4154
4155
4156 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4157 _Tftp_Add_interaction_send_wrq(
4158 TFTP_FIRST_FD,
4159 tftpfs_file,
4160 TFTP_STD_PORT,
4161 tftpfs_ipv4_loopback,
4162 NO_BLOCK_SIZE_OPTION,
4163 NO_WINDOW_SIZE_OPTION,
4164 true
4165 );
4166 _Tftp_Add_interaction_recv_ack(
4167 TFTP_FIRST_FD,
4168 FIRST_TIMEOUT_MILLISECONDS,
4169 SERV_PORT,
4170 tftpfs_ipv4_loopback,
4171 block_num++,
4172 true
4173 );
4174 _Tftp_Add_interaction_send_data(
4175 TFTP_FIRST_FD,
4176 block_num,
4177 pos_in_file,
4178 TFTP_RFC1350_BLOCK_SIZE,
4179 get_file_content,
4180 SERV_PORT,
4181 tftpfs_ipv4_loopback,
4182 true
4183 );
4184 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
4185 _Tftp_Add_interaction_recv_ack(
4186 TFTP_FIRST_FD,
4187 FIRST_TIMEOUT_MILLISECONDS,
4188 SERV_PORT,
4189 tftpfs_ipv4_loopback,
4190 block_num++,
4191 true
4192 );
4193 _Tftp_Add_interaction_send_data(
4194 TFTP_FIRST_FD,
4195 block_num,
4196 pos_in_file,
4197 TFTP_RFC1350_BLOCK_SIZE / 4,
4198 get_file_content,
4199 SERV_PORT,
4200 tftpfs_ipv4_loopback,
4201 true
4202 );
4203 pos_in_file += TFTP_RFC1350_BLOCK_SIZE / 4;
4204 _Tftp_Add_interaction_recv_raw(
4205 TFTP_FIRST_FD,
4206 FIRST_TIMEOUT_MILLISECONDS,
4207 SERV_PORT,
4208 tftpfs_ipv4_loopback,
4209 sizeof( packet_too_short_1 ),
4210 packet_too_short_1,
4211 true
4212 );
4213 _Tftp_Add_interaction_send_error(
4214 TFTP_FIRST_FD,
4215 TFTP_ERROR_CODE_ILLEGAL,
4216 SERV_PORT,
4217 tftpfs_ipv4_loopback,
4218 true
4219 );
4220 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4221
4222 bytes_written = write_tftp_file(
4223 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4224 pos_in_file,
4225 17,
4226 &ctx->fd0
4227 );
4228 T_eq_int( errno, EPROTO );
4229 T_eq_int( bytes_written, -1 );
4230 T_no_more_interactions();
4231 }
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247 T_TEST_CASE_FIXTURE( write_short_file_malformed_opcode, &fixture_rfc1350 )
4248 {
4249 tftp_test_context *ctx = T_fixture_context();
4250 int bytes_written;
4251 uint16_t block_num = 0;
4252 size_t pos_in_file = 0;
4253 static const uint8_t packet_illegal_opcode_2[] = { 0x04, 0x00, 0x00, 0x01 };
4254
4255
4256 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4257 _Tftp_Add_interaction_send_wrq(
4258 TFTP_FIRST_FD,
4259 tftpfs_file,
4260 TFTP_STD_PORT,
4261 tftpfs_ipv4_loopback,
4262 NO_BLOCK_SIZE_OPTION,
4263 NO_WINDOW_SIZE_OPTION,
4264 true
4265 );
4266 _Tftp_Add_interaction_recv_ack(
4267 TFTP_FIRST_FD,
4268 FIRST_TIMEOUT_MILLISECONDS,
4269 SERV_PORT,
4270 tftpfs_ipv4_loopback,
4271 block_num++,
4272 true
4273 );
4274 _Tftp_Add_interaction_send_data(
4275 TFTP_FIRST_FD,
4276 block_num,
4277 pos_in_file,
4278 TFTP_RFC1350_BLOCK_SIZE,
4279 get_file_content,
4280 SERV_PORT,
4281 tftpfs_ipv4_loopback,
4282 true
4283 );
4284 _Tftp_Add_interaction_recv_raw(
4285 TFTP_FIRST_FD,
4286 FIRST_TIMEOUT_MILLISECONDS,
4287 SERV_PORT,
4288 tftpfs_ipv4_loopback,
4289 sizeof( packet_illegal_opcode_2 ),
4290 packet_illegal_opcode_2,
4291 true
4292 );
4293 _Tftp_Add_interaction_send_error(
4294 TFTP_FIRST_FD,
4295 TFTP_ERROR_CODE_ILLEGAL,
4296 SERV_PORT,
4297 tftpfs_ipv4_loopback,
4298 true
4299 );
4300 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4301
4302 bytes_written = write_tftp_file(
4303 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4304 2 * TFTP_RFC1350_BLOCK_SIZE,
4305 17,
4306 &ctx->fd0
4307 );
4308 T_eq_int( errno, EPROTO );
4309 T_eq_int( bytes_written, 510 );
4310 T_no_more_interactions();
4311 }
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336 T_TEST_CASE_FIXTURE( write_short_file_bad_block_numbers, &fixture_rfc1350 )
4337 {
4338 tftp_test_context *ctx = T_fixture_context();
4339 int bytes_written;
4340 uint16_t block_num = 0;
4341 size_t pos_in_file = 0;
4342
4343
4344 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4345 _Tftp_Add_interaction_send_wrq(
4346 TFTP_FIRST_FD,
4347 tftpfs_file,
4348 TFTP_STD_PORT,
4349 tftpfs_ipv4_loopback,
4350 NO_BLOCK_SIZE_OPTION,
4351 NO_WINDOW_SIZE_OPTION,
4352 true
4353 );
4354 _Tftp_Add_interaction_recv_ack(
4355 TFTP_FIRST_FD,
4356 FIRST_TIMEOUT_MILLISECONDS,
4357 SERV_PORT,
4358 tftpfs_ipv4_loopback,
4359 block_num + 1,
4360 true
4361 );
4362 _Tftp_Add_interaction_recv_ack(
4363 TFTP_FIRST_FD,
4364 FIRST_TIMEOUT_MILLISECONDS,
4365 SERV_PORT,
4366 tftpfs_ipv4_loopback,
4367 block_num++,
4368 true
4369 );
4370 _Tftp_Add_interaction_send_data(
4371 TFTP_FIRST_FD,
4372 block_num,
4373 pos_in_file,
4374 TFTP_RFC1350_BLOCK_SIZE,
4375 get_file_content,
4376 SERV_PORT,
4377 tftpfs_ipv4_loopback,
4378 true
4379 );
4380 _Tftp_Add_interaction_recv_ack(
4381 TFTP_FIRST_FD,
4382 FIRST_TIMEOUT_MILLISECONDS,
4383 SERV_PORT,
4384 tftpfs_ipv4_loopback,
4385 block_num - 1,
4386 true
4387 );
4388 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
4389 _Tftp_Add_interaction_recv_ack(
4390 TFTP_FIRST_FD,
4391 FIRST_TIMEOUT_MILLISECONDS,
4392 SERV_PORT,
4393 tftpfs_ipv4_loopback,
4394 block_num++,
4395 true
4396 );
4397 _Tftp_Add_interaction_send_data(
4398 TFTP_FIRST_FD,
4399 block_num,
4400 pos_in_file,
4401 TFTP_RFC1350_BLOCK_SIZE,
4402 get_file_content,
4403 SERV_PORT,
4404 tftpfs_ipv4_loopback,
4405 true
4406 );
4407 _Tftp_Add_interaction_recv_ack(
4408 TFTP_FIRST_FD,
4409 FIRST_TIMEOUT_MILLISECONDS,
4410 SERV_PORT,
4411 tftpfs_ipv4_loopback,
4412 block_num - 2,
4413 true
4414 );
4415 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
4416 _Tftp_Add_interaction_recv_ack(
4417 TFTP_FIRST_FD,
4418 FIRST_TIMEOUT_MILLISECONDS,
4419 SERV_PORT,
4420 tftpfs_ipv4_loopback,
4421 block_num++,
4422 true
4423 );
4424 _Tftp_Add_interaction_send_data(
4425 TFTP_FIRST_FD,
4426 block_num,
4427 pos_in_file,
4428 TFTP_RFC1350_BLOCK_SIZE / 4,
4429 get_file_content,
4430 SERV_PORT,
4431 tftpfs_ipv4_loopback,
4432 true
4433 );
4434 _Tftp_Add_interaction_recv_ack(
4435 TFTP_FIRST_FD,
4436 FIRST_TIMEOUT_MILLISECONDS,
4437 SERV_PORT,
4438 tftpfs_ipv4_loopback,
4439 block_num - 2,
4440 true
4441 );
4442 _Tftp_Add_interaction_recv_ack(
4443 TFTP_FIRST_FD,
4444 FIRST_TIMEOUT_MILLISECONDS,
4445 SERV_PORT,
4446 tftpfs_ipv4_loopback,
4447 block_num + 1,
4448 true
4449 );
4450 pos_in_file += TFTP_RFC1350_BLOCK_SIZE / 4;
4451 _Tftp_Add_interaction_recv_ack(
4452 TFTP_FIRST_FD,
4453 FIRST_TIMEOUT_MILLISECONDS,
4454 SERV_PORT,
4455 tftpfs_ipv4_loopback,
4456 block_num++,
4457 true
4458 );
4459 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4460
4461 bytes_written = write_tftp_file(
4462 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4463 pos_in_file,
4464 TFTP_RFC1350_BLOCK_SIZE,
4465 &ctx->fd0
4466 );
4467 T_eq_int( bytes_written, pos_in_file );
4468 T_no_more_interactions();
4469 }
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492 T_TEST_CASE_FIXTURE( write_one_block_file_stray_packets, &fixture_rfc1350 )
4493 {
4494 tftp_test_context *ctx = T_fixture_context();
4495 int bytes_written;
4496 uint16_t block_num = 0;
4497 size_t pos_in_file = 0;
4498
4499
4500 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4501 _Tftp_Add_interaction_send_wrq(
4502 TFTP_FIRST_FD,
4503 tftpfs_file,
4504 TFTP_STD_PORT,
4505 tftpfs_ipv4_loopback,
4506 NO_BLOCK_SIZE_OPTION,
4507 NO_WINDOW_SIZE_OPTION,
4508 true
4509 );
4510 _Tftp_Add_interaction_recv_ack(
4511 TFTP_FIRST_FD,
4512 FIRST_TIMEOUT_MILLISECONDS,
4513 SERV_PORT,
4514 tftpfs_ipv4_loopback,
4515 block_num++,
4516 true
4517 );
4518 _Tftp_Add_interaction_send_data(
4519 TFTP_FIRST_FD,
4520 block_num,
4521 pos_in_file,
4522 TFTP_RFC1350_BLOCK_SIZE,
4523 get_file_content,
4524 SERV_PORT,
4525 tftpfs_ipv4_loopback,
4526 true
4527 );
4528 _Tftp_Add_interaction_recv_data(
4529 TFTP_FIRST_FD,
4530 FIRST_TIMEOUT_MILLISECONDS,
4531 SERV_PORT + 1,
4532 tftpfs_ipv4_loopback,
4533 block_num,
4534 0,
4535 TFTP_RFC1350_BLOCK_SIZE / 2,
4536 get_bad_file_content,
4537 true
4538 );
4539 _Tftp_Add_interaction_send_error(
4540 TFTP_FIRST_FD,
4541 TFTP_ERROR_CODE_UNKNOWN_ID,
4542 SERV_PORT + 1,
4543 tftpfs_ipv4_loopback,
4544 true
4545 );
4546 _Tftp_Add_interaction_recv_nothing(
4547 TFTP_FIRST_FD,
4548 FIRST_TIMEOUT_MILLISECONDS
4549 );
4550 _Tftp_Add_interaction_send_data(
4551 TFTP_FIRST_FD,
4552 block_num,
4553 pos_in_file,
4554 TFTP_RFC1350_BLOCK_SIZE,
4555 get_file_content,
4556 SERV_PORT,
4557 tftpfs_ipv4_loopback,
4558 true
4559 );
4560 pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
4561 _Tftp_Add_interaction_recv_ack(
4562 TFTP_FIRST_FD,
4563 TIMEOUT_MILLISECONDS,
4564 SERV_PORT,
4565 tftpfs_ipv4_loopback,
4566 block_num++,
4567 true
4568 );
4569 _Tftp_Add_interaction_send_data(
4570 TFTP_FIRST_FD,
4571 block_num,
4572 pos_in_file,
4573 0,
4574 get_file_content,
4575 SERV_PORT,
4576 tftpfs_ipv4_loopback,
4577 true
4578 );
4579 pos_in_file += 0;
4580 _Tftp_Add_interaction_recv_ack(
4581 TFTP_FIRST_FD,
4582 FIRST_TIMEOUT_MILLISECONDS,
4583 SERV_PORT,
4584 tftpfs_ipv4_loopback,
4585 block_num++,
4586 true
4587 );
4588 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4589
4590 bytes_written = write_tftp_file(
4591 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4592 pos_in_file,
4593 TFTP_RFC1350_BLOCK_SIZE,
4594 &ctx->fd0
4595 );
4596 T_eq_int( bytes_written, pos_in_file );
4597 T_no_more_interactions();
4598 }
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612 T_TEST_CASE_FIXTURE( read_file_one_large_block, &fixture_large_blocksize )
4613 {
4614 tftp_test_context *ctx = T_fixture_context();
4615 int bytes_read;
4616 uint16_t block_num = 0;
4617 size_t pos_in_file = 0;
4618 const char options[] =
4619 TFTP_OPTION_BLKSIZE "\0"
4620 RTEMS_XSTRING( LARGE_BLOCK_SIZE );
4621
4622
4623 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4624 _Tftp_Add_interaction_send_rrq(
4625 TFTP_FIRST_FD,
4626 tftpfs_file,
4627 TFTP_STD_PORT,
4628 tftpfs_ipv4_loopback,
4629 LARGE_BLOCK_SIZE,
4630 NO_WINDOW_SIZE_OPTION,
4631 true
4632 );
4633 _Tftp_Add_interaction_recv_oack(
4634 TFTP_FIRST_FD,
4635 FIRST_TIMEOUT_MILLISECONDS,
4636 SERV_PORT,
4637 tftpfs_ipv4_loopback,
4638 options,
4639 sizeof( options ),
4640 true
4641 );
4642 _Tftp_Add_interaction_send_ack(
4643 TFTP_FIRST_FD,
4644 block_num++,
4645 SERV_PORT,
4646 tftpfs_ipv4_loopback,
4647 true
4648 );
4649 _Tftp_Add_interaction_recv_data(
4650 TFTP_FIRST_FD,
4651 FIRST_TIMEOUT_MILLISECONDS,
4652 SERV_PORT,
4653 tftpfs_ipv4_loopback,
4654 block_num,
4655 pos_in_file,
4656 LARGE_BLOCK_SIZE,
4657 get_file_content,
4658 true
4659 );
4660 pos_in_file += LARGE_BLOCK_SIZE;
4661 _Tftp_Add_interaction_send_ack(
4662 TFTP_FIRST_FD,
4663 block_num++,
4664 SERV_PORT,
4665 tftpfs_ipv4_loopback,
4666 true
4667 );
4668 _Tftp_Add_interaction_recv_data(
4669 TFTP_FIRST_FD,
4670 FIRST_TIMEOUT_MILLISECONDS,
4671 SERV_PORT,
4672 tftpfs_ipv4_loopback,
4673 block_num,
4674 pos_in_file,
4675 0,
4676 get_file_content,
4677 true
4678 );
4679 _Tftp_Add_interaction_send_ack(
4680 TFTP_FIRST_FD,
4681 block_num++,
4682 SERV_PORT,
4683 tftpfs_ipv4_loopback,
4684 true
4685 );
4686 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4687
4688 bytes_read = read_tftp_file(
4689 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4690 LARGE_BLOCK_SIZE,
4691 SIZE_MAX,
4692 &ctx->fd0
4693 );
4694 T_eq_int( bytes_read, pos_in_file );
4695 T_no_more_interactions();
4696 }
4697
4698
4699
4700
4701
4702
4703
4704 T_TEST_CASE_FIXTURE( read_too_long_file_name, &fixture_default_options )
4705 {
4706 tftp_test_context *ctx = T_fixture_context();
4707 int bytes_read;
4708 char buffer[TFTP_RFC1350_BLOCK_SIZE -
4709 strlen( TFTP_MODE_OCTET ) - 1 - 5];
4710 int len;
4711
4712
4713 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4714 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4715
4716 len = sizeof( buffer ) - strlen( tftpfs_mount_point ) -
4717 strlen( tftpfs_ipv4_loopback ) - 2 - 4;
4718 len = snprintf(
4719 buffer,
4720 sizeof( buffer ),
4721 "%s/%s:%0*d",
4722 tftpfs_mount_point,
4723 tftpfs_ipv4_loopback,
4724 len,
4725 123
4726 );
4727 T_quiet_gt_int( len, 0 );
4728 T_quiet_lt_int( len, (int) sizeof( buffer ) );
4729
4730 bytes_read = read_tftp_file(
4731 buffer,
4732 TFTP_DEFAULT_BLOCK_SIZE,
4733 SIZE_MAX,
4734 &ctx->fd0
4735 );
4736 T_eq_int( bytes_read, 0 );
4737 T_eq_int( errno, ENAMETOOLONG );
4738 T_no_more_interactions();
4739 }
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752 T_TEST_CASE_FIXTURE( read_file_DATA_instead_of_OACK, &fixture_default_options )
4753 {
4754 tftp_test_context *ctx = T_fixture_context();
4755 int bytes_read;
4756 uint16_t block_num = 1;
4757 size_t pos_in_file = 0;
4758
4759
4760 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4761 _Tftp_Add_interaction_send_rrq(
4762 TFTP_FIRST_FD,
4763 tftpfs_file,
4764 TFTP_STD_PORT,
4765 tftpfs_ipv4_loopback,
4766 TFTP_DEFAULT_BLOCK_SIZE,
4767 TFTP_DEFAULT_WINDOW_SIZE,
4768 true
4769 );
4770 _Tftp_Add_interaction_recv_data(
4771 TFTP_FIRST_FD,
4772 FIRST_TIMEOUT_MILLISECONDS,
4773 SERV_PORT,
4774 tftpfs_ipv4_loopback,
4775 block_num,
4776 pos_in_file,
4777 1,
4778 get_file_content,
4779 true
4780 );
4781 pos_in_file += 1;
4782 _Tftp_Add_interaction_send_ack(
4783 TFTP_FIRST_FD,
4784 block_num++,
4785 SERV_PORT,
4786 tftpfs_ipv4_loopback,
4787 true
4788 );
4789 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4790
4791 bytes_read = read_tftp_file(
4792 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4793 TFTP_DEFAULT_BLOCK_SIZE / 2,
4794 SIZE_MAX,
4795 &ctx->fd0
4796 );
4797 T_eq_int( bytes_read, pos_in_file );
4798 T_no_more_interactions();
4799 }
4800
4801
4802
4803
4804
4805
4806
4807
4808 T_TEST_CASE_FIXTURE( read_tiny_file_OACK_instead_of_DATA, &fixture_rfc1350 )
4809 {
4810 tftp_test_context *ctx = T_fixture_context();
4811 int bytes_read;
4812 const char options[] = {};
4813
4814
4815 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4816 _Tftp_Add_interaction_send_rrq(
4817 TFTP_FIRST_FD,
4818 tftpfs_file,
4819 TFTP_STD_PORT,
4820 tftpfs_ipv4_loopback,
4821 NO_BLOCK_SIZE_OPTION,
4822 NO_WINDOW_SIZE_OPTION,
4823 true
4824 );
4825 _Tftp_Add_interaction_recv_oack(
4826 TFTP_FIRST_FD,
4827 FIRST_TIMEOUT_MILLISECONDS,
4828 SERV_PORT,
4829 tftpfs_ipv4_loopback,
4830 options,
4831 sizeof( options ),
4832 true
4833 );
4834 _Tftp_Add_interaction_send_error(
4835 TFTP_FIRST_FD,
4836 TFTP_ERROR_CODE_ILLEGAL,
4837 SERV_PORT,
4838 tftpfs_ipv4_loopback,
4839 true
4840 );
4841 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4842
4843 bytes_read = read_tftp_file(
4844 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4845 1,
4846 SIZE_MAX,
4847 &ctx->fd0
4848 );
4849 T_eq_int( bytes_read, 0 );
4850 T_eq_int( errno, EPROTO );
4851 T_no_more_interactions();
4852 }
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865 T_TEST_CASE_FIXTURE( read_file_with_default_options, &fixture_default_options )
4866 {
4867 tftp_test_context *ctx = T_fixture_context();
4868 int i;
4869 int bytes_read;
4870 uint16_t block_num = 0;
4871 size_t pos_in_file = 0;
4872 const char options[] =
4873 TFTP_OPTION_BLKSIZE "\0"
4874 RTEMS_XSTRING( TFTP_DEFAULT_BLOCK_SIZE ) "\0"
4875 TFTP_OPTION_WINDOWSIZE"\0"
4876 RTEMS_XSTRING( TFTP_DEFAULT_WINDOW_SIZE );
4877
4878
4879 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
4880 _Tftp_Add_interaction_send_rrq(
4881 TFTP_FIRST_FD,
4882 tftpfs_file,
4883 TFTP_STD_PORT,
4884 tftpfs_ipv4_loopback,
4885 TFTP_DEFAULT_BLOCK_SIZE,
4886 TFTP_DEFAULT_WINDOW_SIZE,
4887 true
4888 );
4889 _Tftp_Add_interaction_recv_oack(
4890 TFTP_FIRST_FD,
4891 FIRST_TIMEOUT_MILLISECONDS,
4892 SERV_PORT,
4893 tftpfs_ipv4_loopback,
4894 options,
4895 sizeof( options ),
4896 true
4897 );
4898 _Tftp_Add_interaction_send_ack(
4899 TFTP_FIRST_FD,
4900 block_num,
4901 SERV_PORT,
4902 tftpfs_ipv4_loopback,
4903 true
4904 );
4905 while ( block_num < 16 ) {
4906 for ( i = 0; i < TFTP_DEFAULT_WINDOW_SIZE; ++i ) {
4907 _Tftp_Add_interaction_recv_data(
4908 TFTP_FIRST_FD,
4909 FIRST_TIMEOUT_MILLISECONDS,
4910 SERV_PORT,
4911 tftpfs_ipv4_loopback,
4912 ++block_num,
4913 pos_in_file,
4914 TFTP_DEFAULT_BLOCK_SIZE,
4915 get_file_content,
4916 true
4917 );
4918 pos_in_file += TFTP_DEFAULT_BLOCK_SIZE;
4919 }
4920 _Tftp_Add_interaction_send_ack(
4921 TFTP_FIRST_FD,
4922 block_num,
4923 SERV_PORT,
4924 tftpfs_ipv4_loopback,
4925 true
4926 );
4927 }
4928 _Tftp_Add_interaction_recv_data(
4929 TFTP_FIRST_FD,
4930 FIRST_TIMEOUT_MILLISECONDS,
4931 SERV_PORT,
4932 tftpfs_ipv4_loopback,
4933 ++block_num,
4934 pos_in_file,
4935 TFTP_DEFAULT_BLOCK_SIZE,
4936 get_file_content,
4937 true
4938 );
4939 pos_in_file += TFTP_DEFAULT_BLOCK_SIZE;
4940 _Tftp_Add_interaction_recv_data(
4941 TFTP_FIRST_FD,
4942 FIRST_TIMEOUT_MILLISECONDS,
4943 SERV_PORT,
4944 tftpfs_ipv4_loopback,
4945 ++block_num,
4946 pos_in_file,
4947 TFTP_DEFAULT_BLOCK_SIZE,
4948 get_file_content,
4949 true
4950 );
4951 pos_in_file += TFTP_DEFAULT_BLOCK_SIZE;
4952 _Tftp_Add_interaction_recv_data(
4953 TFTP_FIRST_FD,
4954 FIRST_TIMEOUT_MILLISECONDS,
4955 SERV_PORT,
4956 tftpfs_ipv4_loopback,
4957 ++block_num,
4958 pos_in_file,
4959 TFTP_DEFAULT_BLOCK_SIZE / 2,
4960 get_file_content,
4961 true
4962 );
4963 pos_in_file += TFTP_DEFAULT_BLOCK_SIZE / 2;
4964 _Tftp_Add_interaction_send_ack(
4965 TFTP_FIRST_FD,
4966 block_num,
4967 SERV_PORT,
4968 tftpfs_ipv4_loopback,
4969 true
4970 );
4971 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
4972
4973 bytes_read = read_tftp_file(
4974 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
4975 2000,
4976 SIZE_MAX,
4977 &ctx->fd0
4978 );
4979 T_eq_int( bytes_read, pos_in_file );
4980 T_no_more_interactions();
4981 }
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999 T_TEST_CASE_FIXTURE( read_file_rfc7440_scenario, &fixture_small_opt_size )
5000 {
5001 tftp_test_context *ctx = T_fixture_context();
5002 int i;
5003 int bytes_read;
5004 uint16_t block_num = 0;
5005 size_t pos_in_file = 0;
5006 const char options[] =
5007 TFTP_OPTION_WINDOWSIZE"\0"
5008 RTEMS_XSTRING( SMALL_WINDOW_SIZE ) "\0"
5009 TFTP_OPTION_BLKSIZE "\0"
5010 RTEMS_XSTRING( SMALL_BLOCK_SIZE );
5011
5012
5013 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
5014 _Tftp_Add_interaction_send_rrq(
5015 TFTP_FIRST_FD,
5016 tftpfs_file,
5017 TFTP_STD_PORT,
5018 tftpfs_ipv4_loopback,
5019 SMALL_BLOCK_SIZE,
5020 SMALL_WINDOW_SIZE,
5021 true
5022 );
5023 _Tftp_Add_interaction_recv_oack(
5024 TFTP_FIRST_FD,
5025 FIRST_TIMEOUT_MILLISECONDS,
5026 SERV_PORT,
5027 tftpfs_ipv4_loopback,
5028 options,
5029 sizeof( options ),
5030 true
5031 );
5032 _Tftp_Add_interaction_send_ack(
5033 TFTP_FIRST_FD,
5034 block_num,
5035 SERV_PORT,
5036 tftpfs_ipv4_loopback,
5037 true
5038 );
5039 for ( i = 0; i < SMALL_WINDOW_SIZE; ++i ) {
5040 _Tftp_Add_interaction_recv_data(
5041 TFTP_FIRST_FD,
5042 FIRST_TIMEOUT_MILLISECONDS,
5043 SERV_PORT,
5044 tftpfs_ipv4_loopback,
5045 ++block_num,
5046 pos_in_file,
5047 SMALL_BLOCK_SIZE,
5048 get_file_content,
5049 true
5050 );
5051 pos_in_file += SMALL_BLOCK_SIZE;
5052 }
5053 _Tftp_Add_interaction_send_ack(
5054 TFTP_FIRST_FD,
5055 block_num,
5056 SERV_PORT,
5057 tftpfs_ipv4_loopback,
5058 true
5059 );
5060 _Tftp_Add_interaction_recv_data(
5061 TFTP_FIRST_FD,
5062 FIRST_TIMEOUT_MILLISECONDS,
5063 SERV_PORT,
5064 tftpfs_ipv4_loopback,
5065 ++block_num,
5066 pos_in_file,
5067 SMALL_BLOCK_SIZE,
5068 get_file_content,
5069 true
5070 );
5071 pos_in_file += SMALL_BLOCK_SIZE;
5072 _Tftp_Add_interaction_recv_data(
5073 TFTP_FIRST_FD,
5074 FIRST_TIMEOUT_MILLISECONDS,
5075 SERV_PORT,
5076 tftpfs_ipv4_loopback,
5077 block_num + 2,
5078 pos_in_file,
5079 SMALL_BLOCK_SIZE,
5080 get_file_content,
5081 true
5082 );
5083 _Tftp_Add_interaction_send_ack(
5084 TFTP_FIRST_FD,
5085 block_num,
5086 SERV_PORT,
5087 tftpfs_ipv4_loopback,
5088 true
5089 );
5090 for ( i = 0; i < SMALL_WINDOW_SIZE; ++i ) {
5091 _Tftp_Add_interaction_recv_data(
5092 TFTP_FIRST_FD,
5093 FIRST_TIMEOUT_MILLISECONDS,
5094 SERV_PORT,
5095 tftpfs_ipv4_loopback,
5096 ++block_num,
5097 pos_in_file,
5098 SMALL_BLOCK_SIZE,
5099 get_file_content,
5100 true
5101 );
5102 pos_in_file += SMALL_BLOCK_SIZE;
5103 }
5104 _Tftp_Add_interaction_send_ack(
5105 TFTP_FIRST_FD,
5106 block_num,
5107 SERV_PORT,
5108 tftpfs_ipv4_loopback,
5109 true
5110 );
5111 _Tftp_Add_interaction_recv_data(
5112 TFTP_FIRST_FD,
5113 FIRST_TIMEOUT_MILLISECONDS,
5114 SERV_PORT,
5115 tftpfs_ipv4_loopback,
5116 ++block_num,
5117 pos_in_file,
5118 SMALL_BLOCK_SIZE,
5119 get_file_content,
5120 true
5121 );
5122 pos_in_file += SMALL_BLOCK_SIZE;
5123 _Tftp_Add_interaction_recv_data(
5124 TFTP_FIRST_FD,
5125 FIRST_TIMEOUT_MILLISECONDS,
5126 SERV_PORT,
5127 tftpfs_ipv4_loopback,
5128 block_num + 2,
5129 pos_in_file,
5130 SMALL_BLOCK_SIZE,
5131 get_file_content,
5132 true
5133 );
5134 _Tftp_Add_interaction_send_ack(
5135 TFTP_FIRST_FD,
5136 block_num,
5137 SERV_PORT,
5138 tftpfs_ipv4_loopback,
5139 true
5140 );
5141 _Tftp_Add_interaction_recv_data(
5142 TFTP_FIRST_FD,
5143 FIRST_TIMEOUT_MILLISECONDS,
5144 SERV_PORT,
5145 tftpfs_ipv4_loopback,
5146 block_num + 3,
5147 pos_in_file,
5148 SMALL_BLOCK_SIZE,
5149 get_file_content,
5150 true
5151 );
5152 block_num = 9;
5153 pos_in_file = block_num * SMALL_BLOCK_SIZE;
5154 for ( i = 0; i < SMALL_WINDOW_SIZE; ++i ) {
5155 _Tftp_Add_interaction_recv_data(
5156 TFTP_FIRST_FD,
5157 FIRST_TIMEOUT_MILLISECONDS,
5158 SERV_PORT,
5159 tftpfs_ipv4_loopback,
5160 ++block_num,
5161 pos_in_file,
5162 SMALL_BLOCK_SIZE,
5163 get_file_content,
5164 true
5165 );
5166 pos_in_file += SMALL_BLOCK_SIZE;
5167 }
5168 _Tftp_Add_interaction_send_ack(
5169 TFTP_FIRST_FD,
5170 block_num,
5171 SERV_PORT,
5172 tftpfs_ipv4_loopback,
5173 true
5174 );
5175 _Tftp_Add_interaction_recv_data(
5176 TFTP_FIRST_FD,
5177 FIRST_TIMEOUT_MILLISECONDS,
5178 SERV_PORT,
5179 tftpfs_ipv4_loopback,
5180 ++block_num,
5181 pos_in_file,
5182 0,
5183 get_file_content,
5184 true
5185 );
5186 _Tftp_Add_interaction_send_ack(
5187 TFTP_FIRST_FD,
5188 block_num,
5189 SERV_PORT,
5190 tftpfs_ipv4_loopback,
5191 true
5192 );
5193 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
5194
5195 bytes_read = read_tftp_file(
5196 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
5197 10,
5198 SIZE_MAX,
5199 &ctx->fd0
5200 );
5201 T_eq_int( bytes_read, pos_in_file );
5202 T_no_more_interactions();
5203 }
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234 T_TEST_CASE_FIXTURE( read_file_windowsize_trouble, &fixture_small_opt_size )
5235 {
5236 tftp_test_context *ctx = T_fixture_context();
5237 int i;
5238 int bytes_read;
5239 uint16_t block_num = 0;
5240 size_t pos_in_file = 0;
5241 int timeout = FIRST_TIMEOUT_MILLISECONDS;
5242 const char options[] =
5243 TFTP_OPTION_WINDOWSIZE"\0"
5244 RTEMS_XSTRING( SMALL_WINDOW_SIZE ) "\0"
5245 TFTP_OPTION_BLKSIZE "\0"
5246 RTEMS_XSTRING( SMALL_BLOCK_SIZE );
5247
5248
5249
5250
5251
5252
5253 int16_t pkg_sequence[] = {
5254 1, 1, 2, 3, 2, 1, 3, 4, -4,
5255 6, -4, 7, 8,
5256 6, 5, 7, -5, 4, 8,
5257
5258 7, 6, 8, -6,
5259
5260 6, 7, 8, 9, -9,
5261 10, 11, 12, 0, -12,
5262 13, 16, -13,
5263 12, 13, 14, 15, -15, 16, 17,
5264
5265 16, 17, 18, 19, -19,
5266 16, 17, 18, 19, -19,
5267
5268 16, 19, -19, 18, 17,
5269
5270 20, -20, 21, 22, 23,
5271
5272 21, 22, 23, 24, -24,
5273 25, 27, -25, 26, 28, -26,
5274
5275
5276
5277
5278 26, 27, 29, -27, 28,
5279
5280 26, 27, 28, 29, -29,
5281 30, 31, 0, -31,
5282 32, 33, 34,
5283
5284
5285 };
5286
5287
5288 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
5289 _Tftp_Add_interaction_send_rrq(
5290 TFTP_FIRST_FD,
5291 tftpfs_file,
5292 TFTP_STD_PORT,
5293 tftpfs_ipv4_loopback,
5294 SMALL_BLOCK_SIZE,
5295 SMALL_WINDOW_SIZE,
5296 true
5297 );
5298 _Tftp_Add_interaction_recv_oack(
5299 TFTP_FIRST_FD,
5300 FIRST_TIMEOUT_MILLISECONDS,
5301 SERV_PORT,
5302 tftpfs_ipv4_loopback,
5303 options,
5304 sizeof( options ),
5305 true
5306 );
5307 _Tftp_Add_interaction_send_ack(
5308 TFTP_FIRST_FD,
5309 block_num,
5310 SERV_PORT,
5311 tftpfs_ipv4_loopback,
5312 true
5313 );
5314 for ( i = 0; i < RTEMS_ARRAY_SIZE( pkg_sequence ); ++i ) {
5315 if ( pkg_sequence[i] == 0 ) {
5316 block_num = pkg_sequence[i];
5317 _Tftp_Add_interaction_recv_nothing(
5318 TFTP_FIRST_FD,
5319 timeout
5320 );
5321 timeout = TIMEOUT_MILLISECONDS;
5322 } else if ( pkg_sequence[i] > 0 ) {
5323 block_num = pkg_sequence[i];
5324 _Tftp_Add_interaction_recv_data(
5325 TFTP_FIRST_FD,
5326 timeout,
5327 SERV_PORT,
5328 tftpfs_ipv4_loopback,
5329 block_num,
5330 ( block_num - 1 ) * SMALL_BLOCK_SIZE,
5331 SMALL_BLOCK_SIZE,
5332 get_file_content,
5333 pkg_sequence[i] > 0
5334 );
5335 timeout = FIRST_TIMEOUT_MILLISECONDS;
5336 pos_in_file = block_num * SMALL_BLOCK_SIZE;
5337 } else {
5338 block_num = -pkg_sequence[i];
5339 _Tftp_Add_interaction_send_ack(
5340 TFTP_FIRST_FD,
5341 block_num,
5342 SERV_PORT,
5343 tftpfs_ipv4_loopback,
5344 true
5345 );
5346 }
5347 }
5348 _Tftp_Add_interaction_recv_data(
5349 TFTP_FIRST_FD,
5350 timeout,
5351 SERV_PORT,
5352 tftpfs_ipv4_loopback,
5353 ++block_num,
5354 pos_in_file,
5355 0,
5356 get_file_content,
5357 true
5358 );
5359 _Tftp_Add_interaction_send_ack(
5360 TFTP_FIRST_FD,
5361 block_num,
5362 SERV_PORT,
5363 tftpfs_ipv4_loopback,
5364 true
5365 );
5366 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
5367
5368 bytes_read = read_tftp_file(
5369 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
5370 100,
5371 SIZE_MAX,
5372 &ctx->fd0
5373 );
5374 T_eq_int( bytes_read, pos_in_file );
5375 T_no_more_interactions();
5376 }
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392 T_TEST_CASE_FIXTURE( write_simple_file_large_blocks, &fixture_large_blocksize )
5393 {
5394 tftp_test_context *ctx = T_fixture_context();
5395 int bytes_written;
5396 size_t pos_in_file = 0;
5397 uint16_t block_num = 1;
5398 uint16_t block_size = 211;
5399 const char options[] = "BLKsiZe" "\0" "211";
5400
5401
5402 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
5403 _Tftp_Add_interaction_send_wrq(
5404 TFTP_FIRST_FD,
5405 tftpfs_file,
5406 TFTP_STD_PORT,
5407 tftpfs_ipv4_loopback,
5408 LARGE_BLOCK_SIZE,
5409 NO_WINDOW_SIZE_OPTION,
5410 true
5411 );
5412 _Tftp_Add_interaction_recv_oack(
5413 TFTP_FIRST_FD,
5414 FIRST_TIMEOUT_MILLISECONDS,
5415 SERV_PORT,
5416 tftpfs_ipv4_loopback,
5417 options,
5418 sizeof( options ),
5419 true
5420 );
5421 _Tftp_Add_interaction_send_data(
5422 TFTP_FIRST_FD,
5423 block_num,
5424 pos_in_file,
5425 block_size,
5426 get_file_content,
5427 SERV_PORT,
5428 tftpfs_ipv4_loopback,
5429 true
5430 );
5431 pos_in_file += block_size;
5432 _Tftp_Add_interaction_recv_ack(
5433 TFTP_FIRST_FD,
5434 FIRST_TIMEOUT_MILLISECONDS,
5435 SERV_PORT,
5436 tftpfs_ipv4_loopback,
5437 block_num++,
5438 true
5439 );
5440 _Tftp_Add_interaction_send_data(
5441 TFTP_FIRST_FD,
5442 block_num,
5443 pos_in_file,
5444 block_size,
5445 get_file_content,
5446 SERV_PORT,
5447 tftpfs_ipv4_loopback,
5448 true
5449 );
5450 pos_in_file += block_size;
5451 _Tftp_Add_interaction_recv_ack(
5452 TFTP_FIRST_FD,
5453 FIRST_TIMEOUT_MILLISECONDS,
5454 SERV_PORT,
5455 tftpfs_ipv4_loopback,
5456 block_num++,
5457 true
5458 );
5459 _Tftp_Add_interaction_send_data(
5460 TFTP_FIRST_FD,
5461 block_num,
5462 pos_in_file,
5463 1,
5464 get_file_content,
5465 SERV_PORT,
5466 tftpfs_ipv4_loopback,
5467 true
5468 );
5469 pos_in_file += 1;
5470 _Tftp_Add_interaction_recv_ack(
5471 TFTP_FIRST_FD,
5472 FIRST_TIMEOUT_MILLISECONDS,
5473 SERV_PORT,
5474 tftpfs_ipv4_loopback,
5475 block_num++,
5476 true
5477 );
5478 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
5479
5480 bytes_written = write_tftp_file(
5481 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
5482 pos_in_file,
5483 333,
5484 &ctx->fd0
5485 );
5486 T_eq_int( bytes_written, pos_in_file );
5487 T_no_more_interactions();
5488 }
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503 T_TEST_CASE_FIXTURE(
5504 write_simple_file_default_options,
5505 &fixture_default_options
5506 )
5507 {
5508 tftp_test_context *ctx = T_fixture_context();
5509 int i;
5510 int bytes_written;
5511 size_t pos_in_file = 0;
5512 uint16_t block_num = 1;
5513 const char options[] =
5514 TFTP_OPTION_BLKSIZE "\0"
5515 RTEMS_XSTRING( TFTP_DEFAULT_BLOCK_SIZE ) "\0"
5516 TFTP_OPTION_WINDOWSIZE "\0"
5517 RTEMS_XSTRING( TFTP_DEFAULT_WINDOW_SIZE );
5518
5519
5520 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
5521 _Tftp_Add_interaction_send_wrq(
5522 TFTP_FIRST_FD,
5523 tftpfs_file,
5524 TFTP_STD_PORT,
5525 tftpfs_ipv4_loopback,
5526 TFTP_DEFAULT_BLOCK_SIZE,
5527 TFTP_DEFAULT_WINDOW_SIZE,
5528 true
5529 );
5530 _Tftp_Add_interaction_recv_oack(
5531 TFTP_FIRST_FD,
5532 FIRST_TIMEOUT_MILLISECONDS,
5533 SERV_PORT,
5534 tftpfs_ipv4_loopback,
5535 options,
5536 sizeof( options ),
5537 true
5538 );
5539 for ( i = 0; i < 23; ++i ) {
5540 _Tftp_Add_interaction_send_data(
5541 TFTP_FIRST_FD,
5542 block_num++,
5543 pos_in_file,
5544 TFTP_DEFAULT_BLOCK_SIZE,
5545 get_file_content,
5546 SERV_PORT,
5547 tftpfs_ipv4_loopback,
5548 true
5549 );
5550 pos_in_file += TFTP_DEFAULT_BLOCK_SIZE;
5551 if ( i % 8 == 7 ) {
5552 _Tftp_Add_interaction_recv_ack(
5553 TFTP_FIRST_FD,
5554 FIRST_TIMEOUT_MILLISECONDS,
5555 SERV_PORT,
5556 tftpfs_ipv4_loopback,
5557 block_num - 1,
5558 true
5559 );
5560 } else {
5561 _Tftp_Add_interaction_recv_nothing(
5562 TFTP_FIRST_FD,
5563 DO_NOT_WAIT_FOR_ANY_TIMEOUT
5564 );
5565 }
5566 }
5567 _Tftp_Add_interaction_send_data(
5568 TFTP_FIRST_FD,
5569 block_num,
5570 pos_in_file,
5571 0,
5572 get_file_content,
5573 SERV_PORT,
5574 tftpfs_ipv4_loopback,
5575 true
5576 );
5577 _Tftp_Add_interaction_recv_ack(
5578 TFTP_FIRST_FD,
5579 FIRST_TIMEOUT_MILLISECONDS,
5580 SERV_PORT,
5581 tftpfs_ipv4_loopback,
5582 block_num++,
5583 true
5584 );
5585 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
5586
5587 bytes_written = write_tftp_file(
5588 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
5589 pos_in_file,
5590 333,
5591 &ctx->fd0
5592 );
5593 T_eq_int( bytes_written, pos_in_file );
5594 T_no_more_interactions();
5595 }
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610 T_TEST_CASE_FIXTURE( write_file_rfc7440_scenario, &fixture_small_opt_size )
5611 {
5612 tftp_test_context *ctx = T_fixture_context();
5613 int i;
5614 int bytes_written;
5615 size_t pos_in_file = 0;
5616 uint16_t block_num = 1;
5617 const char options[] =
5618 TFTP_OPTION_WINDOWSIZE"\0"
5619 RTEMS_XSTRING( SMALL_WINDOW_SIZE ) "\0"
5620 TFTP_OPTION_BLKSIZE "\0"
5621 RTEMS_XSTRING( SMALL_BLOCK_SIZE );
5622
5623
5624 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
5625 _Tftp_Add_interaction_send_wrq(
5626 TFTP_FIRST_FD,
5627 tftpfs_file,
5628 TFTP_STD_PORT,
5629 tftpfs_ipv4_loopback,
5630 SMALL_BLOCK_SIZE,
5631 SMALL_WINDOW_SIZE,
5632 true
5633 );
5634 _Tftp_Add_interaction_recv_oack(
5635 TFTP_FIRST_FD,
5636 FIRST_TIMEOUT_MILLISECONDS,
5637 SERV_PORT,
5638 tftpfs_ipv4_loopback,
5639 options,
5640 sizeof( options ),
5641 true
5642 );
5643 for ( i = 0; i < 6; ++i ) {
5644 _Tftp_Add_interaction_send_data(
5645 TFTP_FIRST_FD,
5646 block_num++,
5647 pos_in_file,
5648 SMALL_BLOCK_SIZE,
5649 get_file_content,
5650 SERV_PORT,
5651 tftpfs_ipv4_loopback,
5652 true
5653 );
5654 pos_in_file += SMALL_BLOCK_SIZE;
5655 if ( i % 4 == 3 ) {
5656 _Tftp_Add_interaction_recv_ack(
5657 TFTP_FIRST_FD,
5658 FIRST_TIMEOUT_MILLISECONDS,
5659 SERV_PORT,
5660 tftpfs_ipv4_loopback,
5661 block_num - 1,
5662 true
5663 );
5664 } else {
5665 _Tftp_Add_interaction_recv_nothing(
5666 TFTP_FIRST_FD,
5667 DO_NOT_WAIT_FOR_ANY_TIMEOUT
5668 );
5669 }
5670 }
5671 _Tftp_Add_interaction_send_data(
5672 TFTP_FIRST_FD,
5673 block_num,
5674 pos_in_file,
5675 SMALL_BLOCK_SIZE,
5676 get_file_content,
5677 SERV_PORT,
5678 tftpfs_ipv4_loopback,
5679 true
5680 );
5681 _Tftp_Add_interaction_recv_ack(
5682 TFTP_FIRST_FD,
5683 DO_NOT_WAIT_FOR_ANY_TIMEOUT,
5684 SERV_PORT,
5685 tftpfs_ipv4_loopback,
5686 5,
5687 true
5688 );
5689 block_num = 6;
5690 pos_in_file = (block_num - 1) * SMALL_BLOCK_SIZE;
5691 for ( i = 0; i < 7; ++i ) {
5692 _Tftp_Add_interaction_send_data(
5693 TFTP_FIRST_FD,
5694 block_num++,
5695 pos_in_file,
5696 SMALL_BLOCK_SIZE,
5697 get_file_content,
5698 SERV_PORT,
5699 tftpfs_ipv4_loopback,
5700 true
5701 );
5702 pos_in_file += SMALL_BLOCK_SIZE;
5703 if ( i % 4 == 3 ) {
5704 _Tftp_Add_interaction_recv_ack(
5705 TFTP_FIRST_FD,
5706 FIRST_TIMEOUT_MILLISECONDS,
5707 SERV_PORT,
5708 tftpfs_ipv4_loopback,
5709 block_num - 1,
5710 true
5711 );
5712 } else {
5713 _Tftp_Add_interaction_recv_nothing(
5714 TFTP_FIRST_FD,
5715 DO_NOT_WAIT_FOR_ANY_TIMEOUT
5716 );
5717 }
5718 }
5719 _Tftp_Add_interaction_send_data(
5720 TFTP_FIRST_FD,
5721 block_num,
5722 pos_in_file,
5723 SMALL_BLOCK_SIZE,
5724 get_file_content,
5725 SERV_PORT,
5726 tftpfs_ipv4_loopback,
5727 true
5728 );
5729 _Tftp_Add_interaction_recv_nothing(
5730 TFTP_FIRST_FD,
5731 FIRST_TIMEOUT_MILLISECONDS
5732 );
5733 block_num = 10;
5734 pos_in_file = (block_num - 1) * SMALL_BLOCK_SIZE;
5735 for ( i = 0; i < 4; ++i ) {
5736 _Tftp_Add_interaction_send_data(
5737 TFTP_FIRST_FD,
5738 block_num++,
5739 pos_in_file,
5740 SMALL_BLOCK_SIZE,
5741 get_file_content,
5742 SERV_PORT,
5743 tftpfs_ipv4_loopback,
5744 true
5745 );
5746 pos_in_file += SMALL_BLOCK_SIZE;
5747 if ( i % 4 == 3 ) {
5748 _Tftp_Add_interaction_recv_ack(
5749 TFTP_FIRST_FD,
5750 FIRST_TIMEOUT_MILLISECONDS,
5751 SERV_PORT,
5752 tftpfs_ipv4_loopback,
5753 block_num - 1,
5754 true
5755 );
5756 } else {
5757 _Tftp_Add_interaction_recv_nothing(
5758 TFTP_FIRST_FD,
5759 DO_NOT_WAIT_FOR_ANY_TIMEOUT
5760 );
5761 }
5762 }
5763 _Tftp_Add_interaction_send_data(
5764 TFTP_FIRST_FD,
5765 block_num,
5766 pos_in_file,
5767 0,
5768 get_file_content,
5769 SERV_PORT,
5770 tftpfs_ipv4_loopback,
5771 true
5772 );
5773 _Tftp_Add_interaction_recv_ack(
5774 TFTP_FIRST_FD,
5775 FIRST_TIMEOUT_MILLISECONDS,
5776 SERV_PORT,
5777 tftpfs_ipv4_loopback,
5778 block_num++,
5779 true
5780 );
5781 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
5782
5783 bytes_written = write_tftp_file(
5784 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
5785 pos_in_file,
5786 10,
5787 &ctx->fd0
5788 );
5789 T_eq_int( bytes_written, pos_in_file );
5790 T_no_more_interactions();
5791 }
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822 T_TEST_CASE_FIXTURE( write_file_windowsize_trouble, &fixture_small_opt_size )
5823 {
5824 tftp_test_context *ctx = T_fixture_context();
5825 int i;
5826 int bytes_written;
5827 size_t pos_in_file = 0;
5828 uint16_t block_num = 1;
5829 int timeout = FIRST_TIMEOUT_MILLISECONDS;
5830 const char options[] =
5831 TFTP_OPTION_BLKSIZE "\0"
5832 RTEMS_XSTRING( SMALL_BLOCK_SIZE ) "\0"
5833 TFTP_OPTION_WINDOWSIZE"\0"
5834 RTEMS_XSTRING( SMALL_WINDOW_SIZE );
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848 int16_t pkg_sequence[] = {
5849 -1, 0, -2, 0, -3, 0, -4, 9999,
5850 -1, 0, -2, 0, -3, 0, -4, 2,
5851
5852 -3, 0, -4, 0, -5, 0, -6, 6,
5853 -7, 0, -8, 0, -9, 0, -10, 6,
5854 -7, 10006,
5855 -7, 0, -8, 10008,
5856
5857 -9, 10007, 0, -10, 10013, 0, -11, 0, -12, 12,
5858
5859
5860
5861
5862 -13, 0, -14, 0, -15, 0, -16, 11, 17, 16,
5863
5864
5865 -17, 0, -18, 0, -10019, 9999,
5866 -17, 0, -18, 0, -10019, 16,
5867 -17, 0, -18, 10017,
5868 -18, 0, -10019, 19
5869 };
5870
5871
5872 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
5873 _Tftp_Add_interaction_send_wrq(
5874 TFTP_FIRST_FD,
5875 tftpfs_file,
5876 TFTP_STD_PORT,
5877 tftpfs_ipv4_loopback,
5878 SMALL_BLOCK_SIZE,
5879 SMALL_WINDOW_SIZE,
5880 true
5881 );
5882 _Tftp_Add_interaction_recv_oack(
5883 TFTP_FIRST_FD,
5884 FIRST_TIMEOUT_MILLISECONDS,
5885 SERV_PORT,
5886 tftpfs_ipv4_loopback,
5887 options,
5888 sizeof( options ),
5889 true
5890 );
5891 for ( i = 0; i < RTEMS_ARRAY_SIZE( pkg_sequence ); ++i ) {
5892 if ( pkg_sequence[i] == 0 ) {
5893 _Tftp_Add_interaction_recv_nothing(
5894 TFTP_FIRST_FD,
5895 DO_NOT_WAIT_FOR_ANY_TIMEOUT
5896 );
5897 timeout = FIRST_TIMEOUT_MILLISECONDS;
5898 } else if ( pkg_sequence[i] == 9999 ) {
5899 _Tftp_Add_interaction_recv_nothing(
5900 TFTP_FIRST_FD,
5901 timeout
5902 );
5903 timeout = FIRST_TIMEOUT_MILLISECONDS;
5904 } else if ( pkg_sequence[i] >= 10000 ) {
5905 block_num = pkg_sequence[i] - 10000;
5906 _Tftp_Add_interaction_recv_ack(
5907 TFTP_FIRST_FD,
5908 DO_NOT_WAIT_FOR_ANY_TIMEOUT,
5909 SERV_PORT,
5910 tftpfs_ipv4_loopback,
5911 block_num++,
5912 true
5913 );
5914 timeout = FIRST_TIMEOUT_MILLISECONDS;
5915 } else if ( pkg_sequence[i] > 0 ) {
5916 block_num = pkg_sequence[i];
5917 _Tftp_Add_interaction_recv_ack(
5918 TFTP_FIRST_FD,
5919 timeout,
5920 SERV_PORT,
5921 tftpfs_ipv4_loopback,
5922 block_num++,
5923 true
5924 );
5925 timeout = FIRST_TIMEOUT_MILLISECONDS;
5926 } else if ( pkg_sequence[i] <= -10000 ) {
5927 block_num = -pkg_sequence[i] - 10000;
5928 pos_in_file = (block_num - 1) * SMALL_BLOCK_SIZE;
5929 _Tftp_Add_interaction_send_data(
5930 TFTP_FIRST_FD,
5931 block_num++,
5932 pos_in_file,
5933 0,
5934 get_file_content,
5935 SERV_PORT,
5936 tftpfs_ipv4_loopback,
5937 true
5938 );
5939 timeout = FIRST_TIMEOUT_MILLISECONDS;
5940 } else {
5941 block_num = -pkg_sequence[i];
5942 pos_in_file = (block_num - 1) * SMALL_BLOCK_SIZE;
5943 _Tftp_Add_interaction_send_data(
5944 TFTP_FIRST_FD,
5945 block_num++,
5946 pos_in_file,
5947 SMALL_BLOCK_SIZE,
5948 get_file_content,
5949 SERV_PORT,
5950 tftpfs_ipv4_loopback,
5951 true
5952 );
5953 timeout = FIRST_TIMEOUT_MILLISECONDS;
5954 pos_in_file += SMALL_BLOCK_SIZE;
5955 }
5956 }
5957 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
5958
5959 bytes_written = write_tftp_file(
5960 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
5961 pos_in_file,
5962 SMALL_BLOCK_SIZE,
5963 &ctx->fd0
5964 );
5965 T_eq_int( bytes_written, pos_in_file );
5966 T_no_more_interactions();
5967 }
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979 T_TEST_CASE_FIXTURE( write_tiny_file_OACK_no_options, &fixture_large_blocksize )
5980 {
5981 tftp_test_context *ctx = T_fixture_context();
5982 int bytes_written;
5983 size_t pos_in_file = 0;
5984 uint16_t block_num = 1;
5985 const char options[] = {};
5986
5987
5988 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
5989 _Tftp_Add_interaction_send_wrq(
5990 TFTP_FIRST_FD,
5991 tftpfs_file,
5992 TFTP_STD_PORT,
5993 tftpfs_ipv4_loopback,
5994 LARGE_BLOCK_SIZE,
5995 NO_WINDOW_SIZE_OPTION,
5996 true
5997 );
5998 _Tftp_Add_interaction_recv_oack(
5999 TFTP_FIRST_FD,
6000 FIRST_TIMEOUT_MILLISECONDS,
6001 SERV_PORT,
6002 tftpfs_ipv4_loopback,
6003 options,
6004 sizeof( options ),
6005 true
6006 );
6007 _Tftp_Add_interaction_send_data(
6008 TFTP_FIRST_FD,
6009 block_num,
6010 pos_in_file,
6011 TFTP_RFC1350_BLOCK_SIZE / 2,
6012 get_file_content,
6013 SERV_PORT,
6014 tftpfs_ipv4_loopback,
6015 true
6016 );
6017 pos_in_file += TFTP_RFC1350_BLOCK_SIZE / 2;
6018 _Tftp_Add_interaction_recv_ack(
6019 TFTP_FIRST_FD,
6020 FIRST_TIMEOUT_MILLISECONDS,
6021 SERV_PORT,
6022 tftpfs_ipv4_loopback,
6023 block_num++,
6024 true
6025 );
6026 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6027
6028 bytes_written = write_tftp_file(
6029 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6030 pos_in_file,
6031 2 * TFTP_RFC1350_BLOCK_SIZE,
6032 &ctx->fd0
6033 );
6034 T_eq_int( bytes_written, pos_in_file );
6035 T_no_more_interactions();
6036 }
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052 T_TEST_CASE_FIXTURE( read_file_fallback_to_no_options,
6053 &fixture_default_options )
6054 {
6055 tftp_test_context *ctx = T_fixture_context();
6056 int bytes_read;
6057 uint16_t block_num = 1;
6058 size_t pos_in_file = 0;
6059
6060
6061 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6062 _Tftp_Add_interaction_send_rrq(
6063 TFTP_FIRST_FD,
6064 tftpfs_file,
6065 TFTP_STD_PORT,
6066 tftpfs_ipv4_loopback,
6067 TFTP_DEFAULT_BLOCK_SIZE,
6068 TFTP_DEFAULT_WINDOW_SIZE,
6069 true
6070 );
6071 _Tftp_Add_interaction_recv_error(
6072 TFTP_FIRST_FD,
6073 FIRST_TIMEOUT_MILLISECONDS,
6074 SERV_PORT,
6075 tftpfs_ipv4_loopback,
6076 TFTP_ERROR_CODE_OPTION_NEGO,
6077 "Don't like options",
6078 true
6079 );
6080 _Tftp_Add_interaction_send_rrq(
6081 TFTP_FIRST_FD,
6082 tftpfs_file,
6083 TFTP_STD_PORT,
6084 tftpfs_ipv4_loopback,
6085 NO_BLOCK_SIZE_OPTION,
6086 NO_WINDOW_SIZE_OPTION,
6087 true
6088 );
6089 _Tftp_Add_interaction_recv_data(
6090 TFTP_FIRST_FD,
6091 FIRST_TIMEOUT_MILLISECONDS,
6092 SERV_PORT,
6093 tftpfs_ipv4_loopback,
6094 block_num,
6095 pos_in_file,
6096 1,
6097 get_file_content,
6098 true
6099 );
6100 pos_in_file += 1;
6101 _Tftp_Add_interaction_send_ack(
6102 TFTP_FIRST_FD,
6103 block_num++,
6104 SERV_PORT,
6105 tftpfs_ipv4_loopback,
6106 true
6107 );
6108 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6109
6110 bytes_read = read_tftp_file(
6111 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6112 TFTP_DEFAULT_BLOCK_SIZE / 2,
6113 SIZE_MAX,
6114 &ctx->fd0
6115 );
6116 T_eq_int( bytes_read, pos_in_file );
6117 T_no_more_interactions();
6118 }
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136 T_TEST_CASE_FIXTURE( read_file_useless_fallback_to_no_options,
6137 &fixture_default_options )
6138 {
6139 tftp_test_context *ctx = T_fixture_context();
6140 int bytes_read;
6141
6142
6143 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6144 _Tftp_Add_interaction_send_rrq(
6145 TFTP_FIRST_FD,
6146 tftpfs_file,
6147 TFTP_STD_PORT,
6148 tftpfs_ipv4_loopback,
6149 TFTP_DEFAULT_BLOCK_SIZE,
6150 TFTP_DEFAULT_WINDOW_SIZE,
6151 true
6152 );
6153 _Tftp_Add_interaction_recv_error(
6154 TFTP_FIRST_FD,
6155 FIRST_TIMEOUT_MILLISECONDS,
6156 SERV_PORT,
6157 tftpfs_ipv4_loopback,
6158 TFTP_ERROR_CODE_ILLEGAL,
6159 "Don't like options",
6160 true
6161 );
6162 _Tftp_Add_interaction_send_rrq(
6163 TFTP_FIRST_FD,
6164 tftpfs_file,
6165 TFTP_STD_PORT,
6166 tftpfs_ipv4_loopback,
6167 NO_BLOCK_SIZE_OPTION,
6168 NO_WINDOW_SIZE_OPTION,
6169 true
6170 );
6171 _Tftp_Add_interaction_recv_error(
6172 TFTP_FIRST_FD,
6173 FIRST_TIMEOUT_MILLISECONDS,
6174 SERV_PORT,
6175 tftpfs_ipv4_loopback,
6176 TFTP_ERROR_CODE_ILLEGAL,
6177 "Go away",
6178 true
6179 );
6180 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6181
6182 bytes_read = read_tftp_file(
6183 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6184 TFTP_DEFAULT_BLOCK_SIZE / 2,
6185 SIZE_MAX,
6186 &ctx->fd0
6187 );
6188 T_eq_int( errno, EINVAL );
6189 T_eq_int( bytes_read, 0 );
6190 T_no_more_interactions();
6191 }
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204 T_TEST_CASE_FIXTURE( write_file_ACK_instead_of_OACK, &fixture_default_options )
6205 {
6206 tftp_test_context *ctx = T_fixture_context();
6207 int bytes_written;
6208 size_t pos_in_file = 0;
6209 uint16_t block_num = 0;
6210
6211
6212 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6213 _Tftp_Add_interaction_send_wrq(
6214 TFTP_FIRST_FD,
6215 tftpfs_file,
6216 TFTP_STD_PORT,
6217 tftpfs_ipv4_loopback,
6218 TFTP_DEFAULT_BLOCK_SIZE,
6219 TFTP_DEFAULT_WINDOW_SIZE,
6220 true
6221 );
6222 _Tftp_Add_interaction_recv_ack(
6223 TFTP_FIRST_FD,
6224 FIRST_TIMEOUT_MILLISECONDS,
6225 SERV_PORT,
6226 tftpfs_ipv4_loopback,
6227 block_num++,
6228 true
6229 );
6230 _Tftp_Add_interaction_send_data(
6231 TFTP_FIRST_FD,
6232 block_num,
6233 pos_in_file,
6234 TFTP_RFC1350_BLOCK_SIZE / 2,
6235 get_file_content,
6236 SERV_PORT,
6237 tftpfs_ipv4_loopback,
6238 true
6239 );
6240 pos_in_file += TFTP_RFC1350_BLOCK_SIZE / 2;
6241 _Tftp_Add_interaction_recv_ack(
6242 TFTP_FIRST_FD,
6243 FIRST_TIMEOUT_MILLISECONDS,
6244 SERV_PORT,
6245 tftpfs_ipv4_loopback,
6246 block_num++,
6247 true
6248 );
6249 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6250
6251 bytes_written = write_tftp_file(
6252 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6253 pos_in_file,
6254 2 * TFTP_RFC1350_BLOCK_SIZE,
6255 &ctx->fd0
6256 );
6257 T_eq_int( bytes_written, pos_in_file );
6258 T_no_more_interactions();
6259 }
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274 T_TEST_CASE_FIXTURE( write_file_fallback_to_no_options,
6275 &fixture_default_options )
6276 {
6277 tftp_test_context *ctx = T_fixture_context();
6278 int bytes_written;
6279 size_t pos_in_file = 0;
6280 uint16_t block_num = 0;
6281
6282
6283 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6284 _Tftp_Add_interaction_send_wrq(
6285 TFTP_FIRST_FD,
6286 tftpfs_file,
6287 TFTP_STD_PORT,
6288 tftpfs_ipv4_loopback,
6289 TFTP_DEFAULT_BLOCK_SIZE,
6290 TFTP_DEFAULT_WINDOW_SIZE,
6291 true
6292 );
6293 _Tftp_Add_interaction_recv_error(
6294 TFTP_FIRST_FD,
6295 FIRST_TIMEOUT_MILLISECONDS,
6296 SERV_PORT,
6297 tftpfs_ipv4_loopback,
6298 TFTP_ERROR_CODE_ILLEGAL,
6299 "Don't like options",
6300 true
6301 );
6302 _Tftp_Add_interaction_send_wrq(
6303 TFTP_FIRST_FD,
6304 tftpfs_file,
6305 TFTP_STD_PORT,
6306 tftpfs_ipv4_loopback,
6307 NO_BLOCK_SIZE_OPTION,
6308 NO_WINDOW_SIZE_OPTION,
6309 true
6310 );
6311 _Tftp_Add_interaction_recv_ack(
6312 TFTP_FIRST_FD,
6313 FIRST_TIMEOUT_MILLISECONDS,
6314 SERV_PORT,
6315 tftpfs_ipv4_loopback,
6316 block_num++,
6317 true
6318 );
6319 _Tftp_Add_interaction_send_data(
6320 TFTP_FIRST_FD,
6321 block_num,
6322 pos_in_file,
6323 TFTP_RFC1350_BLOCK_SIZE / 2,
6324 get_file_content,
6325 SERV_PORT,
6326 tftpfs_ipv4_loopback,
6327 true
6328 );
6329 pos_in_file += TFTP_RFC1350_BLOCK_SIZE / 2;
6330 _Tftp_Add_interaction_recv_ack(
6331 TFTP_FIRST_FD,
6332 FIRST_TIMEOUT_MILLISECONDS,
6333 SERV_PORT,
6334 tftpfs_ipv4_loopback,
6335 block_num++,
6336 true
6337 );
6338 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6339
6340 bytes_written = write_tftp_file(
6341 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6342 pos_in_file,
6343 2 * TFTP_RFC1350_BLOCK_SIZE,
6344 &ctx->fd0
6345 );
6346 T_eq_int( bytes_written, pos_in_file );
6347 T_no_more_interactions();
6348 }
6349
6350
6351
6352
6353 T_TEST_CASE_FIXTURE( OACK_without_null, &fixture_default_options )
6354 {
6355 tftp_test_context *ctx = T_fixture_context();
6356 int bytes_read;
6357 const char options[] = { 'b', 'l', 'k', 's', 'i', 'z', 'e', '\0', '1', '2' };
6358
6359
6360 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6361 _Tftp_Add_interaction_send_rrq(
6362 TFTP_FIRST_FD,
6363 tftpfs_file,
6364 TFTP_STD_PORT,
6365 tftpfs_ipv4_loopback,
6366 TFTP_DEFAULT_BLOCK_SIZE,
6367 TFTP_DEFAULT_WINDOW_SIZE,
6368 true
6369 );
6370 _Tftp_Add_interaction_recv_oack(
6371 TFTP_FIRST_FD,
6372 FIRST_TIMEOUT_MILLISECONDS,
6373 SERV_PORT,
6374 tftpfs_ipv4_loopback,
6375 options,
6376 sizeof( options ),
6377 true
6378 );
6379 _Tftp_Add_interaction_send_error(
6380 TFTP_FIRST_FD,
6381 TFTP_ERROR_CODE_OPTION_NEGO,
6382 SERV_PORT,
6383 tftpfs_ipv4_loopback,
6384 true
6385 );
6386 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6387
6388 bytes_read = read_tftp_file(
6389 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6390 LARGE_BLOCK_SIZE,
6391 SIZE_MAX,
6392 &ctx->fd0
6393 );
6394 T_eq_int( errno, EPROTO );
6395 T_eq_int( bytes_read, 0 );
6396 T_no_more_interactions();
6397 }
6398
6399
6400
6401
6402 T_TEST_CASE_FIXTURE( OACK_without_option_value, &fixture_default_options )
6403 {
6404 tftp_test_context *ctx = T_fixture_context();
6405 int bytes_read;
6406 const char options[] = TFTP_OPTION_BLKSIZE;
6407
6408
6409 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6410 _Tftp_Add_interaction_send_rrq(
6411 TFTP_FIRST_FD,
6412 tftpfs_file,
6413 TFTP_STD_PORT,
6414 tftpfs_ipv4_loopback,
6415 TFTP_DEFAULT_BLOCK_SIZE,
6416 TFTP_DEFAULT_WINDOW_SIZE,
6417 true
6418 );
6419 _Tftp_Add_interaction_recv_oack(
6420 TFTP_FIRST_FD,
6421 FIRST_TIMEOUT_MILLISECONDS,
6422 SERV_PORT,
6423 tftpfs_ipv4_loopback,
6424 options,
6425 sizeof( options ),
6426 true
6427 );
6428 _Tftp_Add_interaction_send_error(
6429 TFTP_FIRST_FD,
6430 TFTP_ERROR_CODE_OPTION_NEGO,
6431 SERV_PORT,
6432 tftpfs_ipv4_loopback,
6433 true
6434 );
6435 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6436
6437 bytes_read = read_tftp_file(
6438 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6439 LARGE_BLOCK_SIZE,
6440 SIZE_MAX,
6441 &ctx->fd0
6442 );
6443 T_eq_int( errno, EPROTO );
6444 T_eq_int( bytes_read, 0 );
6445 T_no_more_interactions();
6446 }
6447
6448
6449
6450
6451 T_TEST_CASE_FIXTURE( OACK_with_unknown_option, &fixture_default_options )
6452 {
6453 tftp_test_context *ctx = T_fixture_context();
6454 int bytes_read;
6455 const char options[] =
6456 "shoesize" "\0"
6457 RTEMS_XSTRING( TFTP_DEFAULT_BLOCK_SIZE );
6458
6459
6460 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6461 _Tftp_Add_interaction_send_rrq(
6462 TFTP_FIRST_FD,
6463 tftpfs_file,
6464 TFTP_STD_PORT,
6465 tftpfs_ipv4_loopback,
6466 TFTP_DEFAULT_BLOCK_SIZE,
6467 TFTP_DEFAULT_WINDOW_SIZE,
6468 true
6469 );
6470 _Tftp_Add_interaction_recv_oack(
6471 TFTP_FIRST_FD,
6472 FIRST_TIMEOUT_MILLISECONDS,
6473 SERV_PORT,
6474 tftpfs_ipv4_loopback,
6475 options,
6476 sizeof( options ),
6477 true
6478 );
6479 _Tftp_Add_interaction_send_error(
6480 TFTP_FIRST_FD,
6481 TFTP_ERROR_CODE_OPTION_NEGO,
6482 SERV_PORT,
6483 tftpfs_ipv4_loopback,
6484 true
6485 );
6486 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6487
6488 bytes_read = read_tftp_file(
6489 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6490 LARGE_BLOCK_SIZE,
6491 SIZE_MAX,
6492 &ctx->fd0
6493 );
6494 T_eq_int( errno, EPROTO );
6495 T_eq_int( bytes_read, 0 );
6496 T_no_more_interactions();
6497 }
6498
6499
6500
6501
6502
6503 T_TEST_CASE_FIXTURE( OACK_malformed_option_value, &fixture_default_options )
6504 {
6505 tftp_test_context *ctx = T_fixture_context();
6506 int bytes_read;
6507 const char options[] = TFTP_OPTION_BLKSIZE "\0" "abc";
6508
6509
6510 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6511 _Tftp_Add_interaction_send_rrq(
6512 TFTP_FIRST_FD,
6513 tftpfs_file,
6514 TFTP_STD_PORT,
6515 tftpfs_ipv4_loopback,
6516 TFTP_DEFAULT_BLOCK_SIZE,
6517 TFTP_DEFAULT_WINDOW_SIZE,
6518 true
6519 );
6520 _Tftp_Add_interaction_recv_oack(
6521 TFTP_FIRST_FD,
6522 FIRST_TIMEOUT_MILLISECONDS,
6523 SERV_PORT,
6524 tftpfs_ipv4_loopback,
6525 options,
6526 sizeof( options ),
6527 true
6528 );
6529 _Tftp_Add_interaction_send_error(
6530 TFTP_FIRST_FD,
6531 TFTP_ERROR_CODE_OPTION_NEGO,
6532 SERV_PORT,
6533 tftpfs_ipv4_loopback,
6534 true
6535 );
6536 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6537
6538 bytes_read = read_tftp_file(
6539 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6540 LARGE_BLOCK_SIZE,
6541 SIZE_MAX,
6542 &ctx->fd0
6543 );
6544 T_eq_int( errno, EPROTO );
6545 T_eq_int( bytes_read, 0 );
6546 T_no_more_interactions();
6547 }
6548
6549
6550
6551
6552 T_TEST_CASE_FIXTURE( OACK_with_empty_option_value, &fixture_default_options )
6553 {
6554 tftp_test_context *ctx = T_fixture_context();
6555 int bytes_read;
6556 const char options[] = TFTP_OPTION_BLKSIZE "\0";
6557
6558
6559 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6560 _Tftp_Add_interaction_send_rrq(
6561 TFTP_FIRST_FD,
6562 tftpfs_file,
6563 TFTP_STD_PORT,
6564 tftpfs_ipv4_loopback,
6565 TFTP_DEFAULT_BLOCK_SIZE,
6566 TFTP_DEFAULT_WINDOW_SIZE,
6567 true
6568 );
6569 _Tftp_Add_interaction_recv_oack(
6570 TFTP_FIRST_FD,
6571 FIRST_TIMEOUT_MILLISECONDS,
6572 SERV_PORT,
6573 tftpfs_ipv4_loopback,
6574 options,
6575 sizeof( options ),
6576 true
6577 );
6578 _Tftp_Add_interaction_send_error(
6579 TFTP_FIRST_FD,
6580 TFTP_ERROR_CODE_OPTION_NEGO,
6581 SERV_PORT,
6582 tftpfs_ipv4_loopback,
6583 true
6584 );
6585 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6586
6587 bytes_read = read_tftp_file(
6588 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6589 LARGE_BLOCK_SIZE,
6590 SIZE_MAX,
6591 &ctx->fd0
6592 );
6593 T_eq_int( errno, EPROTO );
6594 T_eq_int( bytes_read, 0 );
6595 T_no_more_interactions();
6596 }
6597
6598
6599
6600
6601 T_TEST_CASE_FIXTURE( OACK_with_empty_option_name, &fixture_default_options )
6602 {
6603 tftp_test_context *ctx = T_fixture_context();
6604 int bytes_read;
6605 const char options[] = "\0" RTEMS_XSTRING( TFTP_DEFAULT_BLOCK_SIZE );
6606
6607
6608 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6609 _Tftp_Add_interaction_send_rrq(
6610 TFTP_FIRST_FD,
6611 tftpfs_file,
6612 TFTP_STD_PORT,
6613 tftpfs_ipv4_loopback,
6614 TFTP_DEFAULT_BLOCK_SIZE,
6615 TFTP_DEFAULT_WINDOW_SIZE,
6616 true
6617 );
6618 _Tftp_Add_interaction_recv_oack(
6619 TFTP_FIRST_FD,
6620 FIRST_TIMEOUT_MILLISECONDS,
6621 SERV_PORT,
6622 tftpfs_ipv4_loopback,
6623 options,
6624 sizeof( options ),
6625 true
6626 );
6627 _Tftp_Add_interaction_send_error(
6628 TFTP_FIRST_FD,
6629 TFTP_ERROR_CODE_OPTION_NEGO,
6630 SERV_PORT,
6631 tftpfs_ipv4_loopback,
6632 true
6633 );
6634 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6635
6636 bytes_read = read_tftp_file(
6637 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6638 LARGE_BLOCK_SIZE,
6639 SIZE_MAX,
6640 &ctx->fd0
6641 );
6642 T_eq_int( errno, EPROTO );
6643 T_eq_int( bytes_read, 0 );
6644 T_no_more_interactions();
6645 }
6646
6647
6648
6649
6650
6651 T_TEST_CASE_FIXTURE( OACK_blocksize_too_small, &fixture_default_options )
6652 {
6653 tftp_test_context *ctx = T_fixture_context();
6654 int bytes_read;
6655 const char options[] = TFTP_OPTION_BLKSIZE "\0" "7";
6656
6657
6658 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6659 _Tftp_Add_interaction_send_rrq(
6660 TFTP_FIRST_FD,
6661 tftpfs_file,
6662 TFTP_STD_PORT,
6663 tftpfs_ipv4_loopback,
6664 TFTP_DEFAULT_BLOCK_SIZE,
6665 TFTP_DEFAULT_WINDOW_SIZE,
6666 true
6667 );
6668 _Tftp_Add_interaction_recv_oack(
6669 TFTP_FIRST_FD,
6670 FIRST_TIMEOUT_MILLISECONDS,
6671 SERV_PORT,
6672 tftpfs_ipv4_loopback,
6673 options,
6674 sizeof( options ),
6675 true
6676 );
6677 _Tftp_Add_interaction_send_error(
6678 TFTP_FIRST_FD,
6679 TFTP_ERROR_CODE_OPTION_NEGO,
6680 SERV_PORT,
6681 tftpfs_ipv4_loopback,
6682 true
6683 );
6684 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6685
6686 bytes_read = read_tftp_file(
6687 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6688 LARGE_BLOCK_SIZE,
6689 SIZE_MAX,
6690 &ctx->fd0
6691 );
6692 T_eq_int( errno, EPROTO );
6693 T_eq_int( bytes_read, 0 );
6694 T_no_more_interactions();
6695 }
6696
6697
6698
6699
6700
6701 T_TEST_CASE_FIXTURE( OACK_blocksize_too_large, &fixture_default_options )
6702 {
6703 tftp_test_context *ctx = T_fixture_context();
6704 int bytes_read;
6705 const char options[] = TFTP_OPTION_BLKSIZE "\0" "1457";
6706
6707
6708 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6709 _Tftp_Add_interaction_send_rrq(
6710 TFTP_FIRST_FD,
6711 tftpfs_file,
6712 TFTP_STD_PORT,
6713 tftpfs_ipv4_loopback,
6714 TFTP_DEFAULT_BLOCK_SIZE,
6715 TFTP_DEFAULT_WINDOW_SIZE,
6716 true
6717 );
6718 _Tftp_Add_interaction_recv_oack(
6719 TFTP_FIRST_FD,
6720 FIRST_TIMEOUT_MILLISECONDS,
6721 SERV_PORT,
6722 tftpfs_ipv4_loopback,
6723 options,
6724 sizeof( options ),
6725 true
6726 );
6727 _Tftp_Add_interaction_send_error(
6728 TFTP_FIRST_FD,
6729 TFTP_ERROR_CODE_OPTION_NEGO,
6730 SERV_PORT,
6731 tftpfs_ipv4_loopback,
6732 true
6733 );
6734 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6735
6736 bytes_read = read_tftp_file(
6737 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6738 LARGE_BLOCK_SIZE,
6739 SIZE_MAX,
6740 &ctx->fd0
6741 );
6742 T_eq_int( errno, EPROTO );
6743 T_eq_int( bytes_read, 0 );
6744 T_no_more_interactions();
6745 }
6746
6747
6748
6749
6750
6751 T_TEST_CASE_FIXTURE( OACK_windowsize_too_small, &fixture_default_options )
6752 {
6753 tftp_test_context *ctx = T_fixture_context();
6754 int bytes_read;
6755 const char options[] = TFTP_OPTION_WINDOWSIZE "\0" "0";
6756
6757
6758 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6759 _Tftp_Add_interaction_send_rrq(
6760 TFTP_FIRST_FD,
6761 tftpfs_file,
6762 TFTP_STD_PORT,
6763 tftpfs_ipv4_loopback,
6764 TFTP_DEFAULT_BLOCK_SIZE,
6765 TFTP_DEFAULT_WINDOW_SIZE,
6766 true
6767 );
6768 _Tftp_Add_interaction_recv_oack(
6769 TFTP_FIRST_FD,
6770 FIRST_TIMEOUT_MILLISECONDS,
6771 SERV_PORT,
6772 tftpfs_ipv4_loopback,
6773 options,
6774 sizeof( options ),
6775 true
6776 );
6777 _Tftp_Add_interaction_send_error(
6778 TFTP_FIRST_FD,
6779 TFTP_ERROR_CODE_OPTION_NEGO,
6780 SERV_PORT,
6781 tftpfs_ipv4_loopback,
6782 true
6783 );
6784 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6785
6786 bytes_read = read_tftp_file(
6787 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6788 LARGE_BLOCK_SIZE,
6789 SIZE_MAX,
6790 &ctx->fd0
6791 );
6792 T_eq_int( errno, EPROTO );
6793 T_eq_int( bytes_read, 0 );
6794 T_no_more_interactions();
6795 }
6796
6797
6798
6799
6800 T_TEST_CASE_FIXTURE( OACK_windowsize_too_large, &fixture_default_options )
6801 {
6802 tftp_test_context *ctx = T_fixture_context();
6803 int bytes_read;
6804 const char options[] = TFTP_OPTION_WINDOWSIZE "\0" "9";
6805
6806
6807 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6808 _Tftp_Add_interaction_send_rrq(
6809 TFTP_FIRST_FD,
6810 tftpfs_file,
6811 TFTP_STD_PORT,
6812 tftpfs_ipv4_loopback,
6813 TFTP_DEFAULT_BLOCK_SIZE,
6814 TFTP_DEFAULT_WINDOW_SIZE,
6815 true
6816 );
6817 _Tftp_Add_interaction_recv_oack(
6818 TFTP_FIRST_FD,
6819 FIRST_TIMEOUT_MILLISECONDS,
6820 SERV_PORT,
6821 tftpfs_ipv4_loopback,
6822 options,
6823 sizeof( options ),
6824 true
6825 );
6826 _Tftp_Add_interaction_send_error(
6827 TFTP_FIRST_FD,
6828 TFTP_ERROR_CODE_OPTION_NEGO,
6829 SERV_PORT,
6830 tftpfs_ipv4_loopback,
6831 true
6832 );
6833 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6834
6835 bytes_read = read_tftp_file(
6836 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6837 LARGE_BLOCK_SIZE,
6838 SIZE_MAX,
6839 &ctx->fd0
6840 );
6841 T_eq_int( errno, EPROTO );
6842 T_eq_int( bytes_read, 0 );
6843 T_no_more_interactions();
6844 }
6845
6846
6847
6848
6849 T_TEST_CASE_FIXTURE( OACK_with_surplus_option, &fixture_large_blocksize )
6850 {
6851 tftp_test_context *ctx = T_fixture_context();
6852 int bytes_read;
6853 const char options[] =
6854 TFTP_OPTION_BLKSIZE "\0"
6855 RTEMS_XSTRING( LARGE_BLOCK_SIZE ) "\0"
6856 TFTP_OPTION_WINDOWSIZE "\0"
6857 "1";
6858
6859
6860 _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
6861 _Tftp_Add_interaction_send_rrq(
6862 TFTP_FIRST_FD,
6863 tftpfs_file,
6864 TFTP_STD_PORT,
6865 tftpfs_ipv4_loopback,
6866 LARGE_BLOCK_SIZE,
6867 NO_WINDOW_SIZE_OPTION,
6868 true
6869 );
6870 _Tftp_Add_interaction_recv_oack(
6871 TFTP_FIRST_FD,
6872 FIRST_TIMEOUT_MILLISECONDS,
6873 SERV_PORT,
6874 tftpfs_ipv4_loopback,
6875 options,
6876 sizeof( options ),
6877 true
6878 );
6879 _Tftp_Add_interaction_send_error(
6880 TFTP_FIRST_FD,
6881 TFTP_ERROR_CODE_OPTION_NEGO,
6882 SERV_PORT,
6883 tftpfs_ipv4_loopback,
6884 true
6885 );
6886 _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
6887
6888 bytes_read = read_tftp_file(
6889 create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
6890 LARGE_BLOCK_SIZE,
6891 SIZE_MAX,
6892 &ctx->fd0
6893 );
6894 T_eq_int( errno, EPROTO );
6895 T_eq_int( bytes_read, 0 );
6896 T_no_more_interactions();
6897 }
6898
6899 const char rtems_test_name[] = "TFTPFS";
6900
6901 static void Init( rtems_task_argument argument )
6902 {
6903 rtems_test_run( argument, TEST_STATE );
6904 }
6905
6906
6907
6908
6909
6910 #define CONFIGURE_FILESYSTEM_TFTPFS
6911 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
6912
6913
6914
6915
6916
6917 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
6918 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
6919
6920 #define CONFIGURE_MAXIMUM_TASKS 1
6921
6922 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
6923
6924 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
6925
6926 #define CONFIGURE_INIT
6927
6928 #include <rtems/confdefs.h>