Exemplo n.º 1
0
bool
build_check_cxx_o_srcdir(const atf::tests::tc& tc, const char* sfile)
{
    const atf::fs::path sfilepath =
        atf::fs::path(tc.get_config_var("srcdir")) / sfile;
    return build_check_cxx_o(sfilepath.c_str());
}
Exemplo n.º 2
0
static
void
print_diff(const atf::fs::path& p1, const atf::fs::path& p2)
{
    const atf::process::status s =
        atf::process::exec(atf::fs::path("diff"),
                           atf::process::argv_array("diff", "-u", p1.c_str(),
                                                    p2.c_str(), NULL),
                           atf::process::stream_connect(STDOUT_FILENO,
                                                        STDERR_FILENO),
                           atf::process::stream_inherit());

    if (!s.exited())
        std::cerr << "Failed to run diff(3)\n";

    if (s.exitstatus() != 1)
        std::cerr << "Error while running diff(3)\n";
}
Exemplo n.º 3
0
void
atf_check::print_file(const atf::fs::path &p)
    const
{
    std::ifstream f(p.c_str());
    f >> std::noskipws;
    std::istream_iterator< char > begin(f), end;
    std::ostream_iterator< char > out(std::cerr);
    std::copy(begin, end, out);
}
Exemplo n.º 4
0
impl::temp_dir::temp_dir(const atf::fs::path& p)
{
    atf::auto_array< char > buf(new char[p.str().length() + 1]);
    std::strcpy(buf.get(), p.c_str());
    if (::mkdtemp(buf.get()) == NULL)
        throw system_error(IMPL_NAME "::temp_dir::temp_dir(" +
                           p.str() + ")", "mkdtemp(3) failed",
                           errno);

    m_path.reset(new atf::fs::path(buf.get()));
}
Exemplo n.º 5
0
static bool
compare_files(const atf::fs::path& p1, const atf::fs::path& p2)
{
    bool equal = false;

    std::ifstream f1(p1.c_str());
    if (!f1)
        throw std::runtime_error("Failed to open " + p1.str());

    std::ifstream f2(p2.c_str());
    if (!f2)
        throw std::runtime_error("Failed to open " + p1.str());

    for (;;) {
        char buf1[512], buf2[512];

        f1.read(buf1, sizeof(buf1));
        if (f1.bad())
            throw std::runtime_error("Failed to read from " + p1.str());

        f2.read(buf2, sizeof(buf2));
        if (f2.bad())
            throw std::runtime_error("Failed to read from " + p1.str());

        std::cout << "1 read: " << f1.gcount() << "\n";
        std::cout << "2 read: " << f2.gcount() << "\n";
        if ((f1.gcount() == 0) && (f2.gcount() == 0)) {
            equal = true;
            break;
        }

        if ((f1.gcount() != f2.gcount()) ||
            (std::memcmp(buf1, buf2, f1.gcount()) != 0)) {
            break;
        }
    }

    return equal;
}
Exemplo n.º 6
0
atf::fs::path
impl::change_directory(const atf::fs::path& dir)
{
    atf::fs::path olddir = get_current_dir();

    if (olddir != dir) {
        if (::chdir(dir.c_str()) == -1)
            throw system_error(IMPL_NAME "::chdir(" + dir.str() + ")",
                               "chdir(2) failed", errno);
    }

    return olddir;
}
Exemplo n.º 7
0
static
void
cat_file(const atf::fs::path& path)
{
    std::ifstream stream(path.c_str());
    if (!stream)
        throw std::runtime_error("Failed to open " + path.str());

    stream >> std::noskipws;
    std::istream_iterator< char > begin(stream), end;
    std::ostream_iterator< char > out(std::cerr);
    std::copy(begin, end, out);

    stream.close();
}
Exemplo n.º 8
0
static
void
cleanup_aux_dir(const atf::fs::path& p, const atf::fs::file_info& fi,
                bool erase)
{
    if (erase && ((fi.get_mode() & S_IRWXU) != S_IRWXU)) {
        int retries = max_retries;
retry_chmod:
        if (chmod(p.c_str(), fi.get_mode() | S_IRWXU) == -1) {
            if (retries > 0) {
                retries--;
                ::sleep(retry_delay_in_seconds);
                goto retry_chmod;
            } else {
                throw atf::system_error(IMPL_NAME "::cleanup(" +
                                        p.str() + ")", "chmod(2) failed",
                                        errno);
            }
        }
    }

    std::set< std::string > subdirs;
    {
        bool ok = false;
        int retries = max_retries;
        while (!ok) {
            INV(retries > 0);
            try {
                const atf::fs::directory d(p);
                subdirs = d.names();
                ok = true;
            } catch (const atf::system_error& e) {
                retries--;
                if (retries == 0)
                    throw e;
                ::sleep(retry_delay_in_seconds);
            }
        }
        INV(ok);
    }

    for (std::set< std::string >::const_iterator iter = subdirs.begin();
         iter != subdirs.end(); iter++) {
        const std::string& name = *iter;
        if (name != "." && name != "..")
            cleanup_aux(p / name, fi.get_device(), erase);
    }
}
Exemplo n.º 9
0
impl::test_case_result
impl::read_test_case_result(const atf::fs::path& results_path)
{
    std::ifstream results_file(results_path.c_str());
    if (!results_file)
        throw std::runtime_error("Failed to open " + results_path.str());

    std::string line, extra_line;
    std::getline(results_file, line);
    if (!results_file.good())
        throw std::runtime_error("Results file is empty");

    while (std::getline(results_file, extra_line).good())
        line += "<<NEWLINE UNEXPECTED>>" + extra_line;

    results_file.close();

    return detail::parse_test_case_result(line);
}
Exemplo n.º 10
0
static
bool
grep_file(const atf::fs::path& path, const std::string& regexp)
{
    std::ifstream stream(path.c_str());
    if (!stream)
        throw std::runtime_error("Failed to open " + path.str());

    bool found = false;

    std::string line;
    while (!found && std::getline(stream, line).good()) {
        if (atf::text::match(line, regexp))
            found = true;
    }

    stream.close();

    return found;
}
Exemplo n.º 11
0
static
bool
run_output_check(const output_check oc, const atf::fs::path& path,
                 const std::string& stdxxx)
{
    bool result;

    if (oc.type == oc_empty) {
        const bool is_empty = file_empty(path);
        if (!oc.negated && !is_empty) {
            std::cerr << "Fail: " << stdxxx << " not empty\n";
            print_diff(atf::fs::path("/dev/null"), path);
            result = false;
        } else if (oc.negated && is_empty) {
            std::cerr << "Fail: " << stdxxx << " is empty\n";
            result = false;
        } else
            result = true;
    } else if (oc.type == oc_file) {
        const bool equals = compare_files(path, atf::fs::path(oc.value));
        if (!oc.negated && !equals) {
            std::cerr << "Fail: " << stdxxx << " does not match golden "
                "output\n";
            print_diff(atf::fs::path(oc.value), path);
            result = false;
        } else if (oc.negated && equals) {
            std::cerr << "Fail: " << stdxxx << " matches golden output\n";
            cat_file(atf::fs::path(oc.value));
            result = false;
        } else
            result = true;
    } else if (oc.type == oc_ignore) {
        result = true;
    } else if (oc.type == oc_inline) {
        atf::fs::path path2 = atf::fs::path(atf::config::get("atf_workdir"))
                              / "inline.XXXXXX";
        temp_file temp(path2);
        temp.write(decode(oc.value));
        temp.close();

        const bool equals = compare_files(path, temp.get_path());
        if (!oc.negated && !equals) {
            std::cerr << "Fail: " << stdxxx << " does not match expected "
                "value\n";
            print_diff(temp.get_path(), path);
            result = false;
        } else if (oc.negated && equals) {
            std::cerr << "Fail: " << stdxxx << " matches expected value\n";
            cat_file(temp.get_path());
            result = false;
        } else
            result = true;
    } else if (oc.type == oc_match) {
        const bool matches = grep_file(path, oc.value);
        if (!oc.negated && !matches) {
            std::cerr << "Fail: regexp " + oc.value + " not in " << stdxxx
                      << "\n";
            cat_file(path);
            result = false;
        } else if (oc.negated && matches) {
            std::cerr << "Fail: regexp " + oc.value + " is in " << stdxxx
                      << "\n";
            cat_file(path);
            result = false;
        } else
            result = true;
    } else if (oc.type == oc_save) {
        INV(!oc.negated);
        std::ifstream ifs(path.c_str(), std::fstream::binary);
        ifs >> std::noskipws;
        std::istream_iterator< char > begin(ifs), end;

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

        std::copy(begin, end, obegin);
        result = true;
    } else {