docstr: Write the testbench files (myproject_test.cpp and input/output .dat files)
  
  Args:
      model (ModelGraph): the hls4ml model.
docstr_tok: ["Write","the","testbench","files","(","myproject_test.cpp","and","input\/output",".dat","files",")","Args",":","model","(","ModelGraph",")",":","the","hls4ml","model","."]
code: def write_test_bench(self, model):
      """Write the testbench files (myproject_test.cpp and input/output .dat files)
  
      Args:
          model (ModelGraph): the hls4ml model.
      """
  
      filedir = os.path.dirname(os.path.abspath(__file__))
  
      if not os.path.exists(
          f"{model.config.get_output_dir()}/tb_data/"
      ):
          os.mkdir(f"{model.config.get_output_dir()}/tb_data/")
  
      input_data = model.config.get_config_value("InputData")
      output_predictions = model.config.get_config_value(
          "OutputPredictions"
      )
  
      if input_data:
          if input_data[-3:] == "dat":
              copyfile(
                  input_data,
                  f"{model.config.get_output_dir()}/tb_data/tb_input_features.dat",
              )
          else:
              self.__make_dat_file(
                  input_data,
                  f"{model.config.get_output_dir()}/tb_data/tb_input_features.dat",
              )
  
      if output_predictions:
          if output_predictions[-3:] == "dat":
              copyfile(
                  output_predictions,
                  f"{model.config.get_output_dir()}/tb_data/tb_output_predictions.dat",
              )
          else:
              self.__make_dat_file(
                  output_predictions,
                  f"{model.config.get_output_dir()}/tb_data/tb_output_predictions.dat",
              )
  
      f = open(
          os.path.join(
              filedir, "../templates/vivado/myproject_test.cpp"
          )
      )
      fout = open(
          f"{model.config.get_output_dir()}/{model.config.get_project_name()}_test.cpp",
          "w",
      )
  
      model_inputs = model.get_input_variables()
      model_outputs = model.get_output_variables()
      model_brams = [
          var
          for var in model.get_weight_variables()
          if var.storage.lower() == "bram"
      ]
  
      for line in f.readlines():
          indent = " " * (len(line) - len(line.lstrip(" ")))
  
          # Insert numbers
          if "myproject" in line:
              newline = line.replace(
                  "myproject", model.config.get_project_name()
              )
          elif "// hls-fpga-machine-learning insert bram" in line:
              newline = line
              for bram in model_brams:
                  newline += (
                      f'#include "firmware/weights/{bram.name}.h"\n'
                  )
          elif "// hls-fpga-machine-learning insert data" in line:
              newline = line
              offset = 0
              for inp in model_inputs:
                  newline += "      " + inp.definition_cpp() + ";\n"
                  newline += "      nnet::copy_data<float, {}, {}, {}>(in, {});\n".format(
                      inp.type.name, offset, inp.size_cpp(), inp.name
                  )
                  offset += inp.size()
              for out in model_outputs:
                  newline += "      " + out.definition_cpp() + ";\n"
          elif "// hls-fpga-machine-learning insert zero" in line:
              newline = line
              for inp in model_inputs:
                  newline += "    " + inp.definition_cpp() + ";\n"
                  newline += f"    nnet::fill_zero<{inp.type.name}, {inp.size_cpp()}>({inp.name});\n"
              for out in model_outputs:
                  newline += "    " + out.definition_cpp() + ";\n"
          elif (
              "// hls-fpga-machine-learning insert top-level-function"
              in line
          ):
              newline = line
  
              input_vars = ",".join([i.name for i in model_inputs])
              output_vars = ",".join([o.name for o in model_outputs])
              bram_vars = ",".join([b.name for b in model_brams])
  
              # Concatenate the input, output, and bram variables. Filter out empty/null values
              all_vars = ",".join(
                  filter(None, [input_vars, output_vars, bram_vars])
              )
  
              top_level = (
                  indent
                  + f"{model.config.get_project_name()}({all_vars});\n"
              )
  
              newline += top_level
          elif (
              "// hls-fpga-machine-learning insert predictions" in line
          ):
              newline = line
              for out in model_outputs:
                  newline += (
                      indent
                      + f"for(int i = 0; i < {out.size_cpp()}; i++) {{\n"
                  )
                  newline += indent + '  std::cout << pr[i] << " ";\n'
                  newline += indent + "}\n"
                  newline += indent + "std::cout << std::endl;\n"
          elif "// hls-fpga-machine-learning insert tb-output" in line:
              newline = line
              for out in model_outputs:
                  newline += (
                      indent
                      + "nnet::print_result<{}, {}>({}, fout);\n".format(
                          out.type.name, out.size_cpp(), out.name
                      )
                  )  # TODO enable this
          elif (
              "// hls-fpga-machine-learning insert output" in line
              or "// hls-fpga-machine-learning insert quantized" in line
          ):
              newline = line
              for out in model_outputs:
                  newline += (
                      indent
                      + "nnet::print_result<{}, {}>({}, std::cout, true);\n".format(
                          out.type.name, out.size_cpp(), out.name
                      )
                  )
          else:
              newline = line
          fout.write(newline)
      f.close()
      fout.close()
  
imports: import glob
  import os
  import tarfile
  from collections import OrderedDict
  from shutil import copyfile, copytree, rmtree
  import numpy
  import yaml
  from hls4ml.writer.writers import Writer
label_desc: Use image node_id 10 for calling the VivadoWriter obj's underlying member method code with example usage: obj.write_test_bench(model) without return types