utils.c revision a747113422afaa29ce72d2c5ba7f0b7ea9ec2054
/*
* Automated Testing Framework (atf)
*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
/** Searches for a regexp in a string.
*
* \param regex The regexp to look for.
* \param str The string in which to look for the expression.
*
* \return True if there is a match; false otherwise. */
static
bool
{
int res;
return res == 0;
}
/** Prints the contents of a file to stdout.
*
* \param name The name of the file to be printed.
* \param prefix An string to be prepended to every line of the printed
* file. */
void
{
char buffer[1024];
bool continued = false;
if (!continued)
char *end;
*end = '\0';
else
continued = false;
}
continued = true;
}
}
ATF_REQUIRE(count == 0);
}
/** Compares a file against the given golden contents.
*
* \param name Name of the file to be compared.
* \param contents Expected contents of the file.
*
* \return True if the file matches the contents; false otherwise. */
bool
{
char buffer[1024];
return false;
}
}
}
/** Copies a file.
*
* \param source Path to the source file.
* \param destination Path to the destination file. */
void
{
"copy (%s)", source);
"copy (%s)", destination);
char buffer[1024];
"Failed to write to %s during copy", destination);
"Failed to stat source file %s during copy", source);
"Failed to chmod destination file %s during copy",
}
/** Creates a file.
*
* \param name Name of the file to create.
* \param contents Text to write into the created file.
* \param ... Positional parameters to the contents. */
void
{
}
/** Checks if a file exists.
*
* \param path Location of the file to check for.
*
* \return True if the file exists, false otherwise. */
bool
atf_utils_file_exists(const char *path)
{
if (ret == -1) {
else
return false;
} else
return true;
}
/** Spawns a subprocess and redirects its output to files.
*
* Use the atf_utils_wait() function to wait for the completion of the spawned
* subprocess and validate its exit conditions.
*
* \return 0 in the new child; the PID of the new child in the parent. Does
* not return in error conditions. */
atf_utils_fork(void)
{
if (pid == -1)
atf_tc_fail("fork failed");
if (pid == 0) {
}
return pid;
}
/** Frees an dynamically-allocated "argv" array.
*
* \param argv A dynamically-allocated array of dynamically-allocated
* strings. */
void
atf_utils_free_charpp(char **argv)
{
char **ptr;
}
/** Searches for a regexp in a file.
*
* \param regex The regexp to look for.
* \param file The file in which to look for the expression.
* \param ... Positional parameters to the regex.
*
* \return True if there is a match; false otherwise. */
bool
{
int fd;
bool found = false;
}
return found;
}
/** Searches for a regexp in a string.
*
* \param regex The regexp to look for.
* \param str The string in which to look for the expression.
* \param ... Positional parameters to the regex.
*
* \return True if there is a match; false otherwise. */
bool
{
bool res;
return res;
}
/** Reads a line of arbitrary length.
*
* \param fd The descriptor from which to read the line.
*
* \return A pointer to the read line, which must be released with free(), or
* NULL if there was nothing to read from the file. */
char *
atf_utils_readline(const int fd)
{
char ch;
ch != '\n') {
}
return NULL;
} else
return atf_dynstr_fini_disown(&temp);
}
/** Redirects a file descriptor to a file.
*
* \param target_fd The file descriptor to be replaced.
* \param name The name of the file to direct the descriptor to.
*
* \pre Should only be called from the process spawned by fork_for_testing
* because this exits uncontrolledly.
* \post Terminates execution if the redirection fails. */
void
{
if (target_fd == STDOUT_FILENO)
else if (target_fd == STDERR_FILENO)
if (new_fd == -1)
}
}
/** Waits for a subprocess and validates its exit condition.
*
* \param pid The process to be waited for. Must have been started by
* testutils_fork().
* \param exitstatus Expected exit status.
* \param expout Expected contents of stdout.
* \param experr Expected contents of stderr. */
void
const char *experr)
{
int status;
const char *save_prefix = "save:";
} else {
}
} else {
}
}