static void test_device_install_remove(void) { static const rtems_termios_device_handler handler; static const char dev[] = "/foobar"; rtems_resource_snapshot snapshot; rtems_status_code sc; void *greedy; int rv; rtems_resource_snapshot_take( &snapshot ); greedy = rtems_heap_greedy_allocate( NULL, 0 ); sc = rtems_termios_device_install( "/", &handler, NULL, NULL ); rtems_test_assert( sc == RTEMS_NO_MEMORY ); rtems_heap_greedy_free( greedy ); rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); sc = rtems_termios_device_install( "/", &handler, NULL, NULL ); rtems_test_assert( sc == RTEMS_UNSATISFIED ); rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); sc = rtems_termios_device_install( &dev[0], &handler, NULL, NULL ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); rv = unlink( &dev[0] ); rtems_test_assert( rv == 0 ); rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); }
static void test_unix_read_write_not_connected(void) { rtems_resource_snapshot snapshot; int sd; int rv; ssize_t n; char buf[1]; puts("test UNIX(4) read/write not connected"); rtems_resource_snapshot_take(&snapshot); sd = socket(PF_UNIX, SOCK_STREAM, 0); assert(sd >= 0); errno = 0; n = write(sd, &buf[0], sizeof(buf)); assert(n == -1); assert(errno == ENOTCONN); errno = 0; n = read(sd, &buf[0], sizeof(buf)); assert(n == -1); assert(errno == ENOTCONN); rv = close(sd); assert(rv == 0); assert(rtems_resource_snapshot_check(&snapshot)); }
static rtems_status_code test_early_device_install( rtems_device_major_number major, rtems_device_minor_number minor, void *arg ) { static const rtems_termios_device_handler handler; static const char dev[] = "/foobar"; rtems_resource_snapshot snapshot; rtems_status_code sc; int fd; int rv; rtems_resource_snapshot_take( &snapshot ); sc = rtems_termios_device_install( &dev[0], &handler, NULL, NULL ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); errno = 0; fd = open( &dev[0], O_RDWR ); rtems_test_assert( fd == -1 ); rtems_test_assert( errno == ENXIO ); rv = unlink( &dev[0] ); rtems_test_assert( rv == 0 ); rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); return RTEMS_SUCCESSFUL; }
void test_shutdown_filesystem(void) { int rc=0; rc=unmount(BASE_FOR_TEST) ; rtems_test_assert(rc==0); rtems_test_assert(rtems_resource_snapshot_check(&before_mount)); del_ramdisk(); }
rtems_task Init(rtems_task_argument ignored) { pthread_key_t key1; pthread_key_t key2; int eno; bool ok; rtems_resource_snapshot snapshot; void *greedy; void *value; TEST_BEGIN(); greedy = rtems_workspace_greedy_allocate( NULL, 0 ); rtems_resource_snapshot_take( &snapshot ); puts( "Init - pthread_key_create - OK" ); eno = pthread_key_create( &key1, NULL ); rtems_test_assert( eno == 0 ); eno = pthread_setspecific( key1, (void *) 1 ); rtems_test_assert( eno == 0 ); value = pthread_getspecific( key1 ); rtems_test_assert( value == (void *) 1 ); eno = pthread_setspecific( key1, NULL ); rtems_test_assert( eno == 0 ); value = pthread_getspecific( key1 ); rtems_test_assert( value == NULL ); eno = pthread_setspecific( key1, NULL ); rtems_test_assert( eno == 0 ); value = pthread_getspecific( key1 ); rtems_test_assert( value == NULL ); puts( "Init - pthread_key_create - EAGAIN" ); eno = pthread_key_create( &key2, NULL ); rtems_test_assert( eno == EAGAIN ); puts( "Init - pthread_key_delete - OK" ); eno = pthread_key_delete( key1 ); rtems_test_assert( eno == 0 ); puts( "Init - verify workspace has same memory" ); ok = rtems_resource_snapshot_check( &snapshot ); rtems_test_assert( ok ); rtems_workspace_greedy_free( greedy ); TEST_END(); rtems_test_exit(0); }
static void Init(rtems_task_argument arg) { rtems_resource_snapshot snapshot; TEST_BEGIN(); rtems_resource_snapshot_take(&snapshot); test(); rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); TEST_END(); rtems_test_exit(0); }
static void *POSIX_Init(void *arg) { rtems_resource_snapshot snapshot; TEST_BEGIN(); rtems_resource_snapshot_take(&snapshot); test(&test_instance); rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); TEST_END(); rtems_test_exit(0); }
static void test_first_open_error(void) { static const rtems_termios_device_handler handler = { .first_open = first_open_error }; static const char dev[] = "/foobar"; rtems_resource_snapshot snapshot; rtems_status_code sc; int fd; int rv; device_context ctx = { .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "abc" ), .done = false }; rtems_resource_snapshot_take( &snapshot ); sc = rtems_termios_device_install( &dev[0], &handler, NULL, &ctx.base ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); rtems_test_assert( !ctx.done ); errno = 0; fd = open( &dev[0], O_RDWR ); rtems_test_assert( fd == -1 ); rtems_test_assert( errno == ENOMEM ); rtems_test_assert( ctx.done ); rv = unlink( &dev[0] ); rtems_test_assert( rv == 0 ); rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); } static bool set_attributes_error( rtems_termios_device_context *base, const struct termios *term ) { device_context *ctx = (device_context *) base; (void) term; ctx->done = true; return false; }
static void test_unix_bind(bool do_close_before_unlink) { rtems_resource_snapshot snapshot; int sd; int rv; struct sockaddr_un addr; printf("test UNIX(4) bind, %s close before unlink\n", do_close_before_unlink ? "with" : "without"); rtems_resource_snapshot_take(&snapshot); sd = socket(PF_UNIX, SOCK_STREAM, 0); assert(sd >= 0); init_address(&addr); errno = 0; rv = open(&name[0], O_RDWR); assert(rv == -1); assert(errno == ENOENT); rv = bind(sd, (const struct sockaddr *) &addr, SUN_LEN(&addr)); assert(rv == 0); errno = 0; rv = open(&name[0], O_RDWR); assert(rv == -1); assert(errno == ENXIO); if (do_close_before_unlink) { rv = close(sd); assert(rv == 0); rv = unlink(&name[0]); assert(rv == 0); } else { rv = unlink(&name[0]); assert(rv == 0); rv = close(sd); assert(rv == 0); } assert(rtems_resource_snapshot_check(&snapshot)); }
static void Init(rtems_task_argument arg) { rtems_resource_snapshot snapshot; TEST_BEGIN(); rtems_resource_snapshot_take(&snapshot); if (rtems_get_processor_count() == CPU_COUNT) { test(); } rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); TEST_END(); rtems_test_exit(0); }
static void Init(rtems_task_argument arg) { rtems_resource_snapshot snapshot; TEST_BEGIN(); rtems_resource_snapshot_take(&snapshot); test_task_get_set_affinity(); test_task_get_set_scheduler(); test_scheduler_ident(); test_scheduler_get_processors(); rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); TEST_END(); rtems_test_exit(0); }
static void unmount_and_close_device( void ) { int rc; rtems_resource_snapshot now; bool are_resources_freed; delete_folder_tree( MOUNT_DIR ); rc = unmount( MOUNT_DIR ); rtems_test_assert( rc == 0 ); are_resources_freed = rtems_resource_snapshot_check( &before_mount ); if ( !are_resources_freed ) rtems_resource_snapshot_take( &now ); rtems_test_assert( are_resources_freed ); }
static void Init(rtems_task_argument arg) { rtems_resource_snapshot snapshot; TEST_BEGIN(); rtems_resource_snapshot_take(&snapshot); test_mrsp_create_errors(); test_mrsp_obtain_release(); test_mrsp_set_priority_errors(); test_mrsp_set_priority(); test_mrsp_timeout_and_not_owner_of_resource(); rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); TEST_END(); rtems_test_exit(0); }
static void test(void) { test_context *ctx = &test_instance; rtems_status_code sc; int rv; rtems_resource_snapshot snapshot; ctx->main_task_id = rtems_task_self(); rtems_resource_snapshot_take(&snapshot); rv = IMFS_make_generic_node( &file_path[0], S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, &node_control, NULL ); rtems_test_assert(rv == 0); sc = rtems_task_create( rtems_build_name('W', 'O', 'R', 'K'), 2, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &ctx->worker_task_id ); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_task_start(ctx->worker_task_id, worker_task, 0); rtems_test_assert(sc == RTEMS_SUCCESSFUL); wait(); sc = rtems_task_delete(ctx->worker_task_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); rv = unlink(&file_path[0]); rtems_test_assert(rv == 0); rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); }
static void test_unix_socket(bool do_resource_check) { rtems_resource_snapshot snapshot; int sd; int rv; printf("test UNIX(4) socket, %s resource check\n", do_resource_check ? "with" : "without"); rtems_resource_snapshot_take(&snapshot); sd = socket(PF_UNIX, SOCK_STREAM, 0); assert(sd >= 0); rv = close(sd); assert(rv == 0); if (do_resource_check) { assert(rtems_resource_snapshot_check(&snapshot)); } }
static rtems_status_code test_early_device_install( rtems_device_major_number major, rtems_device_minor_number minor, void *arg ) { static const rtems_termios_device_handler handler; static const char dev[] = "/foobar"; rtems_resource_snapshot snapshot; rtems_status_code sc; int fd; int rv; int i; rtems_resource_snapshot_take( &snapshot ); sc = rtems_termios_device_install( &dev[0], &handler, NULL, NULL ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); /* * The loop ensures that file descriptor 0 is the first free file descriptor * after this test case. */ for (i = 0; i < 4; ++i) { errno = 0; fd = open( &dev[0], O_RDWR ); rtems_test_assert( fd == -1 ); rtems_test_assert( errno == ENXIO ); } rv = unlink( &dev[0] ); rtems_test_assert( rv == 0 ); rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); return RTEMS_SUCCESSFUL; }
static void Init(rtems_task_argument arg) { test_context *ctx = &test_instance; rtems_status_code sc; rtems_resource_snapshot snapshot; uint32_t cpu_count = rtems_get_processor_count(); uint32_t cpu_index; TEST_BEGIN(); rtems_resource_snapshot_take(&snapshot); sc = rtems_barrier_create( rtems_build_name('B', 'A', 'R', 'I'), RTEMS_BARRIER_AUTOMATIC_RELEASE, cpu_count, &ctx->barrier_id ); rtems_test_assert(sc == RTEMS_SUCCESSFUL); for (cpu_index = 1; cpu_index < cpu_count; ++cpu_index) { rtems_id scheduler_id; sc = rtems_task_create( rtems_build_name('T', 'A', 'S', 'K'), 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &ctx->task_id[cpu_index] ); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_scheduler_ident(SCHED_NAME(cpu_index), &scheduler_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_task_set_scheduler(ctx->task_id[cpu_index], scheduler_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_task_start(ctx->task_id[cpu_index], test_task, cpu_index); rtems_test_assert(sc == RTEMS_SUCCESSFUL); } tests(); barrier_wait(ctx); sc = rtems_barrier_delete(ctx->barrier_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); done(0); for (cpu_index = 1; cpu_index < cpu_count; ++cpu_index) { sc = rtems_task_delete(ctx->task_id[cpu_index]); rtems_test_assert(sc == RTEMS_SUCCESSFUL); rtems_test_assert(ctx->cpu_index[cpu_index] == cpu_index); done(cpu_index); } rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); TEST_END(); rtems_test_exit(0); }
static void test_bdpart(void) { rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_bdpart_partition created_partitions [PARTITION_COUNT]; rtems_bdpart_format actual_format; rtems_bdpart_partition actual_partitions [PARTITION_COUNT]; rtems_resource_snapshot before; size_t actual_count = PARTITION_COUNT; size_t i = 0; memset(&created_partitions [0], 0, sizeof(created_partitions)); memset(&actual_format, 0, sizeof(actual_format)); memset(&actual_partitions [0], 0, sizeof(actual_partitions)); rtems_resource_snapshot_take(&before); for (i = 0; i < PARTITION_COUNT; ++i) { rtems_bdpart_to_partition_type( RTEMS_BDPART_MBR_FAT_32, created_partitions [i].type ); } sc = rtems_bdpart_create( rda, &format, &created_partitions [0], &distribution [0], PARTITION_COUNT ); ASSERT_SC(sc); sc = rtems_bdpart_write( rda, &format, &created_partitions [0], PARTITION_COUNT ); ASSERT_SC(sc); sc = rtems_bdpart_read( rda, &actual_format, &actual_partitions [0], &actual_count ); ASSERT_SC(sc); rtems_test_assert(actual_format.mbr.disk_id == format.mbr.disk_id); rtems_test_assert( memcmp( &actual_partitions [0], &created_partitions [0], PARTITION_COUNT ) == 0 ); sc = rtems_bdpart_register( rda, actual_partitions, actual_count ); ASSERT_SC(sc); test_logical_disks(&bdpart_rdax [0], true); sc = rtems_bdpart_unregister( rda, actual_partitions, actual_count ); ASSERT_SC(sc); test_logical_disks(&bdpart_rdax [0], false); rtems_test_assert(rtems_resource_snapshot_check(&before)); sc = rtems_bdpart_register_from_disk(rda); ASSERT_SC(sc); test_logical_disks(&bdpart_rdax [0], true); sc = rtems_bdpart_unregister( rda, actual_partitions, actual_count ); ASSERT_SC(sc); test_logical_disks(&bdpart_rdax [0], false); rtems_test_assert(rtems_resource_snapshot_check(&before)); rtems_bdpart_dump(&actual_partitions [0], actual_count); }
static void test_unix_listen_connect_accept_write_read(void) { static const char sd2_to_sd3[] = "some data from sd2 for sd3"; static const char sd3_to_sd2[] = "and other data from sd3 for sd2"; rtems_resource_snapshot snapshot; int sd; int sd2; int sd3; int rv; struct sockaddr_un addr; struct sockaddr_un addr3; socklen_t addr3_len; ssize_t n; char buf[MAX(sizeof(sd2_to_sd3), sizeof(sd3_to_sd2))]; puts("test UNIX(4) listen/connect/accept/write/read"); rtems_resource_snapshot_take(&snapshot); sd = socket(PF_UNIX, SOCK_STREAM, 0); assert(sd >= 0); init_address(&addr); rv = bind(sd, (const struct sockaddr *) &addr, SUN_LEN(&addr)); assert(rv == 0); rv = listen(sd, 0); assert(rv == 0); sd2 = socket(PF_UNIX, SOCK_STREAM, 0); assert(sd2 >= 0); rv = connect(sd2, (const struct sockaddr *) &addr, SUN_LEN(&addr)); assert(rv == 0); addr3_len = sizeof(addr3); sd3 = accept(sd, (struct sockaddr *) &addr3, &addr3_len); assert(sd3 >= 0); n = write(sd2, &sd2_to_sd3[0], sizeof(sd2_to_sd3)); assert(n == (ssize_t) sizeof(sd2_to_sd3)); n = write(sd3, &sd3_to_sd2[0], sizeof(sd3_to_sd2)); assert(n == (ssize_t) sizeof(sd3_to_sd2)); memset(&buf[0], 'X', sizeof(buf)); n = read(sd3, &buf[0], sizeof(buf)); assert(n == (ssize_t) sizeof(sd2_to_sd3)); assert(memcmp(&sd2_to_sd3[0], &buf[0], sizeof(sd2_to_sd3)) == 0); memset(&buf[0], 'X', sizeof(buf)); n = read(sd2, &buf[0], sizeof(buf)); assert(n == (ssize_t) sizeof(sd3_to_sd2)); assert(memcmp(&sd3_to_sd2[0], &buf[0], sizeof(sd3_to_sd2)) == 0); rv = close(sd3); assert(rv == 0); rv = close(sd2); assert(rv == 0); rv = close(sd); assert(rv == 0); rv = unlink(&name[0]); assert(rv == 0); assert(rtems_resource_snapshot_check(&snapshot)); }
static void test_set_attributes_error(void) { static const rtems_termios_device_handler handler = { .set_attributes = set_attributes_error }; static const char dev[] = "/foobar"; rtems_resource_snapshot snapshot; rtems_status_code sc; struct termios term; device_context ctx = { .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "abc" ), .done = false }; int fd; int rv; rtems_resource_snapshot_take( &snapshot ); sc = rtems_termios_device_install( &dev[0], &handler, NULL, &ctx.base ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); fd = open( &dev[0], O_RDWR ); rtems_test_assert( fd >= 0 ); rtems_test_assert( !ctx.done ); errno = 0; rv = ioctl( fd, TIOCSETA, &term ); rtems_test_assert( rv == -1 ); rtems_test_assert( errno == EIO ); rtems_test_assert( ctx.done ); rv = close( fd ); rtems_test_assert( rv == 0 ); rv = unlink( &dev[0] ); rtems_test_assert( rv == 0 ); rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); } static void test_set_best_baud(void) { static const struct { uint32_t baud; speed_t speed; } baud_to_speed_table[] = { { 0, B0 }, { 25, B0 }, { 26, B50 }, { 50, B50 }, { 62, B50 }, { 63, B75 }, { 75, B75 }, { 110, B110 }, { 134, B134 }, { 150, B150 }, { 200, B200 }, { 300, B300 }, { 600, B600 }, { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 }, { 4800, B4800 }, { 9600, B9600 }, { 19200, B19200 }, { 38400, B38400 }, { 57600, B57600 }, { 115200, B115200 }, { 230400, B230400 }, { 460800, B460800 }, { 0xffffffff, B460800 } }; size_t n = RTEMS_ARRAY_SIZE(baud_to_speed_table); size_t i; for ( i = 0; i < n; ++i ) { struct termios term; memset( &term, 0xff, sizeof( term ) ); rtems_termios_set_best_baud( &term, baud_to_speed_table[ i ].baud ); rtems_test_assert( term.c_ispeed == baud_to_speed_table[ i ].speed ); rtems_test_assert( term.c_ospeed == baud_to_speed_table[ i ].speed ); } } static rtems_task Init( rtems_task_argument ignored ) { int rc; rtems_status_code sc; rtems_device_major_number registered; int test; struct termios t; int index = 0; TEST_BEGIN(); test_termios_baud2index(); test_termios_baud2number(); test_termios_number_to_baud(); sc = rtems_termios_bufsize( 256, 128, 64 ); directive_failed( sc, "rtems_termios_bufsize" ); /* * Register a driver */ puts( "\n" "Init - rtems_io_register_driver - Termios Test Driver - OK" ); sc = rtems_io_register_driver( 0, &test_driver, ®istered ); printf( "Init - Major slot returned = %d\n", (int) registered ); directive_failed( sc, "rtems_io_register_driver" ); /* * Test baud rate */ puts( "Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); if ( test == -1 ) { printf( "ERROR - baud opening test device (%d)\n", test ); rtems_test_exit(0); } /* * tcsetattr - ERROR invalid operation */ puts( "tcsetattr - invalid operation - EINVAL" ); rc = tcsetattr( test, INT_MAX, &t ); rtems_test_assert( rc == -1 ); rtems_test_assert( errno == EINVAL ); test_termios_cfmakeraw(); test_termios_cfmakesane(); /* * tcsetattr - TCSADRAIN */ puts( "\ntcsetattr - drain - OK" ); rc = tcsetattr( test, TCSADRAIN, &t ); rtems_test_assert( rc == 0 ); test_termios_set_baud(test); puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); rc = close( test ); if ( rc != 0 ) { printf( "ERROR - baud close test device (%d) %s\n", test, strerror(errno) ); rtems_test_exit(0); } /* * Test character size */ puts( "\n" "Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); if ( test == -1 ) { printf( "ERROR - size open test device (%d) %s\n", test, strerror(errno) ); rtems_test_exit(0); } test_termios_set_charsize(test); puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); rc = close( test ); if ( rc != 0 ) { printf( "ERROR - size close test device (%d) %s\n", test, strerror(errno) ); rtems_test_exit(0); } /* * Test parity */ puts( "\n" "Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); if ( test == -1 ) { printf( "ERROR - parity open test device (%d) %s\n", test, strerror(errno) ); rtems_test_exit(0); } test_termios_set_parity(test); puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); rc = close( test ); if ( rc != 0 ) { printf( "ERROR - parity close test device (%d) %s\n", test, strerror(errno) ); rtems_test_exit(0); } /* * Test stop bits */ puts( "\n" "Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); if ( test == -1 ) { printf( "ERROR - stop bits open test device (%d) %s\n", test, strerror(errno) ); rtems_test_exit(0); } test_termios_set_stop_bits(test); test_termios_cfoutspeed(); test_termios_cfinspeed(); test_termios_cfsetspeed(); puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); rc = close( test ); if ( rc != 0 ) { printf( "ERROR - stop bits close test device (%d) %s\n", test, strerror(errno) ); rtems_test_exit(0); } puts( "Multiple open of the device" ); for( ; index < 26; ++index ) { test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); rtems_test_assert( test != -1 ); rc = close( test ); rtems_test_assert( rc == 0 ); } puts( "" ); test_device_install_remove(); test_first_open_error(); test_set_attributes_error(); test_set_best_baud(); TEST_END(); rtems_test_exit(0); }
rtems_task Init( rtems_task_argument ignored ) { rtems_id region1; rtems_id region2; rtems_status_code sc; bool ok; uintptr_t to_alloc; void *alloced; rtems_resource_snapshot snapshot; void *greedy; TEST_BEGIN(); puts( "Allocate one region -- so second auto extends" ); sc = rtems_region_create( rtems_build_name( 'R', 'N', '1', ' ' ), Area1, sizeof(Area1), 8, RTEMS_DEFAULT_ATTRIBUTES, ®ion1 ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); greedy = rtems_workspace_greedy_allocate_all_except_largest( &to_alloc ); rtems_resource_snapshot_take( &snapshot ); puts( "Init - rtems_region_create - auto-extend - RTEMS_UNSATISFIED" ); while ( to_alloc > 8 ) { ok = rtems_workspace_allocate( to_alloc, &alloced ); rtems_test_assert( ok ); sc = rtems_region_create( rtems_build_name( 'R', 'N', '2', ' ' ), Area2, sizeof(Area2), 8, RTEMS_DEFAULT_ATTRIBUTES, ®ion2 ); rtems_workspace_free( alloced ); if ( sc == RTEMS_SUCCESSFUL ) break; rtems_test_assert( sc == RTEMS_TOO_MANY ); /* * Verify heap is still in same shape if we couldn't allocate a region */ ok = rtems_resource_snapshot_check( &snapshot ); rtems_test_assert( ok ); to_alloc -= 8; } rtems_test_assert( sc == RTEMS_SUCCESSFUL ); /* * Verify heap is still in same shape after we free the region */ puts( "Init - rtems_region_delete - OK" ); sc = rtems_region_delete( region2 ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); puts( "Init - verify workspace has same memory" ); ok = rtems_resource_snapshot_check( &snapshot ); rtems_test_assert( ok ); rtems_workspace_greedy_free( greedy ); TEST_END(); rtems_test_exit(0); }
static void test(void) { rtems_resource_snapshot snapshot; test_bus *bus; int rv; int fd; rtems_resource_snapshot_take(&snapshot); bus = (test_bus *) i2c_bus_alloc_and_init(sizeof(*bus)); rtems_test_assert(bus != NULL); bus->base.transfer = test_transfer; bus->base.set_clock = test_set_clock; bus->base.destroy = test_destroy; bus->base.functionality = I2C_FUNC_I2C | I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_NOSTART; bus->simple_read_write.base.transfer = test_simple_read_write_transfer; bus->devices[0] = &bus->simple_read_write.base; bus->eeprom.base.transfer = test_eeprom_transfer; bus->devices[1] = &bus->eeprom.base; bus->gpio_nxp_pca9535.base.transfer = test_gpio_nxp_pca9535_transfer; bus->devices[2] = &bus->gpio_nxp_pca9535.base; bus->switch_nxp_pca9548a.base.transfer = test_switch_nxp_pca9548a_transfer; bus->devices[3] = &bus->switch_nxp_pca9548a.base; rv = i2c_bus_register(&bus->base, &bus_path[0]); rtems_test_assert(rv == 0); fd = open(&bus_path[0], O_RDWR); rtems_test_assert(fd >= 0); rtems_test_assert(bus->clock == 0); rv = ioctl(fd, I2C_BUS_SET_CLOCK, 0xdeadbeefUL); rtems_test_assert(rv == 0); rtems_test_assert(bus->clock == 0xdeadbeef); rv = ioctl(fd, I2C_BUS_OBTAIN); rtems_test_assert(rv == 0); rv = ioctl(fd, I2C_BUS_RELEASE); rtems_test_assert(rv == 0); rtems_test_assert(!bus->base.ten_bit_address); rv = ioctl(fd, I2C_TENBIT, 1UL); rtems_test_assert(rv == 0); rtems_test_assert(bus->base.ten_bit_address); rv = ioctl(fd, I2C_TENBIT, 0UL); rtems_test_assert(rv == 0); rtems_test_assert(!bus->base.ten_bit_address); rtems_test_assert(!bus->base.use_pec); rv = ioctl(fd, I2C_PEC, 1UL); rtems_test_assert(rv == 0); rtems_test_assert(bus->base.use_pec); rv = ioctl(fd, I2C_PEC, 0UL); rtems_test_assert(rv == 0); rtems_test_assert(!bus->base.use_pec); rv = ioctl(fd, I2C_SLAVE, 123UL); rtems_test_assert(rv == 0); rtems_test_assert(bus->base.default_address == 123); rv = ioctl(fd, I2C_SLAVE_FORCE, 456UL); rtems_test_assert(rv == 0); rtems_test_assert(bus->base.default_address == 456); rtems_test_assert(bus->base.retries == 0); rv = ioctl(fd, I2C_RETRIES, 1UL); rtems_test_assert(rv == 0); rtems_test_assert(bus->base.retries == 1); rv = ioctl(fd, I2C_RETRIES, 0UL); rtems_test_assert(rv == 0); rtems_test_assert(bus->base.retries == 0); rtems_test_assert(bus->base.timeout == 0); rv = ioctl(fd, I2C_TIMEOUT, 1UL); rtems_test_assert(rv == 0); rtems_test_assert(bus->base.timeout == 5); rv = ioctl(fd, I2C_TIMEOUT, 0UL); rtems_test_assert(rv == 0); rtems_test_assert(bus->base.timeout == 0); test_simple_read_write(bus, fd); test_eeprom(bus); test_gpio_nxp_pca9535(); test_switch_nxp_pca9548a(); rv = close(fd); rtems_test_assert(rv == 0); rv = unlink(&bus_path[0]); rtems_test_assert(rv == 0); rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); }