static PRIntn PR_CALLBACK RealMain(int argc, char** argv)
{
    PRUint32 vcpu, cpus = 0, loops = 1000;

	/* The command line argument: -d is used to determine if the test is being run
	in debug mode. The regress tool requires only one line output:PASS or FAIL.
	All of the printfs associated with this test has been handled with a if (debug_mode)
	test.
	Usage: test_name -d
	*/

 /* main test */
	
	PLOptStatus os;
	PLOptState *opt = PL_CreateOptState(argc, argv, "dl:c:");
	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
		if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode */
			debug_mode = 1;
            break;
        case 'c':  /* concurrency counter */
			cpus = atoi(opt->value);
            break;
        case 'l':  /* loop counter */
			loops = atoi(opt->value);
            break;
         default:
            break;
        }
    }
	PL_DestroyOptState(opt);
	
    output = PR_GetSpecialFD(PR_StandardOutput);
    PR_fprintf(output, "inrval: Examine stdout to determine results.\n");

    if (cpus == 0) cpus = 8;
    if (loops == 0) loops = 1000;

    if (debug_mode > 0)
    {
        PR_fprintf(output, "Inrval: Using %d loops\n", loops);
        PR_fprintf(output, "Inrval: Using 1 and %d cpu(s)\n", cpus);
    }

    for (vcpu = 1; vcpu <= cpus; vcpu += cpus - 1)
    {
        if (debug_mode)
            PR_fprintf(output, "\nInrval: Using %d CPU(s)\n\n", vcpu);
        PR_SetConcurrency(vcpu);

        TestNowOverhead();
        TestIntervalOverhead();
        TestConversions();
        TestIntervals();
    }
        
    return 0;
}
Beispiel #2
0
static bool
Test_TfRefPtr()
{
    TestConversions();
    TestNullptrComparisons();
    
    NodeRefPtr chain1 = MakeChain(10);
    NodeRefPtr chain2 = MakeChain(5);

    NodePtr gChain1 = chain1;
    NodePtr gChain2 = chain2;

    TF_AXIOM(chain1->GetLength() == 10);
    TF_AXIOM(chain2->GetLength() == 5);
    TF_AXIOM(gChain1->GetLength() == 10);
    TF_AXIOM(gChain2->GetLength() == 5);

    std::cout
        << "total nodes (should be 15): "
        << Node::GetTotalNodeCount() << std::endl;

    NodeRefPtr start = Node::New();
    start->SetChild(chain1);
    chain1 = TfNullPtr;

    TF_AXIOM(gChain1->GetLength() == 10);
    TF_AXIOM(start->GetLength() == 11);

    std::cout
        << "total nodes (should be one more than previous): "
        << Node::GetTotalNodeCount() << std::endl;

    start->SetChild(gChain2);
    chain2 = TfNullPtr;
    TF_AXIOM(start->GetLength() == 6);
    TF_AXIOM(!gChain1);
    TF_AXIOM(gChain2);

    TF_AXIOM(start->GetLength() == start->GetTail()->GetRevLength());

    std::cout
        << "total nodes (should be 10 less than last): "
        << Node::GetTotalNodeCount() << std::endl;

    start = TfNullPtr;

    TF_AXIOM(!gChain1);
    TF_AXIOM(!gChain2);

    std::cout
        << "total nodes (should be zero): "
        << Node::GetTotalNodeCount() << std::endl;

    TF_AXIOM(Node::GetTotalNodeCount() == 0);

    chain1 = MakeChain(5);
    gChain2 = chain2 = MakeChain(5);
    chain1->GetTail()->SetChild(chain2);

    TF_AXIOM(gChain2->GetRevLength() == 6);
    chain1 = TfNullPtr;
    TF_AXIOM(gChain2->GetRevLength() == 1);
    chain2 = TfNullPtr;
    TF_AXIOM(!gChain2);
    TF_AXIOM(Node::GetTotalNodeCount() == 0);

    SuperNodeRefPtr superPtr = SuperNode::New();
    NodeRefPtr basePtr = superPtr;
    NodePtr baseBackPtr = basePtr;
    
    TF_AXIOM(TfDynamic_cast<SuperNodeRefPtr>(basePtr) == superPtr);
    TF_AXIOM(TfSafeDynamic_cast<SuperNodeRefPtr>(basePtr) == superPtr);

    TF_AXIOM(TfDynamic_cast<SuperNodePtr>(baseBackPtr) == superPtr);
    TF_AXIOM(TfSafeDynamic_cast<SuperNodePtr>(baseBackPtr) == superPtr);

    // Test swap
    {
        const NodeRefPtr n1 = Node::New();
        const NodeRefPtr n2 = Node::New();

        NodeRefPtr a = n1;
        NodeRefPtr b = n2;
        TF_AXIOM(a);
        TF_AXIOM(b);
        TF_AXIOM(a != b);

        TF_AXIOM(a == n1);
        TF_AXIOM(b == n2);
        a.swap(b);
        TF_AXIOM(a == n2);
        TF_AXIOM(b == n1);

        // Test self-swap
        a.swap(a);
        TF_AXIOM(a == n2);
        b.swap(b);
        TF_AXIOM(b == n1);
    }

    // Test move constructor and assignment operators
    {
        NodeRefPtr n1 = Node::New();
        Node* n1Ptr = get_pointer(n1);
        TF_AXIOM(n1);

        NodeRefPtr n2(std::move(n1));
        TF_AXIOM(n2);
        TF_AXIOM(get_pointer(n2) == n1Ptr);
        TF_AXIOM(!n1);

        n1 = Node::New();
        n1Ptr = get_pointer(n1);
        TF_AXIOM(n1);

        n2 = std::move(n1);
        TF_AXIOM(n2);
        TF_AXIOM(get_pointer(n2) == n1Ptr);
        TF_AXIOM(!n1);
    }

    // Test move constructor and assignment operators on
    // convertible pointer types.
    {
        SuperNodeRefPtr subNode = SuperNode::New();
        SuperNode* subNodePtr = get_pointer(subNode);
        TF_AXIOM(subNode);

        NodeRefPtr baseNode(std::move(subNode));
        TF_AXIOM(baseNode);
        TF_AXIOM(get_pointer(baseNode) == subNodePtr);
        TF_AXIOM(!subNode);

        subNode = SuperNode::New();
        subNodePtr = get_pointer(subNode);
        TF_AXIOM(subNode);

        baseNode = std::move(subNode);
        TF_AXIOM(baseNode);
        TF_AXIOM(get_pointer(baseNode) == subNodePtr);
        TF_AXIOM(!subNode);
    }

    return true;
}