// 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_opivx(template_helper, src2, src1, rs1, ref_vv, ref_vx)">
<%
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)
ref_vx = vec_test_helpers.to_carr_str(ref_vx)
%>\
namespace softrvv_${template_helper.op_code}_test {
namespace {
${insert_variable_init(template_helper, src2, src1, rs1, ref_vv, ref_vx)}

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}_test\
</%def>\

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

${var_types.dest_type} ref_vv[kAVL] = {${ref_vv}};
${var_types.dest_type} ref_vx[kAVL] = {${ref_vx}};
</%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) {
  softrvv::${template_helper.op_code}_vv<${datatypes}>(dest, src2, src1, kAVL);\
${insert_check(template_helper, var_types.dest_type, "ref_vv")}\
}

TEST_F(SoftRvv${template_helper.op_code.capitalize()}Test, VX) {
  softrvv::${template_helper.op_code}_vx<${datatypes}>(dest, src2, &rs1, kAVL);\
${insert_check(template_helper, var_types.dest_type, "ref_vx")}\
}
</%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>\
