📄 suppapi.c
字号:
/****************************************************************************** File Name : support.c Description : API test for 'developer support' functions (partition format/delete)******************************************************************************//* Includes ---------------------------------------------------------------- */#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <string.h>#include <assert.h>#include "wrapper.h" /* from ../utils. Uses ../../src */#include "apicomm.h"#include "stavfs.h"/* Private Types ----------------------------------------------------------- *//* Private Constants ------------------------------------------------------- */#define STD_DEV_NAME "GoodDevName" /* standard device name used in normal situations */ #define BOGUS_DEV_NAME "bogus" /* no device ever initialised with this name */ #define LONG_DEV_NAME "ThisIsALongWrongName" /* overlong bogus name to confirm no bad copying occurs before compare */ /* Private Variables ------------------------------------------------------- *//* Private Macros ---------------------------------------------------------- *//* Private Function Prototypes --------------------------------------------- */static TestResult_t CreateEmptyPartitionTable (int TestNo, TestVariant_t Variant);static TestResult_t FormatPartition (int TestNo, TestVariant_t Variant);static TestResult_t DeletePartition (int TestNo, TestVariant_t Variant);static void TryBadCreateEmptyPartitionTable (char * EVTName, char * ATAPIName, U16 UnitNumber, U16 Protocol, char * Descr, TestResult_t * Result_p); static void TryBadFormatPartition (char * DevName, U64 SpaceInSectors, U64 Position, U16 SizeOfCluster, char * Descr, TestResult_t * Result_p);static void TryGoodFormatPartition (char * DevName, U64 SpaceInSectors, U64 Position, U16 SizeOfCluster, char * Descr, TestResult_t * Result_p);static void TryBadDeletePartition (char * DevName, char * Descr, TestResult_t * Result_p); /* Functions --------------------------------------------------------------- *//******************************************************************************Function Name : SupportAPI Description : Support api test section function Parameters :******************************************************************************/BOOL SupportAPI(parse_t * pars_p, char *result_sym_p){ char *Description = "Support API tests"; TestCall_t TestList[] = { CreateEmptyPartitionTable, /* Test 001 */ FormatPartition, /* Test 002 */ DeletePartition, /* Test 003 */ }; GenericTest (pars_p, result_sym_p, Description, TestList, TABLE_LEN(TestList)-1, TEST_VARIANT_A); return (FALSE);}/******************************************************************************Function Name : CreateEmptyPartitionTable Description : API tests for STAVFS_CreateEmptyPartitionTable Parameters :******************************************************************************/static TestResult_t CreateEmptyPartitionTable(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; /* correct parameters: EVT_DEVICE_NAME, ATAPI_DEVICE_NAME, 0, 1. It is very unlikely that the function will actually do anything with parameters other than these, even if it succeeds, because they serve to address what it should be done to */ TryBadCreateEmptyPartitionTable(BOGUS_DEV_NAME, ATAPI_DEVICE_NAME, 0, 1, "with bad EVT name", &Result); TryBadCreateEmptyPartitionTable(LONG_DEV_NAME, ATAPI_DEVICE_NAME, 0, 1, "with bad (and long) EVT name", &Result); TryBadCreateEmptyPartitionTable(EVT_DEVICE_NAME, BOGUS_DEV_NAME, 0, 1, "with bad ATAPI name", &Result); TryBadCreateEmptyPartitionTable(EVT_DEVICE_NAME, LONG_DEV_NAME, 0, 1, "with bad (and long) ATAPI name", &Result); TryBadCreateEmptyPartitionTable(EVT_DEVICE_NAME, ATAPI_DEVICE_NAME, 2, 1, "with out-of range UnitNumber (2)", &Result); TryBadCreateEmptyPartitionTable(EVT_DEVICE_NAME, ATAPI_DEVICE_NAME, (U16) -1, 1, "with out-of range UnitNumber ((U16) -1)", &Result); TryBadCreateEmptyPartitionTable(EVT_DEVICE_NAME, ATAPI_DEVICE_NAME, (U16) 1, 1, "with UnitNumber (1) that is in range but not physically present", &Result); TryBadCreateEmptyPartitionTable(EVT_DEVICE_NAME, ATAPI_DEVICE_NAME, 0, 0, "with out-of range Protocol (0)", &Result); TryBadCreateEmptyPartitionTable(EVT_DEVICE_NAME, ATAPI_DEVICE_NAME, (U16) 0, 2, "with out-of range Protocol (2)", &Result); return (Result);}/******************************************************************************Function Name : TryBadCreateEmptyPartitionTable Description : Simple helper to shorten and clarify CreateEmptyPartitionTable test: try an STAVFS_CreateEmptyPartitionTable that should fail Parameters : EVTName, ATAPIName, UnitNumber, Protocol (for STAVFS_CreateEmptyPartitionTable), description to complete error message, place to record test failure******************************************************************************/static void TryBadCreateEmptyPartitionTable(char * EVTName, char * ATAPIName, U16 UnitNumber, U16 Protocol, char * Descr, TestResult_t * Result_p){ if (ST_NO_ERROR == STAVFS_CreateEmptyPartitionTable (EVTName, ATAPIName, UnitNumber, Protocol)) { STTBX_Print(("STAVFS_CreateEmptyPartitionTable should fail %s\n", Descr)); *Result_p = TEST_FAILED; }}/******************************************************************************Function Name : FormatPartition Description : API tests for STAVFS_FormatPartition Parameters :******************************************************************************/static TestResult_t FormatPartition(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; STAVFS_InitParams_t InitParams; STAVFS_OpenParams_t OpenParams; STAVFS_TermParams_t TermParams; STAVFS_Handle_t DiskHandle; U64 Size, Position; U32 SizeOfCluster; /* correct values for partition 3 */ I64_SetValue(TestPartitionDefs[3].Size, 0, Size); I64_SetValue(TestPartitionDefs[3].Position, 0, Position); SizeOfCluster = TestPartitionDefs[3].SizeOfCluster; TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with uninitialised device (and possibly uninitialised driver too)", &Result); /* if it did damage anything, we don't know what */ /* give the remaining 'bad name' tests one valid name to compare against */ strcpy (InitParams.EVTName, EVT_DEVICE_NAME); strcpy (InitParams.ATAPIName, ATAPI_DEVICE_NAME); InitParams.Flags = 0; InitParams.MemoryPartition = system_partition; InitParams.Protocol = 1; InitParams.UnitNumber = 0; InitParams.PartitionNumber = 3; /* work on partition 3 as out of main use and quickest to format */ OpenParams.Flags = 0; TermParams.Flags = 0; if (ST_NO_ERROR != STAVFS_Init (STD_DEV_NAME, &InitParams)) { STTBX_Print (("Error initialising unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; } else { TryBadFormatPartition (NULL, Size, Position, SizeOfCluster, "with NULL device name", &Result); TryBadFormatPartition (LONG_DEV_NAME, Size, Position, SizeOfCluster, "with overlong device name", &Result); TryBadFormatPartition (BOGUS_DEV_NAME, Size, Position, SizeOfCluster, "with device name that has never been initialised", &Result); TryBadFormatPartition (STD_DEV_NAME, Size, Position, 0, "with zero sized cluster. You may need to reformat partition 3.", &Result); I64_SetValue(0, 0, Size); TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with zero sized partition. You may need to reformat partition 3.", &Result); /* a valid file system requires a certain minimum space for root directory, etc */ I64_SetValue(TestPartitionDefs[3].Size, 0, Size); I64_SetValue(1, 0, Position); /* last reserved sector */ TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with first sector 1. You may need to reformat partition 3.", &Result); /* shouldn't actually cause damage since the sector isn't used */ I64_SetValue(TestPartitionDefs[3].Position, 0, Position); /* encroaching on other partitions */ I64_SetValue(TestPartitionDefs[2].Position, 0, Position); TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with first sector the same as partition 2\n" " You may need to reformat partitions 2 and 3", &Result);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -