1 // Copyright 2012 The Kyua Authors.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "model/metadata.hpp"
33 #include "model/exceptions.hpp"
34 #include "model/types.hpp"
35 #include "utils/config/exceptions.hpp"
36 #include "utils/config/nodes.ipp"
37 #include "utils/config/tree.ipp"
38 #include "utils/datetime.hpp"
39 #include "utils/defs.hpp"
40 #include "utils/format/macros.hpp"
41 #include "utils/fs/exceptions.hpp"
42 #include "utils/fs/path.hpp"
43 #include "utils/noncopyable.hpp"
44 #include "utils/optional.ipp"
45 #include "utils/sanity.hpp"
46 #include "utils/text/exceptions.hpp"
47 #include "utils/text/operations.hpp"
48 #include "utils/units.hpp"
50 namespace config = utils::config;
51 namespace datetime = utils::datetime;
52 namespace fs = utils::fs;
53 namespace text = utils::text;
54 namespace units = utils::units;
56 using utils::optional;
62 /// Global instance of defaults.
64 /// This exists so that the getters in metadata can return references instead
65 /// of object copies. Use get_defaults() to query.
66 static optional< config::tree > defaults;
69 /// A leaf node that holds a bytes quantity.
70 class bytes_node : public config::native_leaf_node< units::bytes > {
74 /// \return A dynamically-allocated node.
78 std::auto_ptr< bytes_node > new_node(new bytes_node());
79 new_node->_value = _value;
80 return new_node.release();
83 /// Pushes the node's value onto the Lua stack.
85 push_lua(lutok::state& /* state */) const
90 /// Sets the value of the node from an entry in the Lua stack.
92 set_lua(lutok::state& /* state */, const int /* index */)
99 /// A leaf node that holds a time delta.
100 class delta_node : public config::typed_leaf_node< datetime::delta > {
104 /// \return A dynamically-allocated node.
106 deep_copy(void) const
108 std::auto_ptr< delta_node > new_node(new delta_node());
109 new_node->_value = _value;
110 return new_node.release();
113 /// Sets the value of the node from a raw string representation.
115 /// \param raw_value The value to set the node to.
117 /// \throw value_error If the value is invalid.
119 set_string(const std::string& raw_value)
121 unsigned int seconds;
123 seconds = text::to_type< unsigned int >(raw_value);
124 } catch (const text::error& e) {
125 throw config::value_error(F("Invalid time delta %s") % raw_value);
127 set(datetime::delta(seconds, 0));
130 /// Converts the contents of the node to a string.
132 /// \pre The node must have a value.
134 /// \return A string representation of the value held by the node.
136 to_string(void) const
138 return F("%s") % value().seconds;
141 /// Pushes the node's value onto the Lua stack.
143 push_lua(lutok::state& /* state */) const
148 /// Sets the value of the node from an entry in the Lua stack.
150 set_lua(lutok::state& /* state */, const int /* index */)
157 /// A leaf node that holds a "required user" property.
159 /// This node is just a string, but it provides validation of the only allowed
161 class user_node : public config::string_node {
164 /// \return A dynamically-allocated node.
166 deep_copy(void) const
168 std::auto_ptr< user_node > new_node(new user_node());
169 new_node->_value = _value;
170 return new_node.release();
173 /// Checks a given user textual representation for validity.
175 /// \param user The value to validate.
177 /// \throw config::value_error If the value is not valid.
179 validate(const value_type& user) const
181 if (!user.empty() && user != "root" && user != "unprivileged")
182 throw config::value_error("Invalid required user value");
187 /// A leaf node that holds a set of paths.
189 /// This node type is used to represent the value of the required files and
190 /// required programs, for example, and these do not allow relative paths. We
192 class paths_set_node : public config::base_set_node< fs::path > {
195 /// \return A dynamically-allocated node.
197 deep_copy(void) const
199 std::auto_ptr< paths_set_node > new_node(new paths_set_node());
200 new_node->_value = _value;
201 return new_node.release();
204 /// Converts a single path to the native type.
206 /// \param raw_value The value to parse.
208 /// \return The parsed value.
210 /// \throw config::value_error If the value is invalid.
212 parse_one(const std::string& raw_value) const
215 return fs::path(raw_value);
216 } catch (const fs::error& e) {
217 throw config::value_error(e.what());
221 /// Checks a collection of paths for validity.
223 /// \param paths The value to validate.
225 /// \throw config::value_error If the value is not valid.
227 validate(const value_type& paths) const
229 for (value_type::const_iterator iter = paths.begin();
230 iter != paths.end(); ++iter) {
231 const fs::path& path = *iter;
232 if (!path.is_absolute() && path.ncomponents() > 1)
233 throw config::value_error(F("Relative path '%s' not allowed") %
240 /// Initializes a tree to hold test case requirements.
242 /// \param [in,out] tree The tree to initialize.
244 init_tree(config::tree& tree)
246 tree.define< config::strings_set_node >("allowed_architectures");
247 tree.define< config::strings_set_node >("allowed_platforms");
248 tree.define_dynamic("custom");
249 tree.define< config::string_node >("description");
250 tree.define< config::bool_node >("has_cleanup");
251 tree.define< config::bool_node >("is_exclusive");
252 tree.define< config::strings_set_node >("required_configs");
253 tree.define< bytes_node >("required_disk_space");
254 tree.define< paths_set_node >("required_files");
255 tree.define< bytes_node >("required_memory");
256 tree.define< paths_set_node >("required_programs");
257 tree.define< user_node >("required_user");
258 tree.define< delta_node >("timeout");
262 /// Sets default values on a tree object.
264 /// \param [in,out] tree The tree to configure.
266 set_defaults(config::tree& tree)
268 tree.set< config::strings_set_node >("allowed_architectures",
269 model::strings_set());
270 tree.set< config::strings_set_node >("allowed_platforms",
271 model::strings_set());
272 tree.set< config::string_node >("description", "");
273 tree.set< config::bool_node >("has_cleanup", false);
274 tree.set< config::bool_node >("is_exclusive", false);
275 tree.set< config::strings_set_node >("required_configs",
276 model::strings_set());
277 tree.set< bytes_node >("required_disk_space", units::bytes(0));
278 tree.set< paths_set_node >("required_files", model::paths_set());
279 tree.set< bytes_node >("required_memory", units::bytes(0));
280 tree.set< paths_set_node >("required_programs", model::paths_set());
281 tree.set< user_node >("required_user", "");
282 // TODO(jmmv): We shouldn't be setting a default timeout like this. See
283 // Issue 5 for details.
284 tree.set< delta_node >("timeout", datetime::delta(300, 0));
288 /// Queries the global defaults tree object with lazy initialization.
290 /// \return A metadata tree. This object is statically allocated so it is
291 /// acceptable to obtain references to it and its members.
301 return defaults.get();
305 /// Looks up a value in a tree with error rewriting.
307 /// \tparam NodeType The type of the node.
308 /// \param tree The tree in which to insert the value.
309 /// \param key The key to set.
311 /// \return A read-write reference to the value in the node.
313 /// \throw model::error If the key is not known or if the value is not valid.
314 template< class NodeType >
315 typename NodeType::value_type&
316 lookup_rw(config::tree& tree, const std::string& key)
319 return tree.lookup_rw< NodeType >(key);
320 } catch (const config::unknown_key_error& e) {
321 throw model::error(F("Unknown metadata property %s") % key);
322 } catch (const config::value_error& e) {
323 throw model::error(F("Invalid value for metadata property %s: %s") %
329 /// Sets a value in a tree with error rewriting.
331 /// \tparam NodeType The type of the node.
332 /// \param tree The tree in which to insert the value.
333 /// \param key The key to set.
334 /// \param value The value to set the node to.
336 /// \throw model::error If the key is not known or if the value is not valid.
337 template< class NodeType >
339 set(config::tree& tree, const std::string& key,
340 const typename NodeType::value_type& value)
343 tree.set< NodeType >(key, value);
344 } catch (const config::unknown_key_error& e) {
345 throw model::error(F("Unknown metadata property %s") % key);
346 } catch (const config::value_error& e) {
347 throw model::error(F("Invalid value for metadata property %s: %s") %
353 } // anonymous namespace
356 /// Internal implementation of the metadata class.
357 struct model::metadata::impl : utils::noncopyable {
358 /// Metadata properties.
363 /// \param props_ Metadata properties of the test.
364 impl(const utils::config::tree& props_) :
369 /// Equality comparator.
371 /// \param other The other object to compare this one to.
373 /// \return True if this object and other are equal; false otherwise.
375 operator==(const impl& other) const
377 return (get_defaults().combine(props) ==
378 get_defaults().combine(other.props));
385 /// \param props Metadata properties of the test.
386 model::metadata::metadata(const utils::config::tree& props) :
387 _pimpl(new impl(props))
393 model::metadata::~metadata(void)
398 /// Applies a set of overrides to this metadata object.
400 /// \param overrides The overrides to apply. Any values explicitly set in this
401 /// other object will override any possible values set in this object.
403 /// \return A new metadata object with the combination.
405 model::metadata::apply_overrides(const metadata& overrides) const
407 return metadata(_pimpl->props.combine(overrides._pimpl->props));
411 /// Returns the architectures allowed by the test.
413 /// \return Set of architectures, or empty if this does not apply.
414 const model::strings_set&
415 model::metadata::allowed_architectures(void) const
417 if (_pimpl->props.is_set("allowed_architectures")) {
418 return _pimpl->props.lookup< config::strings_set_node >(
419 "allowed_architectures");
421 return get_defaults().lookup< config::strings_set_node >(
422 "allowed_architectures");
427 /// Returns the platforms allowed by the test.
429 /// \return Set of platforms, or empty if this does not apply.
430 const model::strings_set&
431 model::metadata::allowed_platforms(void) const
433 if (_pimpl->props.is_set("allowed_platforms")) {
434 return _pimpl->props.lookup< config::strings_set_node >(
435 "allowed_platforms");
437 return get_defaults().lookup< config::strings_set_node >(
438 "allowed_platforms");
443 /// Returns all the user-defined metadata properties.
445 /// \return A key/value map of properties.
446 model::properties_map
447 model::metadata::custom(void) const
449 return _pimpl->props.all_properties("custom", true);
453 /// Returns the description of the test.
455 /// \return Textual description; may be empty.
457 model::metadata::description(void) const
459 if (_pimpl->props.is_set("description")) {
460 return _pimpl->props.lookup< config::string_node >("description");
462 return get_defaults().lookup< config::string_node >("description");
467 /// Returns whether the test has a cleanup part or not.
469 /// \return True if there is a cleanup part; false otherwise.
471 model::metadata::has_cleanup(void) const
473 if (_pimpl->props.is_set("has_cleanup")) {
474 return _pimpl->props.lookup< config::bool_node >("has_cleanup");
476 return get_defaults().lookup< config::bool_node >("has_cleanup");
481 /// Returns whether the test is exclusive or not.
483 /// \return True if the test has to be run on its own, not concurrently with any
484 /// other tests; false otherwise.
486 model::metadata::is_exclusive(void) const
488 if (_pimpl->props.is_set("is_exclusive")) {
489 return _pimpl->props.lookup< config::bool_node >("is_exclusive");
491 return get_defaults().lookup< config::bool_node >("is_exclusive");
496 /// Returns the list of configuration variables needed by the test.
498 /// \return Set of configuration variables.
499 const model::strings_set&
500 model::metadata::required_configs(void) const
502 if (_pimpl->props.is_set("required_configs")) {
503 return _pimpl->props.lookup< config::strings_set_node >(
506 return get_defaults().lookup< config::strings_set_node >(
512 /// Returns the amount of free disk space required by the test.
514 /// \return Number of bytes, or 0 if this does not apply.
516 model::metadata::required_disk_space(void) const
518 if (_pimpl->props.is_set("required_disk_space")) {
519 return _pimpl->props.lookup< bytes_node >("required_disk_space");
521 return get_defaults().lookup< bytes_node >("required_disk_space");
526 /// Returns the list of files needed by the test.
528 /// \return Set of paths.
529 const model::paths_set&
530 model::metadata::required_files(void) const
532 if (_pimpl->props.is_set("required_files")) {
533 return _pimpl->props.lookup< paths_set_node >("required_files");
535 return get_defaults().lookup< paths_set_node >("required_files");
540 /// Returns the amount of memory required by the test.
542 /// \return Number of bytes, or 0 if this does not apply.
544 model::metadata::required_memory(void) const
546 if (_pimpl->props.is_set("required_memory")) {
547 return _pimpl->props.lookup< bytes_node >("required_memory");
549 return get_defaults().lookup< bytes_node >("required_memory");
554 /// Returns the list of programs needed by the test.
556 /// \return Set of paths.
557 const model::paths_set&
558 model::metadata::required_programs(void) const
560 if (_pimpl->props.is_set("required_programs")) {
561 return _pimpl->props.lookup< paths_set_node >("required_programs");
563 return get_defaults().lookup< paths_set_node >("required_programs");
568 /// Returns the user required by the test.
570 /// \return One of unprivileged, root or empty.
572 model::metadata::required_user(void) const
574 if (_pimpl->props.is_set("required_user")) {
575 return _pimpl->props.lookup< user_node >("required_user");
577 return get_defaults().lookup< user_node >("required_user");
582 /// Returns the timeout of the test.
584 /// \return A time delta; should be compared to default_timeout to see if it has
586 const datetime::delta&
587 model::metadata::timeout(void) const
589 if (_pimpl->props.is_set("timeout")) {
590 return _pimpl->props.lookup< delta_node >("timeout");
592 return get_defaults().lookup< delta_node >("timeout");
597 /// Externalizes the metadata to a set of key/value textual pairs.
599 /// \return A key/value representation of the metadata.
600 model::properties_map
601 model::metadata::to_properties(void) const
603 const config::tree fully_specified = get_defaults().combine(_pimpl->props);
604 return fully_specified.all_properties();
608 /// Equality comparator.
610 /// \param other The other object to compare this one to.
612 /// \return True if this object and other are equal; false otherwise.
614 model::metadata::operator==(const metadata& other) const
616 return _pimpl == other._pimpl || *_pimpl == *other._pimpl;
620 /// Inequality comparator.
622 /// \param other The other object to compare this one to.
624 /// \return True if this object and other are different; false otherwise.
626 model::metadata::operator!=(const metadata& other) const
628 return !(*this == other);
632 /// Injects the object into a stream.
634 /// \param output The stream into which to inject the object.
635 /// \param object The object to format.
637 /// \return The output stream.
639 model::operator<<(std::ostream& output, const metadata& object)
641 output << "metadata{";
644 const model::properties_map props = object.to_properties();
645 for (model::properties_map::const_iterator iter = props.begin();
646 iter != props.end(); ++iter) {
649 output << F("%s=%s") % (*iter).first %
650 text::quote((*iter).second, '\'');
659 /// Internal implementation of the metadata_builder class.
660 struct model::metadata_builder::impl : utils::noncopyable {
661 /// Collection of requirements.
664 /// Whether we have created a metadata object or not.
676 /// \param base The base model to construct a copy from.
677 impl(const model::metadata& base) :
678 props(base._pimpl->props.deep_copy()),
686 model::metadata_builder::metadata_builder(void) :
693 model::metadata_builder::metadata_builder(const model::metadata& base) :
694 _pimpl(new impl(base))
700 model::metadata_builder::~metadata_builder(void)
705 /// Accumulates an additional allowed architecture.
707 /// \param arch The architecture.
709 /// \return A reference to this builder.
711 /// \throw model::error If the value is invalid.
712 model::metadata_builder&
713 model::metadata_builder::add_allowed_architecture(const std::string& arch)
715 if (!_pimpl->props.is_set("allowed_architectures")) {
716 _pimpl->props.set< config::strings_set_node >(
717 "allowed_architectures",
718 get_defaults().lookup< config::strings_set_node >(
719 "allowed_architectures"));
721 lookup_rw< config::strings_set_node >(
722 _pimpl->props, "allowed_architectures").insert(arch);
727 /// Accumulates an additional allowed platform.
729 /// \param platform The platform.
731 /// \return A reference to this builder.
733 /// \throw model::error If the value is invalid.
734 model::metadata_builder&
735 model::metadata_builder::add_allowed_platform(const std::string& platform)
737 if (!_pimpl->props.is_set("allowed_platforms")) {
738 _pimpl->props.set< config::strings_set_node >(
740 get_defaults().lookup< config::strings_set_node >(
741 "allowed_platforms"));
743 lookup_rw< config::strings_set_node >(
744 _pimpl->props, "allowed_platforms").insert(platform);
749 /// Accumulates a single user-defined property.
751 /// \param key Name of the property to define.
752 /// \param value Value of the property.
754 /// \return A reference to this builder.
756 /// \throw model::error If the value is invalid.
757 model::metadata_builder&
758 model::metadata_builder::add_custom(const std::string& key,
759 const std::string& value)
761 _pimpl->props.set_string(F("custom.%s") % key, value);
766 /// Accumulates an additional required configuration variable.
768 /// \param var The name of the configuration variable.
770 /// \return A reference to this builder.
772 /// \throw model::error If the value is invalid.
773 model::metadata_builder&
774 model::metadata_builder::add_required_config(const std::string& var)
776 if (!_pimpl->props.is_set("required_configs")) {
777 _pimpl->props.set< config::strings_set_node >(
779 get_defaults().lookup< config::strings_set_node >(
780 "required_configs"));
782 lookup_rw< config::strings_set_node >(
783 _pimpl->props, "required_configs").insert(var);
788 /// Accumulates an additional required file.
790 /// \param path The path to the file.
792 /// \return A reference to this builder.
794 /// \throw model::error If the value is invalid.
795 model::metadata_builder&
796 model::metadata_builder::add_required_file(const fs::path& path)
798 if (!_pimpl->props.is_set("required_files")) {
799 _pimpl->props.set< paths_set_node >(
801 get_defaults().lookup< paths_set_node >("required_files"));
803 lookup_rw< paths_set_node >(_pimpl->props, "required_files").insert(path);
808 /// Accumulates an additional required program.
810 /// \param path The path to the program.
812 /// \return A reference to this builder.
814 /// \throw model::error If the value is invalid.
815 model::metadata_builder&
816 model::metadata_builder::add_required_program(const fs::path& path)
818 if (!_pimpl->props.is_set("required_programs")) {
819 _pimpl->props.set< paths_set_node >(
821 get_defaults().lookup< paths_set_node >("required_programs"));
823 lookup_rw< paths_set_node >(_pimpl->props,
824 "required_programs").insert(path);
829 /// Sets the architectures allowed by the test.
831 /// \param as Set of architectures.
833 /// \return A reference to this builder.
835 /// \throw model::error If the value is invalid.
836 model::metadata_builder&
837 model::metadata_builder::set_allowed_architectures(
838 const model::strings_set& as)
840 set< config::strings_set_node >(_pimpl->props, "allowed_architectures", as);
845 /// Sets the platforms allowed by the test.
847 /// \return ps Set of platforms.
849 /// \return A reference to this builder.
851 /// \throw model::error If the value is invalid.
852 model::metadata_builder&
853 model::metadata_builder::set_allowed_platforms(const model::strings_set& ps)
855 set< config::strings_set_node >(_pimpl->props, "allowed_platforms", ps);
860 /// Sets the user-defined properties.
862 /// \param props The custom properties to set.
864 /// \return A reference to this builder.
866 /// \throw model::error If the value is invalid.
867 model::metadata_builder&
868 model::metadata_builder::set_custom(const model::properties_map& props)
870 for (model::properties_map::const_iterator iter = props.begin();
871 iter != props.end(); ++iter)
872 _pimpl->props.set_string(F("custom.%s") % (*iter).first,
878 /// Sets the description of the test.
880 /// \param description Textual description of the test.
882 /// \return A reference to this builder.
884 /// \throw model::error If the value is invalid.
885 model::metadata_builder&
886 model::metadata_builder::set_description(const std::string& description)
888 set< config::string_node >(_pimpl->props, "description", description);
893 /// Sets whether the test has a cleanup part or not.
895 /// \param cleanup True if the test has a cleanup part; false otherwise.
897 /// \return A reference to this builder.
899 /// \throw model::error If the value is invalid.
900 model::metadata_builder&
901 model::metadata_builder::set_has_cleanup(const bool cleanup)
903 set< config::bool_node >(_pimpl->props, "has_cleanup", cleanup);
908 /// Sets whether the test is exclusive or not.
910 /// \param exclusive True if the test is exclusive; false otherwise.
912 /// \return A reference to this builder.
914 /// \throw model::error If the value is invalid.
915 model::metadata_builder&
916 model::metadata_builder::set_is_exclusive(const bool exclusive)
918 set< config::bool_node >(_pimpl->props, "is_exclusive", exclusive);
923 /// Sets the list of configuration variables needed by the test.
925 /// \param vars Set of configuration variables.
927 /// \return A reference to this builder.
929 /// \throw model::error If the value is invalid.
930 model::metadata_builder&
931 model::metadata_builder::set_required_configs(const model::strings_set& vars)
933 set< config::strings_set_node >(_pimpl->props, "required_configs", vars);
938 /// Sets the amount of free disk space required by the test.
940 /// \param bytes Number of bytes.
942 /// \return A reference to this builder.
944 /// \throw model::error If the value is invalid.
945 model::metadata_builder&
946 model::metadata_builder::set_required_disk_space(const units::bytes& bytes)
948 set< bytes_node >(_pimpl->props, "required_disk_space", bytes);
953 /// Sets the list of files needed by the test.
955 /// \param files Set of paths.
957 /// \return A reference to this builder.
959 /// \throw model::error If the value is invalid.
960 model::metadata_builder&
961 model::metadata_builder::set_required_files(const model::paths_set& files)
963 set< paths_set_node >(_pimpl->props, "required_files", files);
968 /// Sets the amount of memory required by the test.
970 /// \param bytes Number of bytes.
972 /// \return A reference to this builder.
974 /// \throw model::error If the value is invalid.
975 model::metadata_builder&
976 model::metadata_builder::set_required_memory(const units::bytes& bytes)
978 set< bytes_node >(_pimpl->props, "required_memory", bytes);
983 /// Sets the list of programs needed by the test.
985 /// \param progs Set of paths.
987 /// \return A reference to this builder.
989 /// \throw model::error If the value is invalid.
990 model::metadata_builder&
991 model::metadata_builder::set_required_programs(const model::paths_set& progs)
993 set< paths_set_node >(_pimpl->props, "required_programs", progs);
998 /// Sets the user required by the test.
1000 /// \param user One of unprivileged, root or empty.
1002 /// \return A reference to this builder.
1004 /// \throw model::error If the value is invalid.
1005 model::metadata_builder&
1006 model::metadata_builder::set_required_user(const std::string& user)
1008 set< user_node >(_pimpl->props, "required_user", user);
1013 /// Sets a metadata property by name from its textual representation.
1015 /// \param key The property to set.
1016 /// \param value The value to set the property to.
1018 /// \return A reference to this builder.
1020 /// \throw model::error If the value is invalid or the key does not exist.
1021 model::metadata_builder&
1022 model::metadata_builder::set_string(const std::string& key,
1023 const std::string& value)
1026 _pimpl->props.set_string(key, value);
1027 } catch (const config::unknown_key_error& e) {
1028 throw model::format_error(F("Unknown metadata property %s") % key);
1029 } catch (const config::value_error& e) {
1030 throw model::format_error(
1031 F("Invalid value for metadata property %s: %s") % key % e.what());
1037 /// Sets the timeout of the test.
1039 /// \param timeout The timeout to set.
1041 /// \return A reference to this builder.
1043 /// \throw model::error If the value is invalid.
1044 model::metadata_builder&
1045 model::metadata_builder::set_timeout(const datetime::delta& timeout)
1047 set< delta_node >(_pimpl->props, "timeout", timeout);
1052 /// Creates a new metadata object.
1054 /// \pre This has not yet been called. We only support calling this function
1055 /// once due to the way the internal tree works: we pass around references, not
1056 /// deep copies, so if we allowed a second build, we'd encourage reusing the
1057 /// same builder to construct different metadata objects, and this could have
1058 /// unintended consequences.
1060 /// \return The constructed metadata object.
1062 model::metadata_builder::build(void) const
1064 PRE(!_pimpl->built);
1065 _pimpl->built = true;
1067 return metadata(_pimpl->props);