| 1633 | }; |
| 1634 | |
| 1635 | int |
| 1636 | cache_handler(TSCont contp, TSEvent event, void *data) |
| 1637 | { |
| 1638 | Dbg(dbg_ctl_sdk_ut_cache_write, "Event %d data %p", event, data); |
| 1639 | |
| 1640 | CacheVConnStruct *cache_vconn = static_cast<CacheVConnStruct *>(TSContDataGet(contp)); |
| 1641 | |
| 1642 | TSIOBufferBlock blockp; |
| 1643 | char *ptr_block; |
| 1644 | int64_t ntodo, ndone, nbytes, towrite, avail, content_length; |
| 1645 | |
| 1646 | switch (event) { |
| 1647 | case TS_EVENT_CACHE_OPEN_WRITE: |
| 1648 | Dbg(dbg_ctl_sdk_ut_cache_event, "TS_EVENT_CACHE_OPEN_WRITE %d %p", event, data); |
| 1649 | SDK_RPRINT(SDK_Cache_test, "TSCacheWrite", "TestCase1", TC_PASS, "ok"); |
| 1650 | |
| 1651 | // data is write_vc |
| 1652 | cache_vconn->write_vconnp = static_cast<TSVConn>(data); |
| 1653 | |
| 1654 | // Create buffers/readers to write and read data into the cache |
| 1655 | cache_vconn->bufp = TSIOBufferCreate(); |
| 1656 | cache_vconn->readerp = TSIOBufferReaderAlloc(cache_vconn->bufp); |
| 1657 | cache_vconn->out_bufp = TSIOBufferCreate(); |
| 1658 | cache_vconn->out_readerp = TSIOBufferReaderAlloc(cache_vconn->out_bufp); |
| 1659 | |
| 1660 | // Write content into upstream IOBuffer |
| 1661 | ntodo = OBJECT_SIZE; |
| 1662 | ndone = 0; |
| 1663 | while (ntodo > 0) { |
| 1664 | blockp = TSIOBufferStart(cache_vconn->bufp); |
| 1665 | ptr_block = TSIOBufferBlockWriteStart(blockp, &avail); |
| 1666 | towrite = ((ntodo < avail) ? ntodo : avail); |
| 1667 | memcpy(ptr_block, content + ndone, towrite); |
| 1668 | TSIOBufferProduce(cache_vconn->bufp, towrite); |
| 1669 | ntodo -= towrite; |
| 1670 | ndone += towrite; |
| 1671 | } |
| 1672 | |
| 1673 | // first write half of the data. To test TSVIOReenable |
| 1674 | cache_vconn->write_vio = TSVConnWrite(static_cast<TSVConn>(data), contp, cache_vconn->readerp, OBJECT_SIZE / 2); |
| 1675 | return 1; |
| 1676 | |
| 1677 | case TS_EVENT_CACHE_OPEN_WRITE_FAILED: |
| 1678 | Dbg(dbg_ctl_sdk_ut_cache_event, "TS_EVENT_CACHE_OPEN_WRITE_FAILED %d %p", event, data); |
| 1679 | SDK_RPRINT(SDK_Cache_test, "TSCacheWrite", "TestCase1", TC_FAIL, "can't open cache vc, edtata = %p", data); |
| 1680 | TSReleaseAssert(!"cache"); |
| 1681 | |
| 1682 | // no need to continue, return |
| 1683 | *SDK_Cache_pstatus = REGRESSION_TEST_FAILED; |
| 1684 | return 1; |
| 1685 | |
| 1686 | case TS_EVENT_CACHE_OPEN_READ: |
| 1687 | Dbg(dbg_ctl_sdk_ut_cache_event, "TS_EVENT_CACHE_OPEN_READ %d %p", event, data); |
| 1688 | if (read_counter == 2) { |
| 1689 | SDK_RPRINT(SDK_Cache_test, "TSCacheRead", "TestCase2", TC_FAIL, "shouldn't open cache vc"); |
| 1690 | |
| 1691 | // no need to continue, return |
| 1692 | *SDK_Cache_pstatus = REGRESSION_TEST_FAILED; |
nothing calls this directly
no test coverage detected