def test_sv_object_funcs(get_vector_filename, simulator, temp): avail, tester_cls = simulator_map[simulator] if not avail(): pytest.skip(simulator + " is not available") class ClassA: @sv() def __init__(self): self.num = 21 class ClassB: # object is allowed if you want duct typing @sv(a=DataType.Object) def __init__(self, a): self.a = a @sv(return_type=ClassA) def create_a(self, num): a = ClassA() a.num = num return a @sv(a=ClassA) def add(self, a): return self.a.num + a.num lib_path = compile_lib([ClassA, ClassB], cwd=temp) sv_pkg = os.path.join(os.path.abspath(temp), "pysv_pkg.sv") generate_sv_binding([ClassA, ClassB], filename=sv_pkg) tb_file = get_vector_filename("test_sv_object_funcs.sv") tester = tester_cls(lib_path, sv_pkg, tb_file, cwd=temp) tester.run()
def test_sv_simulator(get_vector_filename, simulator, temp): avail, tester_cls = simulator_map[simulator] if not avail(): pytest.skip("{0} not available".format(simulator)) lib_path = compile_lib([BoxFilter], cwd=temp) sv_pkg = os.path.join(os.path.abspath(temp), "pysv_pkg.sv") generate_sv_binding([BoxFilter], filename=sv_pkg) sv_file = get_vector_filename("box_filter.sv") tb_file = get_vector_filename("test_sv_boxfilter.sv") tester = tester_cls(lib_path, sv_pkg, sv_file, tb_file, cwd=temp) tester.run()
def test_sv_return_reference(get_vector_filename, temp): # test out return reference simulator = "xcelium" avail, tester_cls = simulator_map[simulator] if not avail(): pytest.skip(simulator + " is not available") @sv(return_type=Reference(a=DataType.Int, b=DataType.Int)) def set_value(): return 42, 43 lib_path = compile_lib([set_value], cwd=temp) sv_pkg = os.path.join(os.path.abspath(temp), "pysv_pkg.sv") generate_sv_binding([set_value], filename=sv_pkg) tb_file = get_vector_filename("test_sv_return_reference.sv") tester = tester_cls(lib_path, sv_pkg, tb_file, cwd=temp) tester.run()
def test_sv_object_funcs_2(get_vector_filename, temp): # test out a normal function takes in Python object simulator = "xcelium" avail, tester_cls = simulator_map[simulator] if not avail(): pytest.skip(simulator + " is not available") class ClassA2: @sv() def __init__(self): self.num = 1 @sv(a=ClassA2) def add(a): return a.num + 41 lib_path = compile_lib([ClassA2, add], cwd=temp) sv_pkg = os.path.join(os.path.abspath(temp), "pysv_pkg.sv") generate_sv_binding([ClassA2, add], filename=sv_pkg) tb_file = get_vector_filename("test_sv_object_funcs_2.sv") tester = tester_cls(lib_path, sv_pkg, tb_file, cwd=temp) tester.run()
def test_tensorflow(get_vector_filename, temp): # should work with any simulator, but it seems like the Xcelium we have doesn't ship # with the latest libstdc++. Use vcs instead avail, tester_cls = simulator_map["vcs"] if not avail(): pytest.skip("VCS not available") import tensorflow as tf @sv() def simple_mat_mal(a, b): c = tf.constant([[a, a], [a, a]]) d = tf.constant([[b, b], [b, b]]) e = tf.matmul(c, d) n = e.numpy() s = np.sum(n) return s lib_path = compile_lib([simple_mat_mal], cwd=temp) sv_pkg = os.path.join(os.path.abspath(temp), "pysv_pkg.sv") generate_sv_binding([simple_mat_mal], filename=sv_pkg) tb_file = get_vector_filename("test_tensorflow.sv") tester = tester_cls(lib_path, sv_pkg, tb_file, cwd=temp) tester.run()