diff options
author | marcel <marcel@FreeBSD.org> | 2012-09-04 23:16:58 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2012-09-04 23:16:58 +0000 |
commit | aeee2a3118be30ab45d435a42acb987b0552d3d9 (patch) | |
tree | 23437e9f1b950834a802cff34de365b7d2e0b50c /contrib/atf/atf-config | |
parent | f2d384bbd0df5897a4b1f48f872d443dc077957c (diff) | |
parent | 45147a9eddaeb6ce9ca99161e2cd60a912c72e86 (diff) | |
download | FreeBSD-src-aeee2a3118be30ab45d435a42acb987b0552d3d9.zip FreeBSD-src-aeee2a3118be30ab45d435a42acb987b0552d3d9.tar.gz |
Merge ATF 0.16 from vendor/atf/dist.
Provenance: http://code.google.com/p/kyua
Discussed with: gibbs, gnn, keramida, mdf, mlaier,
Discussed with: Garrett Cooper
Diffstat (limited to 'contrib/atf/atf-config')
-rw-r--r-- | contrib/atf/atf-config/Atffile | 5 | ||||
-rw-r--r-- | contrib/atf/atf-config/Kyuafile | 5 | ||||
-rw-r--r-- | contrib/atf/atf-config/Makefile.am.inc | 48 | ||||
-rw-r--r-- | contrib/atf/atf-config/atf-config.1 | 184 | ||||
-rw-r--r-- | contrib/atf/atf-config/atf-config.cpp | 145 | ||||
-rw-r--r-- | contrib/atf/atf-config/integration_test.sh | 180 |
6 files changed, 567 insertions, 0 deletions
diff --git a/contrib/atf/atf-config/Atffile b/contrib/atf/atf-config/Atffile new file mode 100644 index 0000000..146211e --- /dev/null +++ b/contrib/atf/atf-config/Atffile @@ -0,0 +1,5 @@ +Content-Type: application/X-atf-atffile; version="1" + +prop: test-suite = atf + +tp-glob: *_test diff --git a/contrib/atf/atf-config/Kyuafile b/contrib/atf/atf-config/Kyuafile new file mode 100644 index 0000000..8ba4da8 --- /dev/null +++ b/contrib/atf/atf-config/Kyuafile @@ -0,0 +1,5 @@ +syntax("kyuafile", 1) + +test_suite("atf") + +atf_test_program{name="integration_test"} diff --git a/contrib/atf/atf-config/Makefile.am.inc b/contrib/atf/atf-config/Makefile.am.inc new file mode 100644 index 0000000..0f32778 --- /dev/null +++ b/contrib/atf/atf-config/Makefile.am.inc @@ -0,0 +1,48 @@ +# +# Automated Testing Framework (atf) +# +# Copyright (c) 2007 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 +# documentation and/or other materials provided with the distribution. +# +# 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. +# + +bin_PROGRAMS += atf-config/atf-config +atf_config_atf_config_SOURCES = atf-config/atf-config.cpp +atf_config_atf_config_LDADD = $(ATF_CXX_LIBS) +dist_man_MANS += atf-config/atf-config.1 + +tests_atf_config_DATA = atf-config/Atffile \ + atf-config/Kyuafile +tests_atf_configdir = $(pkgtestsdir)/atf-config +EXTRA_DIST += $(tests_atf_config_DATA) + +tests_atf_config_SCRIPTS = atf-config/integration_test +CLEANFILES += atf-config/integration_test +EXTRA_DIST += atf-config/integration_test.sh +atf-config/integration_test: $(srcdir)/atf-config/integration_test.sh + test -d atf-config || mkdir -p atf-config + @src="$(srcdir)/atf-config/integration_test.sh"; \ + dst="atf-config/integration_test"; $(BUILD_SH_TP) + +# vim: syntax=make:noexpandtab:shiftwidth=8:softtabstop=8 diff --git a/contrib/atf/atf-config/atf-config.1 b/contrib/atf/atf-config/atf-config.1 new file mode 100644 index 0000000..deae6f6 --- /dev/null +++ b/contrib/atf/atf-config/atf-config.1 @@ -0,0 +1,184 @@ +.\" +.\" Automated Testing Framework (atf) +.\" +.\" Copyright (c) 2007 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 +.\" documentation and/or other materials provided with the distribution. +.\" +.\" 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. +.\" +.Dd March 14, 2009 +.Dt ATF-CONFIG 1 +.Os +.Sh NAME +.Nm atf-config +.Nd queries static configuration information of ATF +.Sh SYNOPSIS +.Nm +.Op Fl t +.Op Ar var1 Op Ar .. varN +.Nm +.Fl h +.Sh DESCRIPTION +.Nm +is a utility that queries static configuration information of ATF. +Static configuration refers to all those values for settings that +were built into the ATF binaries at build time. +.Pp +In the first synopsis form, +.Nm +will print variable-value pairs for all built-in static variables if +no variable names are provided as arguments. +If any is provided, it will only print the variable-value pairs for +those variables. +The output of the utility does not use the +.Sq = +symbol to separate the variable name from its corresponding value in +an attempt to avoid sourcing the output in shell scripts or Makefiles. +If you need to do that, the +.Fl t +flag allows you to query the value of individual variables without any +surrounding text. +.Pp +In the second synopsis form, +.Nm +will print information about all supported options and their purpose. +.Pp +The following options are available: +.Bl -tag -width flag +.It Fl h +Shows a short summary of all available options and their purpose. +.It Fl t +Changes the output of the utility to show the variable values, one +per line, without the variable names. +.El +.Ss Static configuration variables +The following list describes all the variables that are part of ATF's +static configuration: +.Bl -tag -width atfXbuildXcppflagsXX +.It Va atf_arch +The architecture name detected by ATF. +This is derived from +.Va atf_machine +because it is a subset of it. +Given that this name might be misdetected, it is provided to the user +as a configuration variable so that he can fix its value temporarily +until a real fix is incorporated into mainstream sources. +.It Va atf_build_cc +The C compiler used by the ATF checks that provide build-time tests. +.It Va atf_build_cflags +The C compiler flags used by the ATF checks that provide build-time tests. +.It Va atf_build_cpp +The C/C++ preprocessor used by the ATF checks that provide build-time tests. +.It Va atf_build_cppflags +The C/C++ preprocessor flags used by the ATF checks that provide build-time +tests. +.It Va atf_build_cxx +The C++ compiler used by the ATF checks that provide build-time tests. +.It Va atf_build_cxxflags +The C++ compiler flags used by the ATF checks that provide build-time tests. +.It Va atf_confdir +The path to the directory that contains the system-wide configuration +files for ATF. +.It Va atf_includedir +The path to the directory that contains the ATF header files. +.It Va atf_libdir +The path to the directory that contains the ATF libraries. +.It Va atf_libexecdir +The path to the directory that contains the auxiliary utilities of ATF, +used internally by the public tools. +.It Va atf_machine +The machine type name detected by ATF. +This should not be tunable but is provided for symmetry with +.Va atf_arch . +.It Va atf_pkgdatadir +The path to the directory that contains the files that form the ATF's +shell-scripting library. +.It Va atf_shell +The path to the shell interpreter that will be used by ATF. +.It Va atf_workdir +The path to the temporary directory that the utilities and the test +programs will use to store temporary files in. +.El +.Sh ENVIRONMENT +Every variable that is part of the static configuration can be +overridden at run-time by defining an environment variable. +This environment variable has the exact same name as the one shown by +.Nm +except that the name is all composed of uppercase letters. +.Pp +In general, empty values in the environment will be ignored unless +otherwise noted below. +.Pp +The recognized environment variables are: +.Bl -tag -width ATFXBUILDXCPPFLAGSXX +.It Ev ATF_ARCH +Overrides the built-in value of +.Va atf_arch . +.It Ev ATF_BUILD_CC +Overrides the built-in value of +.Va atf_build_cc . +.It Ev ATF_BUILD_CFLAGS +Overrides the built-in value of +.Va atf_build_cflags . +Empty values are allowed. +.It Ev ATF_BUILD_CPP +Overrides the built-in value of +.Va atf_build_cpp . +.It Ev ATF_BUILD_CPPFLAGS +Overrides the built-in value of +.Va atf_build_cppflags . +Empty values are allowed. +.It Ev ATF_BUILD_CXX +Overrides the built-in value of +.Va atf_build_cxx . +.It Ev ATF_BUILD_CXXFLAGS +Overrides the built-in value of +.Va atf_build_cxxflags . +Empty values are allowed. +.It Ev ATF_CONFDIR +Overrides the built-in value of +.Va atf_confdir . +.It Ev ATF_INCLUDEDIR +Overrides the built-in value of +.Va atf_includedir . +.It Ev ATF_LIBDIR +Overrides the built-in value of +.Va atf_libdir . +.It Ev ATF_LIBEXECDIR +Overrides the built-in value of +.Va atf_libexecdir . +.It Ev ATF_MACHINE +Overrides the built-in value of +.Va atf_machine . +.It Ev ATF_PKGDATADIR +Overrides the built-in value of +.Va atf_pkgdatadir . +.It Ev ATF_SHELL +Overrides the built-in value of +.Va atf_shell . +.It Ev ATF_WORKDIR +Overrides the built-in value of +.Va atf_workdir . +.El +.Sh SEE ALSO +.Xr atf 7 diff --git a/contrib/atf/atf-config/atf-config.cpp b/contrib/atf/atf-config/atf-config.cpp new file mode 100644 index 0000000..e5fdca1 --- /dev/null +++ b/contrib/atf/atf-config/atf-config.cpp @@ -0,0 +1,145 @@ +// +// Automated Testing Framework (atf) +// +// Copyright (c) 2007 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 +// documentation and/or other materials provided with the distribution. +// +// 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 <cstdlib> +#include <iostream> +#include <map> +#include <string> + +extern "C" { +#include "atf-c/defs.h" +} + +#include "atf-c++/config.hpp" + +#include "atf-c++/detail/application.hpp" +#include "atf-c++/detail/sanity.hpp" + +class atf_config : public atf::application::app { + static const char* m_description; + + bool m_tflag; + + void process_option(int, const char*); + std::string specific_args(void) const; + options_set specific_options(void) const; + + std::string format_var(const std::string&, const std::string&); + +public: + atf_config(void); + + int main(void); +}; + +const char* atf_config::m_description = + "atf-config is a tool that queries the value of several " + "installation-specific configuration values of the atf. " + "It can be used by external tools to discover where specific " + "internal atf files are installed."; + +atf_config::atf_config(void) : + app(m_description, "atf-config(1)", "atf(7)"), + m_tflag(false) +{ +} + +void +atf_config::process_option(int ch, const char* arg ATF_DEFS_ATTRIBUTE_UNUSED) +{ + switch (ch) { + case 't': + m_tflag = true; + break; + + default: + UNREACHABLE; + } +} + +std::string +atf_config::specific_args(void) + const +{ + return "[var1 [.. varN]]"; +} + +atf_config::options_set +atf_config::specific_options(void) + const +{ + using atf::application::option; + options_set opts; + opts.insert(option('t', "", "Terse output: show values only")); + return opts; +} + +std::string +atf_config::format_var(const std::string& name, const std::string& val) +{ + std::string str; + + if (m_tflag) + str = val; + else + str = name + " : " + val; + + return str; +} + +int +atf_config::main(void) +{ + if (m_argc < 1) { + std::map< std::string, std::string > cv = atf::config::get_all(); + + for (std::map< std::string, std::string >::const_iterator iter = + cv.begin(); iter != cv.end(); iter++) + std::cout << format_var((*iter).first, (*iter).second) << "\n"; + } else { + for (int i = 0; i < m_argc; i++) { + if (!atf::config::has(m_argv[i])) + throw std::runtime_error(std::string("Unknown variable `") + + m_argv[i] + "'"); + } + + for (int i = 0; i < m_argc; i++) { + std::cout << format_var(m_argv[i], atf::config::get(m_argv[i])) + << "\n"; + } + } + + return EXIT_SUCCESS; +} + +int +main(int argc, char* const* argv) +{ + return atf_config().run(argc, argv); +} diff --git a/contrib/atf/atf-config/integration_test.sh b/contrib/atf/atf-config/integration_test.sh new file mode 100644 index 0000000..5d6505a --- /dev/null +++ b/contrib/atf/atf-config/integration_test.sh @@ -0,0 +1,180 @@ +# +# Automated Testing Framework (atf) +# +# Copyright (c) 2007 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 +# documentation and/or other materials provided with the distribution. +# +# 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. +# + +all_vars="atf_arch \ + atf_build_cc \ + atf_build_cflags \ + atf_build_cpp \ + atf_build_cppflags \ + atf_build_cxx \ + atf_build_cxxflags \ + atf_confdir \ + atf_includedir \ + atf_libdir \ + atf_libexecdir \ + atf_machine \ + atf_pkgdatadir \ + atf_shell \ + atf_workdir" +all_vars_no=15 + +atf_test_case list_all +list_all_head() +{ + atf_set "descr" "Tests that at atf-config prints all expected" \ + "variables, and not more" +} +list_all_body() +{ + atf_check -s eq:0 -o save:stdout -e empty atf-config + atf_check -s eq:0 -o empty -e empty \ + test "$(wc -l stdout | awk '{ print $1 }')" = "${all_vars_no}" + for v in ${all_vars}; do + atf_check -s eq:0 -o ignore -e empty grep "${v}" stdout + done +} + +atf_test_case query_one +query_one_head() +{ + atf_set "descr" "Tests that querying a single variable works" +} +query_one_body() +{ + for v in ${all_vars}; do + atf_check -s eq:0 -o save:stdout -o match:"${v}" -e empty \ + atf-config "${v}" + atf_check -s eq:0 -o empty -e empty \ + test "$(wc -l stdout | awk '{ print $1 }')" = 1 + done +} + +atf_test_case query_one_terse +query_one_terse_head() +{ + atf_set "descr" "Tests that querying a single variable in terse mode" \ + "works" +} +query_one_terse_body() +{ + for v in ${all_vars}; do + atf_check -s eq:0 -o save:stdout -o match:"${v}" -e empty \ + atf-config "${v}" + atf_check -s eq:0 -o empty -e empty \ + test "$(wc -l stdout | awk '{ print $1 }')" = 1 + atf_check -s eq:0 -o save:stdout -e empty cut -d ' ' -f 3- stdout + atf_check -s eq:0 -o empty -e empty mv stdout expout + atf_check -s eq:0 -o file:expout -e empty atf-config -t "${v}" + done +} + +atf_test_case query_multiple +query_multiple_head() +{ + atf_set "descr" "Tests that querying multiple variables works" +} +query_multiple_body() +{ + atf_check -s eq:0 -o save:stdout -o match:'atf_libexecdir' \ + -o match:'atf_shell' -e empty atf-config atf_libexecdir atf_shell + atf_check -s eq:0 -o empty -e empty \ + test "$(wc -l stdout | awk '{ print $1 }')" = 2 +} + +atf_test_case query_unknown +query_unknown_head() +{ + atf_set "descr" "Tests that querying an unknown variable delivers" \ + "the correct error" +} +query_unknown_body() +{ + atf_check -s eq:1 -o empty -e match:'Unknown variable.*non_existent' \ + atf-config non_existent +} + +atf_test_case query_mixture +query_mixture_head() +{ + atf_set "descr" "Tests that querying a known and an unknown variable" \ + "delivers the correct error" +} +query_mixture_body() +{ + for v in ${all_vars}; do + atf_check -s eq:1 -o empty -e match:'Unknown variable.*non_existent' \ + atf-config "${v}" non_existent + atf_check -s eq:1 -o empty -e match:'Unknown variable.*non_existent' \ + atf-config non_existent "${v}" + done +} + +atf_test_case override_env +override_env_head() +{ + atf_set "descr" "Tests that build-time variables can be overriden" \ + "through their corresponding environment variables" +} +override_env_body() +{ + for v in ${all_vars}; do + V=$(echo ${v} | tr '[a-z]' '[A-Z]') + atf_check -s eq:0 -o save:stdout -e empty -x "${V}=testval atf-config" + atf_check -s eq:0 -o empty -e empty mv stdout all + + atf_check -s eq:0 -o save:stdout -e empty grep "^${v} : " all + atf_check -s eq:0 -o empty -e empty mv stdout affected + atf_check -s eq:0 -o save:stdout -e empty grep -v "^${v} : " all + atf_check -s eq:0 -o empty -e empty mv stdout unaffected + + atf_check -s eq:0 -o empty -e empty \ + test "$(wc -l affected | awk '{ print $1 }')" = 1 + atf_check -s eq:0 -o empty -e empty \ + test "$(wc -l unaffected | awk '{ print $1 }')" = \ + "$((${all_vars_no} -1))" + + atf_check -s eq:0 -o ignore -e empty grep "^${v} : testval$" affected + atf_check -s eq:1 -o empty -e empty grep ' : testval$' unaffected + done +} + +atf_init_test_cases() +{ + atf_add_test_case list_all + + atf_add_test_case query_one + atf_add_test_case query_one_terse + atf_add_test_case query_multiple + atf_add_test_case query_unknown + atf_add_test_case query_mixture + + atf_add_test_case override_env +} + +# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 |