diff options
author | Håvard Pettersen <havardpe@oath.com> | 2020-01-31 12:37:33 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2020-01-31 12:37:33 +0000 |
commit | 1ec3d9929dfebd5af6f3825576d9e9b4cd4934bf (patch) | |
tree | 1c5e65d266bbd686eea47b639eadc6efd71c4aee /eval | |
parent | 964a140569dbef3f28cc05e0d2a62214505b40c5 (diff) |
verify that immutable inputs are not modified
Diffstat (limited to 'eval')
-rw-r--r-- | eval/src/vespa/eval/eval/test/eval_fixture.cpp | 14 | ||||
-rw-r--r-- | eval/src/vespa/eval/eval/test/eval_fixture.h | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/eval/src/vespa/eval/eval/test/eval_fixture.cpp b/eval/src/vespa/eval/eval/test/eval_fixture.cpp index e578b28da18..1e17c8284cb 100644 --- a/eval/src/vespa/eval/eval/test/eval_fixture.cpp +++ b/eval/src/vespa/eval/eval/test/eval_fixture.cpp @@ -83,6 +83,19 @@ std::vector<Value::CREF> get_refs(const std::vector<Value::UP> &values) { } // namespace vespalib::eval::test +void +EvalFixture::detect_param_tampering(const ParamRepo ¶m_repo, bool allow_mutable) const +{ + for (size_t i = 0; i < _function->num_params(); ++i) { + auto pos = param_repo.map.find(_function->param_name(i)); + ASSERT_TRUE(pos != param_repo.map.end()); + bool allow_tampering = allow_mutable && pos->second.is_mutable; + if (!allow_tampering) { + ASSERT_EQUAL(pos->second.value, _engine.to_spec(*_param_values[i])); + } + } +} + EvalFixture::EvalFixture(const TensorEngine &engine, const vespalib::string &expr, const ParamRepo ¶m_repo, @@ -104,6 +117,7 @@ EvalFixture::EvalFixture(const TensorEngine &engine, { auto result_type = ValueType::from_spec(_result.type()); ASSERT_TRUE(!result_type.is_error()); + TEST_DO(detect_param_tampering(param_repo, allow_mutable)); } const TensorSpec diff --git a/eval/src/vespa/eval/eval/test/eval_fixture.h b/eval/src/vespa/eval/eval/test/eval_fixture.h index 48f6a7e5d2e..1d39dc52cba 100644 --- a/eval/src/vespa/eval/eval/test/eval_fixture.h +++ b/eval/src/vespa/eval/eval/test/eval_fixture.h @@ -67,6 +67,8 @@ private: } } + void detect_param_tampering(const ParamRepo ¶m_repo, bool allow_mutable) const; + public: EvalFixture(const TensorEngine &engine, const vespalib::string &expr, const ParamRepo ¶m_repo, bool optimized = true, bool allow_mutable = false); |