xref: /freebsd/contrib/kyua/model/metadata.hpp (revision 6549718b70f0e660a15685369afb4f9caf2215ce)
1 // Copyright 2012 The Kyua Authors.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
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.
16 //
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.
28 
29 /// \file model/metadata.hpp
30 /// Definition of the "test metadata" concept.
31 
32 #if !defined(MODEL_METADATA_HPP)
33 #define MODEL_METADATA_HPP
34 
35 #include "model/metadata_fwd.hpp"
36 
37 #include <memory>
38 #include <ostream>
39 #include <string>
40 
41 #include "model/types.hpp"
42 #include "utils/config/tree_fwd.hpp"
43 #include "utils/datetime_fwd.hpp"
44 #include "utils/fs/path_fwd.hpp"
45 #include "utils/noncopyable.hpp"
46 #include "utils/units_fwd.hpp"
47 
48 namespace model {
49 
50 
51 /// Collection of metadata properties of a test.
52 class metadata {
53     struct impl;
54 
55     /// Pointer to the shared internal implementation.
56     std::shared_ptr< impl > _pimpl;
57 
58     friend class metadata_builder;
59 
60 public:
61     metadata(const utils::config::tree&);
62     ~metadata(void);
63 
64     metadata apply_overrides(const metadata&) const;
65 
66     const strings_set& allowed_architectures(void) const;
67     const strings_set& allowed_platforms(void) const;
68     model::properties_map custom(void) const;
69     const std::string& description(void) const;
70     const std::string& execenv(void) const;
71     const std::string& execenv_jail_params(void) const;
72     bool has_cleanup(void) const;
73     bool has_execenv(void) const;
74     bool is_exclusive(void) const;
75     const strings_set& required_configs(void) const;
76     const utils::units::bytes& required_disk_space(void) const;
77     const paths_set& required_files(void) const;
78     const utils::units::bytes& required_memory(void) const;
79     const paths_set& required_programs(void) const;
80     const std::string& required_user(void) const;
81     const utils::datetime::delta& timeout(void) const;
82 
83     model::properties_map to_properties(void) const;
84 
85     bool operator==(const metadata&) const;
86     bool operator!=(const metadata&) const;
87 };
88 
89 
90 std::ostream& operator<<(std::ostream&, const metadata&);
91 
92 
93 /// Builder for a metadata object.
94 class metadata_builder : utils::noncopyable {
95     struct impl;
96 
97     /// Pointer to the shared internal implementation.
98     std::auto_ptr< impl > _pimpl;
99 
100 public:
101     metadata_builder(void);
102     explicit metadata_builder(const metadata&);
103     ~metadata_builder(void);
104 
105     metadata_builder& add_allowed_architecture(const std::string&);
106     metadata_builder& add_allowed_platform(const std::string&);
107     metadata_builder& add_custom(const std::string&, const std::string&);
108     metadata_builder& add_required_config(const std::string&);
109     metadata_builder& add_required_file(const utils::fs::path&);
110     metadata_builder& add_required_program(const utils::fs::path&);
111 
112     metadata_builder& set_allowed_architectures(const strings_set&);
113     metadata_builder& set_allowed_platforms(const strings_set&);
114     metadata_builder& set_custom(const model::properties_map&);
115     metadata_builder& set_description(const std::string&);
116     metadata_builder& set_execenv(const std::string&);
117     metadata_builder& set_execenv_jail_params(const std::string&);
118     metadata_builder& set_has_cleanup(const bool);
119     metadata_builder& set_is_exclusive(const bool);
120     metadata_builder& set_required_configs(const strings_set&);
121     metadata_builder& set_required_disk_space(const utils::units::bytes&);
122     metadata_builder& set_required_files(const paths_set&);
123     metadata_builder& set_required_memory(const utils::units::bytes&);
124     metadata_builder& set_required_programs(const paths_set&);
125     metadata_builder& set_required_user(const std::string&);
126     metadata_builder& set_string(const std::string&, const std::string&);
127     metadata_builder& set_timeout(const utils::datetime::delta&);
128 
129     metadata build(void) const;
130 };
131 
132 
133 }  // namespace model
134 
135 #endif  // !defined(MODEL_METADATA_HPP)
136