/* This FileX test concentrates on the basic media abort operation. */ #ifndef FX_STANDALONE_ENABLE #include "tx_api.h" #endif #include "fx_api.h" #include #include "fx_ram_driver_test.h" void test_control_return(UINT status); #ifndef FX_DISABLE_CACHE #define DEMO_STACK_SIZE 4096 #define CACHE_SIZE 16*128 /* Define the ThreadX and FileX object control blocks... */ #ifndef FX_STANDALONE_ENABLE static TX_THREAD ftest_0; #endif static FX_MEDIA ram_disk; static FX_MEDIA ram_disk2; static FX_FILE my_file; /* Define the counters used in the test application... */ #ifndef FX_STANDALONE_ENABLE static UCHAR *ram_disk_memory; static UCHAR *cache_buffer; static UCHAR *ram_disk_memory2; static UCHAR *cache_buffer2; #else static UCHAR ram_disk_memory2[256*256]; static UCHAR cache_buffer[CACHE_SIZE]; static UCHAR cache_buffer2[CACHE_SIZE]; #endif /* Define thread prototypes. */ void filex_media_abort_application_define(void *first_unused_memory); static void ftest_0_entry(ULONG thread_input); VOID _fx_ram_driver(FX_MEDIA *media_ptr); /* Define what the initial system looks like. */ #ifdef CTEST void test_application_define(void *first_unused_memory) #else void filex_media_abort_application_define(void *first_unused_memory) #endif { #ifndef FX_STANDALONE_ENABLE UCHAR *pointer; /* Setup the working pointer. */ pointer = (UCHAR *) first_unused_memory; /* Create the main thread. */ tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0, pointer, DEMO_STACK_SIZE, 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START); pointer = pointer + DEMO_STACK_SIZE; /* Setup memory for the RAM disk and the sector cache. */ cache_buffer = pointer; pointer = pointer + CACHE_SIZE; cache_buffer2 = pointer; pointer = pointer + CACHE_SIZE; ram_disk_memory = pointer; pointer = pointer + (256 * 128); ram_disk_memory2 = pointer; #endif /* Initialize the FileX system. */ fx_system_initialize(); #ifdef FX_STANDALONE_ENABLE ftest_0_entry(0); #endif } /* Define the test threads. */ static void ftest_0_entry(ULONG thread_input) { UINT status; ULONG actual; UCHAR local_buffer[32]; FX_PARAMETER_NOT_USED(thread_input); /* Print out some test information banners. */ printf("FileX Test: Media abort test......................................."); /* Format the media. This needs to be done before opening it! */ status = fx_media_format(&ram_disk, _fx_ram_driver, // Driver entry ram_disk_memory, // RAM disk memory pointer cache_buffer, // Media buffer pointer CACHE_SIZE, // Media buffer size "MY_RAM_DISK", // Volume Name 1, // Number of FATs 32, // Directory Entries 0, // Hidden sectors 256, // Total sectors 128, // Sector size 1, // Sectors per cluster 1, // Heads 1); // Sectors per track /* Determine if the format had an error. */ if (status) { printf("ERROR!\n"); test_control_return(2); } /* try to abort before the media has been opened */ status = fx_media_abort(&ram_disk); if (status != FX_MEDIA_NOT_OPEN) { printf("ERROR!\n"); test_control_return(3); } /* Open the ram_disk. */ status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE); /* Check the status. */ if (status != FX_SUCCESS) { /* Error, return error code. */ printf("ERROR!\n"); test_control_return(3); } /* Create a file called TEST.TXT in the root directory. */ status = fx_file_create(&ram_disk, "TEST.TXT"); /* Check the create status. */ if (status != FX_SUCCESS) { /* Check for an already created status. This is okay in small sector caches. */ if (status != FX_ALREADY_CREATED) { printf("ERROR!\n"); test_control_return(3); } } /* Open the test file. */ status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE); /* Check the file open status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(4); } /* Seek to the beginning of the test file. */ status = fx_file_seek(&my_file, 0); /* Check the file seek status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(5); } /* Write a string to the test file. */ status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28); /* Check the file write status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(6); } /* Seek to the beginning of the test file. */ status = fx_file_seek(&my_file, 0); /* Check the file seek status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(7); } /* Read the first 28 bytes of the test file. */ status = fx_file_read(&my_file, local_buffer, 28, &actual); /* Check the file read status. */ if ((status != FX_SUCCESS) || (actual != 28)) { printf("ERROR!\n"); test_control_return(8); } /* Close the test file. */ status = fx_file_close(&my_file); /* Check the file close status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(9); } /* Only run this if error checking is enabled */ #ifndef FX_DISABLE_ERROR_CHECKING /* send null pointer to generate an error */ status = fx_media_abort(FX_NULL); if (status != FX_PTR_ERROR) { printf("ERROR!\n"); test_control_return(11); } #endif /* FX_DISABLE_ERROR_CHECKING */ /* Abort the media. */ status = fx_media_abort(&ram_disk); /* Re-Open the ram_disk. */ status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE); /* Check the status. */ if (status != FX_SUCCESS) { /* Error, return error code. */ printf("ERROR!\n"); test_control_return(3); } /* Create a file called TEST.TXT in the root directory. */ status = fx_file_create(&ram_disk, "TEST.TXT"); /* Check for status. */ if (status != FX_SUCCESS) { /* Check for an already created status... this is okay with small sector cache! */ if (status != FX_ALREADY_CREATED) { printf("ERROR!\n"); test_control_return(3); } } /* Open the test file. */ status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE); /* Check the file open status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(4); } /* Seek to the beginning of the test file. */ status = fx_file_seek(&my_file, 0); /* Check the file seek status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(5); } /* Write a string to the test file. */ status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28); /* Check the file write status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(6); } /* Seek to the beginning of the test file. */ status = fx_file_seek(&my_file, 0); /* Check the file seek status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(7); } /* Read the first 28 bytes of the test file. */ status = fx_file_read(&my_file, local_buffer, 28, &actual); /* Check the file read status. */ if ((status != FX_SUCCESS) || (actual != 28)) { printf("ERROR!\n"); test_control_return(8); } /* Close the test file. */ status = fx_file_close(&my_file); /* Check the file close status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(9); } /* Close the media. */ status = fx_media_close(&ram_disk); /* Determine if the test was successful. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(10); } /* Format the media. This needs to be done before opening it! */ status = fx_media_format(&ram_disk, _fx_ram_driver, // Driver entry ram_disk_memory, // RAM disk memory pointer cache_buffer, // Media buffer pointer CACHE_SIZE, // Media buffer size "MY_RAM_DISK", // Volume Name 1, // Number of FATs 32, // Directory Entries 0, // Hidden sectors 256, // Total sectors 128, // Sector size 1, // Sectors per cluster 1, // Heads 1); // Sectors per track /* Format the second media. This needs to be done before opening it! */ status += fx_media_format(&ram_disk2, _fx_ram_driver, // Driver entry ram_disk_memory2, // RAM disk memory pointer cache_buffer2, // Media buffer pointer CACHE_SIZE, // Media buffer size "MY_RAM_DISK", // Volume Name 1, // Number of FATs 32, // Directory Entries 0, // Hidden sectors 256, // Total sectors 128, // Sector size 1, // Sectors per cluster 1, // Heads 1); // Sectors per track /* Determine if the format had an error. */ if (status) { printf("ERROR!\n"); test_control_return(11); } /* Open the ram_disk. */ status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE); /* Check the status. */ if (status != FX_SUCCESS) { /* Error, return error code. */ printf("ERROR!\n"); test_control_return(12); } /* Open the second ram_disk. */ status = fx_media_open(&ram_disk2, "RAM DISK2", _fx_ram_driver, ram_disk_memory2, cache_buffer2, CACHE_SIZE); /* Check the status. */ if (status != FX_SUCCESS) { /* Error opening second media. Return to caller. */ printf("ERROR!\n"); test_control_return(13); } /* Create a file called TEST.TXT in the root directory. */ status = fx_file_create(&ram_disk, "TEST.TXT"); /* Check for an error. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(14); } /* Open the test file. */ status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE); /* Check the file open status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(15); } /* Now abort the media with a file open and with another media instance open. */ status = fx_media_abort(&ram_disk); status += fx_media_abort(&ram_disk2); /* Check the media abort status. */ if (status != FX_SUCCESS) { printf("ERROR!\n"); test_control_return(16); } /* Format the media. This needs to be done before opening it! */ status = fx_media_format(&ram_disk, _fx_ram_driver, // Driver entry ram_disk_memory, // RAM disk memory pointer cache_buffer, // Media buffer pointer CACHE_SIZE, // Media buffer size "MY_RAM_DISK", // Volume Name 1, // Number of FATs 32, // Directory Entries 0, // Hidden sectors 256, // Total sectors 128, // Sector size 1, // Sectors per cluster 1, // Heads 1); // Sectors per track /* Format the second media. This needs to be done before opening it! */ status += fx_media_format(&ram_disk2, _fx_ram_driver, // Driver entry ram_disk_memory2, // RAM disk memory pointer cache_buffer2, // Media buffer pointer CACHE_SIZE, // Media buffer size "MY_RAM_DISK", // Volume Name 1, // Number of FATs 32, // Directory Entries 0, // Hidden sectors 256, // Total sectors 128, // Sector size 1, // Sectors per cluster 1, // Heads 1); // Sectors per track /* Determine if the format had an error. */ if (status) { printf("ERROR!\n"); test_control_return(17); } /* Open the ram_disk. */ status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE); /* Check the status. */ if (status != FX_SUCCESS) { /* Error, return error code. */ printf("ERROR!\n"); test_control_return(18); } /* Open the second ram_disk. */ status = fx_media_open(&ram_disk2, "RAM DISK2", _fx_ram_driver, ram_disk_memory2, cache_buffer2, CACHE_SIZE); /* Check the status. */ if (status != FX_SUCCESS) { /* Error opening second media. Return to caller. */ printf("ERROR!\n"); test_control_return(19); } /* Abort both media pointers. */ status = fx_media_abort(&ram_disk2); status += fx_media_abort(&ram_disk); /* Check the status. */ if (status != FX_SUCCESS) { /* Error opening second media. Return to caller. */ printf("ERROR!\n"); test_control_return(20); } else { printf("SUCCESS!\n"); test_control_return(0); } } #else #ifdef CTEST void test_application_define(void *first_unused_memory) #else void filex_media_abort_application_define(void *first_unused_memory) #endif { FX_PARAMETER_NOT_USED(first_unused_memory); /* Print out some test information banners. */ printf("FileX Test: Media abort test.......................................N/A\n"); test_control_return(255); } #endif