diff --git a/testsuites/samples/base_mp/apptask.c b/testsuites/samples/base_mp/apptask.c index 154748b05b..e8b0e022a8 100644 --- a/testsuites/samples/base_mp/apptask.c +++ b/testsuites/samples/base_mp/apptask.c @@ -44,17 +44,19 @@ #include "tmacros.h" -rtems_task Application_task( - rtems_task_argument node -) +rtems_task Application_task( rtems_task_argument node ) { rtems_id tid; rtems_status_code status; rtems_task_ident( RTEMS_WHO_AM_I, RTEMS_SEARCH_ALL_NODES, &tid ); (void) status; - printf( "This task was invoked with the node argument (%" PRIdrtems_task_argument ")\n", node ); - printf( "This task has the id of 0x%" PRIxrtems_id "\n", tid ); + printf( + "This task was invoked with the node argument (%" PRIdrtems_task_argument + ")\n", + node + ); + printf( "This task has the id of 0x%" PRIxrtems_id "\n", tid ); TEST_END(); exit( 0 ); } diff --git a/testsuites/samples/base_mp/initimpl.h b/testsuites/samples/base_mp/initimpl.h index f653d9de5c..616457f587 100644 --- a/testsuites/samples/base_mp/initimpl.h +++ b/testsuites/samples/base_mp/initimpl.h @@ -37,13 +37,11 @@ #include "tmacros.h" /* forward declarations to avoid warnings */ -rtems_task Init(rtems_task_argument argument); +rtems_task Init( rtems_task_argument argument ); const char rtems_test_name[] = "SAMPLE MULTIPROCESSOR APPLICATION"; -rtems_task Init( - rtems_task_argument argument -) +rtems_task Init( rtems_task_argument argument ) { (void) argument; @@ -54,16 +52,22 @@ rtems_task Init( TEST_BEGIN(); printf( "Creating and starting an application task\n" ); task_name = rtems_build_name( 'T', 'A', '1', ' ' ); - status = rtems_task_create( task_name, 1, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_INTERRUPT_LEVEL(0), RTEMS_DEFAULT_ATTRIBUTES, &tid ); - rtems_test_assert(status == RTEMS_SUCCESSFUL); + status = rtems_task_create( + task_name, + 1, + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_INTERRUPT_LEVEL( 0 ), + RTEMS_DEFAULT_ATTRIBUTES, + &tid + ); + rtems_test_assert( status == RTEMS_SUCCESSFUL ); status = rtems_task_start( tid, Application_task, rtems_object_get_local_node() ); - rtems_test_assert(status == RTEMS_SUCCESSFUL); + rtems_test_assert( status == RTEMS_SUCCESSFUL ); rtems_task_exit(); } diff --git a/testsuites/samples/base_mp/system.h b/testsuites/samples/base_mp/system.h index d4c163aa94..02582c3c47 100644 --- a/testsuites/samples/base_mp/system.h +++ b/testsuites/samples/base_mp/system.h @@ -35,13 +35,9 @@ /* functions */ -rtems_task Init( - rtems_task_argument argument -); +rtems_task Init( rtems_task_argument argument ); -rtems_task Application_task( - rtems_task_argument argument -); +rtems_task Application_task( rtems_task_argument argument ); /* configuration information */ @@ -52,7 +48,7 @@ rtems_task Application_task( #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER -#define CONFIGURE_MAXIMUM_TASKS 2 +#define CONFIGURE_MAXIMUM_TASKS 2 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE diff --git a/testsuites/samples/base_sp/apptask.c b/testsuites/samples/base_sp/apptask.c index 940a05dc93..c047568087 100644 --- a/testsuites/samples/base_sp/apptask.c +++ b/testsuites/samples/base_sp/apptask.c @@ -45,9 +45,7 @@ #include #include -rtems_task Application_task( - rtems_task_argument argument -) +rtems_task Application_task( rtems_task_argument argument ) { rtems_id tid; rtems_status_code status; @@ -58,7 +56,9 @@ rtems_task Application_task( printf( "Application task was invoked with argument (%d) " - "and has id of 0x%" PRIxrtems_id "\n", a, tid + "and has id of 0x%" PRIxrtems_id "\n", + a, + tid ); TEST_END(); diff --git a/testsuites/samples/base_sp/init.c b/testsuites/samples/base_sp/init.c index 91bba607f8..763ed67607 100644 --- a/testsuites/samples/base_sp/init.c +++ b/testsuites/samples/base_sp/init.c @@ -36,15 +36,13 @@ #include /* forward declarations to avoid warnings */ -rtems_task Init(rtems_task_argument argument); +rtems_task Init( rtems_task_argument argument ); const char rtems_test_name[] = "SAMPLE SINGLE PROCESSOR APPLICATION"; #define ARGUMENT 0 -rtems_task Init( - rtems_task_argument argument -) +rtems_task Init( rtems_task_argument argument ) { (void) argument; @@ -57,12 +55,18 @@ rtems_task Init( task_name = rtems_build_name( 'T', 'A', '1', ' ' ); - status = rtems_task_create( task_name, 1, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_INTERRUPT_LEVEL(0), RTEMS_DEFAULT_ATTRIBUTES, &tid ); - directive_failed( status, "create" ); + status = rtems_task_create( + task_name, + 1, + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_INTERRUPT_LEVEL( 0 ), + RTEMS_DEFAULT_ATTRIBUTES, + &tid + ); + directive_failed( status, "create" ); status = rtems_task_start( tid, Application_task, ARGUMENT ); - directive_failed( status, "start" ); + directive_failed( status, "start" ); rtems_task_exit(); } diff --git a/testsuites/samples/base_sp/system.h b/testsuites/samples/base_sp/system.h index 2a88767323..53edaf50d7 100644 --- a/testsuites/samples/base_sp/system.h +++ b/testsuites/samples/base_sp/system.h @@ -35,13 +35,9 @@ /* functions */ -rtems_task Init( - rtems_task_argument argument -); +rtems_task Init( rtems_task_argument argument ); -rtems_task Application_task( - rtems_task_argument argument -); +rtems_task Application_task( rtems_task_argument argument ); /* configuration information */ @@ -50,7 +46,7 @@ rtems_task Application_task( #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER -#define CONFIGURE_MAXIMUM_TASKS 2 +#define CONFIGURE_MAXIMUM_TASKS 2 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION diff --git a/testsuites/samples/capture/init.c b/testsuites/samples/capture/init.c index ddd0d25cb4..7c486763c8 100644 --- a/testsuites/samples/capture/init.c +++ b/testsuites/samples/capture/init.c @@ -44,7 +44,7 @@ const char rtems_test_name[] = "CAPTURE ENGINE"; volatile int can_proceed = 1; -static void notification(int fd, int seconds_remaining, void *arg) +static void notification( int fd, int seconds_remaining, void *arg ) { (void) fd; (void) arg; @@ -55,9 +55,7 @@ static void notification(int fd, int seconds_remaining, void *arg) ); } -rtems_task Init( - rtems_task_argument ignored -) +rtems_task Init( rtems_task_argument ignored ) { (void) ignored; @@ -65,31 +63,25 @@ rtems_task Init( rtems_task_priority old_priority; rtems_mode old_mode; - rtems_print_printer_fprintf_putc(&rtems_test_printer); + rtems_print_printer_fprintf_putc( &rtems_test_printer ); TEST_BEGIN(); - status = rtems_shell_wait_for_input( - STDIN_FILENO, - 20, - notification, - NULL - ); - if (status == RTEMS_SUCCESSFUL) { + status = rtems_shell_wait_for_input( STDIN_FILENO, 20, notification, NULL ); + if ( status == RTEMS_SUCCESSFUL ) { /* lower the task priority to allow created tasks to execute */ - rtems_task_set_priority(RTEMS_SELF, 20, &old_priority); - rtems_task_mode(RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode); + rtems_task_set_priority( RTEMS_SELF, 20, &old_priority ); + rtems_task_mode( RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode ); - while (!can_proceed) - { - printf ("Sleeping\n"); - usleep (1000000); + while ( !can_proceed ) { + printf( "Sleeping\n" ); + usleep( 1000000 ); } - rtems_monitor_init (0); - rtems_capture_cli_init (0); + rtems_monitor_init( 0 ); + rtems_capture_cli_init( 0 ); - setup_tasks_to_watch (); + setup_tasks_to_watch(); rtems_task_exit(); } else { diff --git a/testsuites/samples/capture/system.h b/testsuites/samples/capture/system.h index 181235d0df..97638dc242 100644 --- a/testsuites/samples/capture/system.h +++ b/testsuites/samples/capture/system.h @@ -35,24 +35,15 @@ /* functions */ -rtems_task Init( - rtems_task_argument argument -); +rtems_task Init( rtems_task_argument argument ); -rtems_task test_task( - rtems_task_argument my_number -); +rtems_task test_task( rtems_task_argument my_number ); -void -destory_all_tasks( - const char *who -); +void destory_all_tasks( const char *who ); -bool status_code_bad( - rtems_status_code status_code -); +bool status_code_bad( rtems_status_code status_code ); -extern void setup_tasks_to_watch(void); +extern void setup_tasks_to_watch( void ); /* configuration information */ @@ -68,7 +59,7 @@ extern void setup_tasks_to_watch(void); #define CONFIGURE_UNIFIED_WORK_AREAS #define CONFIGURE_UNLIMITED_OBJECTS -#define CONFIGURE_MAXIMUM_USER_EXTENSIONS (5) +#define CONFIGURE_MAXIMUM_USER_EXTENSIONS ( 5 ) #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION @@ -78,34 +69,32 @@ extern void setup_tasks_to_watch(void); * Keep track of the task id's created, use a large array. */ -#define MAX_TASKS (1000) -#define TASK_INDEX_OFFSET (1) +#define MAX_TASKS ( 1000 ) +#define TASK_INDEX_OFFSET ( 1 ) -extern rtems_id task_id[MAX_TASKS]; +extern rtems_id task_id[ MAX_TASKS ]; /* * Increment the task name. */ -#define NEXT_TASK_NAME(c1, c2, c3, c4) \ - if (c4 == '9') { \ - if (c3 == '9') { \ - if (c2 == 'z') { \ - if (c1 == 'z') { \ - printf("not enough task letters for names !!!\n"); \ - exit( 1 ); \ - } else \ - c1++; \ - c2 = 'a'; \ - } else \ - c2++; \ - c3 = '0'; \ - } else \ - c3++; \ - c4 = '0'; \ - } \ - else \ - c4++ \ - +#define NEXT_TASK_NAME( c1, c2, c3, c4 ) \ + if ( c4 == '9' ) { \ + if ( c3 == '9' ) { \ + if ( c2 == 'z' ) { \ + if ( c1 == 'z' ) { \ + printf( "not enough task letters for names !!!\n" ); \ + exit( 1 ); \ + } else \ + c1++; \ + c2 = 'a'; \ + } else \ + c2++; \ + c3 = '0'; \ + } else \ + c3++; \ + c4 = '0'; \ + } else \ + c4++ /* end of include file */ diff --git a/testsuites/samples/capture/test1.c b/testsuites/samples/capture/test1.c index ee0f5c4f13..7652f20465 100644 --- a/testsuites/samples/capture/test1.c +++ b/testsuites/samples/capture/test1.c @@ -49,10 +49,9 @@ static volatile int capture_CT1a_deleted; static volatile int capture_CT1b_deleted; static volatile int capture_CT1c_deleted; -static void -capture_wait (uint32_t period) +static void capture_wait( uint32_t period ) { - rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (period * 1000)); + rtems_task_wake_after( RTEMS_MICROSECONDS_TO_TICKS( period * 1000 ) ); } /* @@ -65,72 +64,75 @@ capture_wait (uint32_t period) * releases the mutex. This will allow us to capture the * action of priority inversion. */ -static void -capture_CT1a (rtems_task_argument arg) +static void capture_CT1a( rtems_task_argument arg ) { - rtems_id mutex = (rtems_id) arg; + rtems_id mutex = (rtems_id) arg; rtems_status_code sc; - sc = rtems_semaphore_obtain (mutex, RTEMS_WAIT, 0); + sc = rtems_semaphore_obtain( mutex, RTEMS_WAIT, 0 ); - if (sc != RTEMS_SUCCESSFUL) - printf ("error: CT1a: mutex obtain: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( "error: CT1a: mutex obtain: %s\n", rtems_status_text( sc ) ); + } - capture_wait (2500); + capture_wait( 2500 ); - sc = rtems_semaphore_release (mutex); + sc = rtems_semaphore_release( mutex ); - if (sc != RTEMS_SUCCESSFUL) - printf ("error: CT1a: mutex release: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( "error: CT1a: mutex release: %s\n", rtems_status_text( sc ) ); + } capture_CT1a_deleted = 1; rtems_task_exit(); } -static void -capture_CT1b (rtems_task_argument arg) +static void capture_CT1b( rtems_task_argument arg ) { (void) arg; volatile int i; - while (!capture_CT1c_deleted) + while ( !capture_CT1c_deleted ) { i++; + } capture_CT1b_deleted = 1; rtems_task_exit(); } -static void -capture_CT1c (rtems_task_argument arg) +static void capture_CT1c( rtems_task_argument arg ) { rtems_id mutex = (rtems_id) arg; rtems_status_code sc; - sc = rtems_semaphore_obtain (mutex, RTEMS_WAIT, 0); + sc = rtems_semaphore_obtain( mutex, RTEMS_WAIT, 0 ); - if (sc != RTEMS_SUCCESSFUL) - printf ("error: CT1c: mutex obtain: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( "error: CT1c: mutex obtain: %s\n", rtems_status_text( sc ) ); + } - capture_wait (500); + capture_wait( 500 ); - sc = rtems_semaphore_release (mutex); + sc = rtems_semaphore_release( mutex ); - if (sc != RTEMS_SUCCESSFUL) - printf ("error: CT1c: mutex release: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( "error: CT1c: mutex release: %s\n", rtems_status_text( sc ) ); + } capture_CT1c_deleted = 1; rtems_task_exit(); } -static void -capture_test_1 (int argc, - char** argv, - const rtems_monitor_command_arg_t* command_arg, - bool verbose) +static void capture_test_1( + int argc, + char **argv, + const rtems_monitor_command_arg_t *command_arg, + bool verbose +) { (void) argc; (void) argv; @@ -139,7 +141,7 @@ capture_test_1 (int argc, rtems_status_code sc; rtems_name name; - rtems_id id[3]; + rtems_id id[ 3 ]; rtems_id mutex; int loops; @@ -147,140 +149,166 @@ capture_test_1 (int argc, capture_CT1b_deleted = 0; capture_CT1c_deleted = 0; - name = rtems_build_name('C', 'T', 'm', '1'); + name = rtems_build_name( 'C', 'T', 'm', '1' ); - sc = rtems_semaphore_create (name, 1, - RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | - RTEMS_INHERIT_PRIORITY, - 0, &mutex); + sc = rtems_semaphore_create( + name, + 1, + RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY, + 0, + &mutex + ); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: Test 1: cannot mutex: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( "error: Test 1: cannot mutex: %s\n", rtems_status_text( sc ) ); return; } - name = rtems_build_name('C', 'T', '1', 'a'); + name = rtems_build_name( 'C', 'T', '1', 'a' ); - sc = rtems_task_create (name, 102, 2 * 1024, - RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, - RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR, - &id[0]); + sc = rtems_task_create( + name, + 102, + 2 * 1024, + RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, + RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR, + &id[ 0 ] + ); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: Test 1: cannot create CT1a: %s\n", rtems_status_text (sc)); - rtems_semaphore_delete (mutex); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: Test 1: cannot create CT1a: %s\n", + rtems_status_text( sc ) + ); + rtems_semaphore_delete( mutex ); return; } - sc = rtems_task_start (id[0], capture_CT1a, (rtems_task_argument) mutex); + sc = rtems_task_start( id[ 0 ], capture_CT1a, (rtems_task_argument) mutex ); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: Test 1: cannot start CT1a: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: Test 1: cannot start CT1a: %s\n", + rtems_status_text( sc ) + ); rtems_task_exit(); - rtems_semaphore_delete (mutex); + rtems_semaphore_delete( mutex ); return; } - capture_wait (1000); + capture_wait( 1000 ); - name = rtems_build_name('C', 'T', '1', 'b'); + name = rtems_build_name( 'C', 'T', '1', 'b' ); - sc = rtems_task_create (name, 101, 2 * 1024, - RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, - RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR, - &id[1]); + sc = rtems_task_create( + name, + 101, + 2 * 1024, + RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, + RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR, + &id[ 1 ] + ); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: Test 1: cannot create CT1b: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: Test 1: cannot create CT1b: %s\n", + rtems_status_text( sc ) + ); rtems_task_exit(); - rtems_semaphore_delete (mutex); + rtems_semaphore_delete( mutex ); return; } - sc = rtems_task_start (id[1], capture_CT1b, 0); + sc = rtems_task_start( id[ 1 ], capture_CT1b, 0 ); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: Test 1: cannot start CT1b: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: Test 1: cannot start CT1b: %s\n", + rtems_status_text( sc ) + ); rtems_task_exit(); rtems_task_exit(); - rtems_semaphore_delete (mutex); + rtems_semaphore_delete( mutex ); return; } - capture_wait (1000); + capture_wait( 1000 ); - name = rtems_build_name('C', 'T', '1', 'c'); + name = rtems_build_name( 'C', 'T', '1', 'c' ); - sc = rtems_task_create (name, 100, 2 * 1024, - RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, - RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR, - &id[2]); + sc = rtems_task_create( + name, + 100, + 2 * 1024, + RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, + RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR, + &id[ 2 ] + ); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: Test 1: cannot create CT1c: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: Test 1: cannot create CT1c: %s\n", + rtems_status_text( sc ) + ); rtems_task_exit(); rtems_task_exit(); - rtems_semaphore_delete (mutex); + rtems_semaphore_delete( mutex ); return; } - sc = rtems_task_start (id[2], capture_CT1c, (rtems_task_argument) mutex); + sc = rtems_task_start( id[ 2 ], capture_CT1c, (rtems_task_argument) mutex ); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: Test 1: cannot start CT1c: %s\n", rtems_status_text (sc)); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: Test 1: cannot start CT1c: %s\n", + rtems_status_text( sc ) + ); rtems_task_exit(); rtems_task_exit(); rtems_task_exit(); - rtems_semaphore_delete (mutex); + rtems_semaphore_delete( mutex ); return; } loops = 15; - while (!(capture_CT1a_deleted || capture_CT1b_deleted || - capture_CT1c_deleted) && loops) - { + while ( + !( capture_CT1a_deleted || capture_CT1b_deleted || + capture_CT1c_deleted ) && + loops + ) { loops--; - capture_wait (1000); + capture_wait( 1000 ); } - if (!loops) - { - printf ("error: Test 1: test tasks did not delete\n"); + if ( !loops ) { + printf( "error: Test 1: test tasks did not delete\n" ); rtems_task_exit(); rtems_task_exit(); rtems_task_exit(); } - sc = rtems_semaphore_delete (mutex); - if (sc != RTEMS_SUCCESSFUL) - printf ("error: Test 1: deleting the mutex: %s\n", rtems_status_text (sc)); + sc = rtems_semaphore_delete( mutex ); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: Test 1: deleting the mutex: %s\n", + rtems_status_text( sc ) + ); + } } -static rtems_monitor_command_entry_t capture_cmds[] = -{ - { - "test1", - "usage: \n", - 0, - capture_test_1, - { 0 }, - 0 - } +static rtems_monitor_command_entry_t capture_cmds[] = { + { "test1", "usage: \n", 0, capture_test_1, { 0 }, 0 } }; -void setup_tasks_to_watch (void) +void setup_tasks_to_watch( void ) { size_t cmd; - for (cmd = 0; - cmd < sizeof (capture_cmds) / sizeof (rtems_monitor_command_entry_t); - cmd++) - rtems_monitor_insert_cmd (&capture_cmds[cmd]); + for ( + cmd = 0; + cmd < sizeof( capture_cmds ) / sizeof( rtems_monitor_command_entry_t ); + cmd++ + ) { + rtems_monitor_insert_cmd( &capture_cmds[ cmd ] ); + } } diff --git a/testsuites/samples/cdtest/system.h b/testsuites/samples/cdtest/system.h index 748e2ef1bc..50bd32d51f 100644 --- a/testsuites/samples/cdtest/system.h +++ b/testsuites/samples/cdtest/system.h @@ -35,9 +35,7 @@ /* functions */ -rtems_task main_task( - rtems_task_argument argument -); +rtems_task main_task( rtems_task_argument argument ); /* configuration information */ @@ -46,16 +44,16 @@ rtems_task main_task( #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER -#define CONFIGURE_MAXIMUM_TASKS 1 -#define CONFIGURE_MAXIMUM_SEMAPHORES 5 +#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_MAXIMUM_SEMAPHORES 5 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE -#define CONFIGURE_INIT_TASK_ENTRY_POINT main_task -#define CONFIGURE_INIT_TASK_NAME rtems_build_name( 'C', 'T', 'O', 'R' ) -#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT +#define CONFIGURE_INIT_TASK_ENTRY_POINT main_task +#define CONFIGURE_INIT_TASK_NAME rtems_build_name( 'C', 'T', 'O', 'R' ) +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT /* On some platforms _Unwind_RaiseException() needs a lot of stack space */ -#define CONFIGURE_INIT_TASK_STACK_SIZE (4 * RTEMS_MINIMUM_STACK_SIZE) +#define CONFIGURE_INIT_TASK_STACK_SIZE ( 4 * RTEMS_MINIMUM_STACK_SIZE ) #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION diff --git a/testsuites/samples/fileio/init.c b/testsuites/samples/fileio/init.c index 2829237393..bc823ed107 100644 --- a/testsuites/samples/fileio/init.c +++ b/testsuites/samples/fileio/init.c @@ -60,34 +60,28 @@ const char rtems_test_name[] = "FILE I/O"; /** * Let the IO system allocation the next available major number. */ -#define RTEMS_DRIVER_AUTO_MAJOR (0) +#define RTEMS_DRIVER_AUTO_MAJOR ( 0 ) /** * The NV Device descriptor. For this test it is just DRAM. */ -rtems_nvdisk_device_desc rtems_nv_heap_device_descriptor[] = -{ - { - flags: 0, - base: 0, - size: (size_t) 1024 * 1024, - nv_ops: &rtems_nvdisk_sram_handlers - } -}; +rtems_nvdisk_device_desc rtems_nv_heap_device_descriptor[] = { { + flags : 0, + base : 0, + size : (size_t) 1024 * 1024, + nv_ops : &rtems_nvdisk_sram_handlers +} }; /** * The NV Disk configuration. */ -const rtems_nvdisk_config rtems_nvdisk_configuration[] = -{ - { - block_size: 512, - device_count: 1, - devices: &rtems_nv_heap_device_descriptor[0], - flags: 0, - info_level: 0 - } -}; +const rtems_nvdisk_config rtems_nvdisk_configuration[] = { { + block_size : 512, + device_count : 1, + devices : &rtems_nv_heap_device_descriptor[ 0 ], + flags : 0, + info_level : 0 +} }; /** * The number of NV Disk configurations. @@ -100,143 +94,130 @@ uint32_t rtems_nvdisk_configuration_size = 1; * See cpukit/libmisc/fsmount for definition of fields */ fstab_t fs_table[] = { - { - "/dev/hda1","/mnt/hda1", "dosfs", + { "/dev/hda1", + "/mnt/hda1", + "dosfs", RTEMS_FILESYSTEM_READ_WRITE, FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, - 0 - }, - { - "/dev/hda2","/mnt/hda2", "dosfs", + 0 }, + { "/dev/hda2", + "/mnt/hda2", + "dosfs", RTEMS_FILESYSTEM_READ_WRITE, FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, - 0 - }, - { - "/dev/hda3","/mnt/hda3", "dosfs", + 0 }, + { "/dev/hda3", + "/mnt/hda3", + "dosfs", RTEMS_FILESYSTEM_READ_WRITE, FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, - 0 - }, - { - "/dev/hda4","/mnt/hda4", "dosfs", + 0 }, + { "/dev/hda4", + "/mnt/hda4", + "dosfs", RTEMS_FILESYSTEM_READ_WRITE, FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, - 0 - }, - { - "/dev/hdc1","/mnt/hdc1", "dosfs", + 0 }, + { "/dev/hdc1", + "/mnt/hdc1", + "dosfs", RTEMS_FILESYSTEM_READ_WRITE, FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, - 0 - }, - { - "/dev/hdc2","/mnt/hdc2", "dosfs", + 0 }, + { "/dev/hdc2", + "/mnt/hdc2", + "dosfs", RTEMS_FILESYSTEM_READ_WRITE, FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, - 0 - }, - { - "/dev/hdc3","/mnt/hdc3", "dosfs", + 0 }, + { "/dev/hdc3", + "/mnt/hdc3", + "dosfs", RTEMS_FILESYSTEM_READ_WRITE, FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, - 0 - }, - { - "/dev/hdc4","/mnt/hdc4", "dosfs", + 0 }, + { "/dev/hdc4", + "/mnt/hdc4", + "dosfs", RTEMS_FILESYSTEM_READ_WRITE, FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, - 0 - } + 0 } }; #define USE_SHELL #ifdef USE_SHELL -static int -shell_nvdisk_trace (int argc, char* argv[]) +static int shell_nvdisk_trace( int argc, char *argv[] ) { - const char* driver; + const char *driver; int level; - if (argc != 3) - { - printf ("error: invalid number of options\n"); + if ( argc != 3 ) { + printf( "error: invalid number of options\n" ); return 1; } - driver = argv[1]; - level = strtoul (argv[2], 0, 0); - - int fd = open (driver, O_WRONLY, 0); - if (fd < 0) - { - printf ("error: driver open failed: %s\n", strerror (errno)); + driver = argv[ 1 ]; + level = strtoul( argv[ 2 ], 0, 0 ); + + int fd = open( driver, O_WRONLY, 0 ); + if ( fd < 0 ) { + printf( "error: driver open failed: %s\n", strerror( errno ) ); return 1; } - - if (ioctl (fd, RTEMS_NVDISK_IOCTL_INFO_LEVEL, level) < 0) - { - printf ("error: driver set level failed: %s\n", strerror (errno)); + + if ( ioctl( fd, RTEMS_NVDISK_IOCTL_INFO_LEVEL, level ) < 0 ) { + printf( "error: driver set level failed: %s\n", strerror( errno ) ); return 1; } - - close (fd); - + + close( fd ); + return 0; } -static int -shell_nvdisk_erase (int argc, char* argv[]) +static int shell_nvdisk_erase( int argc, char *argv[] ) { - const char* driver = NULL; + const char *driver = NULL; int arg; int fd; - - for (arg = 1; arg < argc; arg++) - { - if (argv[arg][0] == '-') - { - printf ("error: invalid option: %s\n", argv[arg]); + + for ( arg = 1; arg < argc; arg++ ) { + if ( argv[ arg ][ 0 ] == '-' ) { + printf( "error: invalid option: %s\n", argv[ arg ] ); return 1; - } - else - { - if (!driver) - driver = argv[arg]; - else - { - printf ("error: only one driver name allowed: %s\n", argv[arg]); + } else { + if ( !driver ) { + driver = argv[ arg ]; + } else { + printf( "error: only one driver name allowed: %s\n", argv[ arg ] ); return 1; } } } - - printf ("erase nv disk: %s\n", driver); - - fd = open (driver, O_WRONLY, 0); - if (fd < 0) - { - printf ("error: nvdisk driver open failed: %s\n", strerror (errno)); + + printf( "erase nv disk: %s\n", driver ); + + fd = open( driver, O_WRONLY, 0 ); + if ( fd < 0 ) { + printf( "error: nvdisk driver open failed: %s\n", strerror( errno ) ); return 1; } - - if (ioctl (fd, RTEMS_NVDISK_IOCTL_ERASE_DISK) < 0) - { - printf ("error: nvdisk driver erase failed: %s\n", strerror (errno)); + + if ( ioctl( fd, RTEMS_NVDISK_IOCTL_ERASE_DISK ) < 0 ) { + printf( "error: nvdisk driver erase failed: %s\n", strerror( errno ) ); return 1; } - - close (fd); - - printf ("nvdisk erased successful\n"); + + close( fd ); + + printf( "nvdisk erased successful\n" ); return 0; } -static int -shell_bdbuf_trace (int argc, char* argv[]) +static int shell_bdbuf_trace( int argc, char *argv[] ) { (void) argc; (void) argv; @@ -244,77 +225,79 @@ shell_bdbuf_trace (int argc, char* argv[]) #if RTEMS_BDBUF_TRACE extern bool rtems_bdbuf_tracer; rtems_bdbuf_tracer = !rtems_bdbuf_tracer; - printf ("bdbuf trace: %d\n", rtems_bdbuf_tracer); + printf( "bdbuf trace: %d\n", rtems_bdbuf_tracer ); #else - printf ("bdbuf trace disabled. Rebuild with enabled.\n"); + printf( "bdbuf trace disabled. Rebuild with enabled.\n" ); #endif return 0; } -static int -disk_test_set_block_size (rtems_disk_device *dd, size_t size) +static int disk_test_set_block_size( rtems_disk_device *dd, size_t size ) { - return dd->ioctl (dd, RTEMS_BLKIO_SETBLKSIZE, &size); + return dd->ioctl( dd, RTEMS_BLKIO_SETBLKSIZE, &size ); } -static int -disk_test_write_blocks (const char *name, int start, int count, size_t size) +static int disk_test_write_blocks( + const char *name, + int start, + int count, + size_t size +) { int block; - uint32_t* ip; + uint32_t *ip; uint32_t value = 0; size_t i; - rtems_bdbuf_buffer* bd; + rtems_bdbuf_buffer *bd; rtems_status_code sc; int rv = 0; - rtems_disk_device* dd; + rtems_disk_device *dd; int fd; - fd = open(name, O_RDWR); - if (fd < 0) { - printf ("error: cannot open disk\n"); + fd = open( name, O_RDWR ); + if ( fd < 0 ) { + printf( "error: cannot open disk\n" ); rv = 1; } - if (rv == 0 && rtems_disk_fd_get_disk_device(fd, &dd) != 0) - { - printf ("error: cannot obtain disk\n"); + if ( rv == 0 && rtems_disk_fd_get_disk_device( fd, &dd ) != 0 ) { + printf( "error: cannot obtain disk\n" ); rv = 1; } - if (fd >= 0 && close (fd) != 0) - { - printf ("error: close disk failed\n"); + if ( fd >= 0 && close( fd ) != 0 ) { + printf( "error: close disk failed\n" ); rv = 1; } - if (rv == 0 && disk_test_set_block_size (dd, size) < 0) - { - printf ("error: set block size failed: %s\n", strerror (errno)); + if ( rv == 0 && disk_test_set_block_size( dd, size ) < 0 ) { + printf( "error: set block size failed: %s\n", strerror( errno ) ); rv = 1; } - for (block = start; rv == 0 && block < (start + count); block++) - { - sc = rtems_bdbuf_read (dd, block, &bd); - if (sc == RTEMS_SUCCESSFUL) - { - ip = (uint32_t*) bd->buffer; - for (i = 0; i < (size / sizeof (uint32_t)); i++, ip++, value++) - *ip = (size << 16) | value; + for ( block = start; rv == 0 && block < ( start + count ); block++ ) { + sc = rtems_bdbuf_read( dd, block, &bd ); + if ( sc == RTEMS_SUCCESSFUL ) { + ip = (uint32_t *) bd->buffer; + for ( i = 0; i < ( size / sizeof( uint32_t ) ); i++, ip++, value++ ) { + *ip = ( size << 16 ) | value; + } - sc = rtems_bdbuf_release_modified (bd); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: release block %d bd failed: %s\n", - block, rtems_status_text (sc)); + sc = rtems_bdbuf_release_modified( bd ); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: release block %d bd failed: %s\n", + block, + rtems_status_text( sc ) + ); rv = 1; } - } - else - { - printf ("error: get block %d bd failed: %s\n", - block, rtems_status_text (sc)); + } else { + printf( + "error: get block %d bd failed: %s\n", + block, + rtems_status_text( sc ) + ); rv = 1; } } @@ -322,38 +305,34 @@ disk_test_write_blocks (const char *name, int start, int count, size_t size) return rv; } -static int -disk_test_block_sizes (int argc, char *argv[]) +static int disk_test_block_sizes( int argc, char *argv[] ) { - char* name; + char *name; int start; int count; int size; - if (argc != (4 + 1)) - { - printf ("error: need to supply a device path, start, block and size\n"); + if ( argc != ( 4 + 1 ) ) { + printf( "error: need to supply a device path, start, block and size\n" ); return 1; } - name = argv[1]; + name = argv[ 1 ]; - start = strtoul (argv[2], 0, 0); - count = strtoul (argv[3], 0, 0); - size = strtoul (argv[4], 0, 0); + start = strtoul( argv[ 2 ], 0, 0 ); + count = strtoul( argv[ 3 ], 0, 0 ); + size = strtoul( argv[ 4 ], 0, 0 ); - return disk_test_write_blocks (name, start, count, size); + return disk_test_write_blocks( name, start, count, size ); } -static uint32_t -parse_size_arg (const char* arg) +static uint32_t parse_size_arg( const char *arg ) { uint32_t size; uint32_t scalar = 1; - size = strtoul (arg, 0, 0); - switch (arg[strlen (arg) - 1]) - { + size = strtoul( arg, 0, 0 ); + switch ( arg[ strlen( arg ) - 1 ] ) { case 'b': scalar = 1; break; @@ -370,51 +349,50 @@ parse_size_arg (const char* arg) scalar = 1000; break; default: - printf ("error: invalid scalar (b,M/m/K/k): %c\n", arg[strlen (arg) - 1]); + printf( + "error: invalid scalar (b,M/m/K/k): %c\n", + arg[ strlen( arg ) - 1 ] + ); return 0; } return size * scalar; } -static int -create_ramdisk (int argc, char *argv[]) +static int create_ramdisk( int argc, char *argv[] ) { - rtems_status_code sc; - int arg; - uint32_t size = 524288; - uint32_t block_size = 512; - uint32_t block_count; + rtems_status_code sc; + int arg; + uint32_t size = 524288; + uint32_t block_size = 512; + uint32_t block_count; - for (arg = 0; arg < argc; ++arg) - { - if (argv[arg][0] == '-') - { - switch (argv[arg][1]) - { + for ( arg = 0; arg < argc; ++arg ) { + if ( argv[ arg ][ 0 ] == '-' ) { + switch ( argv[ arg ][ 1 ] ) { case 's': ++arg; - if (arg == argc) - { - printf ("error: -s needs a size\n"); + if ( arg == argc ) { + printf( "error: -s needs a size\n" ); return 1; } - size = parse_size_arg (argv[arg]); - if (size == 0) + size = parse_size_arg( argv[ arg ] ); + if ( size == 0 ) { return 1; + } break; case 'b': ++arg; - if (arg == argc) - { - printf ("error: -b needs a size\n"); + if ( arg == argc ) { + printf( "error: -b needs a size\n" ); return 1; } - block_size = parse_size_arg (argv[arg]); - if (size == 0) + block_size = parse_size_arg( argv[ arg ] ); + if ( size == 0 ) { return 1; + } break; default: - printf ("error: invalid option: %s\n", argv[arg]); + printf( "error: invalid option: %s\n", argv[ arg ] ); return 1; } } @@ -425,152 +403,149 @@ create_ramdisk (int argc, char *argv[]) /* * Register the RAM Disk driver. */ - printf ("Register RAM Disk Driver [blocks=%" PRIu32 \ - " block-size=%" PRIu32 "]:", - block_count, - block_size); + printf( + "Register RAM Disk Driver [blocks=%" PRIu32 " block-size=%" PRIu32 "]:", + block_count, + block_size + ); - sc = ramdisk_register(block_size, block_count, false, "/dev/rda"); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: ramdisk driver not initialised: %s\n", - rtems_status_text (sc)); + sc = ramdisk_register( block_size, block_count, false, "/dev/rda" ); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: ramdisk driver not initialised: %s\n", + rtems_status_text( sc ) + ); return 1; } - printf ("successful\n"); + printf( "successful\n" ); return 0; } -static int -create_nvdisk (int argc, char *argv[]) +static int create_nvdisk( int argc, char *argv[] ) { - rtems_status_code sc; - int arg; - uint32_t size = 0; + rtems_status_code sc; + int arg; + uint32_t size = 0; #if ADD_WHEN_NVDISK_HAS_CHANGED - uint32_t block_size = 0; + uint32_t block_size = 0; #endif - - for (arg = 0; arg < argc; ++arg) - { - if (argv[arg][0] == '-') - { - switch (argv[arg][1]) - { + + for ( arg = 0; arg < argc; ++arg ) { + if ( argv[ arg ][ 0 ] == '-' ) { + switch ( argv[ arg ][ 1 ] ) { case 's': ++arg; - if (arg == argc) - { - printf ("error: -s needs a size\n"); + if ( arg == argc ) { + printf( "error: -s needs a size\n" ); return 1; } - size = parse_size_arg (argv[arg]); - if (size == 0) + size = parse_size_arg( argv[ arg ] ); + if ( size == 0 ) { return 1; + } break; #if ADD_WHEN_NVDISK_HAS_CHANGED case 'b': ++arg; - if (arg == argc) - { - printf ("error: -b needs a size\n"); + if ( arg == argc ) { + printf( "error: -b needs a size\n" ); return 1; } - block_size = parse_size_arg (argv[arg]); - if (size == 0) + block_size = parse_size_arg( argv[ arg ] ); + if ( size == 0 ) { return 1; + } break; #endif default: - printf ("error: invalid option: %s\n", argv[arg]); + printf( "error: invalid option: %s\n", argv[ arg ] ); return 1; } } } #if ADD_WHEN_NVDISK_HAS_CHANGED - if (block_size) - rtems_nvdisk_configuration[0].block_size = block_size; + if ( block_size ) { + rtems_nvdisk_configuration[ 0 ].block_size = block_size; + } #endif - if (size) - rtems_nv_heap_device_descriptor[0].size = size; - + if ( size ) { + rtems_nv_heap_device_descriptor[ 0 ].size = size; + } + /* * For our test we do not have any static RAM or EEPROM devices so * we allocate the memory from the heap. */ - rtems_nv_heap_device_descriptor[0].base = - malloc (rtems_nv_heap_device_descriptor[0].size); + rtems_nv_heap_device_descriptor[ 0 ].base = malloc( + rtems_nv_heap_device_descriptor[ 0 ].size + ); - if (!rtems_nv_heap_device_descriptor[0].base) - { - printf ("error: no memory for NV disk\n"); + if ( !rtems_nv_heap_device_descriptor[ 0 ].base ) { + printf( "error: no memory for NV disk\n" ); return 1; } - + /* * Register the RAM Disk driver. */ - printf ("Register NV Disk Driver [size=%" PRIu32 \ - " block-size=%" PRIu32"]:", - rtems_nv_heap_device_descriptor[0].size, - rtems_nvdisk_configuration[0].block_size); + printf( + "Register NV Disk Driver [size=%" PRIu32 " block-size=%" PRIu32 "]:", + rtems_nv_heap_device_descriptor[ 0 ].size, + rtems_nvdisk_configuration[ 0 ].block_size + ); - sc = rtems_nvdisk_initialize (0, 0, NULL); - if (sc != RTEMS_SUCCESSFUL) - { - printf ("error: nvdisk driver not initialised: %s\n", - rtems_status_text (sc)); + sc = rtems_nvdisk_initialize( 0, 0, NULL ); + if ( sc != RTEMS_SUCCESSFUL ) { + printf( + "error: nvdisk driver not initialised: %s\n", + rtems_status_text( sc ) + ); return 1; } - - printf ("successful\n"); + + printf( "successful\n" ); return 0; } -static void writeFile( - const char *name, - mode_t mode, - const char *contents -) +static void writeFile( const char *name, mode_t mode, const char *contents ) { int sc; - sc = setuid(0); + sc = setuid( 0 ); if ( sc ) { - printf( "setuid failed: %s: %s\n", name, strerror(errno) ); + printf( "setuid failed: %s: %s\n", name, strerror( errno ) ); } rtems_shell_write_file( name, contents ); - sc = chmod ( name, mode ); + sc = chmod( name, mode ); if ( sc ) { - printf( "chmod %s: %s\n", name, strerror(errno) ); + printf( "chmod %s: %s\n", name, strerror( errno ) ); } } -#define writeScript( _name, _contents ) \ - writeFile( _name, 0777, _contents ) +#define writeScript( _name, _contents ) writeFile( _name, 0777, _contents ) -static void fileio_start_shell(void) +static void fileio_start_shell( void ) { int sc; - sc = mkdir("/scripts", 0777); + sc = mkdir( "/scripts", 0777 ); if ( sc ) { - printf( "mkdir /scripts: %s:\n", strerror(errno) ); + printf( "mkdir /scripts: %s:\n", strerror( errno ) ); } - sc = mkdir("/etc", 0777); + sc = mkdir( "/etc", 0777 ); if ( sc ) { - printf( "mkdir /etc: %s:\n", strerror(errno) ); + printf( "mkdir /etc: %s:\n", strerror( errno ) ); } - sc = mkdir("/chroot", 0777); + sc = mkdir( "/chroot", 0777 ); if ( sc ) { - printf( "mkdir /chroot: %s:\n", strerror(errno) ); + printf( "mkdir /chroot: %s:\n", strerror( errno ) ); } printf( @@ -586,7 +561,7 @@ static void fileio_start_shell(void) "/etc/passwd", 0644, "root:$6$$FuPOhnllx6lhW2qqlnmWvZQLJ8Thr/09I7ESTdb9VbnTOn5.65" - "/Vh2Mqa6FoKXwT0nHS/O7F0KfrDc6Svb/sH.:0:0:root::/:/bin/sh\n" + "/Vh2Mqa6FoKXwT0nHS/O7F0KfrDc6Svb/sH.:0:0:root::/:/bin/sh\n" "rtems::1:1:RTEMS Application::/:/bin/sh\n" "test:$1$$oPu1Xt2Pw0ngIc7LyDHqu1:2:2:test account::/:/bin/sh\n" "tty:*:3:3:tty owner::/:/bin/false\n" @@ -624,153 +599,187 @@ static void fileio_start_shell(void) "echo j2 DOES NOT have the magic first line\n" ); - rtems_shell_add_cmd ("mkrd", "files", - "Create a RAM disk driver", create_ramdisk); - rtems_shell_add_cmd ("mknvd", "files", - "Create a NV disk driver", create_nvdisk); - rtems_shell_add_cmd ("nverase", "misc", - "nverase driver", shell_nvdisk_erase); - rtems_shell_add_cmd ("nvtrace", "misc", - "nvtrace driver level", shell_nvdisk_trace); - rtems_shell_add_cmd ("bdbuftrace", "files", - "bdbuf trace toggle", shell_bdbuf_trace); - rtems_shell_add_cmd ("td", "files", - "Test disk", disk_test_block_sizes); + rtems_shell_add_cmd( + "mkrd", + "files", + "Create a RAM disk driver", + create_ramdisk + ); + rtems_shell_add_cmd( + "mknvd", + "files", + "Create a NV disk driver", + create_nvdisk + ); + rtems_shell_add_cmd( + "nverase", + "misc", + "nverase driver", + shell_nvdisk_erase + ); + rtems_shell_add_cmd( + "nvtrace", + "misc", + "nvtrace driver level", + shell_nvdisk_trace + ); + rtems_shell_add_cmd( + "bdbuftrace", + "files", + "bdbuf trace toggle", + shell_bdbuf_trace + ); + rtems_shell_add_cmd( "td", "files", "Test disk", disk_test_block_sizes ); #if RTEMS_RFS_TRACE - rtems_shell_add_cmd ("rfs", "files", - "RFS trace", - rtems_rfs_trace_shell_command); + rtems_shell_add_cmd( + "rfs", + "files", + "RFS trace", + rtems_rfs_trace_shell_command + ); #endif #if RTEMS_RFS_RTEMS_TRACE - rtems_shell_add_cmd ("rrfs", "files", - "RTEMS RFS trace", - rtems_rfs_rtems_trace_shell_command); + rtems_shell_add_cmd( + "rrfs", + "files", + "RTEMS RFS trace", + rtems_rfs_rtems_trace_shell_command + ); #endif - printf(" =========================\n"); - printf(" starting shell\n"); - printf(" =========================\n"); + printf( " =========================\n" ); + printf( " starting shell\n" ); + printf( " =========================\n" ); rtems_shell_init( - "SHLL", /* task_name */ - RTEMS_MINIMUM_STACK_SIZE * 5, /* task_stacksize */ - 100, /* task_priority */ - "/dev/foobar", /* devname */ + "SHLL", /* task_name */ + RTEMS_MINIMUM_STACK_SIZE * 5, /* task_stacksize */ + 100, /* task_priority */ + "/dev/foobar", /* devname */ /* device is currently ignored by the shell if it is not a pty */ - false, /* forever */ - true, /* wait */ - rtems_shell_login_check /* login */ + false, /* forever */ + true, /* wait */ + rtems_shell_login_check /* login */ ); } #endif /* USE_SHELL */ -static void fileio_print_free_heap(void) +static void fileio_print_free_heap( void ) { - printf("--- unused dynamic memory: %lu bytes ---\n", - (unsigned long) malloc_free_space()); + printf( + "--- unused dynamic memory: %lu bytes ---\n", + (unsigned long) malloc_free_space() + ); } - -static void fileio_part_table_initialize(void) +static void fileio_part_table_initialize( void ) { - char devname[64]; + char devname[ 64 ]; rtems_status_code rc; - printf(" =========================\n"); - printf(" Initialize partition table\n"); - printf(" =========================\n"); + printf( " =========================\n" ); + printf( " Initialize partition table\n" ); + printf( " =========================\n" ); fileio_print_free_heap(); - printf(" Enter device to initialize ==>"); - fflush(stdout); - fgets(devname,sizeof(devname)-1,stdin); - while (devname[strlen(devname)-1] == '\n') { - devname[strlen(devname)-1] = '\0'; + printf( " Enter device to initialize ==>" ); + fflush( stdout ); + fgets( devname, sizeof( devname ) - 1, stdin ); + while ( devname[ strlen( devname ) - 1 ] == '\n' ) { + devname[ strlen( devname ) - 1 ] = '\0'; } /* * call function */ - rc = rtems_bdpart_register_from_disk(devname); - printf("result = %d\n",rc); + rc = rtems_bdpart_register_from_disk( devname ); + printf( "result = %d\n", rc ); fileio_print_free_heap(); } -static void fileio_fsmount(void) +static void fileio_fsmount( void ) { rtems_status_code rc; - printf(" =========================\n"); - printf(" Process fsmount table\n"); - printf(" =========================\n"); + printf( " =========================\n" ); + printf( " Process fsmount table\n" ); + printf( " =========================\n" ); fileio_print_free_heap(); /* * call function */ - rc = rtems_fsmount( fs_table, - sizeof(fs_table)/sizeof(fs_table[0]), - NULL); - printf("result = %d\n",rc); + rc = rtems_fsmount( + fs_table, + sizeof( fs_table ) / sizeof( fs_table[ 0 ] ), + NULL + ); + printf( "result = %d\n", rc ); fileio_print_free_heap(); } -static void fileio_list_file(void) +static void fileio_list_file( void ) { - char fname[1024]; - char *buf_ptr = NULL; - ssize_t flen = 0; - int fd = -1; + char fname[ 1024 ]; + char *buf_ptr = NULL; + ssize_t flen = 0; + int fd = -1; ssize_t n; - size_t buf_size = 100; + size_t buf_size = 100; - rtems_interval start_tick,curr_tick,ticks_per_sec; + rtems_interval start_tick, curr_tick, ticks_per_sec; - printf(" =========================\n"); - printf(" LIST FILE ... \n"); - printf(" =========================\n"); + printf( " =========================\n" ); + printf( " LIST FILE ... \n" ); + printf( " =========================\n" ); fileio_print_free_heap(); - printf(" Enter filename to list ==>"); - fflush(stdout); - fgets(fname,sizeof(fname)-1,stdin); - while (fname[strlen(fname)-1] == '\n') { - fname[strlen(fname)-1] = '\0'; + printf( " Enter filename to list ==>" ); + fflush( stdout ); + fgets( fname, sizeof( fname ) - 1, stdin ); + while ( fname[ strlen( fname ) - 1 ] == '\n' ) { + fname[ strlen( fname ) - 1 ] = '\0'; } /* * allocate buffer of given size */ - if (buf_size > 0) { - buf_ptr = malloc(buf_size); + if ( buf_size > 0 ) { + buf_ptr = malloc( buf_size ); } - if (buf_ptr != NULL) { - printf("\n Trying to open file \"%s\" for read\n",fname); - fd = open(fname,O_RDONLY); - if (fd < 0) { - printf("*** file failed to open, errno = %d(%s)\n",errno,strerror(errno)); + if ( buf_ptr != NULL ) { + printf( "\n Trying to open file \"%s\" for read\n", fname ); + fd = open( fname, O_RDONLY ); + if ( fd < 0 ) { + printf( + "*** file failed to open, errno = %d(%s)\n", + errno, + strerror( errno ) + ); } } - if (fd >= 0) { + if ( fd >= 0 ) { start_tick = rtems_clock_get_ticks_since_boot(); do { - n = read(fd,buf_ptr,buf_size); - if (n > 0) { - write(1,buf_ptr,(size_t) n); - flen += n; + n = read( fd, buf_ptr, buf_size ); + if ( n > 0 ) { + write( 1, buf_ptr, (size_t) n ); + flen += n; } - } while (n > 0); + } while ( n > 0 ); curr_tick = rtems_clock_get_ticks_since_boot(); - printf("\n ******** End of file reached, flen = %zd\n",flen); - close(fd); + printf( "\n ******** End of file reached, flen = %zd\n", flen ); + close( fd ); ticks_per_sec = rtems_clock_get_ticks_per_second(); - printf("time elapsed for read: %g seconds\n", - ((double)curr_tick-start_tick)/ticks_per_sec); + printf( + "time elapsed for read: %g seconds\n", + ( (double) curr_tick - start_tick ) / ticks_per_sec + ); } /* * free buffer */ - if (buf_ptr != NULL) { - free(buf_ptr); + if ( buf_ptr != NULL ) { + free( buf_ptr ); } fileio_print_free_heap(); } @@ -778,51 +787,48 @@ static void fileio_list_file(void) /* * convert a size string (like 34K or 12M) to actual byte count */ -static bool fileio_str2size(const char *str,uint32_t *res_ptr) +static bool fileio_str2size( const char *str, uint32_t *res_ptr ) { - bool failed = false; + bool failed = false; unsigned long size; unsigned char suffix = ' '; - if (1 > sscanf(str,"%lu%c",&size,&suffix)) { + if ( 1 > sscanf( str, "%lu%c", &size, &suffix ) ) { failed = true; - } - else if (toupper((int)suffix) == 'K') { + } else if ( toupper( (int) suffix ) == 'K' ) { size *= 1024; - } - else if (toupper((int)suffix) == 'M') { - size *= 1024UL*1024UL; - } - else if (isalpha((int)suffix)) { + } else if ( toupper( (int) suffix ) == 'M' ) { + size *= 1024UL * 1024UL; + } else if ( isalpha( (int) suffix ) ) { failed = true; } - if (!failed) { + if ( !failed ) { *res_ptr = size; } return failed; } -static void fileio_write_file(void) +static void fileio_write_file( void ) { - char fname[1024]; - char tmp_str[32]; - uint32_t file_size = 0; - uint32_t buf_size = 0; - size_t curr_pos,bytes_to_copy; - int fd = -1; - ssize_t n; - rtems_interval start_tick,curr_tick,ticks_per_sec; - char *bufptr = NULL; - bool failed = false; - static const char write_test_string[] = - "The quick brown fox jumps over the lazy dog\n"; - static const char write_block_string[] = - "\n----- end of write buffer ------\n"; + char fname[ 1024 ]; + char tmp_str[ 32 ]; + uint32_t file_size = 0; + uint32_t buf_size = 0; + size_t curr_pos, bytes_to_copy; + int fd = -1; + ssize_t n; + rtems_interval start_tick, curr_tick, ticks_per_sec; + char *bufptr = NULL; + bool failed = false; + static const char + write_test_string[] = "The quick brown fox jumps over the lazy dog\n"; + static const char + write_block_string[] = "\n----- end of write buffer ------\n"; - printf(" =========================\n"); - printf(" WRITE FILE ... \n"); - printf(" =========================\n"); + printf( " =========================\n" ); + printf( " WRITE FILE ... \n" ); + printf( " =========================\n" ); fileio_print_free_heap(); /* * get number of ticks per second @@ -832,156 +838,179 @@ static void fileio_write_file(void) /* * get path to file to write */ - if (!failed) { - printf("Enter path/filename ==>"); - fflush(stdout); - fgets(fname,sizeof(fname)-1,stdin); - while (fname[strlen(fname)-1] == '\n') { - fname[strlen(fname)-1] = '\0'; + if ( !failed ) { + printf( "Enter path/filename ==>" ); + fflush( stdout ); + fgets( fname, sizeof( fname ) - 1, stdin ); + while ( fname[ strlen( fname ) - 1 ] == '\n' ) { + fname[ strlen( fname ) - 1 ] = '\0'; } - if (0 == strlen(fname)) { - printf("*** no filename entered, aborted\n"); + if ( 0 == strlen( fname ) ) { + printf( "*** no filename entered, aborted\n" ); failed = true; } } /* * get total file size to write */ - if (!failed) { - printf("use suffix K for Kbytes, M for Mbytes or no suffix for bytes:\n" - "Enter filesize to write ==>"); - fflush(stdout); - fgets(tmp_str,sizeof(tmp_str)-1,stdin); - failed = fileio_str2size(tmp_str,&file_size); - if (failed) { - printf("*** illegal file size, aborted\n"); + if ( !failed ) { + printf( + "use suffix K for Kbytes, M for Mbytes or no suffix for bytes:\n" + "Enter filesize to write ==>" + ); + fflush( stdout ); + fgets( tmp_str, sizeof( tmp_str ) - 1, stdin ); + failed = fileio_str2size( tmp_str, &file_size ); + if ( failed ) { + printf( "*** illegal file size, aborted\n" ); } } /* * get block size to write */ - if (!failed) { - printf("use suffix K for Kbytes, M for Mbytes or no suffix for bytes:\n" - "Enter block size to use for write calls ==>"); - fflush(stdout); - fgets(tmp_str,sizeof(tmp_str)-1,stdin); - failed = fileio_str2size(tmp_str,&buf_size); - if (failed) { - printf("*** illegal block size, aborted\n"); + if ( !failed ) { + printf( + "use suffix K for Kbytes, M for Mbytes or no suffix for bytes:\n" + "Enter block size to use for write calls ==>" + ); + fflush( stdout ); + fgets( tmp_str, sizeof( tmp_str ) - 1, stdin ); + failed = fileio_str2size( tmp_str, &buf_size ); + if ( failed ) { + printf( "*** illegal block size, aborted\n" ); } } /* * allocate buffer */ - if (!failed) { - printf("... allocating %lu bytes of buffer for write data\n", - (unsigned long)buf_size); - bufptr = malloc(buf_size+1); /* extra space for terminating NUL char */ - if (bufptr == NULL) { - printf("*** malloc failed, aborted\n"); + if ( !failed ) { + printf( + "... allocating %lu bytes of buffer for write data\n", + (unsigned long) buf_size + ); + bufptr = malloc( buf_size + 1 ); /* extra space for terminating NUL char */ + if ( bufptr == NULL ) { + printf( "*** malloc failed, aborted\n" ); failed = true; } } /* * fill buffer with test pattern */ - if (!failed) { - printf("... filling buffer with write data\n"); + if ( !failed ) { + printf( "... filling buffer with write data\n" ); curr_pos = 0; /* * fill buffer with test string */ - while (curr_pos < buf_size) { - bytes_to_copy = MIN(buf_size-curr_pos, - sizeof(write_test_string)-1); - memcpy(bufptr+curr_pos,write_test_string,bytes_to_copy); + while ( curr_pos < buf_size ) { + bytes_to_copy = MIN( + buf_size - curr_pos, + sizeof( write_test_string ) - 1 + ); + memcpy( bufptr + curr_pos, write_test_string, bytes_to_copy ); curr_pos += bytes_to_copy; } /* * put "end" mark at end of buffer */ - bytes_to_copy = sizeof(write_block_string)-1; - if (buf_size >= bytes_to_copy) { - memcpy(bufptr+buf_size-bytes_to_copy, - write_block_string, - bytes_to_copy); + bytes_to_copy = sizeof( write_block_string ) - 1; + if ( buf_size >= bytes_to_copy ) { + memcpy( + bufptr + buf_size - bytes_to_copy, + write_block_string, + bytes_to_copy + ); } } /* * create file */ - if (!failed) { - printf("... creating file \"%s\"\n",fname); - fd = open(fname,O_WRONLY | O_CREAT | O_TRUNC,S_IREAD|S_IWRITE); - if (fd < 0) { - printf("*** file create failed, errno = %d(%s)\n",errno,strerror(errno)); + if ( !failed ) { + printf( "... creating file \"%s\"\n", fname ); + fd = open( fname, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE ); + if ( fd < 0 ) { + printf( + "*** file create failed, errno = %d(%s)\n", + errno, + strerror( errno ) + ); failed = true; } } /* * write file */ - if (!failed) { - printf("... writing to file\n"); + if ( !failed ) { + printf( "... writing to file\n" ); start_tick = rtems_clock_get_ticks_since_boot(); curr_pos = 0; do { bytes_to_copy = buf_size; do { - n = write(fd, - bufptr + (buf_size-bytes_to_copy), - MIN(bytes_to_copy,file_size-curr_pos)); - if (n > 0) { - bytes_to_copy -= (size_t) n; - curr_pos += (size_t) n; - } - } while ((bytes_to_copy > 0) && (n > 0)); - } while ((file_size > curr_pos) && (n > 0)); + n = write( + fd, + bufptr + ( buf_size - bytes_to_copy ), + MIN( bytes_to_copy, file_size - curr_pos ) + ); + if ( n > 0 ) { + bytes_to_copy -= (size_t) n; + curr_pos += (size_t) n; + } + } while ( ( bytes_to_copy > 0 ) && ( n > 0 ) ); + } while ( ( file_size > curr_pos ) && ( n > 0 ) ); curr_tick = rtems_clock_get_ticks_since_boot(); - if (n < 0) { + if ( n < 0 ) { failed = true; - printf("*** file write failed, " - "%lu bytes written, " - "errno = %d(%s)\n", - (unsigned long)curr_pos,errno,strerror(errno)); - } - else { - printf("time elapsed for write: %g seconds\n", - ((double)curr_tick-start_tick)/ticks_per_sec); - printf("write data rate: %g KBytes/second\n", - (((double)file_size) / 1024.0 / - (((double)curr_tick-start_tick)/ticks_per_sec))); + printf( + "*** file write failed, " + "%lu bytes written, " + "errno = %d(%s)\n", + (unsigned long) curr_pos, + errno, + strerror( errno ) + ); + } else { + printf( + "time elapsed for write: %g seconds\n", + ( (double) curr_tick - start_tick ) / ticks_per_sec + ); + printf( + "write data rate: %g KBytes/second\n", + ( ( (double) file_size ) / 1024.0 / + ( ( (double) curr_tick - start_tick ) / ticks_per_sec ) ) + ); } } - if (fd >= 0) { - printf("... closing file\n"); - close(fd); + if ( fd >= 0 ) { + printf( "... closing file\n" ); + close( fd ); } - if (bufptr != NULL) { - printf("... deallocating buffer\n"); - free(bufptr); + if ( bufptr != NULL ) { + printf( "... deallocating buffer\n" ); + free( bufptr ); bufptr = NULL; } - printf("\n ******** End of file write\n"); + printf( "\n ******** End of file write\n" ); fileio_print_free_heap(); } -static void fileio_read_file(void) +static void fileio_read_file( void ) { - char fname[1024]; - char tmp_str[32]; - uint32_t buf_size = 0; - size_t curr_pos; - int fd = -1; - ssize_t n; - rtems_interval start_tick,curr_tick,ticks_per_sec; - char *bufptr = NULL; - bool failed = false; + char fname[ 1024 ]; + char tmp_str[ 32 ]; + uint32_t buf_size = 0; + size_t curr_pos; + int fd = -1; + ssize_t n; + rtems_interval start_tick, curr_tick, ticks_per_sec; + char *bufptr = NULL; + bool failed = false; - printf(" =========================\n"); - printf(" READ FILE ... \n"); - printf(" =========================\n"); + printf( " =========================\n" ); + printf( " READ FILE ... \n" ); + printf( " =========================\n" ); fileio_print_free_heap(); /* * get number of ticks per second @@ -991,169 +1020,177 @@ static void fileio_read_file(void) /* * get path to file to read */ - if (!failed) { - printf("Enter path/filename ==>"); - fflush(stdout); - fgets(fname,sizeof(fname)-1,stdin); - while (fname[strlen(fname)-1] == '\n') { - fname[strlen(fname)-1] = '\0'; + if ( !failed ) { + printf( "Enter path/filename ==>" ); + fflush( stdout ); + fgets( fname, sizeof( fname ) - 1, stdin ); + while ( fname[ strlen( fname ) - 1 ] == '\n' ) { + fname[ strlen( fname ) - 1 ] = '\0'; } - if (0 == strlen(fname)) { - printf("*** no filename entered, aborted\n"); + if ( 0 == strlen( fname ) ) { + printf( "*** no filename entered, aborted\n" ); failed = true; } } /* * get block size to read */ - if (!failed) { - printf("use suffix K for Kbytes, M for Mbytes or no suffix for bytes:\n" - "Enter block size to use for read calls ==>"); - fflush(stdout); - fgets(tmp_str,sizeof(tmp_str)-1,stdin); - failed = fileio_str2size(tmp_str,&buf_size); - if (failed) { - printf("*** illegal block size, aborted\n"); + if ( !failed ) { + printf( + "use suffix K for Kbytes, M for Mbytes or no suffix for bytes:\n" + "Enter block size to use for read calls ==>" + ); + fflush( stdout ); + fgets( tmp_str, sizeof( tmp_str ) - 1, stdin ); + failed = fileio_str2size( tmp_str, &buf_size ); + if ( failed ) { + printf( "*** illegal block size, aborted\n" ); } } /* * allocate buffer */ - if (!failed) { - printf("... allocating %lu bytes of buffer for write data\n", - (unsigned long)buf_size); - bufptr = malloc(buf_size+1); /* extra space for terminating NUL char */ - if (bufptr == NULL) { - printf("*** malloc failed, aborted\n"); + if ( !failed ) { + printf( + "... allocating %lu bytes of buffer for write data\n", + (unsigned long) buf_size + ); + bufptr = malloc( buf_size + 1 ); /* extra space for terminating NUL char */ + if ( bufptr == NULL ) { + printf( "*** malloc failed, aborted\n" ); failed = true; } } /* * open file */ - if (!failed) { - printf("... opening file \"%s\"\n",fname); - fd = open(fname,O_RDONLY); - if (fd < 0) { - printf("*** failed to open file, errno = %d(%s)\n",errno,strerror(errno)); + if ( !failed ) { + printf( "... opening file \"%s\"\n", fname ); + fd = open( fname, O_RDONLY ); + if ( fd < 0 ) { + printf( + "*** failed to open file, errno = %d(%s)\n", + errno, + strerror( errno ) + ); failed = true; } } /* * read file */ - if (!failed) { - printf("... reading from file\n"); + if ( !failed ) { + printf( "... reading from file\n" ); start_tick = rtems_clock_get_ticks_since_boot(); curr_pos = 0; do { - n = read(fd, - bufptr, - buf_size); - if (n > 0) { - curr_pos += (size_t) n; + n = read( fd, bufptr, buf_size ); + if ( n > 0 ) { + curr_pos += (size_t) n; } - } while (n > 0); + } while ( n > 0 ); curr_tick = rtems_clock_get_ticks_since_boot(); - if (n < 0) { + if ( n < 0 ) { failed = true; - printf("*** file read failed, " - "%lu bytes read, " - "errno = %d(%s)\n", - (unsigned long)curr_pos,errno,strerror(errno)); - } - else { - printf("%lu bytes read\n", - (unsigned long)curr_pos); - printf("time elapsed for read: %g seconds\n", - ((double)curr_tick-start_tick)/ticks_per_sec); - printf("read data rate: %g KBytes/second\n", - (((double)curr_pos) / 1024.0 / - (((double)curr_tick-start_tick)/ticks_per_sec))); + printf( + "*** file read failed, " + "%lu bytes read, " + "errno = %d(%s)\n", + (unsigned long) curr_pos, + errno, + strerror( errno ) + ); + } else { + printf( "%lu bytes read\n", (unsigned long) curr_pos ); + printf( + "time elapsed for read: %g seconds\n", + ( (double) curr_tick - start_tick ) / ticks_per_sec + ); + printf( + "read data rate: %g KBytes/second\n", + ( ( (double) curr_pos ) / 1024.0 / + ( ( (double) curr_tick - start_tick ) / ticks_per_sec ) ) + ); } } - if (fd >= 0) { - printf("... closing file\n"); - close(fd); + if ( fd >= 0 ) { + printf( "... closing file\n" ); + close( fd ); } - if (bufptr != NULL) { - printf("... deallocating buffer\n"); - free(bufptr); + if ( bufptr != NULL ) { + printf( "... deallocating buffer\n" ); + free( bufptr ); bufptr = NULL; } - printf("\n ******** End of file read\n"); + printf( "\n ******** End of file read\n" ); fileio_print_free_heap(); - } -static void fileio_menu (void) +static void fileio_menu( void ) { - char inbuf[10]; + char inbuf[ 10 ]; /* * Wait for characters from console terminal */ - for (;;) { - printf(" =========================\n"); - printf(" RTEMS FILE I/O Test Menu \n"); - printf(" =========================\n"); - printf(" p -> part_table_initialize\n"); - printf(" f -> mount all disks in fs_table\n"); - printf(" l -> list file\n"); - printf(" r -> read file\n"); - printf(" w -> write file\n"); + for ( ;; ) { + printf( " =========================\n" ); + printf( " RTEMS FILE I/O Test Menu \n" ); + printf( " =========================\n" ); + printf( " p -> part_table_initialize\n" ); + printf( " f -> mount all disks in fs_table\n" ); + printf( " l -> list file\n" ); + printf( " r -> read file\n" ); + printf( " w -> write file\n" ); #ifdef USE_SHELL - printf(" s -> start shell\n"); + printf( " s -> start shell\n" ); #endif - printf(" Enter your selection ==>"); - fflush(stdout); + printf( " Enter your selection ==>" ); + fflush( stdout ); - inbuf[0] = '\0'; - fgets(inbuf,sizeof(inbuf),stdin); - switch (inbuf[0]) { - case 'l': - fileio_list_file (); - break; - case 'r': - fileio_read_file (); - break; - case 'w': - fileio_write_file (); - break; - case 'p': - fileio_part_table_initialize (); - break; - case 'f': - fileio_fsmount (); - break; + inbuf[ 0 ] = '\0'; + fgets( inbuf, sizeof( inbuf ), stdin ); + switch ( inbuf[ 0 ] ) { + case 'l': + fileio_list_file(); + break; + case 'r': + fileio_read_file(); + break; + case 'w': + fileio_write_file(); + break; + case 'p': + fileio_part_table_initialize(); + break; + case 'f': + fileio_fsmount(); + break; #ifdef USE_SHELL - case 's': - fileio_start_shell (); - break; + case 's': + fileio_start_shell(); + break; #endif - default: - printf("Selection `%c` not implemented\n",inbuf[0]); - break; + default: + printf( "Selection `%c` not implemented\n", inbuf[ 0 ] ); + break; } - } - exit (0); + exit( 0 ); } /* * RTEMS File Menu Task */ -static rtems_task -fileio_task (rtems_task_argument ignored) +static rtems_task fileio_task( rtems_task_argument ignored ) { (void) ignored; fileio_menu(); } -static void -notification (int fd, int seconds_remaining, void *arg) +static void notification( int fd, int seconds_remaining, void *arg ) { (void) fd; (void) arg; @@ -1167,38 +1204,35 @@ notification (int fd, int seconds_remaining, void *arg) /* * RTEMS Startup Task */ -rtems_task -Init (rtems_task_argument ignored) +rtems_task Init( rtems_task_argument ignored ) { (void) ignored; - rtems_name Task_name; - rtems_id Task_id; + rtems_name Task_name; + rtems_id Task_id; rtems_status_code status; TEST_BEGIN(); - crypt_add_format(&crypt_md5_format); - crypt_add_format(&crypt_sha512_format); + crypt_add_format( &crypt_md5_format ); + crypt_add_format( &crypt_sha512_format ); - status = rtems_shell_wait_for_input( - STDIN_FILENO, - 20, - notification, - NULL - ); - if (status == RTEMS_SUCCESSFUL) { - Task_name = rtems_build_name('F','M','N','U'); + status = rtems_shell_wait_for_input( STDIN_FILENO, 20, notification, NULL ); + if ( status == RTEMS_SUCCESSFUL ) { + Task_name = rtems_build_name( 'F', 'M', 'N', 'U' ); status = rtems_task_create( - Task_name, 1, RTEMS_MINIMUM_STACK_SIZE * 2, - RTEMS_DEFAULT_MODES , - RTEMS_FLOATING_POINT | RTEMS_DEFAULT_ATTRIBUTES, &Task_id + Task_name, + 1, + RTEMS_MINIMUM_STACK_SIZE * 2, + RTEMS_DEFAULT_MODES, + RTEMS_FLOATING_POINT | RTEMS_DEFAULT_ATTRIBUTES, + &Task_id ); - directive_failed( status, "create" ); + directive_failed( status, "create" ); status = rtems_task_start( Task_id, fileio_task, 1 ); - directive_failed( status, "start" ); + directive_failed( status, "start" ); rtems_task_exit(); } else { @@ -1208,17 +1242,18 @@ Init (rtems_task_argument ignored) } } -#if defined(USE_SHELL) +#if defined( USE_SHELL ) /* * RTEMS Shell Configuration -- Add a command and an alias for it */ -static int main_usercmd(int argc, char **argv) +static int main_usercmd( int argc, char **argv ) { int i; printf( "UserCommand: argc=%d\n", argc ); - for (i=0 ; i /* for device driver prototypes */ #define FILEIO_BUILD 1 -#if defined(RTEMS_BSP_HAS_IDE_DRIVER) -#include /* for ata driver prototype */ +#if defined( RTEMS_BSP_HAS_IDE_DRIVER ) +#include /* for ata driver prototype */ #include /* for general ide driver prototype */ #endif @@ -59,14 +56,14 @@ rtems_task Init( #ifdef RTEMS_BSP_HAS_IDE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER -#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 14 +#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 14 #endif #if FILEIO_BUILD #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK - #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 2 - #define CONFIGURE_BDBUF_MAX_WRITE_BLOCKS 8 - #define CONFIGURE_SWAPOUT_TASK_PRIORITY 15 + #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 2 + #define CONFIGURE_BDBUF_MAX_WRITE_BLOCKS 8 + #define CONFIGURE_SWAPOUT_TASK_PRIORITY 15 #define CONFIGURE_FILESYSTEM_RFS #define CONFIGURE_FILESYSTEM_DOSFS #endif diff --git a/testsuites/samples/hello/init.c b/testsuites/samples/hello/init.c index c9f07118c5..76b939818a 100644 --- a/testsuites/samples/hello/init.c +++ b/testsuites/samples/hello/init.c @@ -35,25 +35,22 @@ const char rtems_test_name[] = "HELLO WORLD"; -static rtems_task Init( - rtems_task_argument ignored -) +static rtems_task Init( rtems_task_argument ignored ) { (void) ignored; - rtems_print_printer_fprintf_putc(&rtems_test_printer); + rtems_print_printer_fprintf_putc( &rtems_test_printer ); TEST_BEGIN(); printf( "Hello World\n" ); TEST_END(); rtems_test_exit( 0 ); } - /* NOTICE: the clock driver is explicitly disabled */ #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER -#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_MAXIMUM_TASKS 1 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE diff --git a/testsuites/samples/iostream/system.h b/testsuites/samples/iostream/system.h index 63d27f9996..819b82a960 100644 --- a/testsuites/samples/iostream/system.h +++ b/testsuites/samples/iostream/system.h @@ -41,13 +41,13 @@ #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER -#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_MAXIMUM_TASKS 1 -#define CONFIGURE_MAXIMUM_SEMAPHORES 5 +#define CONFIGURE_MAXIMUM_SEMAPHORES 5 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE -#define CONFIGURE_INIT_TASK_STACK_SIZE (RTEMS_MINIMUM_STACK_SIZE * 2) -#define CONFIGURE_EXTRA_TASK_STACKS RTEMS_MINIMUM_STACK_SIZE +#define CONFIGURE_INIT_TASK_STACK_SIZE ( RTEMS_MINIMUM_STACK_SIZE * 2 ) +#define CONFIGURE_EXTRA_TASK_STACKS RTEMS_MINIMUM_STACK_SIZE #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION diff --git a/testsuites/samples/minimum/init.c b/testsuites/samples/minimum/init.c index 990bc6355b..dd3006d50a 100644 --- a/testsuites/samples/minimum/init.c +++ b/testsuites/samples/minimum/init.c @@ -85,7 +85,7 @@ static void *Init( uintptr_t ignored ) */ #ifdef RTEMS_GCOV_COVERAGE #define CONFIGURE_MINIMUM_TASK_STACK_SIZE \ - (CPU_STACK_MINIMUM_SIZE - CPU_STACK_ALIGNMENT) + ( CPU_STACK_MINIMUM_SIZE - CPU_STACK_ALIGNMENT ) #else #define CONFIGURE_MINIMUM_TASK_STACK_SIZE 512 #endif diff --git a/testsuites/samples/nsecs/empty.c b/testsuites/samples/nsecs/empty.c index ba41878347..ef41aea044 100644 --- a/testsuites/samples/nsecs/empty.c +++ b/testsuites/samples/nsecs/empty.c @@ -32,5 +32,4 @@ #include "system.h" /* put here hoping it won't get inlined */ -void dummy_function_empty_body_to_force_call(void) {} - +void dummy_function_empty_body_to_force_call( void ) {} diff --git a/testsuites/samples/nsecs/init.c b/testsuites/samples/nsecs/init.c index 650394e1e5..ec42edaa7e 100644 --- a/testsuites/samples/nsecs/init.c +++ b/testsuites/samples/nsecs/init.c @@ -57,9 +57,9 @@ const char rtems_test_name[] = "NANOSECOND CLOCK"; static char *my_ctime( time_t t ) { - static char b[32]; - ctime_r(&t, b); - b[ strlen(b) - 1] = '\0'; + static char b[ 32 ]; + ctime_r( &t, b ); + b[ strlen( b ) - 1 ] = '\0'; return b; } @@ -74,35 +74,32 @@ static void subtract_em( _Timespec_Subtract( start, stop, t ); } - -rtems_task Init( - rtems_task_argument argument -) +rtems_task Init( rtems_task_argument argument ) { (void) argument; rtems_status_code status; rtems_time_of_day time; - int index; + int index; TEST_BEGIN(); - time.year = 2007; - time.month = 03; - time.day = 24; - time.hour = 11; + time.year = 2007; + time.month = 03; + time.day = 24; + time.hour = 11; time.minute = 15; time.second = 0; - time.ticks = 0; + time.ticks = 0; status = rtems_clock_set( &time ); - directive_failed( status, "clock set" ); + directive_failed( status, "clock set" ); /* * Iterate 10 times showing difference in TOD */ printf( "10 iterations of getting TOD\n" ); - for (index=0 ; index <10 ; index++ ) { + for ( index = 0; index < 10; index++ ) { struct timespec start, stop; struct timespec diff; @@ -110,9 +107,12 @@ rtems_task Init( clock_gettime( CLOCK_REALTIME, &stop ); subtract_em( &start, &stop, &diff ); - printf( "Start: %s:%ld\nStop : %s:%ld", - my_ctime(start.tv_sec), start.tv_nsec, - my_ctime(stop.tv_sec), stop.tv_nsec + printf( + "Start: %s:%ld\nStop : %s:%ld", + my_ctime( start.tv_sec ), + start.tv_nsec, + my_ctime( stop.tv_sec ), + stop.tv_nsec ); printf( " --> %" PRIdtime_t ":%ld\n", diff.tv_sec, diff.tv_nsec ); @@ -122,46 +122,54 @@ rtems_task Init( * Iterate 10 times showing difference in Uptime */ printf( "\n10 iterations of getting Uptime\n" ); - for (index=0 ; index <10 ; index++ ) { + for ( index = 0; index < 10; index++ ) { struct timespec start, stop; struct timespec diff; rtems_clock_get_uptime( &start ); rtems_clock_get_uptime( &stop ); subtract_em( &start, &stop, &diff ); - printf( "%" PRIdtime_t ":%ld %" PRIdtime_t ":%ld --> %" PRIdtime_t ":%ld\n", - start.tv_sec, start.tv_nsec, - stop.tv_sec, stop.tv_nsec, - diff.tv_sec, diff.tv_nsec - ); + printf( + "%" PRIdtime_t ":%ld %" PRIdtime_t ":%ld --> %" PRIdtime_t ":%ld\n", + start.tv_sec, + start.tv_nsec, + stop.tv_sec, + stop.tv_nsec, + diff.tv_sec, + diff.tv_nsec + ); } /* * Iterate 10 times showing difference in Uptime with different counts */ printf( "\n10 iterations of getting Uptime with different loop values\n" ); - for (index=1 ; index <=10 ; index++ ) { + for ( index = 1; index <= 10; index++ ) { struct timespec start, stop; struct timespec diff; - long j, max = (index * 10000L); + long j, max = ( index * 10000L ); rtems_clock_get_uptime( &start ); - for (j=0 ; j %" PRIdtime_t ":%ld\n", + printf( + "loop of %ld %" PRIdtime_t ":%ld %" PRIdtime_t ":%ld --> %" PRIdtime_t + ":%ld\n", max, - start.tv_sec, start.tv_nsec, - stop.tv_sec, stop.tv_nsec, - diff.tv_sec, diff.tv_nsec - ); + start.tv_sec, + start.tv_nsec, + stop.tv_sec, + stop.tv_nsec, + diff.tv_sec, + diff.tv_nsec + ); } - sleep(1); + sleep( 1 ); TEST_END(); - exit(0); + exit( 0 ); } - diff --git a/testsuites/samples/nsecs/system.h b/testsuites/samples/nsecs/system.h index b2d31e160c..ce2acdbb0b 100644 --- a/testsuites/samples/nsecs/system.h +++ b/testsuites/samples/nsecs/system.h @@ -40,13 +40,13 @@ #include /* for device driver prototypes */ -extern void dummy_function_empty_body_to_force_call(void); +extern void dummy_function_empty_body_to_force_call( void ); #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_MICROSECONDS_PER_TICK 1000 -#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_MAXIMUM_TASKS 1 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION diff --git a/testsuites/samples/paranoia/init.c b/testsuites/samples/paranoia/init.c index fdeb675a8b..6656cd44c7 100644 --- a/testsuites/samples/paranoia/init.c +++ b/testsuites/samples/paranoia/init.c @@ -35,15 +35,13 @@ #include #include -extern int paranoia(int, char **); +extern int paranoia( int, char ** ); const char rtems_test_name[] = "PARANOIA"; -char *args[2] = { "paranoia", 0 }; +char *args[ 2 ] = { "paranoia", 0 }; -rtems_task Init( - rtems_task_argument ignored -) +rtems_task Init( rtems_task_argument ignored ) { (void) ignored; @@ -52,13 +50,13 @@ rtems_task Init( * is required by this CPU. */ -#if (defined (m68040)) - M68KFPSPInstallExceptionHandlers (); +#if ( defined( m68040 ) ) + M68KFPSPInstallExceptionHandlers(); #endif - rtems_print_printer_fprintf_putc(&rtems_test_printer); + rtems_print_printer_fprintf_putc( &rtems_test_printer ); TEST_BEGIN(); - paranoia(1, args); + paranoia( 1, args ); TEST_END(); rtems_test_exit( 0 ); } diff --git a/testsuites/samples/paranoia/paranoia.c b/testsuites/samples/paranoia/paranoia.c index 8f8557df71..fc97771d14 100644 --- a/testsuites/samples/paranoia/paranoia.c +++ b/testsuites/samples/paranoia/paranoia.c @@ -170,86 +170,86 @@ #ifdef NEED_REENT #include -struct _reent libm_reent = _REENT_INIT(libm_reent); +struct _reent libm_reent = _REENT_INIT( libm_reent ); struct _reent *_impure_ptr = &libm_reent; #endif #ifndef NOSIGNAL #include #include -#else /* NOSIGNAL */ -#define longjmp(e,v) -#define setjmp(e) 0 -#define jmp_buf int +#else /* NOSIGNAL */ +#define longjmp( e, v ) +#define setjmp( e ) 0 +#define jmp_buf int #endif /* NOSIGNAL */ #ifdef SINGLE_PRECISION -#define FLOAT float -#define FABS(x) (float)fabs((double)(x)) -#define FLOOR(x) (float)floor((double)(x)) -#define LOG(x) (float)log((double)(x)) -#define POW(x,y) (float)pow((double)(x),(double)(y)) -#define SQRT(x) (float)sqrt((double)(x)) +#define FLOAT float +#define FABS( x ) (float) fabs( (double) ( x ) ) +#define FLOOR( x ) (float) floor( (double) ( x ) ) +#define LOG( x ) (float) log( (double) ( x ) ) +#define POW( x, y ) (float) pow( (double) ( x ), (double) ( y ) ) +#define SQRT( x ) (float) sqrt( (double) ( x ) ) #else /* !SINGLE_PRECISION */ -#define FLOAT double -#define FABS(x) fabs(x) -#define FLOOR(x) floor(x) -#define LOG(x) log(x) -#define POW(x,y) pow(x,y) -#define SQRT(x) sqrt(x) +#define FLOAT double +#define FABS( x ) fabs( x ) +#define FLOOR( x ) floor( x ) +#define LOG( x ) log( x ) +#define POW( x, y ) pow( x, y ) +#define SQRT( x ) sqrt( x ) #endif /* SINGLE_PRECISION */ -jmp_buf ovfl_buf; +jmp_buf ovfl_buf; /* extern double fabs (), floor (), log (), pow (), sqrt (); */ /* extern void exit (); */ -extern void _sigfpe(int); -typedef void (*Sig_type) (int); -FLOAT Sign (FLOAT), Random (void); -extern void BadCond (int, char*); -extern void SqXMinX (int); -extern void TstCond (int, int, char*); -extern void notify (char *); +extern void _sigfpe( int ); +typedef void ( *Sig_type )( int ); +FLOAT Sign( FLOAT ), Random( void ); +extern void BadCond( int, char * ); +extern void SqXMinX( int ); +extern void TstCond( int, int, char * ); +extern void notify( char * ); /* extern int read (); */ -extern void Characteristics (void); -extern void Heading (void); -extern void History (void); -extern void Instructions (void); -extern void IsYeqX (void); -extern void NewD (void); -extern void Pause (void); -extern void PrintIfNPositive (void); -extern void SR3750 (void); -extern void SR3980 (void); -extern void TstPtUf (void); +extern void Characteristics( void ); +extern void Heading( void ); +extern void History( void ); +extern void Instructions( void ); +extern void IsYeqX( void ); +extern void NewD( void ); +extern void Pause( void ); +extern void PrintIfNPositive( void ); +extern void SR3750( void ); +extern void SR3980( void ); +extern void TstPtUf( void ); -void msglist(char**); +void msglist( char ** ); Sig_type sigsave; #define KEYBOARD 0 -FLOAT Radix, BInvrse, RadixD2, BMinusU2; +FLOAT Radix, BInvrse, RadixD2, BMinusU2; /*Small floating point constants.*/ -FLOAT Zero = 0.0; -FLOAT Half = 0.5; -FLOAT One = 1.0; -FLOAT Two = 2.0; -FLOAT Three = 3.0; -FLOAT Four = 4.0; -FLOAT Five = 5.0; -FLOAT Eight = 8.0; -FLOAT Nine = 9.0; -FLOAT TwentySeven = 27.0; -FLOAT ThirtyTwo = 32.0; -FLOAT TwoForty = 240.0; -FLOAT MinusOne = -1.0; -FLOAT OneAndHalf = 1.5; +FLOAT Zero = 0.0; +FLOAT Half = 0.5; +FLOAT One = 1.0; +FLOAT Two = 2.0; +FLOAT Three = 3.0; +FLOAT Four = 4.0; +FLOAT Five = 5.0; +FLOAT Eight = 8.0; +FLOAT Nine = 9.0; +FLOAT TwentySeven = 27.0; +FLOAT ThirtyTwo = 32.0; +FLOAT TwoForty = 240.0; +FLOAT MinusOne = -1.0; +FLOAT OneAndHalf = 1.5; /*Integer constants*/ -int NoTrials = 20; /*Number of tests for commutativity. */ +int NoTrials = 20; /*Number of tests for commutativity. */ #define False 0 -#define True 1 +#define True 1 /* * Definitions for declared types @@ -258,8 +258,8 @@ int NoTrials = 20; /*Number of tests for commutativity. */ * Message == packed array [1..40] of char; * Class == (Flaw, Defect, Serious, Failure); */ -#define Yes 1 -#define No 0 +#define Yes 1 +#define No 0 #define Chopped 2 #define Rounded 1 #define Other 0 @@ -267,59 +267,60 @@ int NoTrials = 20; /*Number of tests for commutativity. */ #define Defect 2 #define Serious 1 #define Failure 0 -typedef int Guard, Rounding, Class; +typedef int Guard, Rounding, Class; typedef char Message; /* Declarations of Variables */ -int Indx; -char ch[8]; -FLOAT AInvrse, A1; -FLOAT C, CInvrse; -FLOAT D, FourD; -FLOAT E0, E1, Exp2, E3, MinSqEr; -FLOAT SqEr, MaxSqEr, E9; -FLOAT Third; -FLOAT F6, F9; -FLOAT HVar, HInvrse; -int I; -FLOAT StickyBit, J; -FLOAT MyZero; -FLOAT Precision; -FLOAT Q, Q9; -FLOAT R, Random9; -FLOAT T, Underflow, S; -FLOAT OneUlp, UfThold, U1, U2; -FLOAT V, V0, V9; -FLOAT WVar; -FLOAT X, X1, X2, X8, Random1; -FLOAT Y, Y1, Y2, Random2; -FLOAT Z, PseudoZero, Z1, Z2, Z9; -int ErrCnt[4]; -int fpecount; -int Milestone; -int PageNo; -int M, N, N1; -Guard GMult, GDiv, GAddSub; +int Indx; +char ch[ 8 ]; +FLOAT AInvrse, A1; +FLOAT C, CInvrse; +FLOAT D, FourD; +FLOAT E0, E1, Exp2, E3, MinSqEr; +FLOAT SqEr, MaxSqEr, E9; +FLOAT Third; +FLOAT F6, F9; +FLOAT HVar, HInvrse; +int I; +FLOAT StickyBit, J; +FLOAT MyZero; +FLOAT Precision; +FLOAT Q, Q9; +FLOAT R, Random9; +FLOAT T, Underflow, S; +FLOAT OneUlp, UfThold, U1, U2; +FLOAT V, V0, V9; +FLOAT WVar; +FLOAT X, X1, X2, X8, Random1; +FLOAT Y, Y1, Y2, Random2; +FLOAT Z, PseudoZero, Z1, Z2, Z9; +int ErrCnt[ 4 ]; +int fpecount; +int Milestone; +int PageNo; +int M, N, N1; +Guard GMult, GDiv, GAddSub; Rounding RMult, RDiv, RAddSub, RSqrt; -int Break, Done, NotMonot, Monot, Anomaly, IEEE, SqRWrng, UfNGrad; +int Break, Done, NotMonot, Monot, Anomaly, IEEE, SqRWrng, UfNGrad; /* Computed constants. * U1 gap below 1.0, i.e, 1.0 - U1 is next number below 1.0 * U2 gap above 1.0, i.e, 1.0 + U2 is next number above 1.0 */ -int batchmode; /* global batchmode test */ +int batchmode; /* global batchmode test */ /* program name and version variables and macro */ -char *temp; -char *program_name; -char *program_vers; +char *temp; +char *program_name; +char *program_vers; #ifndef VERSION #define VERSION "1.1 [cygnus]" #endif /* VERSION */ -#define basename(cp) ((temp=(char *)strrchr((cp), '/')) ? temp+1 : (cp)) +#define basename( cp ) \ + ( ( temp = (char *) strrchr( ( cp ), '/' ) ) ? temp + 1 : ( cp ) ) #ifndef BATCHMODE # ifdef CYGNUS @@ -328,1690 +329,1811 @@ char *program_vers; #endif /* floating point exception receiver */ -void -_sigfpe (int x) +void _sigfpe( int x ) { - fpecount++; - printf ("\n* * * FLOATING-POINT ERROR %d * * *\n", x); - fflush (stdout); - if (sigsave) { + fpecount++; + printf( "\n* * * FLOATING-POINT ERROR %d * * *\n", x ); + fflush( stdout ); + if ( sigsave ) { #ifndef NOSIGNAL - signal (SIGFPE, sigsave); + signal( SIGFPE, sigsave ); #endif /* NOSIGNAL */ - sigsave = 0; - longjmp (ovfl_buf, 1); - } - exit (1); + sigsave = 0; + longjmp( ovfl_buf, 1 ); + } + exit( 1 ); } #ifdef NOMAIN #define main paranoia -int paranoia(int, char**); +int paranoia( int, char ** ); #endif -int -main ( - int argc, - char **argv -) +int main( int argc, char **argv ) { #ifdef __rtems__ - (void) argc; + (void) argc; #endif - /* First two assignments use integer right-hand sides. */ - Zero = 0; - One = 1; - Two = One + One; - Three = Two + One; - Four = Three + One; - Five = Four + One; - Eight = Four + Four; - Nine = Three * Three; - TwentySeven = Nine * Three; - ThirtyTwo = Four * Eight; - TwoForty = Four * Five * Three * Four; - MinusOne = -One; - Half = One / Two; - OneAndHalf = One + Half; - ErrCnt[Failure] = 0; - ErrCnt[Serious] = 0; - ErrCnt[Defect] = 0; - ErrCnt[Flaw] = 0; - PageNo = 1; + /* First two assignments use integer right-hand sides. */ + Zero = 0; + One = 1; + Two = One + One; + Three = Two + One; + Four = Three + One; + Five = Four + One; + Eight = Four + Four; + Nine = Three * Three; + TwentySeven = Nine * Three; + ThirtyTwo = Four * Eight; + TwoForty = Four * Five * Three * Four; + MinusOne = -One; + Half = One / Two; + OneAndHalf = One + Half; + ErrCnt[ Failure ] = 0; + ErrCnt[ Serious ] = 0; + ErrCnt[ Defect ] = 0; + ErrCnt[ Flaw ] = 0; + PageNo = 1; #ifdef BATCHMODE - batchmode = 1; /* run test in batchmode? */ -#else /* !BATCHMODE */ - batchmode = 0; /* run test interactively */ -#endif /* BATCHMODE */ + batchmode = 1; /* run test in batchmode? */ +#else /* !BATCHMODE */ + batchmode = 0; /* run test interactively */ +#endif /* BATCHMODE */ - program_name = basename (argv[0]); - program_vers = VERSION; + program_name = basename( argv[ 0 ] ); + program_vers = VERSION; - printf ("%s version %s\n", program_name, program_vers); + printf( "%s version %s\n", program_name, program_vers ); - /*=============================================*/ - Milestone = 0; - /*=============================================*/ + /*=============================================*/ + Milestone = 0; + /*=============================================*/ #ifndef NOSIGNAL - signal (SIGFPE, _sigfpe); + signal( SIGFPE, _sigfpe ); #endif - if (!batchmode) { - Instructions (); - Pause (); - Heading (); - Instructions (); - Pause (); - Heading (); - Pause (); - Characteristics (); - Pause (); - History (); - Pause (); - } + if ( !batchmode ) { + Instructions(); + Pause(); + Heading(); + Instructions(); + Pause(); + Heading(); + Pause(); + Characteristics(); + Pause(); + History(); + Pause(); + } - /*=============================================*/ - Milestone = 7; - /*=============================================*/ - printf ("Program is now RUNNING tests on small integers:\n"); - TstCond (Failure, (Zero + Zero == Zero) && (One - One == Zero) - && (One > Zero) && (One + One == Two), - "0+0 != 0, 1-1 != 0, 1 <= 0, or 1+1 != 2"); - Z = -Zero; - if (Z != 0.0) { - ErrCnt[Failure] = ErrCnt[Failure] + 1; - printf ("Comparison alleges that -0.0 is Non-zero!\n"); - U1 = 0.001; - Radix = 1; - TstPtUf (); - } - TstCond (Failure, (Three == Two + One) && (Four == Three + One) - && (Four + Two * (-Two) == Zero) - && (Four - Three - One == Zero), - "3 != 2+1, 4 != 3+1, 4+2*(-2) != 0, or 4-3-1 != 0"); - TstCond (Failure, (MinusOne == (0 - One)) - && (MinusOne + One == Zero) && (One + MinusOne == Zero) - && (MinusOne + FABS (One) == Zero) - && (MinusOne + MinusOne * MinusOne == Zero), - "-1+1 != 0, (-1)+abs(1) != 0, or -1+(-1)*(-1) != 0"); - TstCond (Failure, Half + MinusOne + Half == Zero, - "1/2 + (-1) + 1/2 != 0"); - /*=============================================*/ - Milestone = 10; - /*=============================================*/ - TstCond (Failure, (Nine == Three * Three) - && (TwentySeven == Nine * Three) && (Eight == Four + Four) - && (ThirtyTwo == Eight * Four) - && (ThirtyTwo - TwentySeven - Four - One == Zero), - "9 != 3*3, 27 != 9*3, 32 != 8*4, or 32-27-4-1 != 0"); - TstCond (Failure, (Five == Four + One) && - (TwoForty == Four * Five * Three * Four) - && (TwoForty / Three - Four * Four * Five == Zero) - && (TwoForty / Four - Five * Three * Four == Zero) - && (TwoForty / Five - Four * Three * Four == Zero), - "5 != 4+1, 240/3 != 80, 240/4 != 60, or 240/5 != 48"); - if (ErrCnt[Failure] == 0) { - printf ("-1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240 are O.K.\n"); - printf ("\n"); - } - printf ("Searching for Radix and Precision.\n"); + /*=============================================*/ + Milestone = 7; + /*=============================================*/ + printf( "Program is now RUNNING tests on small integers:\n" ); + TstCond( + Failure, + ( Zero + Zero == Zero ) && ( One - One == Zero ) && ( One > Zero ) && + ( One + One == Two ), + "0+0 != 0, 1-1 != 0, 1 <= 0, or 1+1 != 2" + ); + Z = -Zero; + if ( Z != 0.0 ) { + ErrCnt[ Failure ] = ErrCnt[ Failure ] + 1; + printf( "Comparison alleges that -0.0 is Non-zero!\n" ); + U1 = 0.001; + Radix = 1; + TstPtUf(); + } + TstCond( + Failure, + ( Three == Two + One ) && ( Four == Three + One ) && + ( Four + Two * ( -Two ) == Zero ) && ( Four - Three - One == Zero ), + "3 != 2+1, 4 != 3+1, 4+2*(-2) != 0, or 4-3-1 != 0" + ); + TstCond( + Failure, + ( MinusOne == ( 0 - One ) ) && ( MinusOne + One == Zero ) && + ( One + MinusOne == Zero ) && ( MinusOne + FABS( One ) == Zero ) && + ( MinusOne + MinusOne * MinusOne == Zero ), + "-1+1 != 0, (-1)+abs(1) != 0, or -1+(-1)*(-1) != 0" + ); + TstCond( Failure, Half + MinusOne + Half == Zero, "1/2 + (-1) + 1/2 != 0" ); + /*=============================================*/ + Milestone = 10; + /*=============================================*/ + TstCond( + Failure, + ( Nine == Three * Three ) && ( TwentySeven == Nine * Three ) && + ( Eight == Four + Four ) && ( ThirtyTwo == Eight * Four ) && + ( ThirtyTwo - TwentySeven - Four - One == Zero ), + "9 != 3*3, 27 != 9*3, 32 != 8*4, or 32-27-4-1 != 0" + ); + TstCond( + Failure, + ( Five == Four + One ) && ( TwoForty == Four * Five * Three * Four ) && + ( TwoForty / Three - Four * Four * Five == Zero ) && + ( TwoForty / Four - Five * Three * Four == Zero ) && + ( TwoForty / Five - Four * Three * Four == Zero ), + "5 != 4+1, 240/3 != 80, 240/4 != 60, or 240/5 != 48" + ); + if ( ErrCnt[ Failure ] == 0 ) { + printf( "-1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240 are O.K.\n" ); + printf( "\n" ); + } + printf( "Searching for Radix and Precision.\n" ); + WVar = One; + do { + WVar = WVar + WVar; + Y = WVar + One; + Z = Y - WVar; + Y = Z - One; + } while ( MinusOne + FABS( Y ) < Zero ); + /*.. now WVar is just big enough that |((WVar+1)-WVar)-1| >= 1 ...*/ + Precision = Zero; + Y = One; + do { + Radix = WVar + Y; + Y = Y + Y; + Radix = Radix - WVar; + } while ( Radix == Zero ); + if ( Radix < Two ) { + Radix = One; + } + printf( "Radix = %f .\n", Radix ); + if ( Radix != 1 ) { WVar = One; do { - WVar = WVar + WVar; - Y = WVar + One; - Z = Y - WVar; - Y = Z - One; - } - while (MinusOne + FABS (Y) < Zero); - /*.. now WVar is just big enough that |((WVar+1)-WVar)-1| >= 1 ...*/ - Precision = Zero; - Y = One; - do { - Radix = WVar + Y; - Y = Y + Y; - Radix = Radix - WVar; - } - while (Radix == Zero); - if (Radix < Two) - Radix = One; - printf ("Radix = %f .\n", Radix); - if (Radix != 1) { - WVar = One; - do { - Precision = Precision + One; - WVar = WVar * Radix; - Y = WVar + One; - } - while ((Y - WVar) == One); - } - /*... now WVar == Radix^Precision is barely too big to satisfy (WVar+1)-WVar == 1 + Precision = Precision + One; + WVar = WVar * Radix; + Y = WVar + One; + } while ( ( Y - WVar ) == One ); + } + /*... now WVar == Radix^Precision is barely too big to satisfy (WVar+1)-WVar == 1 ...*/ - U1 = One / WVar; - U2 = Radix * U1; - printf ("Closest relative separation found is U1 = %.7e .\n\n", U1); - printf ("Recalculating radix and precision\n "); + U1 = One / WVar; + U2 = Radix * U1; + printf( "Closest relative separation found is U1 = %.7e .\n\n", U1 ); + printf( "Recalculating radix and precision\n " ); - /*save old values*/ - E0 = Radix; - E1 = U1; - E9 = U2; - E3 = Precision; + /*save old values*/ + E0 = Radix; + E1 = U1; + E9 = U2; + E3 = Precision; - X = Four / Three; - Third = X - One; - F6 = Half - Third; - X = F6 + F6; - X = FABS (X - Third); - if (X < U2) - X = U2; + X = Four / Three; + Third = X - One; + F6 = Half - Third; + X = F6 + F6; + X = FABS( X - Third ); + if ( X < U2 ) { + X = U2; + } - /*... now X = (unknown no.) ulps of 1+...*/ - do { - U2 = X; - Y = Half * U2 + ThirtyTwo * U2 * U2; - Y = One + Y; - X = Y - One; - } - while (!((U2 <= X) || (X <= Zero))); + /*... now X = (unknown no.) ulps of 1+...*/ + do { + U2 = X; + Y = Half * U2 + ThirtyTwo * U2 * U2; + Y = One + Y; + X = Y - One; + } while ( !( ( U2 <= X ) || ( X <= Zero ) ) ); - /*... now U2 == 1 ulp of 1 + ... */ - X = Two / Three; - F6 = X - Half; - Third = F6 + F6; - X = Third - Half; - X = FABS (X + F6); - if (X < U1) - X = U1; - - /*... now X == (unknown no.) ulps of 1 -... */ - do { - U1 = X; - Y = Half * U1 + ThirtyTwo * U1 * U1; - Y = Half - Y; - X = Half + Y; - Y = Half - X; - X = Half + Y; - } - while (!((U1 <= X) || (X <= Zero))); - /*... now U1 == 1 ulp of 1 - ... */ - if (U1 == E1) - printf ("confirms closest relative separation U1 .\n"); - else - printf ("gets better closest relative separation U1 = %.7e .\n", U1); - WVar = One / U1; - F9 = (Half - U1) + Half; - Radix = FLOOR (0.01 + U2 / U1); - if (Radix == E0) - printf ("Radix confirmed.\n"); - else - printf ("MYSTERY: recalculated Radix = %.7e .\n", Radix); - TstCond (Defect, Radix <= Eight + Eight, - "Radix is too big: roundoff problems"); - TstCond (Flaw, (Radix == Two) || (Radix == 10) - || (Radix == One), "Radix is not as good as 2 or 10"); - /*=============================================*/ - Milestone = 20; - /*=============================================*/ - TstCond (Failure, F9 - Half < Half, - "(1-U1)-1/2 < 1/2 is FALSE, prog. fails?"); - X = F9; - I = 1; - Y = X - Half; - Z = Y - Half; - TstCond (Failure, (X != One) - || (Z == Zero), "Comparison is fuzzy,X=1 but X-1/2-1/2 != 0"); - X = One + U2; - I = 0; - /*=============================================*/ - Milestone = 25; - /*=============================================*/ - /*... BMinusU2 = nextafter(Radix, 0) */ - BMinusU2 = Radix - One; - BMinusU2 = (BMinusU2 - U2) + One; - /* Purify Integers */ - if (Radix != One) { - X = -TwoForty * LOG (U1) / LOG (Radix); - Y = FLOOR (Half + X); - if (FABS (X - Y) * Four < One) - X = Y; - Precision = X / TwoForty; - Y = FLOOR (Half + Precision); - if (FABS (Precision - Y) * TwoForty < Half) - Precision = Y; - } - if ((Precision != FLOOR (Precision)) || (Radix == One)) { - printf ("Precision cannot be characterized by an Integer number\n"); - printf ("of significant digits but, by itself, this is a minor flaw.\n"); - } - if (Radix == One) - printf ("logarithmic encoding has precision characterized solely by U1.\n"); - else - printf ("The number of significant digits of the Radix is %f .\n", - Precision); - TstCond (Serious, U2 * Nine * Nine * TwoForty < One, - "Precision worse than 5 decimal figures "); - /*=============================================*/ - Milestone = 30; - /*=============================================*/ - /* Test for extra-precise subepressions */ - X = FABS (((Four / Three - One) - One / Four) * Three - One / Four); - do { - Z2 = X; - X = (One + (Half * Z2 + ThirtyTwo * Z2 * Z2)) - One; - } - while (!((Z2 <= X) || (X <= Zero))); - X = Y = Z = FABS ((Three / Four - Two / Three) * Three - One / Four); - do { - Z1 = Z; - Z = (One / Two - ((One / Two - (Half * Z1 + ThirtyTwo * Z1 * Z1)) - + One / Two)) + One / Two; - } - while (!((Z1 <= Z) || (Z <= Zero))); - do { - do { - Y1 = Y; - Y = (Half - ((Half - (Half * Y1 + ThirtyTwo * Y1 * Y1)) + Half - )) + Half; - } - while (!((Y1 <= Y) || (Y <= Zero))); - X1 = X; - X = ((Half * X1 + ThirtyTwo * X1 * X1) - F9) + F9; - } - while (!((X1 <= X) || (X <= Zero))); - if ((X1 != Y1) || (X1 != Z1)) { - BadCond (Serious, "Disagreements among the values X1, Y1, Z1,\n"); - printf ("respectively %.7e, %.7e, %.7e,\n", X1, Y1, Z1); - printf ("are symptoms of inconsistencies introduced\n"); - printf ("by extra-precise evaluation of arithmetic subexpressions.\n"); - notify ("Possibly some part of this"); - if ((X1 == U1) || (Y1 == U1) || (Z1 == U1)) - printf ( - "That feature is not tested further by this program.\n"); - } else { - if ((Z1 != U1) || (Z2 != U2)) { - if ((Z1 >= U1) || (Z2 >= U2)) { - BadCond (Failure, ""); - notify ("Precision"); - printf ("\tU1 = %.7e, Z1 - U1 = %.7e\n", U1, Z1 - U1); - printf ("\tU2 = %.7e, Z2 - U2 = %.7e\n", U2, Z2 - U2); - } else { - if ((Z1 <= Zero) || (Z2 <= Zero)) { - printf ("Because of unusual Radix = %f", Radix); - printf (", or exact rational arithmetic a result\n"); - printf ("Z1 = %.7e, or Z2 = %.7e ", Z1, Z2); - notify ("of an\nextra-precision"); - } - if (Z1 != Z2 || Z1 > Zero) { - X = Z1 / U1; - Y = Z2 / U2; - if (Y > X) - X = Y; - Q = -LOG (X); - printf ("Some subexpressions appear to be calculated extra\n"); - printf ("precisely with about %g extra B-digits, i.e.\n", - (Q / LOG (Radix))); - printf ("roughly %g extra significant decimals.\n", - Q / LOG (10.)); - } - printf ("That feature is not tested further by this program.\n"); - } - } - } - Pause (); - /*=============================================*/ - Milestone = 35; - /*=============================================*/ - if (Radix >= Two) { - X = WVar / (Radix * Radix); - Y = X + One; - Z = Y - X; - T = Z + U2; - X = T - Z; - TstCond (Failure, X == U2, - "Subtraction is not normalized X=Y,X+Z != Y+Z!"); - if (X == U2) - printf ( - "Subtraction appears to be normalized, as it should be."); - } - printf ("\nChecking for guard digit in *, /, and -.\n"); - Y = F9 * One; - Z = One * F9; - X = F9 - Half; - Y = (Y - Half) - X; - Z = (Z - Half) - X; - X = One + U2; - T = X * Radix; - R = Radix * X; - X = T - Radix; - X = X - Radix * U2; - T = R - Radix; - T = T - Radix * U2; - X = X * (Radix - One); - T = T * (Radix - One); - if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T == Zero)) - GMult = Yes; - else { - GMult = No; - TstCond (Serious, False, - "* lacks a Guard Digit, so 1*X != X"); - } - Z = Radix * U2; - X = One + Z; - Y = FABS ((X + Z) - X * X) - U2; - X = One - U2; - Z = FABS ((X - U2) - X * X) - U1; - TstCond (Failure, (Y <= Zero) - && (Z <= Zero), "* gets too many final digits wrong.\n"); - Y = One - U2; - X = One + U2; - Z = One / Y; - Y = Z - X; - X = One / Three; - Z = Three / Nine; - X = X - Z; - T = Nine / TwentySeven; - Z = Z - T; - TstCond (Defect, X == Zero && Y == Zero && Z == Zero, - "Division lacks a Guard Digit, so error can exceed 1 ulp\n\ -or 1/3 and 3/9 and 9/27 may disagree"); - Y = F9 / One; - X = F9 - Half; - Y = (Y - Half) - X; - X = One + U2; - T = X / One; - X = T - X; - if ((X == Zero) && (Y == Zero) && (Z == Zero)) - GDiv = Yes; - else { - GDiv = No; - TstCond (Serious, False, - "Division lacks a Guard Digit, so X/1 != X"); - } - X = One / (One + U2); - Y = X - Half - Half; - TstCond (Serious, Y < Zero, - "Computed value of 1/1.000..1 >= 1"); - X = One - U2; - Y = One + Radix * U2; - Z = X * Radix; - T = Y * Radix; - R = Z / Radix; - StickyBit = T / Radix; - X = R - X; - Y = StickyBit - Y; - TstCond (Failure, X == Zero && Y == Zero, - "* and/or / gets too many last digits wrong"); - Y = One - U1; - X = One - F9; - Y = One - Y; - T = Radix - U2; - Z = Radix - BMinusU2; - T = Radix - T; - if ((X == U1) && (Y == U1) && (Z == U2) && (T == U2)) - GAddSub = Yes; - else { - GAddSub = No; - TstCond (Serious, False, - "- lacks Guard Digit, so cancellation is obscured"); - } - if (F9 != One && F9 - One >= Zero) { - BadCond (Serious, "comparison alleges (1-U1) < 1 although\n"); - printf (" subtraction yields (1-U1) - 1 = 0 , thereby vitiating\n"); - printf (" such precautions against division by zero as\n"); - printf (" ... if (X == 1.0) {.....} else {.../(X-1.0)...}\n"); - } - if (GMult == Yes && GDiv == Yes && GAddSub == Yes) - printf ( - " *, /, and - appear to have guard digits, as they should.\n"); - /*=============================================*/ - Milestone = 40; - /*=============================================*/ - Pause (); - printf ("Checking rounding on multiply, divide and add/subtract.\n"); - RMult = Other; - RDiv = Other; - RAddSub = Other; - RadixD2 = Radix / Two; - A1 = Two; - Done = False; - do { - AInvrse = Radix; - do { - X = AInvrse; - AInvrse = AInvrse / A1; - } - while (!(FLOOR (AInvrse) != AInvrse)); - Done = (X == One) || (A1 > Three); - if (!Done) - A1 = Nine + One; - } - while (!(Done)); - if (X == One) - A1 = Radix; - AInvrse = One / A1; - X = A1; - Y = AInvrse; - Done = False; - do { - Z = X * Y - Half; - TstCond (Failure, Z == Half, - "X * (1/X) differs from 1"); - Done = X == Radix; - X = Radix; - Y = One / X; - } - while (!(Done)); - Y2 = One + U2; - Y1 = One - U2; - X = OneAndHalf - U2; - Y = OneAndHalf + U2; - Z = (X - U2) * Y2; - T = Y * Y1; - Z = Z - X; - T = T - X; - X = X * Y2; - Y = (Y + U2) * Y1; - X = X - OneAndHalf; - Y = Y - OneAndHalf; - if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T <= Zero)) { - X = (OneAndHalf + U2) * Y2; - Y = OneAndHalf - U2 - U2; - Z = OneAndHalf + U2 + U2; - T = (OneAndHalf - U2) * Y1; - X = X - (Z + U2); - StickyBit = Y * Y1; - S = Z * Y2; - T = T - Y; - Y = (U2 - Y) + StickyBit; - Z = S - (Z + U2 + U2); - StickyBit = (Y2 + U2) * Y1; - Y1 = Y2 * Y1; - StickyBit = StickyBit - Y2; - Y1 = Y1 - Half; - if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T == Zero) - && (StickyBit == Zero) && (Y1 == Half)) { - RMult = Rounded; - printf ("Multiplication appears to round correctly.\n"); - } else if ((X + U2 == Zero) && (Y < Zero) && (Z + U2 == Zero) - && (T < Zero) && (StickyBit + U2 == Zero) - && (Y1 < Half)) { - RMult = Chopped; - printf ("Multiplication appears to chop.\n"); - } else - printf ("* is neither chopped nor correctly rounded.\n"); - if ((RMult == Rounded) && (GMult == No)) - notify ("Multiplication"); - } else - printf ("* is neither chopped nor correctly rounded.\n"); - /*=============================================*/ - Milestone = 45; - /*=============================================*/ - Y2 = One + U2; - Y1 = One - U2; - Z = OneAndHalf + U2 + U2; - X = Z / Y2; - T = OneAndHalf - U2 - U2; - Y = (T - U2) / Y1; - Z = (Z + U2) / Y2; - X = X - OneAndHalf; - Y = Y - T; - T = T / Y1; - Z = Z - (OneAndHalf + U2); - T = (U2 - OneAndHalf) + T; - if (!((X > Zero) || (Y > Zero) || (Z > Zero) || (T > Zero))) { - X = OneAndHalf / Y2; - Y = OneAndHalf - U2; - Z = OneAndHalf + U2; - X = X - Y; - T = OneAndHalf / Y1; - Y = Y / Y1; - T = T - (Z + U2); - Y = Y - Z; - Z = Z / Y2; - Y1 = (Y2 + U2) / Y2; - Z = Z - OneAndHalf; - Y2 = Y1 - Y2; - Y1 = (F9 - U1) / F9; - if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T == Zero) - && (Y2 == Zero) && (Y2 == Zero) - && (Y1 - Half == F9 - Half)) { - RDiv = Rounded; - printf ("Division appears to round correctly.\n"); - if (GDiv == No) - notify ("Division"); - } else if ((X < Zero) && (Y < Zero) && (Z < Zero) && (T < Zero) - && (Y2 < Zero) && (Y1 - Half < F9 - Half)) { - RDiv = Chopped; - printf ("Division appears to chop.\n"); - } - } - if (RDiv == Other) - printf ("/ is neither chopped nor correctly rounded.\n"); - BInvrse = One / Radix; - TstCond (Failure, (BInvrse * Radix - Half == Half), - "Radix * ( 1 / Radix ) differs from 1"); - /*=============================================*/ - Milestone = 50; - /*=============================================*/ - TstCond (Failure, ((F9 + U1) - Half == Half) - && ((BMinusU2 + U2) - One == Radix - One), - "Incomplete carry-propagation in Addition"); - X = One - U1 * U1; - Y = One + U2 * (One - U2); - Z = F9 - Half; - X = (X - Half) - Z; - Y = Y - One; - if ((X == Zero) && (Y == Zero)) { - RAddSub = Chopped; - printf ("Add/Subtract appears to be chopped.\n"); - } - if (GAddSub == Yes) { - X = (Half + U2) * U2; - Y = (Half - U2) * U2; - X = One + X; - Y = One + Y; - X = (One + U2) - X; - Y = One - Y; - if ((X == Zero) && (Y == Zero)) { - X = (Half + U2) * U1; - Y = (Half - U2) * U1; - X = One - X; - Y = One - Y; - X = F9 - X; - Y = One - Y; - if ((X == Zero) && (Y == Zero)) { - RAddSub = Rounded; - printf ("Addition/Subtraction appears to round correctly.\n"); - if (GAddSub == No) - notify ("Add/Subtract"); - } else - printf ("Addition/Subtraction neither rounds nor chops.\n"); - } else - printf ("Addition/Subtraction neither rounds nor chops.\n"); - } else - printf ("Addition/Subtraction neither rounds nor chops.\n"); - S = One; - X = One + Half * (One + Half); - Y = (One + U2) * Half; - Z = X - Y; - T = Y - X; - StickyBit = Z + T; - if (StickyBit != Zero) { - S = Zero; - BadCond (Flaw, "(X - Y) + (Y - X) is non zero!\n"); - } - StickyBit = Zero; - if ((GMult == Yes) && (GDiv == Yes) && (GAddSub == Yes) - && (RMult == Rounded) && (RDiv == Rounded) - && (RAddSub == Rounded) && (FLOOR (RadixD2) == RadixD2)) { - printf ("Checking for sticky bit.\n"); - X = (Half + U1) * U2; - Y = Half * U2; - Z = One + Y; - T = One + X; - if ((Z - One <= Zero) && (T - One >= U2)) { - Z = T + Y; - Y = Z - X; - if ((Z - T >= U2) && (Y - T == Zero)) { - X = (Half + U1) * U1; - Y = Half * U1; - Z = One - Y; - T = One - X; - if ((Z - One == Zero) && (T - F9 == Zero)) { - Z = (Half - U1) * U1; - T = F9 - Z; - Q = F9 - Y; - if ((T - F9 == Zero) && (F9 - U1 - Q == Zero)) { - Z = (One + U2) * OneAndHalf; - T = (OneAndHalf + U2) - Z + U2; - X = One + Half / Radix; - Y = One + Radix * U2; - Z = X * Y; - if (T == Zero && X + Radix * U2 - Z == Zero) { - if (Radix != Two) { - X = Two + U2; - Y = X / Two; - if ((Y - One == Zero)) - StickyBit = S; - } else - StickyBit = S; - } - } - } - } - } - } - if (StickyBit == One) - printf ("Sticky bit apparently used correctly.\n"); - else - printf ("Sticky bit used incorrectly or not at all.\n"); - TstCond (Flaw, !(GMult == No || GDiv == No || GAddSub == No || - RMult == Other || RDiv == Other || RAddSub == Other), - "lack(s) of guard digits or failure(s) to correctly round or chop\n\ -(noted above) count as one flaw in the final tally below"); - /*=============================================*/ - Milestone = 60; - /*=============================================*/ - printf ("\n"); - printf ("Does Multiplication commute? "); - printf ("Testing on %d random pairs.\n", NoTrials); - Random9 = SQRT (3.0); - Random1 = Third; - I = 1; - do { - X = Random (); - Y = Random (); - Z9 = Y * X; - Z = X * Y; - Z9 = Z - Z9; - I = I + 1; - } - while (!((I > NoTrials) || (Z9 != Zero))); - if (I == NoTrials) { - Random1 = One + Half / Three; - Random2 = (U2 + U1) + One; - Z = Random1 * Random2; - Y = Random2 * Random1; - Z9 = (One + Half / Three) * ((U2 + U1) + One) - (One + Half / - Three) * ((U2 + U1) + One); - } - if (!((I == NoTrials) || (Z9 == Zero))) - BadCond (Defect, "X * Y == Y * X trial fails.\n"); - else - printf (" No failures found in %d integer pairs.\n", NoTrials); - /*=============================================*/ - Milestone = 70; - /*=============================================*/ - printf ("\nRunning test of square root(x).\n"); - TstCond (Failure, (Zero == SQRT (Zero)) - && (-Zero == SQRT (-Zero)) - && (One == SQRT (One)), "Square root of 0.0, -0.0 or 1.0 wrong"); - MinSqEr = Zero; - MaxSqEr = Zero; - J = Zero; - X = Radix; - OneUlp = U2; - SqXMinX (Serious); - X = BInvrse; - OneUlp = BInvrse * U1; - SqXMinX (Serious); + /*... now U2 == 1 ulp of 1 + ... */ + X = Two / Three; + F6 = X - Half; + Third = F6 + F6; + X = Third - Half; + X = FABS( X + F6 ); + if ( X < U1 ) { X = U1; - OneUlp = U1 * U1; - SqXMinX (Serious); - if (J != Zero) - Pause (); - printf ("Testing if sqrt(X * X) == X for %d Integers X.\n", NoTrials); - J = Zero; - X = Two; - Y = Radix; - if ((Radix != One)) - do { + } + + /*... now X == (unknown no.) ulps of 1 -... */ + do { + U1 = X; + Y = Half * U1 + ThirtyTwo * U1 * U1; + Y = Half - Y; + X = Half + Y; + Y = Half - X; + X = Half + Y; + } while ( !( ( U1 <= X ) || ( X <= Zero ) ) ); + /*... now U1 == 1 ulp of 1 - ... */ + if ( U1 == E1 ) { + printf( "confirms closest relative separation U1 .\n" ); + } else { + printf( "gets better closest relative separation U1 = %.7e .\n", U1 ); + } + WVar = One / U1; + F9 = ( Half - U1 ) + Half; + Radix = FLOOR( 0.01 + U2 / U1 ); + if ( Radix == E0 ) { + printf( "Radix confirmed.\n" ); + } else { + printf( "MYSTERY: recalculated Radix = %.7e .\n", Radix ); + } + TstCond( + Defect, + Radix <= Eight + Eight, + "Radix is too big: roundoff problems" + ); + TstCond( + Flaw, + ( Radix == Two ) || ( Radix == 10 ) || ( Radix == One ), + "Radix is not as good as 2 or 10" + ); + /*=============================================*/ + Milestone = 20; + /*=============================================*/ + TstCond( + Failure, + F9 - Half < Half, + "(1-U1)-1/2 < 1/2 is FALSE, prog. fails?" + ); + X = F9; + I = 1; + Y = X - Half; + Z = Y - Half; + TstCond( + Failure, + ( X != One ) || ( Z == Zero ), + "Comparison is fuzzy,X=1 but X-1/2-1/2 != 0" + ); + X = One + U2; + I = 0; + /*=============================================*/ + Milestone = 25; + /*=============================================*/ + /*... BMinusU2 = nextafter(Radix, 0) */ + BMinusU2 = Radix - One; + BMinusU2 = ( BMinusU2 - U2 ) + One; + /* Purify Integers */ + if ( Radix != One ) { + X = -TwoForty * LOG( U1 ) / LOG( Radix ); + Y = FLOOR( Half + X ); + if ( FABS( X - Y ) * Four < One ) { + X = Y; + } + Precision = X / TwoForty; + Y = FLOOR( Half + Precision ); + if ( FABS( Precision - Y ) * TwoForty < Half ) { + Precision = Y; + } + } + if ( ( Precision != FLOOR( Precision ) ) || ( Radix == One ) ) { + printf( "Precision cannot be characterized by an Integer number\n" ); + printf( "of significant digits but, by itself, this is a minor flaw.\n" ); + } + if ( Radix == One ) { + printf( + "logarithmic encoding has precision characterized solely by U1.\n" + ); + } else { + printf( + "The number of significant digits of the Radix is %f .\n", + Precision + ); + } + TstCond( + Serious, + U2 * Nine * Nine * TwoForty < One, + "Precision worse than 5 decimal figures " + ); + /*=============================================*/ + Milestone = 30; + /*=============================================*/ + /* Test for extra-precise subepressions */ + X = FABS( ( ( Four / Three - One ) - One / Four ) * Three - One / Four ); + do { + Z2 = X; + X = ( One + ( Half * Z2 + ThirtyTwo * Z2 * Z2 ) ) - One; + } while ( !( ( Z2 <= X ) || ( X <= Zero ) ) ); + X = Y = Z = FABS( ( Three / Four - Two / Three ) * Three - One / Four ); + do { + Z1 = Z; + Z = ( One / Two - ( ( One / Two - ( Half * Z1 + ThirtyTwo * Z1 * Z1 ) ) + + One / Two ) ) + + One / Two; + } while ( !( ( Z1 <= Z ) || ( Z <= Zero ) ) ); + do { + do { + Y1 = Y; + Y = ( Half - + ( ( Half - ( Half * Y1 + ThirtyTwo * Y1 * Y1 ) ) + Half ) ) + + Half; + } while ( !( ( Y1 <= Y ) || ( Y <= Zero ) ) ); + X1 = X; + X = ( ( Half * X1 + ThirtyTwo * X1 * X1 ) - F9 ) + F9; + } while ( !( ( X1 <= X ) || ( X <= Zero ) ) ); + if ( ( X1 != Y1 ) || ( X1 != Z1 ) ) { + BadCond( Serious, "Disagreements among the values X1, Y1, Z1,\n" ); + printf( "respectively %.7e, %.7e, %.7e,\n", X1, Y1, Z1 ); + printf( "are symptoms of inconsistencies introduced\n" ); + printf( "by extra-precise evaluation of arithmetic subexpressions.\n" ); + notify( "Possibly some part of this" ); + if ( ( X1 == U1 ) || ( Y1 == U1 ) || ( Z1 == U1 ) ) { + printf( "That feature is not tested further by this program.\n" ); + } + } else { + if ( ( Z1 != U1 ) || ( Z2 != U2 ) ) { + if ( ( Z1 >= U1 ) || ( Z2 >= U2 ) ) { + BadCond( Failure, "" ); + notify( "Precision" ); + printf( "\tU1 = %.7e, Z1 - U1 = %.7e\n", U1, Z1 - U1 ); + printf( "\tU2 = %.7e, Z2 - U2 = %.7e\n", U2, Z2 - U2 ); + } else { + if ( ( Z1 <= Zero ) || ( Z2 <= Zero ) ) { + printf( "Because of unusual Radix = %f", Radix ); + printf( ", or exact rational arithmetic a result\n" ); + printf( "Z1 = %.7e, or Z2 = %.7e ", Z1, Z2 ); + notify( "of an\nextra-precision" ); + } + if ( Z1 != Z2 || Z1 > Zero ) { + X = Z1 / U1; + Y = Z2 / U2; + if ( Y > X ) { X = Y; - Y = Radix * Y; + } + Q = -LOG( X ); + printf( "Some subexpressions appear to be calculated extra\n" ); + printf( + "precisely with about %g extra B-digits, i.e.\n", + ( Q / LOG( Radix ) ) + ); + printf( "roughly %g extra significant decimals.\n", Q / LOG( 10. ) ); } - while (!((Y - X >= NoTrials))); - OneUlp = X * U2; - I = 1; - while (I <= NoTrials) { - X = X + One; - SqXMinX (Defect); - if (J > Zero) - break; - I = I + 1; + printf( "That feature is not tested further by this program.\n" ); + } } - printf ("Test for sqrt monotonicity.\n"); - I = -1; - X = BMinusU2; - Y = Radix; - Z = Radix + Radix * U2; - NotMonot = False; - Monot = False; - while (!(NotMonot || Monot)) { - I = I + 1; - X = SQRT (X); - Q = SQRT (Y); - Z = SQRT (Z); - if ((X > Q) || (Q > Z)) - NotMonot = True; - else { - Q = FLOOR (Q + Half); - if ((I > 0) || (Radix == Q * Q)) - Monot = True; - else if (I > 0) { - if (I > 1) - Monot = True; - else { - Y = Y * BInvrse; - X = Y - U1; - Z = Y + U1; + } + Pause(); + /*=============================================*/ + Milestone = 35; + /*=============================================*/ + if ( Radix >= Two ) { + X = WVar / ( Radix * Radix ); + Y = X + One; + Z = Y - X; + T = Z + U2; + X = T - Z; + TstCond( + Failure, + X == U2, + "Subtraction is not normalized X=Y,X+Z != Y+Z!" + ); + if ( X == U2 ) { + printf( "Subtraction appears to be normalized, as it should be." ); + } + } + printf( "\nChecking for guard digit in *, /, and -.\n" ); + Y = F9 * One; + Z = One * F9; + X = F9 - Half; + Y = ( Y - Half ) - X; + Z = ( Z - Half ) - X; + X = One + U2; + T = X * Radix; + R = Radix * X; + X = T - Radix; + X = X - Radix * U2; + T = R - Radix; + T = T - Radix * U2; + X = X * ( Radix - One ); + T = T * ( Radix - One ); + if ( ( X == Zero ) && ( Y == Zero ) && ( Z == Zero ) && ( T == Zero ) ) { + GMult = Yes; + } else { + GMult = No; + TstCond( Serious, False, "* lacks a Guard Digit, so 1*X != X" ); + } + Z = Radix * U2; + X = One + Z; + Y = FABS( ( X + Z ) - X * X ) - U2; + X = One - U2; + Z = FABS( ( X - U2 ) - X * X ) - U1; + TstCond( + Failure, + ( Y <= Zero ) && ( Z <= Zero ), + "* gets too many final digits wrong.\n" + ); + Y = One - U2; + X = One + U2; + Z = One / Y; + Y = Z - X; + X = One / Three; + Z = Three / Nine; + X = X - Z; + T = Nine / TwentySeven; + Z = Z - T; + TstCond( + Defect, + X == Zero && Y == Zero && Z == Zero, + "Division lacks a Guard Digit, so error can exceed 1 ulp\n\ +or 1/3 and 3/9 and 9/27 may disagree" + ); + Y = F9 / One; + X = F9 - Half; + Y = ( Y - Half ) - X; + X = One + U2; + T = X / One; + X = T - X; + if ( ( X == Zero ) && ( Y == Zero ) && ( Z == Zero ) ) { + GDiv = Yes; + } else { + GDiv = No; + TstCond( Serious, False, "Division lacks a Guard Digit, so X/1 != X" ); + } + X = One / ( One + U2 ); + Y = X - Half - Half; + TstCond( Serious, Y < Zero, "Computed value of 1/1.000..1 >= 1" ); + X = One - U2; + Y = One + Radix * U2; + Z = X * Radix; + T = Y * Radix; + R = Z / Radix; + StickyBit = T / Radix; + X = R - X; + Y = StickyBit - Y; + TstCond( + Failure, + X == Zero && Y == Zero, + "* and/or / gets too many last digits wrong" + ); + Y = One - U1; + X = One - F9; + Y = One - Y; + T = Radix - U2; + Z = Radix - BMinusU2; + T = Radix - T; + if ( ( X == U1 ) && ( Y == U1 ) && ( Z == U2 ) && ( T == U2 ) ) { + GAddSub = Yes; + } else { + GAddSub = No; + TstCond( + Serious, + False, + "- lacks Guard Digit, so cancellation is obscured" + ); + } + if ( F9 != One && F9 - One >= Zero ) { + BadCond( Serious, "comparison alleges (1-U1) < 1 although\n" ); + printf( " subtraction yields (1-U1) - 1 = 0 , thereby vitiating\n" ); + printf( " such precautions against division by zero as\n" ); + printf( " ... if (X == 1.0) {.....} else {.../(X-1.0)...}\n" ); + } + if ( GMult == Yes && GDiv == Yes && GAddSub == Yes ) { + printf( + " *, /, and - appear to have guard digits, as they should.\n" + ); + } + /*=============================================*/ + Milestone = 40; + /*=============================================*/ + Pause(); + printf( "Checking rounding on multiply, divide and add/subtract.\n" ); + RMult = Other; + RDiv = Other; + RAddSub = Other; + RadixD2 = Radix / Two; + A1 = Two; + Done = False; + do { + AInvrse = Radix; + do { + X = AInvrse; + AInvrse = AInvrse / A1; + } while ( !( FLOOR( AInvrse ) != AInvrse ) ); + Done = ( X == One ) || ( A1 > Three ); + if ( !Done ) { + A1 = Nine + One; + } + } while ( !( Done ) ); + if ( X == One ) { + A1 = Radix; + } + AInvrse = One / A1; + X = A1; + Y = AInvrse; + Done = False; + do { + Z = X * Y - Half; + TstCond( Failure, Z == Half, "X * (1/X) differs from 1" ); + Done = X == Radix; + X = Radix; + Y = One / X; + } while ( !( Done ) ); + Y2 = One + U2; + Y1 = One - U2; + X = OneAndHalf - U2; + Y = OneAndHalf + U2; + Z = ( X - U2 ) * Y2; + T = Y * Y1; + Z = Z - X; + T = T - X; + X = X * Y2; + Y = ( Y + U2 ) * Y1; + X = X - OneAndHalf; + Y = Y - OneAndHalf; + if ( ( X == Zero ) && ( Y == Zero ) && ( Z == Zero ) && ( T <= Zero ) ) { + X = ( OneAndHalf + U2 ) * Y2; + Y = OneAndHalf - U2 - U2; + Z = OneAndHalf + U2 + U2; + T = ( OneAndHalf - U2 ) * Y1; + X = X - ( Z + U2 ); + StickyBit = Y * Y1; + S = Z * Y2; + T = T - Y; + Y = ( U2 - Y ) + StickyBit; + Z = S - ( Z + U2 + U2 ); + StickyBit = ( Y2 + U2 ) * Y1; + Y1 = Y2 * Y1; + StickyBit = StickyBit - Y2; + Y1 = Y1 - Half; + if ( + ( X == Zero ) && ( Y == Zero ) && ( Z == Zero ) && ( T == Zero ) && + ( StickyBit == Zero ) && ( Y1 == Half ) + ) { + RMult = Rounded; + printf( "Multiplication appears to round correctly.\n" ); + } else if ( + ( X + U2 == Zero ) && ( Y < Zero ) && ( Z + U2 == Zero ) && + ( T < Zero ) && ( StickyBit + U2 == Zero ) && ( Y1 < Half ) + ) { + RMult = Chopped; + printf( "Multiplication appears to chop.\n" ); + } else { + printf( "* is neither chopped nor correctly rounded.\n" ); + } + if ( ( RMult == Rounded ) && ( GMult == No ) ) { + notify( "Multiplication" ); + } + } else { + printf( "* is neither chopped nor correctly rounded.\n" ); + } + /*=============================================*/ + Milestone = 45; + /*=============================================*/ + Y2 = One + U2; + Y1 = One - U2; + Z = OneAndHalf + U2 + U2; + X = Z / Y2; + T = OneAndHalf - U2 - U2; + Y = ( T - U2 ) / Y1; + Z = ( Z + U2 ) / Y2; + X = X - OneAndHalf; + Y = Y - T; + T = T / Y1; + Z = Z - ( OneAndHalf + U2 ); + T = ( U2 - OneAndHalf ) + T; + if ( !( ( X > Zero ) || ( Y > Zero ) || ( Z > Zero ) || ( T > Zero ) ) ) { + X = OneAndHalf / Y2; + Y = OneAndHalf - U2; + Z = OneAndHalf + U2; + X = X - Y; + T = OneAndHalf / Y1; + Y = Y / Y1; + T = T - ( Z + U2 ); + Y = Y - Z; + Z = Z / Y2; + Y1 = ( Y2 + U2 ) / Y2; + Z = Z - OneAndHalf; + Y2 = Y1 - Y2; + Y1 = ( F9 - U1 ) / F9; + if ( + ( X == Zero ) && ( Y == Zero ) && ( Z == Zero ) && ( T == Zero ) && + ( Y2 == Zero ) && ( Y2 == Zero ) && ( Y1 - Half == F9 - Half ) + ) { + RDiv = Rounded; + printf( "Division appears to round correctly.\n" ); + if ( GDiv == No ) { + notify( "Division" ); + } + } else if ( + ( X < Zero ) && ( Y < Zero ) && ( Z < Zero ) && ( T < Zero ) && + ( Y2 < Zero ) && ( Y1 - Half < F9 - Half ) + ) { + RDiv = Chopped; + printf( "Division appears to chop.\n" ); + } + } + if ( RDiv == Other ) { + printf( "/ is neither chopped nor correctly rounded.\n" ); + } + BInvrse = One / Radix; + TstCond( + Failure, + ( BInvrse * Radix - Half == Half ), + "Radix * ( 1 / Radix ) differs from 1" + ); + /*=============================================*/ + Milestone = 50; + /*=============================================*/ + TstCond( + Failure, + ( ( F9 + U1 ) - Half == Half ) && + ( ( BMinusU2 + U2 ) - One == Radix - One ), + "Incomplete carry-propagation in Addition" + ); + X = One - U1 * U1; + Y = One + U2 * ( One - U2 ); + Z = F9 - Half; + X = ( X - Half ) - Z; + Y = Y - One; + if ( ( X == Zero ) && ( Y == Zero ) ) { + RAddSub = Chopped; + printf( "Add/Subtract appears to be chopped.\n" ); + } + if ( GAddSub == Yes ) { + X = ( Half + U2 ) * U2; + Y = ( Half - U2 ) * U2; + X = One + X; + Y = One + Y; + X = ( One + U2 ) - X; + Y = One - Y; + if ( ( X == Zero ) && ( Y == Zero ) ) { + X = ( Half + U2 ) * U1; + Y = ( Half - U2 ) * U1; + X = One - X; + Y = One - Y; + X = F9 - X; + Y = One - Y; + if ( ( X == Zero ) && ( Y == Zero ) ) { + RAddSub = Rounded; + printf( "Addition/Subtraction appears to round correctly.\n" ); + if ( GAddSub == No ) { + notify( "Add/Subtract" ); + } + } else { + printf( "Addition/Subtraction neither rounds nor chops.\n" ); + } + } else { + printf( "Addition/Subtraction neither rounds nor chops.\n" ); + } + } else { + printf( "Addition/Subtraction neither rounds nor chops.\n" ); + } + S = One; + X = One + Half * ( One + Half ); + Y = ( One + U2 ) * Half; + Z = X - Y; + T = Y - X; + StickyBit = Z + T; + if ( StickyBit != Zero ) { + S = Zero; + BadCond( Flaw, "(X - Y) + (Y - X) is non zero!\n" ); + } + StickyBit = Zero; + if ( + ( GMult == Yes ) && ( GDiv == Yes ) && ( GAddSub == Yes ) && + ( RMult == Rounded ) && ( RDiv == Rounded ) && ( RAddSub == Rounded ) && + ( FLOOR( RadixD2 ) == RadixD2 ) + ) { + printf( "Checking for sticky bit.\n" ); + X = ( Half + U1 ) * U2; + Y = Half * U2; + Z = One + Y; + T = One + X; + if ( ( Z - One <= Zero ) && ( T - One >= U2 ) ) { + Z = T + Y; + Y = Z - X; + if ( ( Z - T >= U2 ) && ( Y - T == Zero ) ) { + X = ( Half + U1 ) * U1; + Y = Half * U1; + Z = One - Y; + T = One - X; + if ( ( Z - One == Zero ) && ( T - F9 == Zero ) ) { + Z = ( Half - U1 ) * U1; + T = F9 - Z; + Q = F9 - Y; + if ( ( T - F9 == Zero ) && ( F9 - U1 - Q == Zero ) ) { + Z = ( One + U2 ) * OneAndHalf; + T = ( OneAndHalf + U2 ) - Z + U2; + X = One + Half / Radix; + Y = One + Radix * U2; + Z = X * Y; + if ( T == Zero && X + Radix * U2 - Z == Zero ) { + if ( Radix != Two ) { + X = Two + U2; + Y = X / Two; + if (( Y - One == Zero )) { + StickyBit = S; } - } else { - Y = Q; - X = Y - U2; - Z = Y + U2; + } else { + StickyBit = S; + } } + } } + } } - if (Monot) - printf ("sqrt has passed a test for Monotonicity.\n"); - else { - BadCond (Defect, ""); - printf ("sqrt(X) is non-monotonic for X near %.7e .\n", Y); + } + if ( StickyBit == One ) { + printf( "Sticky bit apparently used correctly.\n" ); + } else { + printf( "Sticky bit used incorrectly or not at all.\n" ); + } + TstCond( + Flaw, + !( GMult == No || GDiv == No || GAddSub == No || RMult == Other || + RDiv == Other || RAddSub == Other ), + "lack(s) of guard digits or failure(s) to correctly round or chop\n\ +(noted above) count as one flaw in the final tally below" + ); + /*=============================================*/ + Milestone = 60; + /*=============================================*/ + printf( "\n" ); + printf( "Does Multiplication commute? " ); + printf( "Testing on %d random pairs.\n", NoTrials ); + Random9 = SQRT( 3.0 ); + Random1 = Third; + I = 1; + do { + X = Random(); + Y = Random(); + Z9 = Y * X; + Z = X * Y; + Z9 = Z - Z9; + I = I + 1; + } while ( !( ( I > NoTrials ) || ( Z9 != Zero ) ) ); + if ( I == NoTrials ) { + Random1 = One + Half / Three; + Random2 = ( U2 + U1 ) + One; + Z = Random1 * Random2; + Y = Random2 * Random1; + Z9 = ( One + Half / Three ) * ( ( U2 + U1 ) + One ) - + ( One + Half / Three ) * ( ( U2 + U1 ) + One ); + } + if ( !( ( I == NoTrials ) || ( Z9 == Zero ) ) ) { + BadCond( Defect, "X * Y == Y * X trial fails.\n" ); + } else { + printf( " No failures found in %d integer pairs.\n", NoTrials ); + } + /*=============================================*/ + Milestone = 70; + /*=============================================*/ + printf( "\nRunning test of square root(x).\n" ); + TstCond( + Failure, + ( Zero == SQRT( Zero ) ) && ( -Zero == SQRT( -Zero ) ) && + ( One == SQRT( One ) ), + "Square root of 0.0, -0.0 or 1.0 wrong" + ); + MinSqEr = Zero; + MaxSqEr = Zero; + J = Zero; + X = Radix; + OneUlp = U2; + SqXMinX( Serious ); + X = BInvrse; + OneUlp = BInvrse * U1; + SqXMinX( Serious ); + X = U1; + OneUlp = U1 * U1; + SqXMinX( Serious ); + if ( J != Zero ) { + Pause(); + } + printf( "Testing if sqrt(X * X) == X for %d Integers X.\n", NoTrials ); + J = Zero; + X = Two; + Y = Radix; + if (( Radix != One )) { + do { + X = Y; + Y = Radix * Y; + } while ( !(( Y - X >= NoTrials )) ); + } + OneUlp = X * U2; + I = 1; + while ( I <= NoTrials ) { + X = X + One; + SqXMinX( Defect ); + if ( J > Zero ) { + break; } - /*=============================================*/ - Milestone = 80; - /*=============================================*/ - MinSqEr = MinSqEr + Half; - MaxSqEr = MaxSqEr - Half; - Y = (SQRT (One + U2) - One) / U2; - SqEr = (Y - One) + U2 / Eight; - if (SqEr > MaxSqEr) - MaxSqEr = SqEr; - SqEr = Y + U2 / Eight; - if (SqEr < MinSqEr) - MinSqEr = SqEr; - Y = ((SQRT (F9) - U2) - (One - U2)) / U1; - SqEr = Y + U1 / Eight; - if (SqEr > MaxSqEr) - MaxSqEr = SqEr; - SqEr = (Y + One) + U1 / Eight; - if (SqEr < MinSqEr) - MinSqEr = SqEr; - OneUlp = U2; - X = OneUlp; - for (Indx = 1; Indx <= 3; ++Indx) { - Y = SQRT ((X + U1 + X) + F9); - Y = ((Y - U2) - ((One - U2) + X)) / OneUlp; - Z = ((U1 - X) + F9) * Half * X * X / OneUlp; - SqEr = (Y + Half) + Z; - if (SqEr < MinSqEr) - MinSqEr = SqEr; - SqEr = (Y - Half) + Z; - if (SqEr > MaxSqEr) - MaxSqEr = SqEr; - if (((Indx == 1) || (Indx == 3))) - X = OneUlp * Sign (X) * FLOOR (Eight / (Nine * SQRT (OneUlp))); - else { - OneUlp = U1; - X = -OneUlp; + I = I + 1; + } + printf( "Test for sqrt monotonicity.\n" ); + I = -1; + X = BMinusU2; + Y = Radix; + Z = Radix + Radix * U2; + NotMonot = False; + Monot = False; + while ( !( NotMonot || Monot ) ) { + I = I + 1; + X = SQRT( X ); + Q = SQRT( Y ); + Z = SQRT( Z ); + if ( ( X > Q ) || ( Q > Z ) ) { + NotMonot = True; + } else { + Q = FLOOR( Q + Half ); + if ( ( I > 0 ) || ( Radix == Q * Q ) ) { + Monot = True; + } else if ( I > 0 ) { + if ( I > 1 ) { + Monot = True; + } else { + Y = Y * BInvrse; + X = Y - U1; + Z = Y + U1; } + } else { + Y = Q; + X = Y - U2; + Z = Y + U2; + } } - /*=============================================*/ - Milestone = 85; - /*=============================================*/ - SqRWrng = False; - Anomaly = False; - RSqrt = Other; /* ~dgh */ - if (Radix != One) { - printf ("Testing whether sqrt is rounded or chopped.\n"); - D = FLOOR (Half + POW (Radix, One + Precision - FLOOR (Precision))); - /* ... == Radix^(1 + fract) if (Precision == Integer + fract. */ - X = D / Radix; - Y = D / A1; - if ((X != FLOOR (X)) || (Y != FLOOR (Y))) { + } + if ( Monot ) { + printf( "sqrt has passed a test for Monotonicity.\n" ); + } else { + BadCond( Defect, "" ); + printf( "sqrt(X) is non-monotonic for X near %.7e .\n", Y ); + } + /*=============================================*/ + Milestone = 80; + /*=============================================*/ + MinSqEr = MinSqEr + Half; + MaxSqEr = MaxSqEr - Half; + Y = ( SQRT( One + U2 ) - One ) / U2; + SqEr = ( Y - One ) + U2 / Eight; + if ( SqEr > MaxSqEr ) { + MaxSqEr = SqEr; + } + SqEr = Y + U2 / Eight; + if ( SqEr < MinSqEr ) { + MinSqEr = SqEr; + } + Y = ( ( SQRT( F9 ) - U2 ) - ( One - U2 ) ) / U1; + SqEr = Y + U1 / Eight; + if ( SqEr > MaxSqEr ) { + MaxSqEr = SqEr; + } + SqEr = ( Y + One ) + U1 / Eight; + if ( SqEr < MinSqEr ) { + MinSqEr = SqEr; + } + OneUlp = U2; + X = OneUlp; + for ( Indx = 1; Indx <= 3; ++Indx ) { + Y = SQRT( ( X + U1 + X ) + F9 ); + Y = ( ( Y - U2 ) - ( ( One - U2 ) + X ) ) / OneUlp; + Z = ( ( U1 - X ) + F9 ) * Half * X * X / OneUlp; + SqEr = ( Y + Half ) + Z; + if ( SqEr < MinSqEr ) { + MinSqEr = SqEr; + } + SqEr = ( Y - Half ) + Z; + if ( SqEr > MaxSqEr ) { + MaxSqEr = SqEr; + } + if (( ( Indx == 1 ) || ( Indx == 3 ) )) { + X = OneUlp * Sign( X ) * FLOOR( Eight / ( Nine * SQRT( OneUlp ) ) ); + } else { + OneUlp = U1; + X = -OneUlp; + } + } + /*=============================================*/ + Milestone = 85; + /*=============================================*/ + SqRWrng = False; + Anomaly = False; + RSqrt = Other; /* ~dgh */ + if ( Radix != One ) { + printf( "Testing whether sqrt is rounded or chopped.\n" ); + D = FLOOR( Half + POW( Radix, One + Precision - FLOOR( Precision ) ) ); + /* ... == Radix^(1 + fract) if (Precision == Integer + fract. */ + X = D / Radix; + Y = D / A1; + if ( ( X != FLOOR( X ) ) || ( Y != FLOOR( Y ) ) ) { + Anomaly = True; + } else { + X = Zero; + Z2 = X; + Y = One; + Y2 = Y; + Z1 = Radix - One; + FourD = Four * D; + do { + if ( Y2 > Z2 ) { + Q = Radix; + Y1 = Y; + do { + X1 = FABS( Q + FLOOR( Half - Q / Y1 ) * Y1 ); + Q = Y1; + Y1 = X1; + } while ( !( X1 <= Zero ) ); + if ( Q <= One ) { + Z2 = Y2; + Z = Y; + } + } + Y = Y + Two; + X = X + Eight; + Y2 = Y2 + X; + if ( Y2 >= FourD ) { + Y2 = Y2 - FourD; + } + } while ( !( Y >= D ) ); + X8 = FourD - Z2; + Q = ( X8 + Z * Z ) / FourD; + X8 = X8 / Eight; + if ( Q != FLOOR( Q ) ) { + Anomaly = True; + } else { + Break = False; + do { + X = Z1 * Z; + X = X - FLOOR( X / Radix ) * Radix; + if ( X == One ) { + Break = True; + } else { + Z1 = Z1 - One; + } + } while ( !( Break || ( Z1 <= Zero ) ) ); + if ( ( Z1 <= Zero ) && ( !Break ) ) { + Anomaly = True; + } else { + if ( Z1 > RadixD2 ) { + Z1 = Z1 - Radix; + } + do { + NewD(); + } while ( !( U2 * D >= F9 ) ); + if ( D * Radix - D != WVar - D ) { Anomaly = True; - } else { - X = Zero; - Z2 = X; - Y = One; - Y2 = Y; - Z1 = Radix - One; - FourD = Four * D; - do { - if (Y2 > Z2) { - Q = Radix; - Y1 = Y; - do { - X1 = FABS (Q + FLOOR (Half - Q / Y1) * Y1); - Q = Y1; - Y1 = X1; - } - while (!(X1 <= Zero)); - if (Q <= One) { - Z2 = Y2; - Z = Y; - } - } - Y = Y + Two; - X = X + Eight; - Y2 = Y2 + X; - if (Y2 >= FourD) - Y2 = Y2 - FourD; - } - while (!(Y >= D)); - X8 = FourD - Z2; - Q = (X8 + Z * Z) / FourD; - X8 = X8 / Eight; - if (Q != FLOOR (Q)) + } else { + Z2 = D; + I = 0; + Y = D + ( One + Z ) * Half; + X = D + Z + Q; + SR3750(); + Y = D + ( One - Z ) * Half + D; + X = D - Z + D; + X = X + Q + X; + SR3750(); + NewD(); + if ( D - Z2 != WVar - Z2 ) { + Anomaly = True; + } else { + Y = ( D - Z2 ) + ( Z2 + ( One - Z ) * Half ); + X = ( D - Z2 ) + ( Z2 - Z + Q ); + SR3750(); + Y = ( One + Z ) * Half; + X = Q; + SR3750(); + if ( I == 0 ) { Anomaly = True; - else { - Break = False; - do { - X = Z1 * Z; - X = X - FLOOR (X / Radix) * Radix; - if (X == One) - Break = True; - else - Z1 = Z1 - One; - } - while (!(Break || (Z1 <= Zero))); - if ((Z1 <= Zero) && (!Break)) - Anomaly = True; - else { - if (Z1 > RadixD2) - Z1 = Z1 - Radix; - do { - NewD (); - } - while (!(U2 * D >= F9)); - if (D * Radix - D != WVar - D) - Anomaly = True; - else { - Z2 = D; - I = 0; - Y = D + (One + Z) * Half; - X = D + Z + Q; - SR3750 (); - Y = D + (One - Z) * Half + D; - X = D - Z + D; - X = X + Q + X; - SR3750 (); - NewD (); - if (D - Z2 != WVar - Z2) - Anomaly = True; - else { - Y = (D - Z2) + (Z2 + (One - Z) * Half); - X = (D - Z2) + (Z2 - Z + Q); - SR3750 (); - Y = (One + Z) * Half; - X = Q; - SR3750 (); - if (I == 0) - Anomaly = True; - } - } - } + } } + } } - if ((I == 0) || Anomaly) { - BadCond (Failure, "Anomalous arithmetic with Integer < "); - printf ("Radix^Precision = %.7e\n", WVar); - printf (" fails test whether sqrt rounds or chops.\n"); - SqRWrng = True; - } + } } - if (!Anomaly) { - if (!((MinSqEr < Zero) || (MaxSqEr > Zero))) { - RSqrt = Rounded; - printf ("Square root appears to be correctly rounded.\n"); - } else { - if ((MaxSqEr + U2 > U2 - Half) || (MinSqEr > Half) - || (MinSqEr + Radix < Half)) - SqRWrng = True; - else { - RSqrt = Chopped; - printf ("Square root appears to be chopped.\n"); - } - } + if ( ( I == 0 ) || Anomaly ) { + BadCond( Failure, "Anomalous arithmetic with Integer < " ); + printf( "Radix^Precision = %.7e\n", WVar ); + printf( " fails test whether sqrt rounds or chops.\n" ); + SqRWrng = True; } - if (SqRWrng) { - printf ("Square root is neither chopped nor correctly rounded.\n"); - printf ("Observed errors run from %.7e ", MinSqEr - Half); - printf ("to %.7e ulps.\n", Half + MaxSqEr); - TstCond (Serious, MaxSqEr - MinSqEr < Radix * Radix, - "sqrt gets too many last digits wrong"); + } + if ( !Anomaly ) { + if ( !( ( MinSqEr < Zero ) || ( MaxSqEr > Zero ) ) ) { + RSqrt = Rounded; + printf( "Square root appears to be correctly rounded.\n" ); + } else { + if ( + ( MaxSqEr + U2 > U2 - Half ) || ( MinSqEr > Half ) || + ( MinSqEr + Radix < Half ) + ) { + SqRWrng = True; + } else { + RSqrt = Chopped; + printf( "Square root appears to be chopped.\n" ); + } } - /*=============================================*/ - Milestone = 90; - /*=============================================*/ - Pause (); - printf ("Testing powers Z^i for small Integers Z and i.\n"); - N = 0; - /* ... test powers of zero. */ - I = 0; - Z = -Zero; - M = 3; - Break = False; + } + if ( SqRWrng ) { + printf( "Square root is neither chopped nor correctly rounded.\n" ); + printf( "Observed errors run from %.7e ", MinSqEr - Half ); + printf( "to %.7e ulps.\n", Half + MaxSqEr ); + TstCond( + Serious, + MaxSqEr - MinSqEr < Radix * Radix, + "sqrt gets too many last digits wrong" + ); + } + /*=============================================*/ + Milestone = 90; + /*=============================================*/ + Pause(); + printf( "Testing powers Z^i for small Integers Z and i.\n" ); + N = 0; + /* ... test powers of zero. */ + I = 0; + Z = -Zero; + M = 3; + Break = False; + do { + X = One; + SR3980(); + if ( I <= 10 ) { + I = 1023; + SR3980(); + } + if ( Z == MinusOne ) { + Break = True; + } else { + Z = MinusOne; + /* .. if(-1)^N is invalid, replace MinusOne by One. */ + I = -4; + } + } while ( !Break ); + PrintIfNPositive(); + N1 = N; + N = 0; + Z = A1; + M = (int) FLOOR( Two * LOG( WVar ) / LOG( A1 ) ); + Break = False; + do { + X = Z; + I = 1; + SR3980(); + if ( Z == AInvrse ) { + Break = True; + } else { + Z = AInvrse; + } + } while ( !( Break ) ); + /*=============================================*/ + Milestone = 100; + /*=============================================*/ + /* Powers of Radix have been tested, */ + /* next try a few primes */ + M = NoTrials; + Z = Three; + do { + X = Z; + I = 1; + SR3980(); do { - X = One; - SR3980 (); - if (I <= 10) { - I = 1023; - SR3980 (); - } - if (Z == MinusOne) - Break = True; - else { - Z = MinusOne; - /* .. if(-1)^N is invalid, replace MinusOne by One. */ - I = -4; - } - } - while (!Break); - PrintIfNPositive (); - N1 = N; - N = 0; - Z = A1; - M = (int) FLOOR (Two * LOG (WVar) / LOG (A1)); - Break = False; + Z = Z + Two; + } while ( Three * FLOOR( Z / Three ) == Z ); + } while ( Z < Eight * Three ); + if ( N > 0 ) { + printf( "Errors like this may invalidate financial calculations\n" ); + printf( "\tinvolving interest rates.\n" ); + } + PrintIfNPositive(); + N += N1; + if ( N == 0 ) { + printf( "... no discrepancies found.\n" ); + } + if ( N > 0 ) { + Pause(); + } else { + printf( "\n" ); + } + /*=============================================*/ + Milestone = 110; + /*=============================================*/ + printf( "Seeking Underflow thresholds UfThold and E0.\n" ); + D = U1; + if ( Precision != FLOOR( Precision ) ) { + D = BInvrse; + X = Precision; do { - X = Z; - I = 1; - SR3980 (); - if (Z == AInvrse) - Break = True; - else - Z = AInvrse; - } - while (!(Break)); - /*=============================================*/ - Milestone = 100; - /*=============================================*/ - /* Powers of Radix have been tested, */ - /* next try a few primes */ - M = NoTrials; - Z = Three; - do { - X = Z; - I = 1; - SR3980 (); - do { - Z = Z + Two; - } - while (Three * FLOOR (Z / Three) == Z); - } - while (Z < Eight * Three); - if (N > 0) { - printf ("Errors like this may invalidate financial calculations\n"); - printf ("\tinvolving interest rates.\n"); - } - PrintIfNPositive (); - N += N1; - if (N == 0) - printf ("... no discrepancies found.\n"); - if (N > 0) - Pause (); - else - printf ("\n"); - /*=============================================*/ - Milestone = 110; - /*=============================================*/ - printf ("Seeking Underflow thresholds UfThold and E0.\n"); - D = U1; - if (Precision != FLOOR (Precision)) { - D = BInvrse; - X = Precision; - do { - D = D * BInvrse; - X = X - One; - } - while (X > Zero); - } - Y = One; - Z = D; - /* ... D is power of 1/Radix < 1. */ - do { - C = Y; - Y = Z; - Z = Y * Y; - } - while ((Y > Z) && (Z + Z > Z)); - Y = C; + D = D * BInvrse; + X = X - One; + } while ( X > Zero ); + } + Y = One; + Z = D; + /* ... D is power of 1/Radix < 1. */ + do { + C = Y; + Y = Z; + Z = Y * Y; + } while ( ( Y > Z ) && ( Z + Z > Z ) ); + Y = C; + Z = Y * D; + do { + C = Y; + Y = Z; Z = Y * D; - do { - C = Y; - Y = Z; - Z = Y * D; - } - while ((Y > Z) && (Z + Z > Z)); - if (Radix < Two) - HInvrse = Two; - else - HInvrse = Radix; - HVar = One / HInvrse; - /* ... 1/HInvrse == HVar == Min(1/Radix, 1/2) */ - CInvrse = One / C; - E0 = C; + } while ( ( Y > Z ) && ( Z + Z > Z ) ); + if ( Radix < Two ) { + HInvrse = Two; + } else { + HInvrse = Radix; + } + HVar = One / HInvrse; + /* ... 1/HInvrse == HVar == Min(1/Radix, 1/2) */ + CInvrse = One / C; + E0 = C; + Z = E0 * HVar; + /* ...1/Radix^(BIG Integer) << 1 << CInvrse == 1/C */ + do { + Y = E0; + E0 = Z; Z = E0 * HVar; - /* ...1/Radix^(BIG Integer) << 1 << CInvrse == 1/C */ - do { - Y = E0; - E0 = Z; - Z = E0 * HVar; - } - while ((E0 > Z) && (Z + Z > Z)); - UfThold = E0; - E1 = Zero; - Q = Zero; - E9 = U2; + } while ( ( E0 > Z ) && ( Z + Z > Z ) ); + UfThold = E0; + E1 = Zero; + Q = Zero; + E9 = U2; + S = One + E9; + D = C * S; + if ( D <= C ) { + E9 = Radix * U2; S = One + E9; D = C * S; - if (D <= C) { - E9 = Radix * U2; - S = One + E9; - D = C * S; - if (D <= C) { - BadCond (Failure, "multiplication gets too many last digits wrong.\n"); - Underflow = E0; - Y1 = Zero; - PseudoZero = Z; - Pause (); - } - } else { - Underflow = D; - PseudoZero = Underflow * HVar; - UfThold = Zero; - do { - Y1 = Underflow; - Underflow = PseudoZero; - if (E1 + E1 <= E1) { - Y2 = Underflow * HInvrse; - E1 = FABS (Y1 - Y2); - Q = Y1; - if ((UfThold == Zero) && (Y1 != Y2)) - UfThold = Y1; - } - PseudoZero = PseudoZero * HVar; - } - while ((Underflow > PseudoZero) - && (PseudoZero + PseudoZero > PseudoZero)); + if ( D <= C ) { + BadCond( Failure, "multiplication gets too many last digits wrong.\n" ); + Underflow = E0; + Y1 = Zero; + PseudoZero = Z; + Pause(); } - /* Comment line 4530 .. 4560 */ - if (PseudoZero != Zero) { - printf ("\n"); - Z = PseudoZero; - /* ... Test PseudoZero for "phoney- zero" violates */ - /* ... PseudoZero < Underflow or PseudoZero < PseudoZero + PseudoZero + } else { + Underflow = D; + PseudoZero = Underflow * HVar; + UfThold = Zero; + do { + Y1 = Underflow; + Underflow = PseudoZero; + if ( E1 + E1 <= E1 ) { + Y2 = Underflow * HInvrse; + E1 = FABS( Y1 - Y2 ); + Q = Y1; + if ( ( UfThold == Zero ) && ( Y1 != Y2 ) ) { + UfThold = Y1; + } + } + PseudoZero = PseudoZero * HVar; + } while ( + ( Underflow > PseudoZero ) && ( PseudoZero + PseudoZero > PseudoZero ) + ); + } + /* Comment line 4530 .. 4560 */ + if ( PseudoZero != Zero ) { + printf( "\n" ); + Z = PseudoZero; + /* ... Test PseudoZero for "phoney- zero" violates */ + /* ... PseudoZero < Underflow or PseudoZero < PseudoZero + PseudoZero ... */ - if (PseudoZero <= Zero) { - BadCond (Failure, "Positive expressions can underflow to an\n"); - printf ("allegedly negative value\n"); - printf ("PseudoZero that prints out as: %g .\n", PseudoZero); - X = -PseudoZero; - if (X <= Zero) { - printf ("But -PseudoZero, which should be\n"); - printf ("positive, isn't; it prints out as %g .\n", X); - } - } else { - BadCond (Flaw, "Underflow can stick at an allegedly positive\n"); - printf ("value PseudoZero that prints out as %g .\n", PseudoZero); - } - TstPtUf (); + if ( PseudoZero <= Zero ) { + BadCond( Failure, "Positive expressions can underflow to an\n" ); + printf( "allegedly negative value\n" ); + printf( "PseudoZero that prints out as: %g .\n", PseudoZero ); + X = -PseudoZero; + if ( X <= Zero ) { + printf( "But -PseudoZero, which should be\n" ); + printf( "positive, isn't; it prints out as %g .\n", X ); + } + } else { + BadCond( Flaw, "Underflow can stick at an allegedly positive\n" ); + printf( "value PseudoZero that prints out as %g .\n", PseudoZero ); } - /*=============================================*/ - Milestone = 120; - /*=============================================*/ - if (CInvrse * Y > CInvrse * Y1) { - S = HVar * S; - E0 = Underflow; + TstPtUf(); + } + /*=============================================*/ + Milestone = 120; + /*=============================================*/ + if ( CInvrse * Y > CInvrse * Y1 ) { + S = HVar * S; + E0 = Underflow; + } + if ( !( ( E1 == Zero ) || ( E1 == E0 ) ) ) { + BadCond( Defect, "" ); + if ( E1 < E0 ) { + printf( "Products underflow at a higher" ); + printf( " threshold than differences.\n" ); + if ( PseudoZero == Zero ) { + E0 = E1; + } + } else { + printf( "Difference underflows at a higher" ); + printf( " threshold than products.\n" ); } - if (!((E1 == Zero) || (E1 == E0))) { - BadCond (Defect, ""); - if (E1 < E0) { - printf ("Products underflow at a higher"); - printf (" threshold than differences.\n"); - if (PseudoZero == Zero) - E0 = E1; - } else { - printf ("Difference underflows at a higher"); - printf (" threshold than products.\n"); - } - } - printf ("Smallest strictly positive number found is E0 = %g .\n", E0); - Z = E0; - TstPtUf (); - Underflow = E0; - if (N == 1) - Underflow = Y; - I = 4; - if (E1 == Zero) - I = 3; - if (UfThold == Zero) - I = I - 2; - UfNGrad = True; - switch (I) { + } + printf( "Smallest strictly positive number found is E0 = %g .\n", E0 ); + Z = E0; + TstPtUf(); + Underflow = E0; + if ( N == 1 ) { + Underflow = Y; + } + I = 4; + if ( E1 == Zero ) { + I = 3; + } + if ( UfThold == Zero ) { + I = I - 2; + } + UfNGrad = True; + switch ( I ) { case 1: - UfThold = Underflow; - if ((CInvrse * Q) != ((CInvrse * Y) * S)) { - UfThold = Y; - BadCond (Failure, "Either accuracy deteriorates as numbers\n"); - printf ("approach a threshold = %.17e\n", UfThold); - printf (" coming down from %.17e\n", C); - printf (" or else multiplication gets too many last digits wrong.\n"); - } - Pause (); - break; + UfThold = Underflow; + if ( ( CInvrse * Q ) != ( ( CInvrse * Y ) * S ) ) { + UfThold = Y; + BadCond( Failure, "Either accuracy deteriorates as numbers\n" ); + printf( "approach a threshold = %.17e\n", UfThold ); + printf( " coming down from %.17e\n", C ); + printf( " or else multiplication gets too many last digits wrong.\n" ); + } + Pause(); + break; case 2: - BadCond (Failure, "Underflow confuses Comparison, which alleges that\n"); - printf ("Q == Y while denying that |Q - Y| == 0; these values\n"); - printf ("print out as Q = %.17e, Y = %.17e .\n", Q, Y2); - printf ("|Q - Y| = %.17e .\n", FABS (Q - Y2)); - UfThold = Q; - break; + BadCond( + Failure, + "Underflow confuses Comparison, which alleges that\n" + ); + printf( "Q == Y while denying that |Q - Y| == 0; these values\n" ); + printf( "print out as Q = %.17e, Y = %.17e .\n", Q, Y2 ); + printf( "|Q - Y| = %.17e .\n", FABS( Q - Y2 ) ); + UfThold = Q; + break; case 3: - X = X; - break; + X = X; + break; case 4: - if ((Q == UfThold) && (E1 == E0) - && (FABS (UfThold - E1 / E9) <= E1)) { - UfNGrad = False; - printf ("Underflow is gradual; it incurs Absolute Error =\n"); - printf ("(roundoff in UfThold) < E0.\n"); - Y = E0 * CInvrse; - Y = Y * (OneAndHalf + U2); - X = CInvrse * (One + U2); - Y = Y / X; - IEEE = (Y == E0); - } - } - if (UfNGrad) { - printf ("\n"); - sigsave = _sigfpe; - if (setjmp (ovfl_buf)) { - printf ("Underflow / UfThold failed!\n"); - R = HVar + HVar; - } else - R = SQRT (Underflow / UfThold); - sigsave = 0; - if (R <= HVar) { - Z = R * UfThold; - X = Z * (One + R * HVar * (One + HVar)); - } else { - Z = UfThold; - X = Z * (One + HVar * HVar * (One + HVar)); - } - if (!((X == Z) || (X - Z != Zero))) { - BadCond (Flaw, ""); - printf ("X = %.17e\n\tis not equal to Z = %.17e .\n", X, Z); - Z9 = X - Z; - printf ("yet X - Z yields %.17e .\n", Z9); - printf (" Should this NOT signal Underflow, "); - printf ("this is a SERIOUS DEFECT\nthat causes "); - printf ("confusion when innocent statements like\n"); - printf (" if (X == Z) ... else"); - printf (" ... (f(X) - f(Z)) / (X - Z) ...\n"); - printf ("encounter Division by Zero although actually\n"); - sigsave = _sigfpe; - if (setjmp (ovfl_buf)) - printf ("X / Z fails!\n"); - else - printf ("X / Z = 1 + %g .\n", (X / Z - Half) - Half); - sigsave = 0; - } - } - printf ("The Underflow threshold is %.17e, %s\n", UfThold, - " below which"); - printf ("calculation may suffer larger Relative error than "); - printf ("merely roundoff.\n"); - Y2 = U1 * U1; - Y = Y2 * Y2; - Y2 = Y * U1; - if (Y2 <= UfThold) { - if (Y > E0) { - BadCond (Defect, ""); - I = 5; - } else { - BadCond (Serious, ""); - I = 4; - } - printf ("Range is too narrow; U1^%d Underflows.\n", I); - } - /*=============================================*/ - Milestone = 130; - /*=============================================*/ - Y = -FLOOR (Half - TwoForty * LOG (UfThold) / LOG (HInvrse)) / TwoForty; - Y2 = Y + Y; - printf ("Since underflow occurs below the threshold\n"); - printf ("UfThold = (%.17e) ^ (%.17e)\nonly underflow ", HInvrse, Y); - printf ("should afflict the expression\n\t(%.17e) ^ (%.17e);\n", - HInvrse, Y2); - printf ("actually calculating yields:"); - if (setjmp (ovfl_buf)) { - sigsave = 0; - BadCond (Serious, "trap on underflow.\n"); - } else { - sigsave = _sigfpe; - V9 = POW (HInvrse, Y2); - sigsave = 0; - printf (" %.17e .\n", V9); - if (!((V9 >= Zero) && (V9 <= (Radix + Radix + E9) * UfThold))) { - BadCond (Serious, "this is not between 0 and underflow\n"); - printf (" threshold = %.17e .\n", UfThold); - } else if (!(V9 > UfThold * (One + E9))) - printf ("This computed value is O.K.\n"); - else { - BadCond (Defect, "this is not between 0 and underflow\n"); - printf (" threshold = %.17e .\n", UfThold); - } - } - /*=============================================*/ - Milestone = 140; - /*=============================================*/ - printf ("\n"); - /* ...calculate Exp2 == exp(2) == 7.389056099... */ - X = Zero; - I = 2; - Y = Two * Three; - Q = Zero; - N = 0; - do { - Z = X; - I = I + 1; - Y = Y / (I + I); - R = Y + Q; - X = Z + R; - Q = (Z - X) + R; - } - while (X > Z); - Z = (OneAndHalf + One / Eight) + X / (OneAndHalf * ThirtyTwo); - X = Z * Z; - Exp2 = X * X; - X = F9; - Y = X - U1; - printf ("Testing X^((X + 1) / (X - 1)) vs. exp(2) = %.17e as X -> 1.\n", - Exp2); - for (I = 1;;) { - Z = X - BInvrse; - Z = (X + One) / (Z - (One - BInvrse)); - Q = POW (X, Z) - Exp2; - if (FABS (Q) > TwoForty * U2) { - N = 1; - V9 = (X - BInvrse) - (One - BInvrse); - BadCond (Defect, "Calculated"); - printf (" %.17e for\n", POW (X, Z)); - printf ("\t(1 + (%.17e) ^ (%.17e);\n", V9, Z); - printf ("\tdiffers from correct value by %.17e .\n", Q); - printf ("\tThis much error may spoil financial\n"); - printf ("\tcalculations involving tiny interest rates.\n"); - break; - } else { - Z = (Y - X) * Two + Y; - X = Y; - Y = Z; - Z = One + (X - F9) * (X - F9); - if (Z > One && I < NoTrials) - I++; - else { - if (X > One) { - if (N == 0) - printf ("Accuracy seems adequate.\n"); - break; - } else { - X = One + U2; - Y = U2 + U2; - Y += X; - I = 1; - } - } - } - } - /*=============================================*/ - Milestone = 150; - /*=============================================*/ - printf ("Testing powers Z^Q at four nearly extreme values.\n"); - N = 0; - Z = A1; - Q = FLOOR (Half - LOG (C) / LOG (A1)); - Break = False; - do { - X = CInvrse; - Y = POW (Z, Q); - IsYeqX (); - Q = -Q; - X = C; - Y = POW (Z, Q); - IsYeqX (); - if (Z < One) - Break = True; - else - Z = AInvrse; - } - while (!(Break)); - PrintIfNPositive (); - if (N == 0) - printf (" ... no discrepancies found.\n"); - printf ("\n"); - - /*=============================================*/ - Milestone = 160; - /*=============================================*/ - Pause (); - printf ("Searching for Overflow threshold:\n"); - printf ("This may generate an error.\n"); - Y = -CInvrse; - V9 = HInvrse * Y; + if ( + ( Q == UfThold ) && ( E1 == E0 ) && ( FABS( UfThold - E1 / E9 ) <= E1 ) + ) { + UfNGrad = False; + printf( "Underflow is gradual; it incurs Absolute Error =\n" ); + printf( "(roundoff in UfThold) < E0.\n" ); + Y = E0 * CInvrse; + Y = Y * ( OneAndHalf + U2 ); + X = CInvrse * ( One + U2 ); + Y = Y / X; + IEEE = ( Y == E0 ); + } + } + if ( UfNGrad ) { + printf( "\n" ); sigsave = _sigfpe; - if (setjmp (ovfl_buf)) { - I = 0; - V9 = Y; - goto overflow; + if ( setjmp( ovfl_buf ) ) { + printf( "Underflow / UfThold failed!\n" ); + R = HVar + HVar; + } else { + R = SQRT( Underflow / UfThold ); } - do { - V = Y; - Y = V9; - V9 = HInvrse * Y; - } - while (V9 < Y); - I = 1; - overflow: sigsave = 0; - Z = V9; - printf ("Can `Z = -Y' overflow?\n"); - printf ("Trying it on Y = %.17e .\n", Y); - V9 = -Y; - V0 = V9; - if (V - Y == V + V0) - printf ("Seems O.K.\n"); - else { - printf ("finds a "); - BadCond (Flaw, "-(-Y) differs from Y.\n"); - } - if (Z != Y) { - BadCond (Serious, ""); - printf ("overflow past %.17e\n\tshrinks to %.17e .\n", Y, Z); - } - if (I) { - Y = V * (HInvrse * U2 - HInvrse); - Z = Y + ((One - HInvrse) * U2) * V; - if (Z < V0) - Y = Z; - if (Y < V0) - V = Y; - if (V0 - V < V0) - V = V0; + if ( R <= HVar ) { + Z = R * UfThold; + X = Z * ( One + R * HVar * ( One + HVar ) ); } else { - V = Y * (HInvrse * U2 - HInvrse); - V = V + ((One - HInvrse) * U2) * Y; + Z = UfThold; + X = Z * ( One + HVar * HVar * ( One + HVar ) ); } - printf ("Overflow threshold is V = %.17e .\n", V); - if (I) - printf ("Overflow saturates at V0 = %.17e .\n", V0); - else - printf ("There is no saturation value because \ -the system traps on overflow.\n"); - V9 = V * One; - printf ("No Overflow should be signaled for V * 1 = %.17e\n", V9); - V9 = V / One; - printf (" nor for V / 1 = %.17e .\n", V9); - printf ("Any overflow signal separating this * from the one\n"); - printf ("above is a DEFECT.\n"); - /*=============================================*/ - Milestone = 170; - /*=============================================*/ - if (!(-V < V && -V0 < V0 && -UfThold < V && UfThold < V)) { - BadCond (Failure, "Comparisons involving "); - printf ("+-%g, +-%g\nand +-%g are confused by Overflow.", - V, V0, UfThold); + if ( !( ( X == Z ) || ( X - Z != Zero ) ) ) { + BadCond( Flaw, "" ); + printf( "X = %.17e\n\tis not equal to Z = %.17e .\n", X, Z ); + Z9 = X - Z; + printf( "yet X - Z yields %.17e .\n", Z9 ); + printf( " Should this NOT signal Underflow, " ); + printf( "this is a SERIOUS DEFECT\nthat causes " ); + printf( "confusion when innocent statements like\n" ); + printf( " if (X == Z) ... else" ); + printf( " ... (f(X) - f(Z)) / (X - Z) ...\n" ); + printf( "encounter Division by Zero although actually\n" ); + sigsave = _sigfpe; + if ( setjmp( ovfl_buf ) ) { + printf( "X / Z fails!\n" ); + } else { + printf( "X / Z = 1 + %g .\n", ( X / Z - Half ) - Half ); + } + sigsave = 0; } - /*=============================================*/ - Milestone = 175; - /*=============================================*/ - printf ("\n"); - for (Indx = 1; Indx <= 3; ++Indx) { - switch (Indx) { - case 1: - Z = UfThold; - break; - case 2: - Z = E0; - break; - case 3: - Z = PseudoZero; - break; - } - if (Z != Zero) { - V9 = SQRT (Z); - Y = V9 * V9; - if (Y / (One - Radix * E9) < Z - || Y > (One + Radix * E9) * Z) { /* dgh: + E9 --> * E9 */ - if (V9 > U1) - BadCond (Serious, ""); - else - BadCond (Defect, ""); - printf ("Comparison alleges that what prints as Z = %.17e\n", Z); - printf (" is too far from sqrt(Z) ^ 2 = %.17e .\n", Y); - } - } - } - /*=============================================*/ - Milestone = 180; - /*=============================================*/ - for (Indx = 1; Indx <= 2; ++Indx) { - if (Indx == 1) - Z = V; - else - Z = V0; - V9 = SQRT (Z); - X = (One - Radix * E9) * V9; - V9 = V9 * X; - if (((V9 < (One - Two * Radix * E9) * Z) || (V9 > Z))) { - Y = V9; - if (X < WVar) - BadCond (Serious, ""); - else - BadCond (Defect, ""); - printf ("Comparison alleges that Z = %17e\n", Z); - printf (" is too far from sqrt(Z) ^ 2 (%.17e) .\n", Y); - } - } - /*=============================================*/ - Milestone = 190; - /*=============================================*/ - Pause (); - X = UfThold * V; - Y = Radix * Radix; - if (X * Y < One || X > Y) { - if (X * Y < U1 || X > Y / U1) - BadCond (Defect, "Badly"); - else - BadCond (Flaw, ""); - - printf (" unbalanced range; UfThold * V = %.17e\n\t%s\n", - X, "is too far from 1.\n"); - } - /*=============================================*/ - Milestone = 200; - /*=============================================*/ - for (Indx = 1; Indx <= 5; ++Indx) { - X = F9; - switch (Indx) { - case 2: - X = One + U2; - break; - case 3: - X = V; - break; - case 4: - X = UfThold; - break; - case 5: - X = Radix; - } - Y = X; - sigsave = _sigfpe; - if (setjmp (ovfl_buf)) - printf (" X / X traps when X = %g\n", X); - else { - V9 = (Y / X - Half) - Half; - if (V9 == Zero) - continue; - if (V9 == -U1 && Indx < 5) - BadCond (Flaw, ""); - else - BadCond (Serious, ""); - printf (" X / X differs from 1 when X = %.17e\n", X); - printf (" instead, X / X - 1/2 - 1/2 = %.17e .\n", V9); - } - sigsave = 0; - } - /*=============================================*/ - Milestone = 210; - /*=============================================*/ - MyZero = Zero; - printf ("\n"); - printf ("What message and/or values does Division by Zero produce?\n"); -#ifndef BATCHMODE - printf ("This can interupt your program. You can "); - printf ("skip this part if you wish.\n"); - printf ("Do you wish to compute 1 / 0? "); - fflush (stdout); - read (KEYBOARD, ch, 8); - if ((ch[0] == 'Y') || (ch[0] == 'y')) { -#endif /* !BATCHMODE */ - sigsave = _sigfpe; - printf (" Trying to compute 1 / 0 produces ..."); - if (!setjmp (ovfl_buf)) - printf (" %.7e .\n", One / MyZero); - sigsave = 0; -#ifndef BATCHMODE - } else - printf ("O.K.\n"); - printf ("\nDo you wish to compute 0 / 0? "); - fflush (stdout); - read (KEYBOARD, ch, 80); - if ((ch[0] == 'Y') || (ch[0] == 'y')) { -#endif /* !BATCHMODE */ - sigsave = _sigfpe; - printf ("\n Trying to compute 0 / 0 produces ..."); - if (!setjmp (ovfl_buf)) - printf (" %.7e .\n", Zero / MyZero); - sigsave = 0; -#ifndef BATCHMODE - } else - printf ("O.K.\n"); -#endif /* !BATCHMODE */ - /*=============================================*/ - Milestone = 220; - /*=============================================*/ - - Pause (); - printf ("\n"); - { - static char *msg[] = - { - "FAILUREs encountered =", - "SERIOUS DEFECTs discovered =", - "DEFECTs discovered =", - "FLAWs discovered ="}; - int i; - for (i = 0; i < 4; i++) - if (ErrCnt[i]) - printf ("The number of %-29s %d.\n", - msg[i], ErrCnt[i]); - } - - printf ("\n"); - if ((ErrCnt[Failure] + ErrCnt[Serious] + ErrCnt[Defect] - + ErrCnt[Flaw]) > 0) { - if ((ErrCnt[Failure] + ErrCnt[Serious] + ErrCnt[ - Defect] == 0) && (ErrCnt[Flaw] > 0)) { - printf ("The arithmetic diagnosed seems "); - printf ("Satisfactory though flawed.\n"); - } - if ((ErrCnt[Failure] + ErrCnt[Serious] == 0) - && (ErrCnt[Defect] > 0)) { - printf ("The arithmetic diagnosed may be Acceptable\n"); - printf ("despite inconvenient Defects.\n"); - } - if ((ErrCnt[Failure] + ErrCnt[Serious]) > 0) { - printf ("The arithmetic diagnosed has "); - printf ("unacceptable Serious Defects.\n"); - } - if (ErrCnt[Failure] > 0) { - printf ("Potentially fatal FAILURE may have spoiled this"); - printf (" program's subsequent diagnoses.\n"); - } + } + printf( "The Underflow threshold is %.17e, %s\n", UfThold, " below which" ); + printf( "calculation may suffer larger Relative error than " ); + printf( "merely roundoff.\n" ); + Y2 = U1 * U1; + Y = Y2 * Y2; + Y2 = Y * U1; + if ( Y2 <= UfThold ) { + if ( Y > E0 ) { + BadCond( Defect, "" ); + I = 5; } else { - - printf ("No failures, defects nor flaws have been discovered.\n"); - if (!((RMult == Rounded) && (RDiv == Rounded) - && (RAddSub == Rounded) && (RSqrt == Rounded))) - printf ("The arithmetic diagnosed seems Satisfactory.\n"); - else { - if (StickyBit >= One && - (Radix - Two) * (Radix - Nine - One) == Zero) { - printf ("Rounding appears to conform to "); - printf ("the proposed IEEE standard P"); - if ((Radix == Two) && - ((Precision - Four * Three * Two) * - (Precision - TwentySeven - - TwentySeven + One) == Zero)) - printf ("754"); - else - printf ("854"); - if (IEEE) - printf (".\n"); - else { - printf (",\nexcept for possibly Double Rounding"); - printf (" during Gradual Underflow.\n"); - } - } - printf ("The arithmetic diagnosed appears to be Excellent!\n"); + BadCond( Serious, "" ); + I = 4; + } + printf( "Range is too narrow; U1^%d Underflows.\n", I ); + } + /*=============================================*/ + Milestone = 130; + /*=============================================*/ + Y = -FLOOR( Half - TwoForty * LOG( UfThold ) / LOG( HInvrse ) ) / TwoForty; + Y2 = Y + Y; + printf( "Since underflow occurs below the threshold\n" ); + printf( "UfThold = (%.17e) ^ (%.17e)\nonly underflow ", HInvrse, Y ); + printf( + "should afflict the expression\n\t(%.17e) ^ (%.17e);\n", + HInvrse, + Y2 + ); + printf( "actually calculating yields:" ); + if ( setjmp( ovfl_buf ) ) { + sigsave = 0; + BadCond( Serious, "trap on underflow.\n" ); + } else { + sigsave = _sigfpe; + V9 = POW( HInvrse, Y2 ); + sigsave = 0; + printf( " %.17e .\n", V9 ); + if ( !( ( V9 >= Zero ) && ( V9 <= ( Radix + Radix + E9 ) * UfThold ) ) ) { + BadCond( Serious, "this is not between 0 and underflow\n" ); + printf( " threshold = %.17e .\n", UfThold ); + } else if ( !( V9 > UfThold * ( One + E9 ) ) ) { + printf( "This computed value is O.K.\n" ); + } else { + BadCond( Defect, "this is not between 0 and underflow\n" ); + printf( " threshold = %.17e .\n", UfThold ); + } + } + /*=============================================*/ + Milestone = 140; + /*=============================================*/ + printf( "\n" ); + /* ...calculate Exp2 == exp(2) == 7.389056099... */ + X = Zero; + I = 2; + Y = Two * Three; + Q = Zero; + N = 0; + do { + Z = X; + I = I + 1; + Y = Y / ( I + I ); + R = Y + Q; + X = Z + R; + Q = ( Z - X ) + R; + } while ( X > Z ); + Z = ( OneAndHalf + One / Eight ) + X / ( OneAndHalf * ThirtyTwo ); + X = Z * Z; + Exp2 = X * X; + X = F9; + Y = X - U1; + printf( + "Testing X^((X + 1) / (X - 1)) vs. exp(2) = %.17e as X -> 1.\n", + Exp2 + ); + for ( I = 1;; ) { + Z = X - BInvrse; + Z = ( X + One ) / ( Z - ( One - BInvrse ) ); + Q = POW( X, Z ) - Exp2; + if ( FABS( Q ) > TwoForty * U2 ) { + N = 1; + V9 = ( X - BInvrse ) - ( One - BInvrse ); + BadCond( Defect, "Calculated" ); + printf( " %.17e for\n", POW( X, Z ) ); + printf( "\t(1 + (%.17e) ^ (%.17e);\n", V9, Z ); + printf( "\tdiffers from correct value by %.17e .\n", Q ); + printf( "\tThis much error may spoil financial\n" ); + printf( "\tcalculations involving tiny interest rates.\n" ); + break; + } else { + Z = ( Y - X ) * Two + Y; + X = Y; + Y = Z; + Z = One + ( X - F9 ) * ( X - F9 ); + if ( Z > One && I < NoTrials ) { + I++; + } else { + if ( X > One ) { + if ( N == 0 ) { + printf( "Accuracy seems adequate.\n" ); + } + break; + } else { + X = One + U2; + Y = U2 + U2; + Y += X; + I = 1; } + } + } + } + /*=============================================*/ + Milestone = 150; + /*=============================================*/ + printf( "Testing powers Z^Q at four nearly extreme values.\n" ); + N = 0; + Z = A1; + Q = FLOOR( Half - LOG( C ) / LOG( A1 ) ); + Break = False; + do { + X = CInvrse; + Y = POW( Z, Q ); + IsYeqX(); + Q = -Q; + X = C; + Y = POW( Z, Q ); + IsYeqX(); + if ( Z < One ) { + Break = True; + } else { + Z = AInvrse; + } + } while ( !( Break ) ); + PrintIfNPositive(); + if ( N == 0 ) { + printf( " ... no discrepancies found.\n" ); + } + printf( "\n" ); + + /*=============================================*/ + Milestone = 160; + /*=============================================*/ + Pause(); + printf( "Searching for Overflow threshold:\n" ); + printf( "This may generate an error.\n" ); + Y = -CInvrse; + V9 = HInvrse * Y; + sigsave = _sigfpe; + if ( setjmp( ovfl_buf ) ) { + I = 0; + V9 = Y; + goto overflow; + } + do { + V = Y; + Y = V9; + V9 = HInvrse * Y; + } while ( V9 < Y ); + I = 1; +overflow: + sigsave = 0; + Z = V9; + printf( "Can `Z = -Y' overflow?\n" ); + printf( "Trying it on Y = %.17e .\n", Y ); + V9 = -Y; + V0 = V9; + if ( V - Y == V + V0 ) { + printf( "Seems O.K.\n" ); + } else { + printf( "finds a " ); + BadCond( Flaw, "-(-Y) differs from Y.\n" ); + } + if ( Z != Y ) { + BadCond( Serious, "" ); + printf( "overflow past %.17e\n\tshrinks to %.17e .\n", Y, Z ); + } + if ( I ) { + Y = V * ( HInvrse * U2 - HInvrse ); + Z = Y + ( ( One - HInvrse ) * U2 ) * V; + if ( Z < V0 ) { + Y = Z; + } + if ( Y < V0 ) { + V = Y; + } + if ( V0 - V < V0 ) { + V = V0; + } + } else { + V = Y * ( HInvrse * U2 - HInvrse ); + V = V + ( ( One - HInvrse ) * U2 ) * Y; + } + printf( "Overflow threshold is V = %.17e .\n", V ); + if ( I ) { + printf( "Overflow saturates at V0 = %.17e .\n", V0 ); + } else { + printf( "There is no saturation value because \ +the system traps on overflow.\n" ); + } + V9 = V * One; + printf( "No Overflow should be signaled for V * 1 = %.17e\n", V9 ); + V9 = V / One; + printf( " nor for V / 1 = %.17e .\n", V9 ); + printf( "Any overflow signal separating this * from the one\n" ); + printf( "above is a DEFECT.\n" ); + /*=============================================*/ + Milestone = 170; + /*=============================================*/ + if ( !( -V < V && -V0 < V0 && -UfThold < V && UfThold < V ) ) { + BadCond( Failure, "Comparisons involving " ); + printf( "+-%g, +-%g\nand +-%g are confused by Overflow.", V, V0, UfThold ); + } + /*=============================================*/ + Milestone = 175; + /*=============================================*/ + printf( "\n" ); + for ( Indx = 1; Indx <= 3; ++Indx ) { + switch ( Indx ) { + case 1: + Z = UfThold; + break; + case 2: + Z = E0; + break; + case 3: + Z = PseudoZero; + break; + } + if ( Z != Zero ) { + V9 = SQRT( Z ); + Y = V9 * V9; + if ( + Y / ( One - Radix * E9 ) < Z || Y > ( One + Radix * E9 ) * Z + ) { /* dgh: + E9 --> * E9 */ + if ( V9 > U1 ) { + BadCond( Serious, "" ); + } else { + BadCond( Defect, "" ); + } + printf( "Comparison alleges that what prints as Z = %.17e\n", Z ); + printf( " is too far from sqrt(Z) ^ 2 = %.17e .\n", Y ); + } + } + } + /*=============================================*/ + Milestone = 180; + /*=============================================*/ + for ( Indx = 1; Indx <= 2; ++Indx ) { + if ( Indx == 1 ) { + Z = V; + } else { + Z = V0; + } + V9 = SQRT( Z ); + X = ( One - Radix * E9 ) * V9; + V9 = V9 * X; + if (( ( V9 < ( One - Two * Radix * E9 ) * Z ) || ( V9 > Z ) )) { + Y = V9; + if ( X < WVar ) { + BadCond( Serious, "" ); + } else { + BadCond( Defect, "" ); + } + printf( "Comparison alleges that Z = %17e\n", Z ); + printf( " is too far from sqrt(Z) ^ 2 (%.17e) .\n", Y ); + } + } + /*=============================================*/ + Milestone = 190; + /*=============================================*/ + Pause(); + X = UfThold * V; + Y = Radix * Radix; + if ( X * Y < One || X > Y ) { + if ( X * Y < U1 || X > Y / U1 ) { + BadCond( Defect, "Badly" ); + } else { + BadCond( Flaw, "" ); } - if (fpecount) - printf ("\nA total of %d floating point exceptions were registered.\n", - fpecount); - printf ("END OF TEST.\n"); - return 0; + printf( + " unbalanced range; UfThold * V = %.17e\n\t%s\n", + X, + "is too far from 1.\n" + ); + } + /*=============================================*/ + Milestone = 200; + /*=============================================*/ + for ( Indx = 1; Indx <= 5; ++Indx ) { + X = F9; + switch ( Indx ) { + case 2: + X = One + U2; + break; + case 3: + X = V; + break; + case 4: + X = UfThold; + break; + case 5: + X = Radix; + } + Y = X; + sigsave = _sigfpe; + if ( setjmp( ovfl_buf ) ) { + printf( " X / X traps when X = %g\n", X ); + } else { + V9 = ( Y / X - Half ) - Half; + if ( V9 == Zero ) { + continue; + } + if ( V9 == -U1 && Indx < 5 ) { + BadCond( Flaw, "" ); + } else { + BadCond( Serious, "" ); + } + printf( " X / X differs from 1 when X = %.17e\n", X ); + printf( " instead, X / X - 1/2 - 1/2 = %.17e .\n", V9 ); + } + sigsave = 0; + } + /*=============================================*/ + Milestone = 210; + /*=============================================*/ + MyZero = Zero; + printf( "\n" ); + printf( "What message and/or values does Division by Zero produce?\n" ); +#ifndef BATCHMODE + printf( "This can interupt your program. You can " ); + printf( "skip this part if you wish.\n" ); + printf( "Do you wish to compute 1 / 0? " ); + fflush( stdout ); + read( KEYBOARD, ch, 8 ); + if ( ( ch[ 0 ] == 'Y' ) || ( ch[ 0 ] == 'y' ) ) { +#endif /* !BATCHMODE */ + sigsave = _sigfpe; + printf( " Trying to compute 1 / 0 produces ..." ); + if ( !setjmp( ovfl_buf ) ) { + printf( " %.7e .\n", One / MyZero ); + } + sigsave = 0; +#ifndef BATCHMODE + } else { + printf( "O.K.\n" ); + } + printf( "\nDo you wish to compute 0 / 0? " ); + fflush( stdout ); + read( KEYBOARD, ch, 80 ); + if ( ( ch[ 0 ] == 'Y' ) || ( ch[ 0 ] == 'y' ) ) { +#endif /* !BATCHMODE */ + sigsave = _sigfpe; + printf( "\n Trying to compute 0 / 0 produces ..." ); + if ( !setjmp( ovfl_buf ) ) { + printf( " %.7e .\n", Zero / MyZero ); + } + sigsave = 0; +#ifndef BATCHMODE + } else { + printf( "O.K.\n" ); + } +#endif /* !BATCHMODE */ + /*=============================================*/ + Milestone = 220; + /*=============================================*/ + + Pause(); + printf( "\n" ); + { + static char *msg[] = { + "FAILUREs encountered =", + "SERIOUS DEFECTs discovered =", + "DEFECTs discovered =", + "FLAWs discovered =" + }; + int i; + for ( i = 0; i < 4; i++ ) { + if ( ErrCnt[ i ] ) { + printf( "The number of %-29s %d.\n", msg[ i ], ErrCnt[ i ] ); + } + } + } + + printf( "\n" ); + if ( + ( ErrCnt[ Failure ] + ErrCnt[ Serious ] + ErrCnt[ Defect ] + + ErrCnt[ Flaw ] ) > 0 + ) { + if ( + ( ErrCnt[ Failure ] + ErrCnt[ Serious ] + ErrCnt[ Defect ] == 0 ) && + ( ErrCnt[ Flaw ] > 0 ) + ) { + printf( "The arithmetic diagnosed seems " ); + printf( "Satisfactory though flawed.\n" ); + } + if ( + ( ErrCnt[ Failure ] + ErrCnt[ Serious ] == 0 ) && + ( ErrCnt[ Defect ] > 0 ) + ) { + printf( "The arithmetic diagnosed may be Acceptable\n" ); + printf( "despite inconvenient Defects.\n" ); + } + if ( ( ErrCnt[ Failure ] + ErrCnt[ Serious ] ) > 0 ) { + printf( "The arithmetic diagnosed has " ); + printf( "unacceptable Serious Defects.\n" ); + } + if ( ErrCnt[ Failure ] > 0 ) { + printf( "Potentially fatal FAILURE may have spoiled this" ); + printf( " program's subsequent diagnoses.\n" ); + } + } else { + printf( "No failures, defects nor flaws have been discovered.\n" ); + if ( !( ( RMult == Rounded ) && ( RDiv == Rounded ) && + ( RAddSub == Rounded ) && ( RSqrt == Rounded ) ) ) { + printf( "The arithmetic diagnosed seems Satisfactory.\n" ); + } else { + if ( + StickyBit >= One && ( Radix - Two ) * ( Radix - Nine - One ) == Zero + ) { + printf( "Rounding appears to conform to " ); + printf( "the proposed IEEE standard P" ); + if ( + ( Radix == Two ) && + ( ( Precision - Four * Three * Two ) * + ( Precision - TwentySeven - TwentySeven + One ) == + Zero ) + ) { + printf( "754" ); + } else { + printf( "854" ); + } + if ( IEEE ) { + printf( ".\n" ); + } else { + printf( ",\nexcept for possibly Double Rounding" ); + printf( " during Gradual Underflow.\n" ); + } + } + printf( "The arithmetic diagnosed appears to be Excellent!\n" ); + } + } + + if ( fpecount ) { + printf( + "\nA total of %d floating point exceptions were registered.\n", + fpecount + ); + } + printf( "END OF TEST.\n" ); + return 0; } FLOAT -Sign (FLOAT X) +Sign( FLOAT X ) { - return X >= 0. ? 1.0 : -1.0; + return X >= 0. ? 1.0 : -1.0; } -void -Pause () +void Pause() { #ifndef BATCHMODE - char ch[8]; + char ch[ 8 ]; - printf ("\nTo continue, press RETURN"); - fflush (stdout); - read (KEYBOARD, ch, 8); + printf( "\nTo continue, press RETURN" ); + fflush( stdout ); + read( KEYBOARD, ch, 8 ); #endif /* !BATCHMODE */ #ifndef CYGNUS - printf ("\nDiagnosis resumes after milestone Number %d", Milestone); - printf (" Page: %d\n\n", PageNo); - ++Milestone; - ++PageNo; + printf( "\nDiagnosis resumes after milestone Number %d", Milestone ); + printf( " Page: %d\n\n", PageNo ); + ++Milestone; + ++PageNo; #endif /* !CYGNUS */ } -void -TstCond (int K, int Valid, char *T) +void TstCond( int K, int Valid, char *T ) { #ifdef CYGNUS - printf ("TEST: %s\n", T); + printf( "TEST: %s\n", T ); #endif /* CYGNUS */ - if (!Valid) { - BadCond (K, T); - printf (".\n"); - } + if ( !Valid ) { + BadCond( K, T ); + printf( ".\n" ); + } #ifdef CYGNUS - printf ("PASS: %s\n", T); + printf( "PASS: %s\n", T ); #endif /* CYGNUS */ } -void -BadCond (int K, char *T) +void BadCond( int K, char *T ) { - static char *msg[] = - {"FAILURE", "SERIOUS DEFECT", "DEFECT", "FLAW"}; + static char *msg[] = { "FAILURE", "SERIOUS DEFECT", "DEFECT", "FLAW" }; - ErrCnt[K] = ErrCnt[K] + 1; + ErrCnt[ K ] = ErrCnt[ K ] + 1; #ifndef CYGNUS - printf ("%s: %s", msg[K], T); + printf( "%s: %s", msg[ K ], T ); #else - printf ("ERROR: Severity: %s: %s", msg[K], T); + printf( "ERROR: Severity: %s: %s", msg[ K ], T ); #endif /* CYGNUS */ } @@ -2022,287 +2144,282 @@ BadCond (int K, char *T) * and returns the new value of Random1 */ FLOAT -Random () +Random() { - FLOAT X, Y; + FLOAT X, Y; - X = Random1 + Random9; - Y = X * X; - Y = Y * Y; - X = X * Y; - Y = X - FLOOR (X); - Random1 = Y + X * 0.000005; - return (Random1); + X = Random1 + Random9; + Y = X * X; + Y = Y * Y; + X = X * Y; + Y = X - FLOOR( X ); + Random1 = Y + X * 0.000005; + return ( Random1 ); } -void -SqXMinX (int ErrKind) +void SqXMinX( int ErrKind ) { - FLOAT XA, XB; + FLOAT XA, XB; - XB = X * BInvrse; - XA = X - XB; - SqEr = ((SQRT (X * X) - XB) - XA) / OneUlp; - if (SqEr != Zero) { - if (SqEr < MinSqEr) - MinSqEr = SqEr; - if (SqEr > MaxSqEr) - MaxSqEr = SqEr; - J = J + 1.0; - BadCond (ErrKind, "\n"); - printf ("sqrt( %.17e) - %.17e = %.17e\n", X * X, X, OneUlp * SqEr); - printf ("\tinstead of correct value 0 .\n"); + XB = X * BInvrse; + XA = X - XB; + SqEr = ( ( SQRT( X * X ) - XB ) - XA ) / OneUlp; + if ( SqEr != Zero ) { + if ( SqEr < MinSqEr ) { + MinSqEr = SqEr; } -} - -void -NewD () -{ - X = Z1 * Q; - X = FLOOR (Half - X / Radix) * Radix + X; - Q = (Q - X * Z) / Radix + X * X * (D / Radix); - Z = Z - Two * X * D; - if (Z <= Zero) { - Z = -Z; - Z1 = -Z1; + if ( SqEr > MaxSqEr ) { + MaxSqEr = SqEr; } - D = Radix * D; + J = J + 1.0; + BadCond( ErrKind, "\n" ); + printf( "sqrt( %.17e) - %.17e = %.17e\n", X * X, X, OneUlp * SqEr ); + printf( "\tinstead of correct value 0 .\n" ); + } } -void -SR3750 () +void NewD() { - if (!((X - Radix < Z2 - Radix) || (X - Z2 > WVar - Z2))) { - I = I + 1; - X2 = SQRT (X * D); - Y2 = (X2 - Z2) - (Y - Z2); - X2 = X8 / (Y - Half); - X2 = X2 - Half * X2 * X2; - SqEr = (Y2 + Half) + (Half - X2); - if (SqEr < MinSqEr) - MinSqEr = SqEr; - SqEr = Y2 - X2; - if (SqEr > MaxSqEr) - MaxSqEr = SqEr; + X = Z1 * Q; + X = FLOOR( Half - X / Radix ) * Radix + X; + Q = ( Q - X * Z ) / Radix + X * X * ( D / Radix ); + Z = Z - Two * X * D; + if ( Z <= Zero ) { + Z = -Z; + Z1 = -Z1; + } + D = Radix * D; +} + +void SR3750() +{ + if ( !( ( X - Radix < Z2 - Radix ) || ( X - Z2 > WVar - Z2 ) ) ) { + I = I + 1; + X2 = SQRT( X * D ); + Y2 = ( X2 - Z2 ) - ( Y - Z2 ); + X2 = X8 / ( Y - Half ); + X2 = X2 - Half * X2 * X2; + SqEr = ( Y2 + Half ) + ( Half - X2 ); + if ( SqEr < MinSqEr ) { + MinSqEr = SqEr; } -} - -void -IsYeqX () -{ - if (Y != X) { - if (N <= 0) { - if (Z == Zero && Q <= Zero) - printf ("WARNING: computing\n"); - else - BadCond (Defect, "computing\n"); - printf ("\t(%.17e) ^ (%.17e)\n", Z, Q); - printf ("\tyielded %.17e;\n", Y); - printf ("\twhich compared unequal to correct %.17e ;\n", - X); - printf ("\t\tthey differ by %.17e .\n", Y - X); - } - N = N + 1; /* ... count discrepancies. */ + SqEr = Y2 - X2; + if ( SqEr > MaxSqEr ) { + MaxSqEr = SqEr; } + } } -void -SR3980 () +void IsYeqX() { - do { - Q = (FLOAT) I; - Y = POW (Z, Q); - IsYeqX (); - if (++I > M) - break; - X = Z * X; + if ( Y != X ) { + if ( N <= 0 ) { + if ( Z == Zero && Q <= Zero ) { + printf( "WARNING: computing\n" ); + } else { + BadCond( Defect, "computing\n" ); + } + printf( "\t(%.17e) ^ (%.17e)\n", Z, Q ); + printf( "\tyielded %.17e;\n", Y ); + printf( "\twhich compared unequal to correct %.17e ;\n", X ); + printf( "\t\tthey differ by %.17e .\n", Y - X ); } - while (X < WVar); + N = N + 1; /* ... count discrepancies. */ + } } -void -PrintIfNPositive () +void SR3980() { - if (N > 0) - printf ("Similar discrepancies have occurred %d times.\n", N); -} - -void -TstPtUf () -{ - N = 0; - if (Z != Zero) { - printf ("Since comparison denies Z = 0, evaluating "); - printf ("(Z + Z) / Z should be safe.\n"); - sigsave = _sigfpe; - if (setjmp (ovfl_buf)) - goto very_serious; - Q9 = (Z + Z) / Z; - printf ("What the machine gets for (Z + Z) / Z is %.17e .\n", - Q9); - if (FABS (Q9 - Two) < Radix * U2) { - printf ("This is O.K., provided Over/Underflow"); - printf (" has NOT just been signaled.\n"); - } else { - if ((Q9 < One) || (Q9 > Two)) { - very_serious: - N = 1; - ErrCnt[Serious] = ErrCnt[Serious] + 1; - printf ("This is a VERY SERIOUS DEFECT!\n"); - } else { - N = 1; - ErrCnt[Defect] = ErrCnt[Defect] + 1; - printf ("This is a DEFECT!\n"); - } - } - sigsave = 0; - V9 = Z * One; - Random1 = V9; - V9 = One * Z; - Random2 = V9; - V9 = Z / One; - if ((Z == Random1) && (Z == Random2) && (Z == V9)) { - if (N > 0) - Pause (); - } else { - N = 1; - BadCond (Defect, "What prints as Z = "); - printf ("%.17e\n\tcompares different from ", Z); - if (Z != Random1) - printf ("Z * 1 = %.17e ", Random1); - if (!((Z == Random2) - || (Random2 == Random1))) - printf ("1 * Z == %g\n", Random2); - if (!(Z == V9)) - printf ("Z / 1 = %.17e\n", V9); - if (Random2 != Random1) { - ErrCnt[Defect] = ErrCnt[Defect] + 1; - BadCond (Defect, "Multiplication does not commute!\n"); - printf ("\tComparison alleges that 1 * Z = %.17e\n", - Random2); - printf ("\tdiffers from Z * 1 = %.17e\n", Random1); - } - Pause (); - } + do { + Q = (FLOAT) I; + Y = POW( Z, Q ); + IsYeqX(); + if ( ++I > M ) { + break; } + X = Z * X; + } while ( X < WVar ); } -void -notify (char *s) +void PrintIfNPositive() { - printf ("%s test appears to be inconsistent...\n", s); - printf (" PLEASE NOTIFY KARPINKSI!\n"); + if ( N > 0 ) { + printf( "Similar discrepancies have occurred %d times.\n", N ); + } } -void -msglist (char **s) +void TstPtUf() { - while (*s) - printf ("%s\n", *s++); + N = 0; + if ( Z != Zero ) { + printf( "Since comparison denies Z = 0, evaluating " ); + printf( "(Z + Z) / Z should be safe.\n" ); + sigsave = _sigfpe; + if ( setjmp( ovfl_buf ) ) { + goto very_serious; + } + Q9 = ( Z + Z ) / Z; + printf( "What the machine gets for (Z + Z) / Z is %.17e .\n", Q9 ); + if ( FABS( Q9 - Two ) < Radix * U2 ) { + printf( "This is O.K., provided Over/Underflow" ); + printf( " has NOT just been signaled.\n" ); + } else { + if ( ( Q9 < One ) || ( Q9 > Two ) ) { + very_serious: + N = 1; + ErrCnt[ Serious ] = ErrCnt[ Serious ] + 1; + printf( "This is a VERY SERIOUS DEFECT!\n" ); + } else { + N = 1; + ErrCnt[ Defect ] = ErrCnt[ Defect ] + 1; + printf( "This is a DEFECT!\n" ); + } + } + sigsave = 0; + V9 = Z * One; + Random1 = V9; + V9 = One * Z; + Random2 = V9; + V9 = Z / One; + if ( ( Z == Random1 ) && ( Z == Random2 ) && ( Z == V9 ) ) { + if ( N > 0 ) { + Pause(); + } + } else { + N = 1; + BadCond( Defect, "What prints as Z = " ); + printf( "%.17e\n\tcompares different from ", Z ); + if ( Z != Random1 ) { + printf( "Z * 1 = %.17e ", Random1 ); + } + if ( !( ( Z == Random2 ) || ( Random2 == Random1 ) ) ) { + printf( "1 * Z == %g\n", Random2 ); + } + if ( !( Z == V9 ) ) { + printf( "Z / 1 = %.17e\n", V9 ); + } + if ( Random2 != Random1 ) { + ErrCnt[ Defect ] = ErrCnt[ Defect ] + 1; + BadCond( Defect, "Multiplication does not commute!\n" ); + printf( "\tComparison alleges that 1 * Z = %.17e\n", Random2 ); + printf( "\tdiffers from Z * 1 = %.17e\n", Random1 ); + } + Pause(); + } + } } -void -Instructions () +void notify( char *s ) { - static char *instr[] = - { - "Lest this program stop prematurely, i.e. before displaying\n", - " `END OF TEST',\n", - "try to persuade the computer NOT to terminate execution when an", - "error like Over/Underflow or Division by Zero occurs, but rather", - "to persevere with a surrogate value after, perhaps, displaying some", - "warning. If persuasion avails naught, don't despair but run this", - "program anyway to see how many milestones it passes, and then", - "amend it to make further progress.\n", - "Answer questions with Y, y, N or n (unless otherwise indicated).\n", - 0}; - - msglist (instr); + printf( "%s test appears to be inconsistent...\n", s ); + printf( " PLEASE NOTIFY KARPINKSI!\n" ); } -void -Heading () +void msglist( char **s ) { - static char *head[] = - { - "Users are invited to help debug and augment this program so it will", - "cope with unanticipated and newly uncovered arithmetic pathologies.\n", - "Please send suggestions and interesting results to", - "\tRichard Karpinski", - "\tComputer Center U-76", - "\tUniversity of California", - "\tSan Francisco, CA 94143-0704, USA\n", - "In doing so, please include the following information:", + while ( *s ) { + printf( "%s\n", *s++ ); + } +} + +void Instructions() +{ + static char *instr[] = { + "Lest this program stop prematurely, i.e. before displaying\n", + " `END OF TEST',\n", + "try to persuade the computer NOT to terminate execution when an", + "error like Over/Underflow or Division by Zero occurs, but rather", + "to persevere with a surrogate value after, perhaps, displaying some", + "warning. If persuasion avails naught, don't despair but run this", + "program anyway to see how many milestones it passes, and then", + "amend it to make further progress.\n", + "Answer questions with Y, y, N or n (unless otherwise indicated).\n", + 0 + }; + + msglist( instr ); +} + +void Heading() +{ + static char *head[] = { + "Users are invited to help debug and augment this program so it will", + "cope with unanticipated and newly uncovered arithmetic pathologies.\n", + "Please send suggestions and interesting results to", + "\tRichard Karpinski", + "\tComputer Center U-76", + "\tUniversity of California", + "\tSan Francisco, CA 94143-0704, USA\n", + "In doing so, please include the following information:", #ifdef SINGLE_PRECISION - "\tPrecision:\tsingle;", -#else /* !SINGLE_PRECISION */ - "\tPrecision:\tdouble;", + "\tPrecision:\tsingle;", +#else /* !SINGLE_PRECISION */ + "\tPrecision:\tdouble;", #endif /* SINGLE_PRECISION */ - "\tVersion:\t10 February 1989;", - "\tComputer:\n", - "\tCompiler:\n", - "\tOptimization level:\n", - "\tOther relevant compiler options:", - 0}; + "\tVersion:\t10 February 1989;", + "\tComputer:\n", + "\tCompiler:\n", + "\tOptimization level:\n", + "\tOther relevant compiler options:", + 0 + }; - msglist (head); + msglist( head ); } -void -Characteristics () +void Characteristics() { - static char *chars[] = - { - "Running this program should reveal these characteristics:", - " Radix = 1, 2, 4, 8, 10, 16, 100, 256 ...", - " Precision = number of significant digits carried.", - " U2 = Radix/Radix^Precision = One Ulp", - "\t(OneUlpnit in the Last Place) of 1.000xxx .", - " U1 = 1/Radix^Precision = One Ulp of numbers a little less than 1.0 .", - " Adequacy of guard digits for Mult., Div. and Subt.", - " Whether arithmetic is chopped, correctly rounded, or something else", - "\tfor Mult., Div., Add/Subt. and Sqrt.", - " Whether a Sticky Bit used correctly for rounding.", - " UnderflowThreshold = an underflow threshold.", - " E0 and PseudoZero tell whether underflow is abrupt, gradual, or fuzzy.", - " V = an overflow threshold, roughly.", - " V0 tells, roughly, whether Infinity is represented.", - " Comparisions are checked for consistency with subtraction", - "\tand for contamination with pseudo-zeros.", - " Sqrt is tested. Y^X is not tested.", - " Extra-precise subexpressions are revealed but NOT YET tested.", - " Decimal-Binary conversion is NOT YET tested for accuracy.", - 0}; + static char *chars[] = { + "Running this program should reveal these characteristics:", + " Radix = 1, 2, 4, 8, 10, 16, 100, 256 ...", + " Precision = number of significant digits carried.", + " U2 = Radix/Radix^Precision = One Ulp", + "\t(OneUlpnit in the Last Place) of 1.000xxx .", + " U1 = 1/Radix^Precision = One Ulp of numbers a little less than 1.0 .", + " Adequacy of guard digits for Mult., Div. and Subt.", + " Whether arithmetic is chopped, correctly rounded, or something else", + "\tfor Mult., Div., Add/Subt. and Sqrt.", + " Whether a Sticky Bit used correctly for rounding.", + " UnderflowThreshold = an underflow threshold.", + " E0 and PseudoZero tell whether underflow is abrupt, gradual, or fuzzy.", + " V = an overflow threshold, roughly.", + " V0 tells, roughly, whether Infinity is represented.", + " Comparisions are checked for consistency with subtraction", + "\tand for contamination with pseudo-zeros.", + " Sqrt is tested. Y^X is not tested.", + " Extra-precise subexpressions are revealed but NOT YET tested.", + " Decimal-Binary conversion is NOT YET tested for accuracy.", + 0 + }; - msglist (chars); + msglist( chars ); } -void -History () -{ /* History */ - /* Converted from Brian Wichmann's Pascal version to C by Thos Sumner, +void History() +{ /* History */ + /* Converted from Brian Wichmann's Pascal version to C by Thos Sumner, with further massaging by David M. Gay. */ - static char *hist[] = - { - "The program attempts to discriminate among", - " FLAWs, like lack of a sticky bit,", - " Serious DEFECTs, like lack of a guard digit, and", - " FAILUREs, like 2+2 == 5 .", - "Failures may confound subsequent diagnoses.\n", - "The diagnostic capabilities of this program go beyond an earlier", - "program called `MACHAR', which can be found at the end of the", - "book `Software Manual for the Elementary Functions' (1980) by", - "W. J. Cody and W. Waite. Although both programs try to discover", - "the Radix, Precision and range (over/underflow thresholds)", - "of the arithmetic, this program tries to cope with a wider variety", - "of pathologies, and to say how well the arithmetic is implemented.", - "\nThe program is based upon a conventional radix representation for", - "floating-point numbers, but also allows logarithmic encoding", - "as used by certain early WANG machines.\n", - "BASIC version of this program (C) 1983 by Prof. W. M. Kahan;", - "see source comments for more history.", - 0}; + static char *hist[] = { + "The program attempts to discriminate among", + " FLAWs, like lack of a sticky bit,", + " Serious DEFECTs, like lack of a guard digit, and", + " FAILUREs, like 2+2 == 5 .", + "Failures may confound subsequent diagnoses.\n", + "The diagnostic capabilities of this program go beyond an earlier", + "program called `MACHAR', which can be found at the end of the", + "book `Software Manual for the Elementary Functions' (1980) by", + "W. J. Cody and W. Waite. Although both programs try to discover", + "the Radix, Precision and range (over/underflow thresholds)", + "of the arithmetic, this program tries to cope with a wider variety", + "of pathologies, and to say how well the arithmetic is implemented.", + "\nThe program is based upon a conventional radix representation for", + "floating-point numbers, but also allows logarithmic encoding", + "as used by certain early WANG machines.\n", + "BASIC version of this program (C) 1983 by Prof. W. M. Kahan;", + "see source comments for more history.", + 0 + }; - msglist (hist); + msglist( hist ); } diff --git a/testsuites/samples/paranoia/system.h b/testsuites/samples/paranoia/system.h index 7915a78c44..750eb2ab7d 100644 --- a/testsuites/samples/paranoia/system.h +++ b/testsuites/samples/paranoia/system.h @@ -35,9 +35,7 @@ /* functions */ -rtems_task Init( - rtems_task_argument argument -); +rtems_task Init( rtems_task_argument argument ); /* configuration information */ @@ -46,13 +44,13 @@ rtems_task Init( #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER -#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_MAXIMUM_TASKS 1 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE -#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT -#define CONFIGURE_INIT_TASK_STACK_SIZE (RTEMS_MINIMUM_STACK_SIZE * 2) +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT +#define CONFIGURE_INIT_TASK_STACK_SIZE ( RTEMS_MINIMUM_STACK_SIZE * 2 ) -#define CONFIGURE_EXTRA_TASK_STACKS (1 * RTEMS_MINIMUM_STACK_SIZE) +#define CONFIGURE_EXTRA_TASK_STACKS ( 1 * RTEMS_MINIMUM_STACK_SIZE ) #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION diff --git a/testsuites/samples/ticker/init.c b/testsuites/samples/ticker/init.c index 8cccbf4955..542cc2490b 100644 --- a/testsuites/samples/ticker/init.c +++ b/testsuites/samples/ticker/init.c @@ -39,12 +39,10 @@ const char rtems_test_name[] = "CLOCK TICK"; * Keep the names and IDs in global variables so another task can use them. */ -rtems_id Task_id[ 4 ]; /* array of task ids */ -rtems_name Task_name[ 4 ]; /* array of task names */ +rtems_id Task_id[ 4 ]; /* array of task ids */ +rtems_name Task_name[ 4 ]; /* array of task names */ -rtems_task Init( - rtems_task_argument argument -) +rtems_task Init( rtems_task_argument argument ) { (void) argument; @@ -53,13 +51,13 @@ rtems_task Init( TEST_BEGIN(); - time.year = 1988; - time.month = 12; - time.day = 31; - time.hour = 9; + time.year = 1988; + time.month = 12; + time.day = 31; + time.hour = 9; time.minute = 0; time.second = 0; - time.ticks = 0; + time.ticks = 0; status = rtems_clock_set( &time ); directive_failed( status, "clock set" ); @@ -69,31 +67,43 @@ rtems_task Init( Task_name[ 3 ] = rtems_build_name( 'T', 'A', '3', ' ' ); status = rtems_task_create( - Task_name[ 1 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ] + Task_name[ 1 ], + 1, + RTEMS_MINIMUM_STACK_SIZE * 2, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &Task_id[ 1 ] ); - directive_failed( status, "create 1" ); + directive_failed( status, "create 1" ); status = rtems_task_create( - Task_name[ 2 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ] + Task_name[ 2 ], + 1, + RTEMS_MINIMUM_STACK_SIZE * 2, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &Task_id[ 2 ] ); - directive_failed( status, "create 2" ); + directive_failed( status, "create 2" ); status = rtems_task_create( - Task_name[ 3 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 3 ] + Task_name[ 3 ], + 1, + RTEMS_MINIMUM_STACK_SIZE * 2, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &Task_id[ 3 ] ); - directive_failed( status, "create 3" ); + directive_failed( status, "create 3" ); status = rtems_task_start( Task_id[ 1 ], Test_task, 1 ); - directive_failed( status, "start 1" ); + directive_failed( status, "start 1" ); status = rtems_task_start( Task_id[ 2 ], Test_task, 2 ); - directive_failed( status, "start 2" ); + directive_failed( status, "start 2" ); status = rtems_task_start( Task_id[ 3 ], Test_task, 3 ); - directive_failed( status, "start 3" ); + directive_failed( status, "start 3" ); rtems_task_exit(); } diff --git a/testsuites/samples/ticker/system.h b/testsuites/samples/ticker/system.h index 9495f45547..2c7ecd170e 100644 --- a/testsuites/samples/ticker/system.h +++ b/testsuites/samples/ticker/system.h @@ -37,13 +37,9 @@ /* functions */ -rtems_task Init( - rtems_task_argument argument -); +rtems_task Init( rtems_task_argument argument ); -rtems_task Test_task( - rtems_task_argument argument -); +rtems_task Test_task( rtems_task_argument argument ); /* global variables */ @@ -51,9 +47,8 @@ rtems_task Test_task( * Keep the names and IDs in global variables so another task can use them. */ -extern rtems_id Task_id[ 4 ]; /* array of task ids */ -extern rtems_name Task_name[ 4 ]; /* array of task names */ - +extern rtems_id Task_id[ 4 ]; /* array of task ids */ +extern rtems_name Task_name[ 4 ]; /* array of task names */ /* configuration information */ @@ -62,11 +57,11 @@ extern rtems_name Task_name[ 4 ]; /* array of task names */ #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER -#define CONFIGURE_MAXIMUM_TASKS 4 +#define CONFIGURE_MAXIMUM_TASKS 4 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE -#define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) +#define CONFIGURE_EXTRA_TASK_STACKS ( 3 * RTEMS_MINIMUM_STACK_SIZE ) #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION @@ -82,9 +77,9 @@ extern rtems_name Task_name[ 4 ]; /* array of task names */ * But it shows how rtems_id's can sometimes be used. */ -#define task_number( tid ) \ - ( rtems_object_id_get_index( tid ) - \ - rtems_configuration_get_rtems_api_configuration()-> \ - number_of_initialization_tasks ) +#define task_number( tid ) \ + ( rtems_object_id_get_index( tid ) - \ + rtems_configuration_get_rtems_api_configuration() \ + ->number_of_initialization_tasks ) /* end of include file */ diff --git a/testsuites/samples/ticker/tasks.c b/testsuites/samples/ticker/tasks.c index 92c17ede4a..2e61dcc555 100644 --- a/testsuites/samples/ticker/tasks.c +++ b/testsuites/samples/ticker/tasks.c @@ -40,9 +40,7 @@ #include "system.h" -rtems_task Test_task( - rtems_task_argument unused -) +rtems_task Test_task( rtems_task_argument unused ) { (void) unused; @@ -52,10 +50,10 @@ rtems_task Test_task( rtems_status_code status; status = rtems_task_ident( RTEMS_WHO_AM_I, RTEMS_SEARCH_ALL_NODES, &tid ); - directive_failed( status, "task ident" ); + directive_failed( status, "task ident" ); task_index = task_number( tid ); - for ( ; ; ) { + for ( ;; ) { status = rtems_clock_get_tod( &time ); if ( time.second >= 35 ) { TEST_END(); @@ -66,6 +64,6 @@ rtems_task Test_task( status = rtems_task_wake_after( task_index * 5 * rtems_clock_get_ticks_per_second() ); - directive_failed( status, "wake after" ); + directive_failed( status, "wake after" ); } } diff --git a/testsuites/samples/unlimited/init.c b/testsuites/samples/unlimited/init.c index 63236fc2e1..6a2aef429d 100644 --- a/testsuites/samples/unlimited/init.c +++ b/testsuites/samples/unlimited/init.c @@ -39,11 +39,9 @@ const char rtems_test_name[] = "UNLIMITED TASK"; -rtems_id task_id[MAX_TASKS]; +rtems_id task_id[ MAX_TASKS ]; -rtems_task Init( - rtems_task_argument ignored -) +rtems_task Init( rtems_task_argument ignored ) { (void) ignored; @@ -56,15 +54,19 @@ rtems_task Init( /* lower the task priority to allow created tasks to execute */ rtems_task_set_priority( - RTEMS_SELF, RTEMS_MAXIMUM_PRIORITY - 1, &old_priority); - rtems_task_mode(RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode); + RTEMS_SELF, + RTEMS_MAXIMUM_PRIORITY - 1, + &old_priority + ); + rtems_task_mode( RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode ); /* * Invalid state if the task id is 0 */ - for (task = 0; task < MAX_TASKS; task++) - task_id[task] = 0; + for ( task = 0; task < MAX_TASKS; task++ ) { + task_id[ task ] = 0; + } test1(); test2(); @@ -74,66 +76,57 @@ rtems_task Init( exit( 0 ); } -rtems_task test_task( - rtems_task_argument my_number -) +rtems_task test_task( rtems_task_argument my_number ) { rtems_event_set out; unsigned int my_n = (unsigned int) my_number; - printf( "task %u has started.\n", my_n); + printf( "task %u has started.\n", my_n ); - rtems_event_receive(1, RTEMS_WAIT | RTEMS_EVENT_ANY, 0, &out); + rtems_event_receive( 1, RTEMS_WAIT | RTEMS_EVENT_ANY, 0, &out ); - printf( "task %u ending.\n", my_n); + printf( "task %u ending.\n", my_n ); rtems_task_exit(); } -void destroy_all_tasks( - const char *who -) +void destroy_all_tasks( const char *who ) { - uint32_t task; + uint32_t task; /* * If the id is not zero, signal the task to delete. */ - for (task = 0; task < MAX_TASKS; task++) { - if (task_id[task]) { + for ( task = 0; task < MAX_TASKS; task++ ) { + if ( task_id[ task ] ) { printf( " %s : signal task %08" PRIxrtems_id " to delete, ", - who, - task_id[task] + who, + task_id[ task ] ); - fflush(stdout); - rtems_event_send(task_id[task], 1); - task_id[task] = 0; + fflush( stdout ); + rtems_event_send( task_id[ task ], 1 ); + task_id[ task ] = 0; } } } -bool status_code_bad( - rtems_status_code status_code -) +bool status_code_bad( rtems_status_code status_code ) { - if (status_code != RTEMS_SUCCESSFUL) - { - printf("failure, "); + if ( status_code != RTEMS_SUCCESSFUL ) { + printf( "failure, " ); - if (status_code == RTEMS_TOO_MANY) - { - printf("too many.\n"); + if ( status_code == RTEMS_TOO_MANY ) { + printf( "too many.\n" ); return TRUE; } - if (status_code == RTEMS_UNSATISFIED) - { - printf("unsatisfied.\n"); + if ( status_code == RTEMS_UNSATISFIED ) { + printf( "unsatisfied.\n" ); return TRUE; } - printf("error code = %i\n", status_code); + printf( "error code = %i\n", status_code ); exit( 1 ); } return FALSE; diff --git a/testsuites/samples/unlimited/system.h b/testsuites/samples/unlimited/system.h index daf80975a7..b5ea024dd5 100644 --- a/testsuites/samples/unlimited/system.h +++ b/testsuites/samples/unlimited/system.h @@ -34,26 +34,17 @@ /* functions */ -rtems_task Init( - rtems_task_argument argument -); +rtems_task Init( rtems_task_argument argument ); -rtems_task test_task( - rtems_task_argument my_number -); +rtems_task test_task( rtems_task_argument my_number ); -void -destroy_all_tasks( - const char *who -); +void destroy_all_tasks( const char *who ); -bool status_code_bad( - rtems_status_code status_code -); +bool status_code_bad( rtems_status_code status_code ); -extern void test1(void); -extern void test2(void); -extern void test3(void); +extern void test1( void ); +extern void test2( void ); +extern void test3( void ); /* configuration information */ @@ -66,45 +57,42 @@ extern void test3(void); #define CONFIGURE_UNIFIED_WORK_AREAS #define CONFIGURE_RTEMS_INIT_TASKS_TABLE -#define TASK_ALLOCATION_SIZE (5) +#define TASK_ALLOCATION_SIZE ( 5 ) #define CONFIGURE_UNLIMITED_OBJECTS #define CONFIGURE_UNLIMITED_ALLOCATION_SIZE TASK_ALLOCATION_SIZE - #include /* * Keep track of the task id's created, use a large array. */ -#define MAX_TASKS (1000) -#define TASK_INDEX_OFFSET (1) +#define MAX_TASKS ( 1000 ) +#define TASK_INDEX_OFFSET ( 1 ) -extern rtems_id task_id[MAX_TASKS]; +extern rtems_id task_id[ MAX_TASKS ]; /* * Increment the task name. */ -#define NEXT_TASK_NAME(c1, c2, c3, c4) \ - if (c4 == '9') { \ - if (c3 == '9') { \ - if (c2 == 'z') { \ - if (c1 == 'z') { \ - printf("not enough task letters for names !!!\n"); \ - exit( 1 ); \ - } else \ - c1++; \ - c2 = 'a'; \ - } else \ - c2++; \ - c3 = '0'; \ - } else \ - c3++; \ - c4 = '0'; \ - } \ - else \ - c4++ \ - +#define NEXT_TASK_NAME( c1, c2, c3, c4 ) \ + if ( c4 == '9' ) { \ + if ( c3 == '9' ) { \ + if ( c2 == 'z' ) { \ + if ( c1 == 'z' ) { \ + printf( "not enough task letters for names !!!\n" ); \ + exit( 1 ); \ + } else \ + c1++; \ + c2 = 'a'; \ + } else \ + c2++; \ + c3 = '0'; \ + } else \ + c3++; \ + c4 = '0'; \ + } else \ + c4++ /* end of include file */ diff --git a/testsuites/samples/unlimited/test1.c b/testsuites/samples/unlimited/test1.c index 5c5e427761..17c0ab8f83 100644 --- a/testsuites/samples/unlimited/test1.c +++ b/testsuites/samples/unlimited/test1.c @@ -54,10 +54,10 @@ void test1() uint32_t task_count = 0; Objects_Information *the_information; - char c1 = 'a'; - char c2 = 'a'; - char c3 = '0'; - char c4 = '0'; + char c1 = 'a'; + char c2 = 'a'; + char c3 = '0'; + char c4 = '0'; printf( "\n TEST1 : auto-extend disabled.\n" ); @@ -66,60 +66,75 @@ void test1() * saves having another test. */ - the_information = - _Objects_Information_table[OBJECTS_CLASSIC_API][OBJECTS_RTEMS_TASKS]; + the_information = _Objects_Information_table[ OBJECTS_CLASSIC_API ] + [ OBJECTS_RTEMS_TASKS ]; objects_per_block = the_information->objects_per_block; the_information->objects_per_block = 0; the_information->allocate = _Objects_Allocate_static; - while (task_count < MAX_TASKS) - { + while ( task_count < MAX_TASKS ) { rtems_name name; - printf(" TEST1 : creating task '%c%c%c%c', ", c1, c2, c3, c4); + printf( " TEST1 : creating task '%c%c%c%c', ", c1, c2, c3, c4 ); - name = rtems_build_name(c1, c2, c3, c4); + name = rtems_build_name( c1, c2, c3, c4 ); - result = rtems_task_create(name, - 10, - RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_ATTRIBUTES, - RTEMS_LOCAL, - &task_id[task_count]); + result = rtems_task_create( + name, + 10, + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_ATTRIBUTES, + RTEMS_LOCAL, + &task_id[ task_count ] + ); - if (status_code_bad(result)) + if ( status_code_bad( result ) ) { break; + } - printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]); + printf( + "number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", + task_count, + task_id[ task_count ] + ); - fflush(stdout); - result = rtems_task_start(task_id[task_count], - test_task, - (rtems_task_argument) task_count); + fflush( stdout ); + result = rtems_task_start( + task_id[ task_count ], + test_task, + (rtems_task_argument) task_count + ); - if (status_code_bad(result)) + if ( status_code_bad( result ) ) { break; + } /* * Update the name. */ - NEXT_TASK_NAME(c1, c2, c3, c4); + NEXT_TASK_NAME( c1, c2, c3, c4 ); task_count++; } - if (task_count >= MAX_TASKS) - printf( "\nMAX_TASKS too small for work-space size, please make larger !!\n\n" ); + if ( task_count >= MAX_TASKS ) { + printf( + "\nMAX_TASKS too small for work-space size, please make larger !!\n\n" + ); + } - if (task_count != (TASK_ALLOCATION_SIZE - 1)) { - printf( " FAIL1 : the number of tasks does not equal the expected size -\n" - " task created = %" PRIi32 ", required number = %i\n", - task_count, TASK_ALLOCATION_SIZE); + if ( task_count != ( TASK_ALLOCATION_SIZE - 1 ) ) { + printf( + " FAIL1 : the number of tasks does not equal the expected size -\n" + " task created = %" PRIi32 ", required number = %i\n", + task_count, + TASK_ALLOCATION_SIZE + ); exit( 1 ); } - destroy_all_tasks("TEST1"); + destroy_all_tasks( "TEST1" ); the_information->objects_per_block = objects_per_block; the_information->allocate = _Thread_Allocate_unlimited; diff --git a/testsuites/samples/unlimited/test2.c b/testsuites/samples/unlimited/test2.c index 72546c4f91..424d2ad9a5 100644 --- a/testsuites/samples/unlimited/test2.c +++ b/testsuites/samples/unlimited/test2.c @@ -50,58 +50,69 @@ void test2() { - rtems_status_code result; - uint32_t remove_task; - uint32_t task; - uint32_t block; - uint32_t task_count = 0; - rtems_id removed_ids[TASK_ALLOCATION_SIZE * 2]; + rtems_status_code result; + uint32_t remove_task; + uint32_t task; + uint32_t block; + uint32_t task_count = 0; + rtems_id removed_ids[ TASK_ALLOCATION_SIZE * 2 ]; - char c1 = 'a'; - char c2 = 'a'; - char c3 = '0'; - char c4 = '0'; + char c1 = 'a'; + char c2 = 'a'; + char c3 = '0'; + char c4 = '0'; - printf( "\n TEST2 : re-allocate of index numbers, and a block free'ed and one inactive\n" ); + printf( + "\n TEST2 : re-allocate of index numbers, and a block free'ed and one inactive\n" + ); /* * Allocate enought tasks so the Inactive list is empty. Remember * to count the Init task, ie ... - 1. */ - while (task_count < ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET)) - { + while ( task_count < ( ( TASK_ALLOCATION_SIZE * 5 ) - TASK_INDEX_OFFSET ) ) { rtems_name name; - printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4); + printf( " TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4 ); - name = rtems_build_name(c1, c2, c3, c4); + name = rtems_build_name( c1, c2, c3, c4 ); - result = rtems_task_create(name, - 10, - RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_ATTRIBUTES, - RTEMS_LOCAL, - &task_id[task_count]); + result = rtems_task_create( + name, + 10, + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_ATTRIBUTES, + RTEMS_LOCAL, + &task_id[ task_count ] + ); - if (status_code_bad(result)) + if ( status_code_bad( result ) ) { break; + } - printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]); - fflush(stdout); + printf( + "number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", + task_count, + task_id[ task_count ] + ); + fflush( stdout ); - result = rtems_task_start(task_id[task_count], - test_task, - (rtems_task_argument) task_count); + result = rtems_task_start( + task_id[ task_count ], + test_task, + (rtems_task_argument) task_count + ); - if (status_code_bad(result)) + if ( status_code_bad( result ) ) { break; + } /* * Update the name. */ - NEXT_TASK_NAME(c1, c2, c3, c4); + NEXT_TASK_NAME( c1, c2, c3, c4 ); task_count++; } @@ -110,28 +121,33 @@ void test2() * Take out the second and fourth allocation size block of tasks */ - if (task_count != ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET)) { - printf( " FAIL2 : not enough tasks created -\n" - " task created = %" PRIi32 ", required number = %i\n", - task_count, (TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET); - destroy_all_tasks("TEST2"); + if ( task_count != ( ( TASK_ALLOCATION_SIZE * 5 ) - TASK_INDEX_OFFSET ) ) { + printf( + " FAIL2 : not enough tasks created -\n" + " task created = %" PRIi32 ", required number = %i\n", + task_count, + ( TASK_ALLOCATION_SIZE * 5 ) - TASK_INDEX_OFFSET + ); + destroy_all_tasks( "TEST2" ); exit( 1 ); } task = 0; - for (block = 1; block < 4; block += 2) - { - for (remove_task = (block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET; - remove_task < (((block + 1) * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET); - remove_task++) - { - if (!task_id[remove_task]) - { - printf( " FAIL2 : remove task has a 0 id -\n" - " task number = %" PRIi32 "\n", - remove_task); - destroy_all_tasks("TEST2"); + for ( block = 1; block < 4; block += 2 ) { + for ( + remove_task = ( block * TASK_ALLOCATION_SIZE ) - TASK_INDEX_OFFSET; + remove_task < + ( ( ( block + 1 ) * TASK_ALLOCATION_SIZE ) - TASK_INDEX_OFFSET ); + remove_task++ + ) { + if ( !task_id[ remove_task ] ) { + printf( + " FAIL2 : remove task has a 0 id -\n" + " task number = %" PRIi32 "\n", + remove_task + ); + destroy_all_tasks( "TEST2" ); exit( 1 ); } @@ -139,68 +155,80 @@ void test2() * Save the id's to match them against the reallocated ids */ - removed_ids[task++] = task_id[remove_task]; + removed_ids[ task++ ] = task_id[ remove_task ]; - printf(" TEST2 : block %" PRIi32 " remove, signal task %08" - PRIxrtems_id ", ", block, task_id[remove_task]); - rtems_event_send(task_id[remove_task], 1); - task_id[remove_task] = 0; + printf( + " TEST2 : block %" PRIi32 " remove, signal task %08" PRIxrtems_id ", ", + block, + task_id[ remove_task ] + ); + rtems_event_send( task_id[ remove_task ], 1 ); + task_id[ remove_task ] = 0; } } - for (task = 0; task < (TASK_ALLOCATION_SIZE * 2); task++) - { - rtems_name name; + for ( task = 0; task < ( TASK_ALLOCATION_SIZE * 2 ); task++ ) { + rtems_name name; uint32_t id_slot; /* * Find a free slot in the task id table. */ - for (id_slot = 0; id_slot < MAX_TASKS; id_slot++) - if (!task_id[id_slot]) + for ( id_slot = 0; id_slot < MAX_TASKS; id_slot++ ) { + if ( !task_id[ id_slot ] ) { break; + } + } - if (id_slot == MAX_TASKS) - { - printf( " FAIL2 : no free task id slot.\n"); - destroy_all_tasks("TEST2"); + if ( id_slot == MAX_TASKS ) { + printf( " FAIL2 : no free task id slot.\n" ); + destroy_all_tasks( "TEST2" ); exit( 1 ); } - printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4); + printf( " TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4 ); - name = rtems_build_name(c1, c2, c3, c4); + name = rtems_build_name( c1, c2, c3, c4 ); - result = rtems_task_create(name, - 10, - RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_ATTRIBUTES, - RTEMS_LOCAL, - &task_id[id_slot]); + result = rtems_task_create( + name, + 10, + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_ATTRIBUTES, + RTEMS_LOCAL, + &task_id[ id_slot ] + ); - if (status_code_bad(result)) - { - printf( " FAIL2 : re-creating a task -\n" - " task number = %" PRIi32 "\n", - id_slot); - destroy_all_tasks("TEST2"); + if ( status_code_bad( result ) ) { + printf( + " FAIL2 : re-creating a task -\n" + " task number = %" PRIi32 "\n", + id_slot + ); + destroy_all_tasks( "TEST2" ); exit( 1 ); } - printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", - task_count, task_id[id_slot]); + printf( + "number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", + task_count, + task_id[ id_slot ] + ); - result = rtems_task_start(task_id[id_slot], - test_task, - (rtems_task_argument) task_count); + result = rtems_task_start( + task_id[ id_slot ], + test_task, + (rtems_task_argument) task_count + ); - if (status_code_bad(result)) - { - printf( " FAIL : re-starting a task -\n" - " task number = %" PRIi32 "\n", - id_slot); - destroy_all_tasks("TEST2"); + if ( status_code_bad( result ) ) { + printf( + " FAIL : re-starting a task -\n" + " task number = %" PRIi32 "\n", + id_slot + ); + destroy_all_tasks( "TEST2" ); exit( 1 ); } @@ -208,49 +236,57 @@ void test2() * Update the name. */ - NEXT_TASK_NAME(c1, c2, c3, c4); + NEXT_TASK_NAME( c1, c2, c3, c4 ); /* * Search the removed ids to see if it existed, clear the removed id * when found */ - for (remove_task = 0; remove_task < (TASK_ALLOCATION_SIZE * 2); remove_task++) - if (removed_ids[remove_task] == task_id[id_slot]) - { - removed_ids[remove_task] = 0; + for ( + remove_task = 0; remove_task < ( TASK_ALLOCATION_SIZE * 2 ); + remove_task++ + ) { + if ( removed_ids[ remove_task ] == task_id[ id_slot ] ) { + removed_ids[ remove_task ] = 0; break; } + } /* * If not located in the removed id table, check and make sure it is not * already allocated */ - if (remove_task == (TASK_ALLOCATION_SIZE * 2)) - { - uint32_t allocated_id; + if ( remove_task == ( TASK_ALLOCATION_SIZE * 2 ) ) { + uint32_t allocated_id; - for (allocated_id = 0; allocated_id < MAX_TASKS; allocated_id++) - if ((task_id[id_slot] == task_id[allocated_id]) && (id_slot != allocated_id)) - { + for ( allocated_id = 0; allocated_id < MAX_TASKS; allocated_id++ ) { + if ( + ( task_id[ id_slot ] == task_id[ allocated_id ] ) && + ( id_slot != allocated_id ) + ) { printf( " FAIL2 : the new id is the same as an id already allocated -\n" " task id = %08" PRIxrtems_id "\n", - task_id[id_slot]); + task_id[ id_slot ] + ); exit( 1 ); } + } - printf( " FAIL2 : could not find the task id in the removed table -\n" - " task id = %08" PRIxrtems_id "\n", - task_id[id_slot]); + printf( + " FAIL2 : could not find the task id in the removed table -\n" + " task id = %08" PRIxrtems_id "\n", + task_id[ id_slot ] + ); exit( 1 ); } task_count++; } - destroy_all_tasks("TEST2"); + destroy_all_tasks( "TEST2" ); printf( " TEST2 : completed\n" ); } diff --git a/testsuites/samples/unlimited/test3.c b/testsuites/samples/unlimited/test3.c index c67bdb9351..ec834e98c4 100644 --- a/testsuites/samples/unlimited/test3.c +++ b/testsuites/samples/unlimited/test3.c @@ -49,66 +49,76 @@ void test3() { - rtems_status_code result; - uint32_t remove_task; - uint32_t block; - uint32_t task_count = 0; + rtems_status_code result; + uint32_t remove_task; + uint32_t block; + uint32_t task_count = 0; - char c1 = 'a'; - char c2 = 'a'; - char c3 = '0'; - char c4 = '0'; + char c1 = 'a'; + char c2 = 'a'; + char c3 = '0'; + char c4 = '0'; - printf( "\n TEST3 : free more than 3 x allocation size, but not the same block,\n" - " then free a block\n"); + printf( + "\n TEST3 : free more than 3 x allocation size, but not the same block,\n" + " then free a block\n" + ); /* * Check the value of the allocation unit */ - if (TASK_ALLOCATION_SIZE < 4) - { - printf( " FAIL3 : task allocation size must be greater than 4.\n"); + if ( TASK_ALLOCATION_SIZE < 4 ) { + printf( " FAIL3 : task allocation size must be greater than 4.\n" ); exit( 1 ); } - /* + /* * Allocate as many tasks as possible. */ - while (task_count < MAX_TASKS) - { + while ( task_count < MAX_TASKS ) { rtems_name name; - printf(" TEST3 : creating task '%c%c%c%c', ", c1, c2, c3, c4); + printf( " TEST3 : creating task '%c%c%c%c', ", c1, c2, c3, c4 ); - name = rtems_build_name(c1, c2, c3, c4); + name = rtems_build_name( c1, c2, c3, c4 ); - result = rtems_task_create(name, - 10, - RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_ATTRIBUTES, - RTEMS_LOCAL, - &task_id[task_count]); + result = rtems_task_create( + name, + 10, + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_ATTRIBUTES, + RTEMS_LOCAL, + &task_id[ task_count ] + ); - if (status_code_bad(result)) + if ( status_code_bad( result ) ) { break; + } - printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]); - fflush(stdout); + printf( + "number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", + task_count, + task_id[ task_count ] + ); + fflush( stdout ); - result = rtems_task_start(task_id[task_count], - test_task, - (rtems_task_argument) task_count); + result = rtems_task_start( + task_id[ task_count ], + test_task, + (rtems_task_argument) task_count + ); - if (status_code_bad(result)) + if ( status_code_bad( result ) ) { break; + } /* * Update the name. */ - NEXT_TASK_NAME(c1, c2, c3, c4); + NEXT_TASK_NAME( c1, c2, c3, c4 ); task_count++; } @@ -118,31 +128,38 @@ void test3() * allocation size number of blocks. */ - if (task_count < (TASK_ALLOCATION_SIZE * 11)) - { - printf( " FAIL3 : not enough tasks created -\n" - " task created = %" PRIi32 ", required number = %i\n", - task_count, (TASK_ALLOCATION_SIZE * 11)); + if ( task_count < ( TASK_ALLOCATION_SIZE * 11 ) ) { + printf( + " FAIL3 : not enough tasks created -\n" + " task created = %" PRIi32 ", required number = %i\n", + task_count, + ( TASK_ALLOCATION_SIZE * 11 ) + ); exit( 1 ); } - for (block = 0; block < TASK_ALLOCATION_SIZE; block++) - { - for (remove_task = ((block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET); - remove_task < (((block * TASK_ALLOCATION_SIZE) + 3) - TASK_INDEX_OFFSET); - remove_task++) - { - if (!task_id[remove_task]) - { - printf( " FAIL3 : remove task has a 0 id -\n" - " task number = %" PRIi32 "\n", - remove_task); + for ( block = 0; block < TASK_ALLOCATION_SIZE; block++ ) { + for ( + remove_task = ( ( block * TASK_ALLOCATION_SIZE ) - TASK_INDEX_OFFSET ); + remove_task < + ( ( ( block * TASK_ALLOCATION_SIZE ) + 3 ) - TASK_INDEX_OFFSET ); + remove_task++ + ) { + if ( !task_id[ remove_task ] ) { + printf( + " FAIL3 : remove task has a 0 id -\n" + " task number = %" PRIi32 "\n", + remove_task + ); exit( 1 ); } - printf(" TEST3 : remove, signal task %08" PRIxrtems_id ", ", task_id[remove_task]); - rtems_event_send(task_id[remove_task], 1); - task_id[remove_task] = 0; + printf( + " TEST3 : remove, signal task %08" PRIxrtems_id ", ", + task_id[ remove_task ] + ); + rtems_event_send( task_id[ remove_task ], 1 ); + task_id[ remove_task ] = 0; } } @@ -151,19 +168,22 @@ void test3() * allocator's free routine */ - for (remove_task = (TASK_ALLOCATION_SIZE - TASK_INDEX_OFFSET); - remove_task < ((TASK_ALLOCATION_SIZE * 2) - - TASK_INDEX_OFFSET); - remove_task++) - { - if (task_id[remove_task]) - { - printf(" TEST3 : remove, signal task %08" PRIxrtems_id ", ", task_id[remove_task]); - rtems_event_send(task_id[remove_task], 1); - task_id[remove_task] = 0; + for ( + remove_task = ( TASK_ALLOCATION_SIZE - TASK_INDEX_OFFSET ); + remove_task < ( ( TASK_ALLOCATION_SIZE * 2 ) - -TASK_INDEX_OFFSET ); + remove_task++ + ) { + if ( task_id[ remove_task ] ) { + printf( + " TEST3 : remove, signal task %08" PRIxrtems_id ", ", + task_id[ remove_task ] + ); + rtems_event_send( task_id[ remove_task ], 1 ); + task_id[ remove_task ] = 0; } } - destroy_all_tasks("TEST3"); + destroy_all_tasks( "TEST3" ); printf( " TEST3 : completed\n" ); }