// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

<%!
import vec_test_helpers
%>\
<%def name="test_opivv(template_helper, src2, src1,  ref_vv)">
<%
src1 = vec_test_helpers.to_carr_str(src1)
src2 = vec_test_helpers.to_carr_str(src2)
ref_vv = vec_test_helpers.to_carr_str(ref_vv)
%>\
namespace softrvv_${template_helper.op_code}_vv_test {
namespace {
${insert_variable_init(template_helper, src2, src1, ref_vv)}

class SoftRvv${template_helper.op_code.capitalize()}Test : public ::testing::Test {
 protected:
  void SetUp() override { memset(dest, 0, sizeof(dest)); }
};
${insert_test(template_helper)}\
}  // namespace
}  // namespace softrvv_${op}_vv_test\
</%def>\

<%def name="insert_variable_init(template_helper, src2, src1, ref_vv)">
<%
  var_types = template_helper.get_var_types()
%>\
${var_types.src1_type} src1[] = {${src1}};
${var_types.src2_type} src2[] = {${src2}};
const int kAVL = sizeof(src1)/sizeof(src1[0]);
${var_types.dest_type} dest[kAVL];

${var_types.dest_type} ref_vv[kAVL] = {${ref_vv}};
</%def>\

<%def name="insert_test(template_helper)">
<%
var_types = template_helper.get_var_types()
datatypes = template_helper.get_softrvv_template_data_type()
%>\
TEST_F(SoftRvv${template_helper.op_code.capitalize()}Test, VV) {
  % if template_helper.is_floating():
    softrvv::${template_helper.op_code}_vv(dest, src2, src1, kAVL);\
  % else:
    softrvv::${template_helper.op_code}_vv<${datatypes}>(dest, src2, src1, kAVL);\
  % endif
${insert_check(template_helper, var_types.dest_type, "ref_vv")}\
}

</%def>\

<%def name="insert_check(template_helper, dest_type, ref_var)">
% if template_helper.is_destination_mask_register():
  assert_vec_mask_eq<${dest_type}>(kAVL, dest, ${ref_var});
% else:
  assert_vec_elem_eq<${dest_type}>(kAVL, dest, ${ref_var});
% endif
</%def>\
