VirtualBox

Changeset 40562 in vbox for trunk


Ignore:
Timestamp:
Mar 21, 2012 11:58:06 AM (13 years ago)
Author:
vboxsync
Message:

Additions/VBoxGuest: first test of transparent IOCtl in Solaris STREAMS code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-solaris-streams.c

    r40552 r40562  
    564564static struct
    565565{
    566     unsigned char iDBType;
    567566    int iIOCCmd;
    568567    size_t cbData;
     
    573572    int rcExp;
    574573    void (*pfnExtra)(RTTEST hTest, queue_t *pWriteQueue, struct msgb *pMBlk);
     574    bool fCanTransparent;
    575575} g_asTestWPut[] =
    576576{
    577    /* iDBType  iIOCCmd          cbData           pvDataIn   cbDataIn
    578       pvDataOut   cbDataOut rcExp   pfnExtra */
    579     { M_IOCTL, VUIDGFORMAT,     sizeof(int),     NULL,      0,
    580       PVGFORMAT, CBGFORMAT, 0,      NULL },
    581     { M_IOCTL, VUIDGFORMAT,     sizeof(int) - 1, NULL,      0,
    582       NULL,       0,        EINVAL, NULL },
    583     { M_IOCTL, VUIDGFORMAT,     sizeof(int) + 1, NULL,      0,
    584       PVGFORMAT, CBGFORMAT, 0,      NULL },
    585     { M_IOCTL, VUIDSFORMAT,     sizeof(int),     PVGFORMAT, CBGFORMAT,
    586       NULL,       0,        0,      NULL },
    587     { M_IOCTL, MSIOSRESOLUTION, CBMSIOSRES,      PMSIOSRES, CBMSIOSRES,
    588       NULL,       0,        0,      testSetResolution },
    589     { M_IOCTL, VUIDGWHEELINFO,  0,               NULL,      0,
    590       NULL,       0,        EINVAL, NULL }
     577   /* iIOCCmd          cbData           pvDataIn   cbDataIn
     578      pvDataOut   cbDataOut rcExp   pfnExtra           fCanTransparent */
     579    { VUIDGFORMAT,     sizeof(int),     NULL,      0,
     580      PVGFORMAT, CBGFORMAT, 0,      NULL,              false },
     581    { VUIDGFORMAT,     sizeof(int) - 1, NULL,      0,
     582      NULL,       0,        EINVAL, NULL,              false },
     583    { VUIDGFORMAT,     sizeof(int) + 1, NULL,      0,
     584      PVGFORMAT, CBGFORMAT, 0,      NULL,              false },
     585    { VUIDSFORMAT,     sizeof(int),     PVGFORMAT, CBGFORMAT,
     586      NULL,       0,        0,      NULL,              false },
     587    { MSIOSRESOLUTION, CBMSIOSRES,      PMSIOSRES, CBMSIOSRES,
     588      NULL,       0,        0,      testSetResolution, false },
     589    { VUIDGWHEELINFO,  0,               NULL,      0,
     590      NULL,       0,        EINVAL, NULL,              true }
    591591};
    592592
     
    596596# undef CBMSIOSRES
    597597
     598/* Helpers for testWPut. */
     599static void testWPutStreams(RTTEST hTest, unsigned i);
     600static void testWPutTransparent(RTTEST hTest, unsigned i);
     601
    598602/** Test WPut's handling of different IOCtls, which is bulk of the logic in
    599603 * this file. */
    600604static void testWPut(RTTEST hTest)
     605{
     606    unsigned i;
     607
     608    RTTestSub(hTest, "Testing vbgr0WPut");
     609    for (i = 0; i < RT_ELEMENTS(g_asTestWPut); ++i)
     610    {
     611        testWPutStreams(hTest, i);
     612        if (g_asTestWPut[i].fCanTransparent)
     613            testWPutTransparent(hTest, i);
     614    }
     615}
     616
     617/** Simulate sending a streams IOCtl to WPut with the parameters from table
     618 * line @a i. */
     619void testWPutStreams(RTTEST hTest, unsigned i)
    601620{
    602621    queue_t aQueues[2];
     
    606625    struct iocblk IOCBlk;
    607626    int rc, cFormat = 0;
    608     unsigned i;
    609 
    610     /* Single simple test to start with.  We can try to make it more systematic
    611      * next. */
    612     RTTestSub(hTest, "Testing vbgr0WPut");
    613     for (i = 0; i < RT_ELEMENTS(g_asTestWPut); ++i)
    614     {
    615         unsigned char acData[1024];
    616 
    617         RT_ZERO(aQueues);
    618         doInitQueues(&aQueues[0]);
    619         rc = vbgr0SolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
    620         RTTEST_CHECK_MSG(hTest, rc == 0, (hTest, "i=%u, rc=%d\n", i, rc));
    621         RTTEST_CHECK_MSG(hTest,    g_aOpenNodeStates[1].pWriteQueue
    622                                 == WR(&aQueues[0]), (hTest, "i=%u\n", i));
    623         RT_ZERO(MBlk);
    624         RT_ZERO(DBlk);
    625         RT_ZERO(IOCBlk);
    626         RT_ZERO(MBlkCont);
    627         RT_ZERO(acData);
    628         DBlk.db_type = g_asTestWPut[i].iDBType;
    629         IOCBlk.ioc_cmd = g_asTestWPut[i].iIOCCmd;
    630         IOCBlk.ioc_count = g_asTestWPut[i].cbData;
    631         AssertReturnVoid(g_asTestWPut[i].cbData <= sizeof(acData));
    632         AssertReturnVoid(g_asTestWPut[i].cbDataIn <= g_asTestWPut[i].cbData);
    633         AssertReturnVoid(g_asTestWPut[i].cbDataOut <= g_asTestWPut[i].cbData);
    634         memcpy(acData, g_asTestWPut[i].pvDataIn, g_asTestWPut[i].cbDataIn);
    635         MBlkCont.b_rptr = acData;
    636         MBlkCont.b_wptr = acData + g_asTestWPut[i].cbData;
    637         MBlk.b_cont = &MBlkCont;
    638         MBlk.b_rptr = (unsigned char *)&IOCBlk;
    639         MBlk.b_wptr = (unsigned char *)&IOCBlk + sizeof(IOCBlk);
    640         MBlk.b_datap = &DBlk;
    641         rc = vbgr0SolWPut(WR(&aQueues[0]), &MBlk);
    642         RTTEST_CHECK_MSG(hTest, IOCBlk.ioc_error == g_asTestWPut[i].rcExp,
    643                          (hTest, "i=%u, IOCBlk.ioc_error=%d\n", i,
    644                           IOCBlk.ioc_error));
    645         RTTEST_CHECK_MSG(hTest, IOCBlk.ioc_count == g_asTestWPut[i].cbDataOut,
    646                          (hTest, "i=%u, ioc_count=%u\n", i, IOCBlk.ioc_count));
    647         RTTEST_CHECK_MSG(hTest, !memcmp(acData, g_asTestWPut[i].pvDataOut,
    648                                         g_asTestWPut[i].cbDataOut),
    649                          (hTest, "i=%u\n", i));
    650         /* Hack to ensure that miocpullup() gets called when needed. */
    651         if (   g_asTestWPut[i].iDBType == M_IOCTL
    652             && g_asTestWPut[i].cbData > 0)  /* TRANSPARENT == -1 */
    653             RTTEST_CHECK_MSG(hTest, MBlk.b_flag == 1, (hTest, "i=%u\n", i));
    654         if (g_asTestWPut[i].pfnExtra)
    655             g_asTestWPut[i].pfnExtra(hTest, WR(&aQueues[0]), &MBlk);
    656         vbgr0SolClose(RD(&aQueues[1]), 0, NULL);
    657     }
     627    unsigned char acData[1024];
     628
     629    RT_ZERO(aQueues);
     630    doInitQueues(&aQueues[0]);
     631    rc = vbgr0SolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
     632    RTTEST_CHECK_MSG(hTest, rc == 0, (hTest, "i=%u, rc=%d\n", i, rc));
     633    RTTEST_CHECK_MSG(hTest,    g_aOpenNodeStates[1].pWriteQueue
     634                            == WR(&aQueues[0]), (hTest, "i=%u\n", i));
     635    RT_ZERO(MBlk);
     636    RT_ZERO(DBlk);
     637    RT_ZERO(IOCBlk);
     638    RT_ZERO(MBlkCont);
     639    RT_ZERO(acData);
     640    DBlk.db_type = M_IOCTL;
     641    IOCBlk.ioc_cmd = g_asTestWPut[i].iIOCCmd;
     642    IOCBlk.ioc_count = g_asTestWPut[i].cbData;
     643    AssertReturnVoid(g_asTestWPut[i].cbData <= sizeof(acData));
     644    AssertReturnVoid(g_asTestWPut[i].cbDataIn <= g_asTestWPut[i].cbData);
     645    AssertReturnVoid(g_asTestWPut[i].cbDataOut <= g_asTestWPut[i].cbData);
     646    memcpy(acData, g_asTestWPut[i].pvDataIn, g_asTestWPut[i].cbDataIn);
     647    MBlkCont.b_rptr = acData;
     648    MBlkCont.b_wptr = acData + g_asTestWPut[i].cbData;
     649    MBlk.b_cont = &MBlkCont;
     650    MBlk.b_rptr = (unsigned char *)&IOCBlk;
     651    MBlk.b_wptr = (unsigned char *)&IOCBlk + sizeof(IOCBlk);
     652    MBlk.b_datap = &DBlk;
     653    rc = vbgr0SolWPut(WR(&aQueues[0]), &MBlk);
     654    RTTEST_CHECK_MSG(hTest, IOCBlk.ioc_error == g_asTestWPut[i].rcExp,
     655                     (hTest, "i=%u, IOCBlk.ioc_error=%d\n", i,
     656                      IOCBlk.ioc_error));
     657    RTTEST_CHECK_MSG(hTest, IOCBlk.ioc_count == g_asTestWPut[i].cbDataOut,
     658                     (hTest, "i=%u, ioc_count=%u\n", i, IOCBlk.ioc_count));
     659    RTTEST_CHECK_MSG(hTest, !memcmp(acData, g_asTestWPut[i].pvDataOut,
     660                                    g_asTestWPut[i].cbDataOut),
     661                     (hTest, "i=%u\n", i));
     662    /* Hack to ensure that miocpullup() gets called when needed. */
     663    if (g_asTestWPut[i].cbData > 0)
     664        RTTEST_CHECK_MSG(hTest, MBlk.b_flag == 1, (hTest, "i=%u\n", i));
     665    if (g_asTestWPut[i].pfnExtra)
     666        g_asTestWPut[i].pfnExtra(hTest, WR(&aQueues[0]), &MBlk);
     667    vbgr0SolClose(RD(&aQueues[1]), 0, NULL);
     668}
     669
     670
     671/** Simulate sending a transparent IOCtl to WPut with the parameters from table
     672 * line @a i. */
     673void testWPutTransparent(RTTEST hTest, unsigned i)
     674{
     675    queue_t aQueues[2];
     676    dev_t device = 0;
     677    struct msgb MBlk, MBlkCont;
     678    struct datab DBlk;
     679    struct iocblk IOCBlk;
     680    int rc, cFormat = 0;
     681    unsigned char acData[1024];
     682
     683    RT_ZERO(aQueues);
     684    doInitQueues(&aQueues[0]);
     685    rc = vbgr0SolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
     686    RTTEST_CHECK_MSG(hTest, rc == 0, (hTest, "i=%u, rc=%d\n", i, rc));
     687    RTTEST_CHECK_MSG(hTest,    g_aOpenNodeStates[1].pWriteQueue
     688                            == WR(&aQueues[0]), (hTest, "i=%u\n", i));
     689    RT_ZERO(MBlk);
     690    RT_ZERO(DBlk);
     691    RT_ZERO(IOCBlk);
     692    RT_ZERO(MBlkCont);
     693    RT_ZERO(acData);
     694    DBlk.db_type = M_IOCTL;
     695    IOCBlk.ioc_cmd = g_asTestWPut[i].iIOCCmd;
     696    IOCBlk.ioc_count = TRANSPARENT;
     697    AssertReturnVoid(g_asTestWPut[i].cbData <= sizeof(acData));
     698    AssertReturnVoid(g_asTestWPut[i].cbDataIn <= g_asTestWPut[i].cbData);
     699    AssertReturnVoid(g_asTestWPut[i].cbDataOut <= g_asTestWPut[i].cbData);
     700    memcpy(acData, g_asTestWPut[i].pvDataIn, g_asTestWPut[i].cbDataIn);
     701    MBlkCont.b_rptr = acData;
     702    MBlkCont.b_wptr = acData + g_asTestWPut[i].cbData;
     703    MBlk.b_cont = &MBlkCont;
     704    MBlk.b_rptr = (unsigned char *)&IOCBlk;
     705    MBlk.b_wptr = (unsigned char *)&IOCBlk + sizeof(IOCBlk);
     706    MBlk.b_datap = &DBlk;
     707    rc = vbgr0SolWPut(WR(&aQueues[0]), &MBlk);
     708    RTTEST_CHECK_MSG(hTest, IOCBlk.ioc_error == g_asTestWPut[i].rcExp,
     709                     (hTest, "i=%u, IOCBlk.ioc_error=%d\n", i,
     710                      IOCBlk.ioc_error));
     711    RTTEST_CHECK_MSG(hTest, IOCBlk.ioc_count == g_asTestWPut[i].cbDataOut,
     712                     (hTest, "i=%u, ioc_count=%u\n", i, IOCBlk.ioc_count));
     713    RTTEST_CHECK_MSG(hTest, !memcmp(acData, g_asTestWPut[i].pvDataOut,
     714                                    g_asTestWPut[i].cbDataOut),
     715                     (hTest, "i=%u\n", i));
     716    /* Hack to ensure that miocpullup() gets called when needed. */
     717    if (g_asTestWPut[i].cbData > 0)
     718        RTTEST_CHECK_MSG(hTest, MBlk.b_flag == 1, (hTest, "i=%u\n", i));
     719    if (g_asTestWPut[i].pfnExtra)
     720        g_asTestWPut[i].pfnExtra(hTest, WR(&aQueues[0]), &MBlk);
     721    vbgr0SolClose(RD(&aQueues[1]), 0, NULL);
    658722}
    659723#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette