⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topapi.c

📁 ST5518机顶盒系统文件系统源代码!绝对超值!
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************    File Name   : topapi.c    Description : API Test for top level API calls******************************************************************************//* 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    "1234567890123456"    /* 16 char name to stuff ATAPI/EVTName and confirm nothing crashes, and      to try as the shortest overlong STAVFS device name */    /* Private Variables ------------------------------------------------------- *//* Private Macros ---------------------------------------------------------- *//* Private Function Prototypes --------------------------------------------- */static TestResult_t   Init              (int TestNo, TestVariant_t Variant);static TestResult_t   Open              (int TestNo, TestVariant_t Variant);static TestResult_t   OpenBadPartition  (int TestNo, TestVariant_t Variant);static TestResult_t   Close             (int TestNo, TestVariant_t Variant);static TestResult_t   Term              (int TestNo, TestVariant_t Variant);static void           TryBadInit   (char * DevName, STAVFS_InitParams_t * InitParams_p,                                    char * Descr, TestResult_t * Result_p);static void           TryBadOpen   (char * DevName, STAVFS_OpenParams_t * OpenParams_p,                                    char * Descr, TestResult_t * Result_p);/* Functions --------------------------------------------------------------- *//******************************************************************************Function Name : TopAPI  Description : Top level api test section function   Parameters :******************************************************************************/BOOL TopAPI (parse_t * pars_p, char *result_sym_p){    char *Description = "Top level API tests";        TestCall_t TestList[] =    {         Init,              /* Test 001 */         Open,              /* Test 002 */         OpenBadPartition,  /* Test 003 */         Close,             /* Test 004 */         Term,              /* Test 005 */    };        GenericTest (pars_p, result_sym_p,                 Description,                 TestList, TABLE_LEN(TestList)-1,		 TEST_VARIANT_A);                     return (FALSE);}/******************************************************************************Function Name : Init  Description : API tests for STAVFS_Init   Parameters :******************************************************************************/static TestResult_t Init(int TestNo, TestVariant_t Variant){    TestResult_t        Result = TEST_PASSED;    STAVFS_InitParams_t InitParams;    STAVFS_TermParams_t TermParams;    /* 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; /* 1 also possible in certain circumstances */    InitParams.PartitionNumber = 0; /* 1, 2, 3 also allowed */    TermParams.Flags = 0;    /* InitParams argument */    TryBadInit (STD_DEV_NAME, NULL, "with NULL InitParams_p", &Result);            /* Flags argument */    InitParams.Flags = (U32) -1;    TryBadInit (STD_DEV_NAME, &InitParams, "with out-of-range Flags ((U32) -1)", &Result);        InitParams.Flags = 1;    TryBadInit (STD_DEV_NAME, &InitParams, "with out-of-range Flags (1)", &Result);        InitParams.Flags = 0; /* put the correct arg back in */            /* EVTName argument. First a short name other than 'EVT', second one that fills all      16 bytes, with no terminating zero, so that the 'string' runs straight into the      MemoryPartition member */        strcpy (InitParams.EVTName, BOGUS_DEV_NAME);    TryBadInit (STD_DEV_NAME, &InitParams, "with bad EVTName", &Result);    assert(strlen(LONG_DEV_NAME) == sizeof(ST_DeviceName_t));        memcpy (InitParams.EVTName, LONG_DEV_NAME, sizeof(ST_DeviceName_t));    TryBadInit (STD_DEV_NAME, &InitParams, "with bad (and long) EVTName", &Result);        strcpy (InitParams.EVTName, EVT_DEVICE_NAME);        /* ATAPIName argument. Similar treatment */        strcpy (InitParams.ATAPIName, BOGUS_DEV_NAME);    TryBadInit (STD_DEV_NAME, &InitParams, "with bad ATAPIName", &Result);    memcpy (InitParams.ATAPIName, LONG_DEV_NAME, sizeof(ST_DeviceName_t));    TryBadInit (STD_DEV_NAME, &InitParams, "with bad (and long) ATAPIName", &Result);    strcpy (InitParams.ATAPIName, ATAPI_DEVICE_NAME);            /* MemoryPartition argument */        InitParams.MemoryPartition = NULL;    TryBadInit (STD_DEV_NAME, &InitParams, "with NULL MemoryPartition", &Result);        InitParams.MemoryPartition = system_partition;            /* device Name argument */        TryBadInit (NULL, &InitParams, "with NULL device Name", &Result);        /* still try a matched STAVFS_Term call if this fails */    TryBadInit ("", &InitParams, "with zero length device Name", &Result);    TryBadInit (LONG_DEV_NAME, &InitParams, "with overlong device Name", &Result);    if (ST_NO_ERROR != STAVFS_Init (STD_DEV_NAME, &InitParams))    {        STTBX_Print (("Error initialising unit 0 partition 0\n"));        Result = TEST_FAILED;    }    else /* some tests with one initialised device */    {        /* same name, different (valid) partition */        InitParams.PartitionNumber = 1;        TryBadInit (STD_DEV_NAME, NULL, "when device name is already in use", &Result);            /* send two Term calls (one here, one later) if it does initialise; the second may              fail depending on exactly how the driver operates */        InitParams.PartitionNumber = 0;        /* attempt to initialise same partition twice, different names */        TryBadInit ("OtherDev", &InitParams, "initialising the same partition number twice (different names)", &Result);        /* attempt to initialise same partition twice, same name */        TryBadInit (STD_DEV_NAME, &InitParams, "initialising the same partition number twice (same name)", &Result);            /* again, try two Term calls; second one may fail */        /* trying to initialise two different units simultaneously. On a single disc          system, this will also fail because disc 1 does not exist */        InitParams.UnitNumber = 1;        TryBadInit ("OtherUnit", &InitParams, "trying to initialise a second unit", &Result);        InitParams.UnitNumber = 0;        /* terminate the original device */        if (ST_NO_ERROR != STAVFS_Term (STD_DEV_NAME, &TermParams))        {            STTBX_Print (("Error terminating unit 0 partition 0\n"));            Result = TEST_FAILED;        }    }        /* should be able to initialise unit 1 now, were it present /        InitParams.UnitNumber = 1;    if (ST_NO_ERROR != STAVFS_Init (STD_DEV_NAME, &InitParams))    {        STTBX_Print (("STAVFS_Init should succeed trying to initialise unit 1 once unit 0 has been terminated\n"));        Result = TEST_FAILED;    }    else if (ST_NO_ERROR != STAVFS_Term (STD_DEV_NAME, &TermParams))    {        STTBX_Print (("Failed terminating unit 1\n"));        Result = TEST_FAILED;    }        InitParams.UnitNumber = 0;    */        /* PartitionNumber argument */        InitParams.PartitionNumber = 4;    TryBadInit (STD_DEV_NAME, &InitParams, "with out-of range PartitionNumber (4)", &Result);    InitParams.PartitionNumber = (U16) -1;    TryBadInit (STD_DEV_NAME, &InitParams, "with out-of range PartitionNumber ((U16) -1)", &Result);        InitParams.PartitionNumber = 0;    /* UnitNumber argument */        InitParams.UnitNumber = 2;    TryBadInit (STD_DEV_NAME, &InitParams, "with out-of range UnitNumber (2)", &Result);    InitParams.UnitNumber = (U16) -1;    TryBadInit (STD_DEV_NAME, &InitParams, "with out-of range UnitNumber ((U16) -1)", &Result);        InitParams.UnitNumber = 0;    /* Protocol argument */    InitParams.Protocol = 0;    TryBadInit (STD_DEV_NAME, &InitParams, "with out-of range Protocol (0)", &Result);    InitParams.Protocol = 2;    TryBadInit (STD_DEV_NAME, &InitParams, "with out-of range Protocol (2)", &Result);        InitParams.Protocol = 1;            return (Result);}/******************************************************************************Function Name : TryBadInit  Description : Helper for Init: attempt an initialisation 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, InitParams (both for STAVFS_Init), description to complete error                message, place to record test failure******************************************************************************/static void TryBadInit (char * DevName, STAVFS_InitParams_t * InitParams_p,                        char * Descr, TestResult_t * Result_p){    STAVFS_TermParams_t TermParams;    TermParams.Flags = 0;    if (ST_NO_ERROR == STAVFS_Init (DevName, InitParams_p))    {        STTBX_Print (("STAVFS_Init should fail %s\n", Descr));                if (Result_p != NULL)        {            *Result_p = TEST_FAILED;        }                if (ST_NO_ERROR != STAVFS_Term (DevName, &TermParams))        {            STTBX_Print (("Failed terminating that device\n"));        }    }    }/******************************************************************************Function Name : Open  Description : API tests for STAVFS_Open   Parameters :******************************************************************************/static TestResult_t Open(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;    /* 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; /* 1 also possible in certain circumstances */    InitParams.PartitionNumber = 0; /* 1, 2, 3 also allowed */    OpenParams.Flags = 0;    TermParams.Flags = 0;        /* try one Open before any Init, so that if this is the first test to be executed, we will      prove that the case of a completely uninitialised driver is handled correctly */    TryBadOpen (STD_DEV_NAME, &OpenParams, "with uninitialised device (and possibly uninitialised driver too)", &Result);        /* Define one standard initialised device, sitting there for the remaining bad name      name comparisons to fail against */    if (ST_NO_ERROR != STAVFS_Init (STD_DEV_NAME, &InitParams))    {        STTBX_Print (("Failed initialising unit 0 partition 0\n"));        Result = TEST_FAILED;    }    else    {        /* device Name argument */        TryBadOpen (NULL, &OpenParams, "with NULL device name", &Result);        TryBadOpen (LONG_DEV_NAME, &OpenParams, "with overlong device name", &Result);        TryBadOpen (BOGUS_DEV_NAME, &OpenParams, "with device name that has never been initialised", &Result);                        /* Flags argument */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -