Пример #1
0
MAIN(httpMain, int argc, char *argv[])
{
    MprTime     start;
    double      elapsed;

    if (mprCreate(argc, argv, MPR_USER_EVENTS_THREAD) == 0) {
        return MPR_ERR_MEMORY;
    }
    if ((app = mprAllocObj(App, manageApp)) == 0) {
        return MPR_ERR_MEMORY;
    }
    mprAddRoot(app);
    mprAddStandardSignals();

    initSettings();
    if (!parseArgs(argc, argv)) {
        showUsage();
        return MPR_ERR_BAD_ARGS;
    }
    mprSetMaxWorkers(app->workers);

#if BLD_FEATURE_SSL
    if (!mprLoadSsl(1)) {
        mprError("Can't load SSL");
        exit(1);
    }
#endif
    if (mprStart() < 0) {
        mprError("Can't start MPR for %s", mprGetAppTitle());
        exit(2);
    }
    start = mprGetTime();
    app->http = httpCreate();
    httpEaseLimits(app->http->clientLimits);

    processing();
    mprServiceEvents(-1, 0);

    if (app->benchmark) {
        elapsed = (double) (mprGetTime() - start);
        if (app->fetchCount == 0) {
            elapsed = 0;
            app->fetchCount = 1;
        }
        mprPrintf("\nRequest Count:       %13d\n", app->fetchCount);
        mprPrintf("Time elapsed:        %13.4f sec\n", elapsed / 1000.0);
        mprPrintf("Time per request:    %13.4f sec\n", elapsed / 1000.0 / app->fetchCount);
        mprPrintf("Requests per second: %13.4f\n", app->fetchCount * 1.0 / (elapsed / 1000.0));
        mprPrintf("Load threads:        %13d\n", app->loadThreads);
        mprPrintf("Worker threads:      %13d\n", app->workers);
    }
    if (!app->success && app->verbose) {
        mprError("Request failed");
    }
    return (app->success) ? 0 : 255;
}
Пример #2
0
MAIN(testMain, int argc, char *argv[]) 
{
    Mpr             *mpr;
    MprTestService  *ts;
    MprTestGroup    *gp;
    int             rc;

    mpr = mprCreate(argc, argv, 0);

#if VXWORKS || WINCE
    /*
     *  These platforms pass an arg string in via the argc value. Assumes 32-bit.
     */
    mprMakeArgv(mpr, "testMpr", (char*) argc, &argc, &argv);
#endif

    ts = mprCreateTestService(mpr);
    if (ts == 0) {
        mprError(mpr, "Can't create test service");
        exit(2);
    }
    
    if (mprParseTestArgs(ts, argc, argv) < 0) {
        mprFree(mpr);
        exit(3);
    }
    
    gp = mprAddTestGroup(ts, &master);
    if (gp == 0) {
        exit(4);
    }

#if BLD_FEATURE_SSL && (BLD_FEATURE_MATRIXSSL || BLD_FEATURE_OPENSSL)
    if (!mprLoadSsl(mpr, 0)) {
        exit(5);
    }
#endif

    /*
     *  Need a background event thread as we use the main thread to run the tests.
     */
    if (mprStart(mpr, 0)) {
        mprError(mpr, "Can't start mpr services");
        exit(4);
    }

    /*
     *  Run the tests and return zero if 100% success
     */
    rc = mprRunTests(ts);
    mprReportTestResults(ts);

    return (rc == 0) ? 0 : 6;
}
Пример #3
0
int main(int argc, char *argv[]) 
{
    Mpr             *mpr;
    int             rc;

    mpr = mprCreate(argc, argv, MPR_USER_EVENTS_THREAD);
    mprAddStandardSignals();

    app = mprAllocObj(App, manageApp);
    mprAddRoot(app);

    app->host = sclone("127.0.0.1");
    app->port = 4100;

    if ((ts = mprCreateTestService(mpr)) == 0) {
        mprLog("appweb test", 0, "Cannot create test service");
        exit(2);
    }
    if (mprParseTestArgs(ts, argc, argv, parseArgs) < 0) {
        mprEprintf("\n"
            "  Commands specifically for %s\n"
            "    --host ip:port      # Set the default host address for testing\n\n",
            mprGetAppName(mpr));
        exit(3);
    }
    if (mprAddTestGroup(ts, &master) == 0) {
        exit(4);
    }

#if BIT_PACK_SSL
    if (mprLoadSsl(0) < 0) {
        return 0;
    }
#endif
    /*
        Need a background event thread as we use the main thread to run the tests.
     */
    if (mprStart(mpr)) {
        mprLog("appweb test", 0, "Cannot start mpr services");
        exit(5);
    }
    /*
        Run the tests and return zero if 100% success
     */
    rc = mprRunTests(ts);
    mprReportTestResults(ts);
    mprDestroy();
    return (rc == 0) ? 0 : -1;
}
Пример #4
0
MAIN(httpMain, int argc, char *argv[])
{
    MprTime         start;
    double          elapsed;

    /*
     *  Explicit initialization of globals for re-entrancy on Vxworks
     */
    activeLoadThreads = benchmark = continueOnErrors = fetchCount = iterations = isBinary = httpVersion = 0;
    success = loadThreads = nextArg = noout = nofollow = showHeaders = printable = workers = 0;
    retries = singleStep = timeout = verbose = 0;

    chunkSize = host = method = password = ranges = 0;
    username = 0;
    mpr = 0;
    headers = 0;
    formData = 0;

    mpr = mprCreate(argc, argv, NULL);

    initSettings(mpr);
    if (!parseArgs(mpr, argc, argv)) {
        showUsage(mpr);
        return MPR_ERR_BAD_ARGS;
    }
#if BLD_FEATURE_MULTITHREAD
    mprSetMaxWorkers(mpr, workers);
#endif

#if BLD_FEATURE_SSL
    if (!mprLoadSsl(mpr, 1)) {
        mprError(mpr, "Can't load SSL");
        exit(1);
    }
#endif

    /*
     *  Start the Timer, Socket and Worker services
     */
    if (mprStart(mpr, 0) < 0) {
        mprError(mpr, "Can't start MPR for %s", mprGetAppTitle(mpr));
        exit(2);
    }
    start = mprGetTime(mpr);
    processing();

    /*
     *  Wait for all the threads to complete (simple but effective). Keep servicing events as we wind down.
     */
    while (activeLoadThreads > 0) {
        mprServiceEvents(mprGetDispatcher(mpr), 250, MPR_SERVICE_EVENTS | MPR_SERVICE_IO);
    }
    if (benchmark) {
        elapsed = (double) (mprGetTime(mpr) - start);
        if (fetchCount == 0) {
            elapsed = 0;
            fetchCount = 1;
        }
        mprPrintf(mpr, "\nRequest Count:       %13d\n", fetchCount);
        mprPrintf(mpr, "Time elapsed:        %13.4f sec\n", elapsed / 1000.0);
        mprPrintf(mpr, "Time per request:    %13.4f sec\n", elapsed / 1000.0 / fetchCount);
        mprPrintf(mpr, "Requests per second: %13.4f\n", fetchCount * 1.0 / (elapsed / 1000.0));
        mprPrintf(mpr, "Load threads:        %13d\n", loadThreads);
        mprPrintf(mpr, "Worker threads:      %13d\n", workers);
    }
    if (!success && verbose) {
        mprError(mpr, "Request failed");
    }
    return (success) ? 0 : 255;
}