xref: /minix3/external/bsd/kyua-cli/dist/engine/metadata.hpp (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
111be35a1SLionel Sambuc // Copyright 2012 Google Inc.
211be35a1SLionel Sambuc // All rights reserved.
311be35a1SLionel Sambuc //
411be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
511be35a1SLionel Sambuc // modification, are permitted provided that the following conditions are
611be35a1SLionel Sambuc // met:
711be35a1SLionel Sambuc //
811be35a1SLionel Sambuc // * Redistributions of source code must retain the above copyright
911be35a1SLionel Sambuc //   notice, this list of conditions and the following disclaimer.
1011be35a1SLionel Sambuc // * Redistributions in binary form must reproduce the above copyright
1111be35a1SLionel Sambuc //   notice, this list of conditions and the following disclaimer in the
1211be35a1SLionel Sambuc //   documentation and/or other materials provided with the distribution.
1311be35a1SLionel Sambuc // * Neither the name of Google Inc. nor the names of its contributors
1411be35a1SLionel Sambuc //   may be used to endorse or promote products derived from this software
1511be35a1SLionel Sambuc //   without specific prior written permission.
1611be35a1SLionel Sambuc //
1711be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1811be35a1SLionel Sambuc // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1911be35a1SLionel Sambuc // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2011be35a1SLionel Sambuc // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2111be35a1SLionel Sambuc // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2211be35a1SLionel Sambuc // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2311be35a1SLionel Sambuc // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2411be35a1SLionel Sambuc // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2511be35a1SLionel Sambuc // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2611be35a1SLionel Sambuc // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2711be35a1SLionel Sambuc // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2811be35a1SLionel Sambuc 
2911be35a1SLionel Sambuc /// \file engine/metadata.hpp
3011be35a1SLionel Sambuc /// Representation of the metadata of a test program or test case.
3111be35a1SLionel Sambuc 
3211be35a1SLionel Sambuc #if !defined(ENGINE_METADATA_HPP)
3311be35a1SLionel Sambuc #define ENGINE_METADATA_HPP
3411be35a1SLionel Sambuc 
3511be35a1SLionel Sambuc #include <map>
3611be35a1SLionel Sambuc #include <memory>
3711be35a1SLionel Sambuc #include <ostream>
3811be35a1SLionel Sambuc #include <set>
3911be35a1SLionel Sambuc #include <string>
4011be35a1SLionel Sambuc 
4111be35a1SLionel Sambuc #include "utils/noncopyable.hpp"
42*84d9c625SLionel Sambuc #include "utils/shared_ptr.hpp"
4311be35a1SLionel Sambuc 
4411be35a1SLionel Sambuc namespace utils {
4511be35a1SLionel Sambuc namespace config { class tree; }
4611be35a1SLionel Sambuc namespace datetime { class delta; }
4711be35a1SLionel Sambuc namespace fs { class path; }
4811be35a1SLionel Sambuc namespace units { class bytes; }
4911be35a1SLionel Sambuc }  // namespace utils
5011be35a1SLionel Sambuc 
5111be35a1SLionel Sambuc namespace engine {
5211be35a1SLionel Sambuc 
5311be35a1SLionel Sambuc 
5411be35a1SLionel Sambuc // TODO(jmmv): All these types should probably be in individual header files so
5511be35a1SLionel Sambuc // that we could include them without pulling in additional dependencies.
5611be35a1SLionel Sambuc /// Collection of paths.
5711be35a1SLionel Sambuc typedef std::set< utils::fs::path > paths_set;
5811be35a1SLionel Sambuc /// Collection of strings.
5911be35a1SLionel Sambuc typedef std::set< std::string > strings_set;
6011be35a1SLionel Sambuc /// Collection of test properties in their textual form.
6111be35a1SLionel Sambuc typedef std::map< std::string, std::string > properties_map;
6211be35a1SLionel Sambuc 
6311be35a1SLionel Sambuc 
6411be35a1SLionel Sambuc extern utils::datetime::delta default_timeout;
6511be35a1SLionel Sambuc 
6611be35a1SLionel Sambuc 
6711be35a1SLionel Sambuc class metadata_builder;
6811be35a1SLionel Sambuc 
6911be35a1SLionel Sambuc 
7011be35a1SLionel Sambuc /// Collection of metadata properties of a test.
7111be35a1SLionel Sambuc class metadata {
7211be35a1SLionel Sambuc     struct impl;
7311be35a1SLionel Sambuc 
7411be35a1SLionel Sambuc     /// Pointer to the shared internal implementation.
75*84d9c625SLionel Sambuc     std::shared_ptr< impl > _pimpl;
7611be35a1SLionel Sambuc 
7711be35a1SLionel Sambuc     friend class metadata_builder;
7811be35a1SLionel Sambuc 
7911be35a1SLionel Sambuc public:
8011be35a1SLionel Sambuc     metadata(const utils::config::tree&);
8111be35a1SLionel Sambuc     ~metadata(void);
8211be35a1SLionel Sambuc 
8311be35a1SLionel Sambuc     const strings_set& allowed_architectures(void) const;
8411be35a1SLionel Sambuc     const strings_set& allowed_platforms(void) const;
8511be35a1SLionel Sambuc     properties_map custom(void) const;
8611be35a1SLionel Sambuc     const std::string& description(void) const;
8711be35a1SLionel Sambuc     bool has_cleanup(void) const;
8811be35a1SLionel Sambuc     const strings_set& required_configs(void) const;
8911be35a1SLionel Sambuc     const paths_set& required_files(void) const;
9011be35a1SLionel Sambuc     const utils::units::bytes& required_memory(void) const;
9111be35a1SLionel Sambuc     const paths_set& required_programs(void) const;
9211be35a1SLionel Sambuc     const std::string& required_user(void) const;
9311be35a1SLionel Sambuc     const utils::datetime::delta& timeout(void) const;
9411be35a1SLionel Sambuc 
9511be35a1SLionel Sambuc     engine::properties_map to_properties(void) const;
9611be35a1SLionel Sambuc 
9711be35a1SLionel Sambuc     bool operator==(const metadata&) const;
9811be35a1SLionel Sambuc     bool operator!=(const metadata&) const;
9911be35a1SLionel Sambuc };
10011be35a1SLionel Sambuc 
10111be35a1SLionel Sambuc 
10211be35a1SLionel Sambuc std::ostream& operator<<(std::ostream&, const metadata&);
10311be35a1SLionel Sambuc 
10411be35a1SLionel Sambuc 
10511be35a1SLionel Sambuc /// Builder for a metadata object.
10611be35a1SLionel Sambuc class metadata_builder : utils::noncopyable {
10711be35a1SLionel Sambuc     struct impl;
10811be35a1SLionel Sambuc 
10911be35a1SLionel Sambuc     /// Pointer to the shared internal implementation.
11011be35a1SLionel Sambuc     std::auto_ptr< impl > _pimpl;
11111be35a1SLionel Sambuc 
11211be35a1SLionel Sambuc public:
11311be35a1SLionel Sambuc     metadata_builder(void);
11411be35a1SLionel Sambuc     explicit metadata_builder(const engine::metadata&);
11511be35a1SLionel Sambuc     ~metadata_builder(void);
11611be35a1SLionel Sambuc 
11711be35a1SLionel Sambuc     metadata_builder& add_allowed_architecture(const std::string&);
11811be35a1SLionel Sambuc     metadata_builder& add_allowed_platform(const std::string&);
11911be35a1SLionel Sambuc     metadata_builder& add_custom(const std::string&, const std::string&);
12011be35a1SLionel Sambuc     metadata_builder& add_required_config(const std::string&);
12111be35a1SLionel Sambuc     metadata_builder& add_required_file(const utils::fs::path&);
12211be35a1SLionel Sambuc     metadata_builder& add_required_program(const utils::fs::path&);
12311be35a1SLionel Sambuc 
12411be35a1SLionel Sambuc     metadata_builder& set_allowed_architectures(const strings_set&);
12511be35a1SLionel Sambuc     metadata_builder& set_allowed_platforms(const strings_set&);
12611be35a1SLionel Sambuc     metadata_builder& set_custom(const properties_map&);
12711be35a1SLionel Sambuc     metadata_builder& set_description(const std::string&);
12811be35a1SLionel Sambuc     metadata_builder& set_has_cleanup(const bool);
12911be35a1SLionel Sambuc     metadata_builder& set_required_configs(const strings_set&);
13011be35a1SLionel Sambuc     metadata_builder& set_required_files(const paths_set&);
13111be35a1SLionel Sambuc     metadata_builder& set_required_memory(const utils::units::bytes&);
13211be35a1SLionel Sambuc     metadata_builder& set_required_programs(const paths_set&);
13311be35a1SLionel Sambuc     metadata_builder& set_required_user(const std::string&);
13411be35a1SLionel Sambuc     metadata_builder& set_string(const std::string&, const std::string&);
13511be35a1SLionel Sambuc     metadata_builder& set_timeout(const utils::datetime::delta&);
13611be35a1SLionel Sambuc 
13711be35a1SLionel Sambuc     metadata build(void) const;
13811be35a1SLionel Sambuc };
13911be35a1SLionel Sambuc 
14011be35a1SLionel Sambuc 
14111be35a1SLionel Sambuc std::string check_reqs(const engine::metadata&, const utils::config::tree&,
14211be35a1SLionel Sambuc                        const std::string&);
14311be35a1SLionel Sambuc 
14411be35a1SLionel Sambuc 
14511be35a1SLionel Sambuc }  // namespace engine
14611be35a1SLionel Sambuc 
14711be35a1SLionel Sambuc 
14811be35a1SLionel Sambuc #endif  // !defined(ENGINE_METADATA_HPP)
149