Esempio n. 1
0
bool
atf_check::run_status_check(const atf::check::check_result &r)
    const
{
    int status = r.status();
    bool retval = true;

    if (m_status_check == sc_equal) {
        if (m_status_arg != status) {
            std::cerr << "Fail: incorrect exit status: "
                      << status << ", expected: "
                      << m_status_arg << std::endl;
            retval = false;
        }
    } else if (m_status_check == sc_not_equal) {
        if (m_status_arg == status) {
            std::cerr << "Fail: incorrect exit status: "
                      << status << ", expected: "
                      << "anything other" << std::endl;
            retval = false;
        }
    }

    if (retval == false) {
        std::cerr << "stdout:" << std::endl;
        print_file(r.stdout_path());
        std::cerr << std::endl;

        std::cerr << "stderr:" << std::endl;
        print_file(r.stderr_path());
        std::cerr << std::endl;
    }

    return retval;
}
Esempio n. 2
0
bool
atf_check::run_output_check(const atf::check::check_result &r,
                            const std::string &stdxxx)
    const
{
    atf::fs::path path("/");
    std::string arg;
    output_check_t check = m_stdout_check;

    if (stdxxx == "stdout") {
        path = r.stdout_path();
        arg = m_stdout_arg.c_str();
        check = m_stdout_check;
    } else if (stdxxx == "stderr") {
        path = r.stderr_path();
        arg = m_stderr_arg.c_str();
        check = m_stderr_check;
    } else
        UNREACHABLE;

    if (check == oc_empty) {
        if (!file_empty(path)) {
            std::cerr << "Fail: incorrect " << stdxxx << std::endl;
            print_diff(atf::fs::path("/dev/null"), path);

            return false;
        }
    } else if (check == oc_file) {
        if (atf::io::cmp(path, atf::fs::path(arg)) != 0) {
            std::cerr << "Fail: incorrect " << stdxxx << std::endl;
            print_diff(atf::fs::path(arg), path);

            return false;
        }
    } else if (check == oc_inline) {
        std::string decoded = decode(arg);
        atf::fs::path path2 = atf::fs::path(atf::config::get("atf_workdir")) \
                              / "inline.XXXXXX";
        atf::fs::temp_file temp(path2);
        temp.write(decoded);

        if (atf::io::cmp(path, temp.get_path()) != 0) {
            std::cerr << "Fail: incorrect " << stdxxx << std::endl;
            print_diff(temp.get_path(), path);

            return false;
        }
    } else if (check == oc_save) {
        std::ifstream ifs(path.c_str(), std::fstream::binary);
        ifs >> std::noskipws;
        std::istream_iterator< char > begin(ifs), end;

        std::ofstream ofs(arg.c_str(), std::fstream::binary
                                     | std::fstream::trunc);
        std::ostream_iterator <char> obegin(ofs);

        std::copy(begin, end, obegin);
    }
Esempio n. 3
0
static
bool
run_status_check(const status_check& sc, const atf::check::check_result& cr)
{
    bool result;

    if (sc.type == sc_exit) {
        if (cr.exited() && sc.value != INT_MIN) {
            const int status = cr.exitcode();

            if (!sc.negated && sc.value != status) {
                std::cerr << "Fail: incorrect exit status: "
                          << status << ", expected: "
                          << sc.value << "\n";
                result = false;
            } else if (sc.negated && sc.value == status) {
                std::cerr << "Fail: incorrect exit status: "
                          << status << ", expected: "
                          << "anything else\n";
                result = false;
            } else
                result = true;
        } else if (cr.exited() && sc.value == INT_MIN) {
            result = true;
        } else {
            std::cerr << "Fail: program did not exit cleanly\n";
            result = false;
        }
    } else if (sc.type == sc_ignore) {
        result = true;
    } else if (sc.type == sc_signal) {
        if (cr.signaled() && sc.value != INT_MIN) {
            const int status = cr.termsig();

            if (!sc.negated && sc.value != status) {
                std::cerr << "Fail: incorrect signal received: "
                          << status << ", expected: " << sc.value << "\n";
                result = false;
            } else if (sc.negated && sc.value == status) {
                std::cerr << "Fail: incorrect signal received: "
                          << status << ", expected: "
                          << "anything else\n";
                result = false;
            } else
                result = true;
        } else if (cr.signaled() && sc.value == INT_MIN) {
            result = true;
        } else {
            std::cerr << "Fail: program did not receive a signal\n";
            result = false;
        }
    } else {
        UNREACHABLE;
        result = false;
    }

    if (result == false) {
        std::cerr << "stdout:\n";
        cat_file(atf::fs::path(cr.stdout_path()));
        std::cerr << "\n";

        std::cerr << "stderr:\n";
        cat_file(atf::fs::path(cr.stderr_path()));
        std::cerr << "\n";
    }

    return result;
}