Beispiel #1
0
void compare_section_start(struct test *test,
    scanstate *cmpscan, int fd,
    const char *sectionname)
{
    // rewind the file
    if(lseek(fd, 0, SEEK_SET) < 0) {
        test_abort(test, "compare_section_start lseek compare: %s\n",
            strerror(errno));
    }

    scanstate_reset(cmpscan);
    readfd_attach(cmpscan, fd);
    compare_attach(cmpscan);

    // we may want to check the token to see if there are any
    // special requests (like detabbing).
}
Beispiel #2
0
scanstate* readfd_open(const char *path, size_t bufsiz)
{
    scanstate *ss;
    int fd;

    fd = open(path, O_RDONLY);
    if(fd < 0) {
        return NULL;
    }

    ss = dynscan_create(bufsiz);
    if(!ss) {
        close(fd);
        return NULL;
    }

    return readfd_attach(ss, fd);
}
Beispiel #3
0
scanstate* readfd_open(const char *path, size_t bufsiz)
{
    scanstate *ss;
    int fd;

	// _open() is marked as deprecated due to security concerns; however,
	// using the suggested function, _sopen_s(), is overkill for my needs here.
	// Thus, I suppress the deprecation warning for this statement only.
#pragma warning(suppress: 4996)
    fd = _open(path, O_RDONLY);
    if(fd < 0) {
        return NULL;
    }

    ss = dynscan_create(bufsiz);
    if(!ss) {
        _close(fd);
        return NULL;
    }

    return readfd_attach(ss, fd);
}
Beispiel #4
0
void scan_status_file(struct test *test)
{
    char lastfile[PATH_MAX];
    int lastfile_good = 0;
    char buf[BUFSIZ];
    scanstate ss;
    int tok;
    int state = 0;

    // first rewind the status file
    if(lseek(test->statusfd, 0, SEEK_SET) < 0) {
        test_abort(test, "read_file lseek on status file: %s\n",
            strerror(errno));
    }

    // then create our scanner
    scanstate_init(&ss, buf, sizeof(buf));
    readfd_attach(&ss, test->statusfd);
    stscan_attach(&ss);

    // now, if we see the token "CBRUNNING" in the token stream,
    // it means that we attempted to start the test.  If not,
    // then the test bailed early.
    do {
        tok = scan_next_token(&ss);

        // look for errors...
        if(tok < 0) {
            test_abort(test, "Error %d pulling status tokens: %s\n",
                tok, strerror(errno));
        } else if(tok == stGARBAGE) {
            fprintf(stderr, "Garbage on line %d in the status file: '%.*s'\n",
                    ss.line, (int)token_length(&ss)-1, token_start(&ss));
        } else {
            state = tok;
        }

        switch(tok) {
            case stSTART:
                // nothing to do
                break;

            case stCONFIG:
                if(test->status == test_pending) {
                    test->num_config_files += 1;
                    if(copy_status_arg(token_start(&ss), token_end(&ss), lastfile, sizeof(lastfile))) {
                        lastfile_good = 1;
                    } else {
                        fprintf(stderr, "CONFIG needs arg on line %d of the status file: '%.*s'\n",
                                ss.line, (int)token_length(&ss)-1, token_start(&ss));
                    }
                } else {
                    fprintf(stderr, "CONFIG but status (%d) wasn't pending on line %d of the status file: '%.*s'\n",
                            test->status, ss.line, (int)token_length(&ss)-1, token_start(&ss));
                }
                break;

            case stPREPARE:
                // nothing to do
                break;

            case stRUNNING:
                if(test->status == test_pending) {
                    test->status = test_was_started;
                    if(strlen(test->testfile) < sizeof(lastfile)) {
                        strcpy(lastfile, test->testfile);
                        lastfile_good = 1;
                    } else {
                        fprintf(stderr, "RUNNING lastfile is not big enough for %s", test->testfile);
                    }
                } else {
                    fprintf(stderr, "RUNNING but status (%d) wasn't pending on line %d of the status file: '%.*s'\n",
                            test->status, ss.line, (int)token_length(&ss)-1, token_start(&ss));
                }
                break;

            case stDONE:
                if(test->status == test_was_started) {
                    test->status = test_was_completed;
                } else {
                    fprintf(stderr, "DONE but status (%d) wasn't RUNNING on line %d of the status file: '%.*s'\n",
                            test->status, ss.line, (int)token_length(&ss)-1, token_start(&ss));
                }
                break;

            case stABORTED:
                test->status = (test->status >= test_was_started ? test_was_aborted : config_was_aborted);
                test->status_reason = dup_status_arg(token_start(&ss), token_end(&ss));
                break;

            case stDISABLED:
                test->status = (test->status >= test_was_started ? test_was_disabled : config_was_disabled);
                test->status_reason = dup_status_arg(token_start(&ss), token_end(&ss));
                break;

            default:
                fprintf(stderr, "Unknown token (%d) on line %d of the status file: '%.*s'\n",
                        tok, ss.line, (int)token_length(&ss)-1, token_start(&ss));
        }
    } while(!scan_is_finished(&ss));

    if(lastfile_good) {
        test->last_file_processed = strdup(lastfile);
    }
}