2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
#include "TestHarness.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "prinrval.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIPipe.h" // new implementation
|
2008-09-25 11:06:13 -07:00
|
|
|
|
2009-07-22 20:55:02 -07:00
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
using namespace mozilla;
|
2008-09-25 11:06:13 -07:00
|
|
|
|
|
|
|
/** NS_NewPipe2 reimplemented, because it's not exported by XPCOM */
|
|
|
|
nsresult TP_NewPipe2(nsIAsyncInputStream** input,
|
|
|
|
nsIAsyncOutputStream** output,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nonBlockingInput,
|
|
|
|
bool nonBlockingOutput,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t segmentSize,
|
|
|
|
uint32_t segmentCount,
|
2008-09-25 11:06:13 -07:00
|
|
|
nsIMemory* segmentAlloc)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPipe> pipe = do_CreateInstance("@mozilla.org/pipe;1");
|
|
|
|
if (!pipe)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv = pipe->Init(nonBlockingInput,
|
|
|
|
nonBlockingOutput,
|
|
|
|
segmentSize,
|
|
|
|
segmentCount,
|
|
|
|
segmentAlloc);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
pipe->GetInputStream(input);
|
|
|
|
pipe->GetOutputStream(output);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** NS_NewPipe reimplemented, because it's not exported by XPCOM */
|
|
|
|
#define TP_DEFAULT_SEGMENT_SIZE 4096
|
|
|
|
nsresult TP_NewPipe(nsIInputStream **pipeIn,
|
|
|
|
nsIOutputStream **pipeOut,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t segmentSize = 0,
|
|
|
|
uint32_t maxSize = 0,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nonBlockingInput = false,
|
|
|
|
bool nonBlockingOutput = false,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIMemory *segmentAlloc = nullptr);
|
2008-09-25 11:06:13 -07:00
|
|
|
nsresult TP_NewPipe(nsIInputStream **pipeIn,
|
|
|
|
nsIOutputStream **pipeOut,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t segmentSize,
|
|
|
|
uint32_t maxSize,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nonBlockingInput,
|
|
|
|
bool nonBlockingOutput,
|
2008-09-25 11:06:13 -07:00
|
|
|
nsIMemory *segmentAlloc)
|
|
|
|
{
|
|
|
|
if (segmentSize == 0)
|
|
|
|
segmentSize = TP_DEFAULT_SEGMENT_SIZE;
|
|
|
|
|
2012-09-27 23:57:33 -07:00
|
|
|
// Handle maxSize of UINT32_MAX as a special case
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t segmentCount;
|
2012-09-27 23:57:33 -07:00
|
|
|
if (maxSize == UINT32_MAX)
|
|
|
|
segmentCount = UINT32_MAX;
|
2008-09-25 11:06:13 -07:00
|
|
|
else
|
|
|
|
segmentCount = maxSize / segmentSize;
|
|
|
|
|
|
|
|
nsIAsyncInputStream *in;
|
|
|
|
nsIAsyncOutputStream *out;
|
|
|
|
nsresult rv = TP_NewPipe2(&in, &out, nonBlockingInput, nonBlockingOutput,
|
|
|
|
segmentSize, segmentCount, segmentAlloc);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*pipeIn = in;
|
|
|
|
*pipeOut = out;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define KEY 0xa7
|
|
|
|
#define ITERATIONS 33333
|
|
|
|
char kTestPattern[] = "My hovercraft is full of eels.\n";
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool gTrace = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
WriteAll(nsIOutputStream *os, const char *buf, uint32_t bufLen, uint32_t *lenWritten)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const char *p = buf;
|
|
|
|
*lenWritten = 0;
|
|
|
|
while (bufLen) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t n;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = os->Write(p, bufLen, &n);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
p += n;
|
|
|
|
bufLen -= n;
|
|
|
|
*lenWritten += n;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsReceiver : public nsIRunnable {
|
|
|
|
public:
|
2013-07-18 19:31:26 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsresult rv;
|
|
|
|
char buf[101];
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRIntervalTime start = PR_IntervalNow();
|
2011-10-17 07:59:28 -07:00
|
|
|
while (true) {
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = mIn->Read(buf, 100, &count);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
printf("read failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (count == 0) {
|
|
|
|
// printf("EOF count = %d\n", mCount);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gTrace) {
|
|
|
|
buf[count] = '\0';
|
2008-08-24 12:16:33 -07:00
|
|
|
printf("read: %s\n", buf);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
mCount += count;
|
|
|
|
}
|
|
|
|
PRIntervalTime end = PR_IntervalNow();
|
|
|
|
printf("read %d bytes, time = %dms\n", mCount,
|
|
|
|
PR_IntervalToMilliseconds(end - start));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsReceiver(nsIInputStream* in) : mIn(in), mCount(0) {
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t GetBytesRead() { return mCount; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIInputStream> mIn;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsReceiver, nsIRunnable)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
TestPipe(nsIInputStream* in, nsIOutputStream* out)
|
|
|
|
{
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsReceiver> receiver = new nsReceiver(in);
|
|
|
|
if (!receiver)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
rv = NS_NewThread(getter_AddRefs(thread), receiver);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t total = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRIntervalTime start = PR_IntervalNow();
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < ITERATIONS; i++) {
|
|
|
|
uint32_t writeCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
char *buf = PR_smprintf("%d %s", i, kTestPattern);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len = strlen(buf);
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = WriteAll(out, buf, len, &writeCount);
|
|
|
|
if (gTrace) {
|
|
|
|
printf("wrote: ");
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t j = 0; j < writeCount; j++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
putc(buf[j], stdout);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
PR_smprintf_free(buf);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
total += writeCount;
|
|
|
|
}
|
|
|
|
rv = out->Close();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PRIntervalTime end = PR_IntervalNow();
|
|
|
|
|
|
|
|
thread->Shutdown();
|
|
|
|
|
|
|
|
printf("wrote %d bytes, time = %dms\n", total,
|
|
|
|
PR_IntervalToMilliseconds(end - start));
|
|
|
|
NS_ASSERTION(receiver->GetBytesRead() == total, "didn't read everything");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class nsShortReader : public nsIRunnable {
|
|
|
|
public:
|
2013-07-18 19:31:26 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsresult rv;
|
|
|
|
char buf[101];
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count;
|
|
|
|
uint32_t total = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
while (true) {
|
2007-03-22 10:30:00 -07:00
|
|
|
//if (gTrace)
|
|
|
|
// printf("calling Read\n");
|
|
|
|
rv = mIn->Read(buf, 100, &count);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
printf("read failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (count == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2008-08-24 12:16:33 -07:00
|
|
|
|
|
|
|
if (gTrace) {
|
|
|
|
// For next |printf()| call and possible others elsewhere.
|
|
|
|
buf[count] = '\0';
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
printf("read %d bytes: %s\n", count, buf);
|
2008-08-24 12:16:33 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
Received(count);
|
|
|
|
total += count;
|
|
|
|
}
|
|
|
|
printf("read %d bytes\n", total);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsShortReader(nsIInputStream* in) : mIn(in), mReceived(0) {
|
2009-07-22 20:55:02 -07:00
|
|
|
mMon = new Monitor("nsShortReader");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void Received(uint32_t count) {
|
2009-07-22 20:55:02 -07:00
|
|
|
MonitorAutoEnter mon(*mMon);
|
2007-03-22 10:30:00 -07:00
|
|
|
mReceived += count;
|
|
|
|
mon.Notify();
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t WaitForReceipt(const uint32_t aWriteCount) {
|
2009-07-22 20:55:02 -07:00
|
|
|
MonitorAutoEnter mon(*mMon);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t result = mReceived;
|
2008-08-24 12:16:33 -07:00
|
|
|
|
|
|
|
while (result < aWriteCount) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mon.Wait();
|
2008-08-24 12:16:33 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(mReceived > result, "failed to receive");
|
2007-03-22 10:30:00 -07:00
|
|
|
result = mReceived;
|
|
|
|
}
|
2008-08-24 12:16:33 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mReceived = 0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIInputStream> mIn;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mReceived;
|
2009-07-22 20:55:02 -07:00
|
|
|
Monitor* mMon;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsShortReader, nsIRunnable)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
TestShortWrites(nsIInputStream* in, nsIOutputStream* out)
|
|
|
|
{
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsShortReader> receiver = new nsShortReader(in);
|
|
|
|
if (!receiver)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
rv = NS_NewThread(getter_AddRefs(thread), receiver);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t total = 0;
|
|
|
|
for (uint32_t i = 0; i < ITERATIONS; i++) {
|
|
|
|
uint32_t writeCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
char* buf = PR_smprintf("%d %s", i, kTestPattern);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len = strlen(buf);
|
2007-03-22 10:30:00 -07:00
|
|
|
len = len * rand() / RAND_MAX;
|
2013-01-15 04:22:03 -08:00
|
|
|
len = XPCOM_MAX(1, len);
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = WriteAll(out, buf, len, &writeCount);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_ASSERTION(writeCount == len, "didn't write enough");
|
|
|
|
total += writeCount;
|
|
|
|
|
|
|
|
if (gTrace)
|
|
|
|
printf("wrote %d bytes: %s\n", writeCount, buf);
|
|
|
|
PR_smprintf_free(buf);
|
|
|
|
//printf("calling Flush\n");
|
|
|
|
out->Flush();
|
|
|
|
//printf("calling WaitForReceipt\n");
|
2010-07-11 06:00:19 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t received =
|
2010-07-11 06:00:19 -07:00
|
|
|
#endif
|
|
|
|
receiver->WaitForReceipt(writeCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(received == writeCount, "received wrong amount");
|
|
|
|
}
|
|
|
|
rv = out->Close();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
thread->Shutdown();
|
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
printf("wrote %d bytes\n", total);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class nsPump : public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:31:26 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsresult rv;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count;
|
2011-10-17 07:59:28 -07:00
|
|
|
while (true) {
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = mOut->WriteFrom(mIn, ~0U, &count);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
printf("Write failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (count == 0) {
|
|
|
|
printf("EOF count = %d\n", mCount);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gTrace) {
|
|
|
|
printf("Wrote: %d\n", count);
|
|
|
|
}
|
|
|
|
mCount += count;
|
|
|
|
}
|
|
|
|
mOut->Close();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPump(nsIInputStream* in,
|
|
|
|
nsIOutputStream* out)
|
|
|
|
: mIn(in), mOut(out), mCount(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIInputStream> mIn;
|
|
|
|
nsCOMPtr<nsIOutputStream> mOut;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsPump, nsIRunnable)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
TestChainedPipes()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
printf("TestChainedPipes\n");
|
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIInputStream> in1;
|
|
|
|
nsCOMPtr<nsIOutputStream> out1;
|
|
|
|
rv = TP_NewPipe(getter_AddRefs(in1), getter_AddRefs(out1), 20, 1999);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIInputStream> in2;
|
|
|
|
nsCOMPtr<nsIOutputStream> out2;
|
|
|
|
rv = TP_NewPipe(getter_AddRefs(in2), getter_AddRefs(out2), 200, 401);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsPump> pump = new nsPump(in1, out2);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (pump == nullptr) return NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
rv = NS_NewThread(getter_AddRefs(thread), pump);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsReceiver> receiver = new nsReceiver(in2);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (receiver == nullptr) return NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIThread> receiverThread;
|
|
|
|
rv = NS_NewThread(getter_AddRefs(receiverThread), receiver);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t total = 0;
|
|
|
|
for (uint32_t i = 0; i < ITERATIONS; i++) {
|
|
|
|
uint32_t writeCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
char* buf = PR_smprintf("%d %s", i, kTestPattern);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len = strlen(buf);
|
2007-03-22 10:30:00 -07:00
|
|
|
len = len * rand() / RAND_MAX;
|
2013-01-15 04:22:03 -08:00
|
|
|
len = XPCOM_MAX(1, len);
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = WriteAll(out1, buf, len, &writeCount);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_ASSERTION(writeCount == len, "didn't write enough");
|
|
|
|
total += writeCount;
|
|
|
|
|
|
|
|
if (gTrace)
|
|
|
|
printf("wrote %d bytes: %s\n", writeCount, buf);
|
|
|
|
|
|
|
|
PR_smprintf_free(buf);
|
|
|
|
}
|
|
|
|
printf("wrote total of %d bytes\n", total);
|
|
|
|
rv = out1->Close();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
thread->Shutdown();
|
|
|
|
receiverThread->Shutdown();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
RunTests(uint32_t segSize, uint32_t segCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIInputStream> in;
|
|
|
|
nsCOMPtr<nsIOutputStream> out;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t bufSize = segSize * segCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
printf("Testing New Pipes: segment size %d buffer size %d\n", segSize, bufSize);
|
|
|
|
|
|
|
|
printf("Testing long writes...\n");
|
2008-09-25 11:06:13 -07:00
|
|
|
rv = TP_NewPipe(getter_AddRefs(in), getter_AddRefs(out), segSize, bufSize);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "TP_NewPipe failed");
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = TestPipe(in, out);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "TestPipe failed");
|
|
|
|
|
|
|
|
printf("Testing short writes...\n");
|
2008-09-25 11:06:13 -07:00
|
|
|
rv = TP_NewPipe(getter_AddRefs(in), getter_AddRefs(out), segSize, bufSize);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "TP_NewPipe failed");
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = TestShortWrites(in, out);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "TestPipe failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-05-23 09:54:47 -07:00
|
|
|
#if 0
|
2011-08-18 06:46:39 -07:00
|
|
|
extern void
|
2007-03-22 10:30:00 -07:00
|
|
|
TestSegmentedBuffer();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2008-09-25 11:06:13 -07:00
|
|
|
nsCOMPtr<nsIServiceManager> servMgr;
|
2013-10-10 13:42:16 -07:00
|
|
|
rv = NS_InitXPCOM2(getter_AddRefs(servMgr), nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (argc > 1 && nsCRT::strcmp(argv[1], "-trace") == 0)
|
2011-10-17 07:59:28 -07:00
|
|
|
gTrace = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
rv = TestChainedPipes();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "TestChainedPipes failed");
|
|
|
|
RunTests(16, 1);
|
|
|
|
RunTests(4096, 16);
|
2008-09-25 11:06:13 -07:00
|
|
|
|
|
|
|
servMgr = 0;
|
2013-10-10 13:42:16 -07:00
|
|
|
rv = NS_ShutdownXPCOM(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
2008-09-25 11:06:13 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|