📄 topapi.c
字号:
OpenParams.Flags = (U32) -1; TryBadOpen (STD_DEV_NAME, &OpenParams, "with out-of-range Flags ((U32) -1)", &Result); OpenParams.Flags = 1; TryBadOpen (STD_DEV_NAME, &OpenParams, "with out-of-range Flags (1)", &Result); OpenParams.Flags = 0; /* Handle argument; written-out adaptation of TryBadOpen */ if (ST_NO_ERROR == STAVFS_Open (STD_DEV_NAME, &OpenParams, NULL)) { STTBX_Print (("STAVFS_Open should fail with NULL Handle argument\n")); Result = TEST_FAILED; /* try a matched Close with what is likely to be the handle value */ if (ST_NO_ERROR == STAVFS_Close (NULL)) { STTBX_Print (("Failed closing that handle\n")); } } if (ST_NO_ERROR != STAVFS_Open (STD_DEV_NAME, &OpenParams, &Handle)) { STTBX_Print (("Failed opening unit 0 partition 0\n")); Result = TEST_FAILED; } else { /* partition that is already open */ TryBadOpen (STD_DEV_NAME, &OpenParams, "with partition (identified by name) that is already open", &Result); /* will run a close if it fails, otherwise let it go straight to Term below */ } if (ST_NO_ERROR != STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("Failed terminating unit 0 partition 0\n")); Result = TEST_FAILED; } } /* device that was initialised, but is now terminated */ TryBadOpen (STD_DEV_NAME, &OpenParams, "with device (identified by name) that has been terminated", &Result); /* Partition number that is valid but not present is a separate test, because of the need to delete and later reformat partition 3 used for the test */ return (Result);}/******************************************************************************Function Name : TryBadOpen Description : Helper for Open: attempt an open that should fail, but do attempt to clean up if it nonetheless succeeds, in an effort to insulate later tests. Updating *Result_p turns out to be more convenient for Init than a return value. Parameters : Device name, OpenParams (both for STAVFS_Open), description to complete error message, place to record test failure******************************************************************************/static void TryBadOpen (char * DevName, STAVFS_OpenParams_t * OpenParams_p, char * Descr, TestResult_t * Result_p){ STAVFS_Handle_t Handle; if (ST_NO_ERROR == STAVFS_Open (DevName, OpenParams_p, &Handle)) { STTBX_Print (("STAVFS_Open should fail %s\n", Descr)); if (Result_p != NULL) { *Result_p = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_Close (Handle)) { STTBX_Print (("Failed closing that handle\n")); } } }/******************************************************************************Function Name : OpenBadPartition Description : API test that STAVFS_Open fails for unformatted but valid partition number, separated out because of the need to delete and later reformat the partition Parameters :******************************************************************************/static TestResult_t OpenBadPartition(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; STAVFS_InitParams_t InitParams; STAVFS_OpenParams_t OpenParams; STAVFS_TermParams_t TermParams; U64 Position, Size; /* for partition 3 reformat */ /* Start with a valid set of parameters. Subtests change and restore these */ 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; OpenParams.Flags = 0; TermParams.Flags = 0; if (ST_NO_ERROR != STAVFS_Init (STD_DEV_NAME, &InitParams)) { STTBX_Print (("Failed initialising unit 0 partition 3\n")); Result = TEST_FAILED; } else { if (ST_NO_ERROR != STAVFS_DeletePartition (STD_DEV_NAME)) { STTBX_Print (("Failed deleting unit 0 partition 3\n")); Result = TEST_FAILED; } else { TryBadOpen (STD_DEV_NAME, &OpenParams, "for partition 3, which has been deleted", &Result); /* Put the partition back again, as created by ../unittest/toplevel.c Format */ I64_SetValue(TestPartitionDefs[3].Size, 0, Size); I64_SetValue(TestPartitionDefs[3].Position, 0, Position); if (ST_NO_ERROR != STAVFS_FormatPartition (STD_DEV_NAME, Size, Position, TestPartitionDefs[3].SizeOfCluster)) { STTBX_Print (("Failed reformatting unit 0 partition 3\n")); Result = TEST_FAILED; } } if (ST_NO_ERROR != STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("Failed terminating unit 0 partition 3\n")); Result = TEST_FAILED; } } return (Result);}/******************************************************************************Function Name : Close Description : API tests for STAVFS_Close Parameters :******************************************************************************/static TestResult_t Close(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 Handle; 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; /* 1 also possible in certain circumstances */ InitParams.PartitionNumber = 0; /* 1, 2, 3 also allowed */ OpenParams.Flags = 0; TermParams.Flags = 0; /* Bad handles: other tests have used partitions 0 and 3, so if you've only run this test set since start-up, handle 2 has never been touched */ if (ST_NO_ERROR == STAVFS_Close((void*) 2)) { STTBX_Print (("STAVFS_Close should fail with a device handle that has never been opened (inside the range used)\n")); Result = TEST_FAILED; } if (ST_NO_ERROR == STAVFS_Close((void*) 10000)) { STTBX_Print (("STAVFS_Close should fail with out-of-range device handle\n")); Result = TEST_FAILED; } /* Handle already closed/terminated */ if (ST_NO_ERROR != STAVFS_Init (STD_DEV_NAME, &InitParams)) { STTBX_Print (("Failed initialising unit 0 partition 0\n")); Result = TEST_FAILED; } else { if (ST_NO_ERROR != STAVFS_Open (STD_DEV_NAME, &OpenParams, &Handle)) { STTBX_Print (("Failed opening unit 0 partition 0\n")); Result = TEST_FAILED; } else { if (ST_NO_ERROR != STAVFS_Close (Handle)) { STTBX_Print (("Failed closing unit 0 partition 0\n")); Result = TEST_FAILED; /* device is still supposed to be closed if an error occurred, so go on with the test */ } /* the actual test */ if (ST_NO_ERROR == STAVFS_Close(Handle)) { STTBX_Print (("STAVFS_Close should fail with a handle that has already been closed\n")); Result = TEST_FAILED; } /* try to reopen before terminate in order to make "was open but now terminated" test a bit more strict */ if (ST_NO_ERROR != STAVFS_Open (STD_DEV_NAME, &OpenParams, &Handle)) { STTBX_Print (("Failed reopening unit 0 partition 0\n")); Result = TEST_FAILED; } } if (ST_NO_ERROR != STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("Failed terminating unit 0 partition 0\n")); Result = TEST_FAILED; /* device is still supposed to be terminated if an error occurred, so go on with the test */ } if (ST_NO_ERROR == STAVFS_Close(Handle)) { STTBX_Print (("STAVFS_Close should fail with a handle whose device has been terminated\n")); Result = TEST_FAILED; } } return (Result);}/******************************************************************************Function Name : Term Description : API tests for STAVFS_Term Parameters :******************************************************************************/static TestResult_t Term(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; BOOL GotDevice = FALSE; STAVFS_InitParams_t InitParams; STAVFS_TermParams_t TermParams; 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; /* 1 also possible in certain circumstances */ InitParams.PartitionNumber = 0; /* 1, 2, 3 also allowed */ TermParams.Flags = 0; if (ST_NO_ERROR == STAVFS_Term (NULL, &TermParams)) { STTBX_Print (("STAVFS_Term should fail with NULL device name (and possibly uninitialised driver)\n")); Result = TEST_FAILED; } if (ST_NO_ERROR == STAVFS_Term (LONG_DEV_NAME, &TermParams)) { STTBX_Print (("STAVFS_Term should fail with overlong device name\n")); Result = TEST_FAILED; } if (ST_NO_ERROR == STAVFS_Term (BOGUS_DEV_NAME, &TermParams)) { STTBX_Print (("STAVFS_Term should fail with device name that has never been initialised\n")); Result = TEST_FAILED; } /* name that was in use but now terminated - covered at end */ /* Various tests needing an initialised device. First the Flags one */ if (ST_NO_ERROR != STAVFS_Init (STD_DEV_NAME, &InitParams)) { STTBX_Print (("Failed initialising unit 0 partition 0\n")); Result = TEST_FAILED; } else { GotDevice = TRUE; TermParams.Flags = (U32) -1; if (ST_NO_ERROR == STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("STAVFS_Term should fail with out-of-range Flags ((U32) -1)\n")); Result = TEST_FAILED; GotDevice = FALSE; } TermParams.Flags = 1; if (GotDevice == TRUE && ST_NO_ERROR == STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("STAVFS_Term should fail with out-of-range Flags (1)\n")); Result = TEST_FAILED; GotDevice = FALSE; } TermParams.Flags = 0; if (GotDevice == TRUE && STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("Failed terminating unit 0 partition 0\n")); Result = TEST_FAILED; } /* final name validity test from above */ if (ST_NO_ERROR == STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("STAVFS_Term should fail with device name that has been used but is now terminated\n")); Result = TEST_FAILED; } } return (Result);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -