コード例 #1
0
ファイル: testenv.c プロジェクト: randombit/hacrypto
int
tests_begin(int argc, char * const *argv)
{
    const char *testcase = NULL;
    bool initialized = false;
    int verbose=0;
    int testix = -1;
	int ch;
    int retval;
    char *seed=NULL;
    for (;;) {
        while (!testcase && (ch = getopt(argc, argv, "vws:")) != -1)
        {
            switch  (ch)
            {
            case 's':
                seed = optarg;
                break;
            case 'w':
                sleep(100);
                break;
            case 'v':
                verbose=1;
                break;
            case '?':
            default:
                printf("invalid option %c\n",ch); 
                usage(argv[0]);
            }
        }

        if (optind < argc) {
            testix = tests_named_index(argv[optind]);
            if(testix<0) {
                printf("invalid test %s\n",argv[optind]); 
                usage(argv[0]);
            }
            argc -= optind;
            argv += optind;
        }

        if (testix < 0) {
            if (!initialized) {
                //initialized = true;
                if (tests_init(seed)!=0) return -1;
                tests_run_all(argc, argv);
            }
            break;
        } else {
            if (!initialized) {
                if (tests_init(seed)!=0) return -1;
                initialized = true;
            }
            tests_run_index(testix, argc, argv);
            testix = -1;
        }
    }

    retval=tests_summary(verbose);

    /* Cleanups */
    tests_end();
    
    return retval;
}
コード例 #2
0
int
tests_begin(int argc, char * const *argv)
{
    const char *testcase = NULL;
    bool initialized = false;
    bool print_security_logs = false;
    int testix = -1;
    int failcount = 0;
	int ch;
    int loop = 0;
    int list = 0;

    // TODO Currently our callers do this, but we can move this here together with the build date info.
    const char *progname = strrchr(argv[0], '/');
    progname = progname ? progname + 1 : argv[0];

    for (;;) {
        while (!testcase && (ch = getopt(argc, argv, "bklL1vwqs")) != -1)
        {
            switch  (ch)
            {
#ifdef NO_SERVER
            case 'k':
                keep_scratch_dir = true;
                break;
#endif
            case 's':
                print_security_logs = true;
                break;

            case 'b':
                test_strict_bats = 0;
                break;

            case 'v':
                test_verbose++;
                break;

            case 'w':
                sleep(100);
                break;
            case 'l':
                loop=1;
                break;
            case 'L':
                list=1;
                break;
            case '1':
                test_onebatstest=1;
                break;
            case '?':
            default:
                printf("invalid option %c\n",ch); 
                usage(argv[0]);
            }
        }

        if (optind < argc) {
            testix = tests_named_index(argv[optind]);
            if(testix<0) {
                printf("invalid test %s\n",argv[optind]); 
                usage(argv[0]);
            }
        }

        if (print_security_logs) {
            add_security_log_handler(^(int level, CFStringRef scope, const char *function, const char *file, int line, CFStringRef message) {
                time_t now = time(NULL);
                char *date = ctime(&now);
                date[19] = '\0';
                CFStringRef logStr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
                                                              CFSTR("%s %@ %s %@\n"), date + 4,
                                                              scope ? scope : CFSTR(""), function, message);
                CFShow(logStr);
                CFReleaseSafe(logStr);
            });
        }

        if (!list && !initialized && !test_onebatstest)
            fprintf(stdout, "[TEST] %s\n", progname);
        if (testix < 0) {
            if (!initialized) {
                tests_init();
                initialized = true;
                (void)initialized;
                if (!list)
                    failcount+=tests_run_all(argc, argv);
            }
            break;
        } else {
            if (!initialized) {
                tests_init();
                initialized = true;
                for (int i = 0; testlist[i].name; ++i) {
                    testlist[i].off = 1;
                }
            }
            optind++;
            testlist[testix].off = 0;
            if (!list)
                failcount+=tests_run_index(testix, argc, argv);
            testix = -1;
        }
    }