# Path: mozz/test.py
# def run_test_module(name, file):
# 	outputfile = mozz.util.python_path_basename(file) + '.out'
# 
# 	m = sys.modules[name]
# 	ldr = unittest.loader.defaultTestLoader
# 	tests = ldr.loadTestsFromModule(m)
# 
# 	with open(outputfile, 'w') as f:
# 		duper = mozz.util.IOWriteDuplicator(
# 			sys.stderr, f
# 		)
# 		unittest.runner.TextTestRunner(
# 			verbosity = 2,
# 			stream = duper
# 		).run(tests)
# 
# def abs_path(base_file, rel_path):
# 	return os.path.join(
# 		os.path.dirname(os.path.abspath(base_file)),
# 		rel_path
# 	)
# 
# Path: mozz/abi/call.py
# def native_convention():
# 	import mozz.system
# 	mach = mozz.system.architecture()
# 	if mach == mozz.system.ARCH_X86_64:
# 		return X8664SYSVConvention
# 	elif mach == mozz.system.ARCH_X86:
# 		return X86SYSVConvention
# 
# 	raise NativeConventionUnknown("no calling convention " + \
# 									"known for machine type: " + \
# 									repr(mach))


import unittest
import mozz
import mozz.system
from mozz.test import run_test_module, abs_path
from mozz.prototype import *
from mozz.abi.call import native_convention
			Pointer64, Pointer64, Pointer64
		)
		def test_function(host, fn_ctx, n, a, b, c, d, e, \
							buf1, buf2, output_var):
			host.log("test_function(%d):" % n)
			host.log("  a=%d" % a.value())
			host.log("  b=%d" % b.value())
			host.log("  c=%d" % c.value())
			host.log("  d=%d" % d.value())
			host.log("  e=%d" % e.value())
			host.log("  buf1=%x:%r" % (buf1.value(), buf1.string(host)))
			host.log("  buf2=%x:%r" % (buf2.value(), buf2.string(host)))
			host.log("  output_var=%x" % output_var.value())

			result['count'] += 1
			if n < 3 and self.check_params(n,host,a,b,c,d,e,buf1,buf2):
				result['params_correct'][n] = 1

		mozz.run_session(s)
		self.assertEqual(result['count'], 3)
		for i in range(3):
			print("check params #%d" % i)
			self.assertEqual(result['params_correct'][i], 1)
		self.assertEqual(result['default_case'], 1)

	def test_mockup_function(self):
		arch = mozz.system.architecture()
		if arch != mozz.system.ARCH_X86_64:
			return #this test not yet supported on non x86_64 systems


# Path: mozz/test.py
# def run_test_module(name, file):
# 	outputfile = mozz.util.python_path_basename(file) + '.out'
# 
# 	m = sys.modules[name]
# 	ldr = unittest.loader.defaultTestLoader
# 	tests = ldr.loadTestsFromModule(m)
# 
# 	with open(outputfile, 'w') as f:
# 		duper = mozz.util.IOWriteDuplicator(
# 			sys.stderr, f
# 		)
# 		unittest.runner.TextTestRunner(
# 			verbosity = 2,
# 			stream = duper
# 		).run(tests)
# 
# def abs_path(base_file, rel_path):
# 	return os.path.join(
# 		os.path.dirname(os.path.abspath(base_file)),
# 		rel_path
# 	)
# 
# Path: mozz/abi/call.py
# def native_convention():
# 	import mozz.system
# 	mach = mozz.system.architecture()
# 	if mach == mozz.system.ARCH_X86_64:
# 		return X8664SYSVConvention
# 	elif mach == mozz.system.ARCH_X86:
# 		return X86SYSVConvention
# 
# 	raise NativeConventionUnknown("no calling convention " + \
# 									"known for machine type: " + \
# 									repr(mach))


# Path: test/function_test.py
import unittest
import mozz
import mozz.system
from mozz.test import run_test_module, abs_path
from mozz.prototype import *
from mozz.abi.call import native_convention

			Pointer64, Pointer64, Pointer64
		)
		def test_function(host, fn_ctx, n, a, b, c, d, e, \
							buf1, buf2, output_var):
			host.log("test_function(%d):" % n)
			host.log("  a=%d" % a.value())
			host.log("  b=%d" % b.value())
			host.log("  c=%d" % c.value())
			host.log("  d=%d" % d.value())
			host.log("  e=%d" % e.value())
			host.log("  buf1=%x:%r" % (buf1.value(), buf1.string(host)))
			host.log("  buf2=%x:%r" % (buf2.value(), buf2.string(host)))
			host.log("  output_var=%x" % output_var.value())

			result['count'] += 1
			if n < 3 and self.check_params(n,host,a,b,c,d,e,buf1,buf2):
				result['params_correct'][n] = 1

		mozz.run_session(s)
		self.assertEqual(result['count'], 3)
		for i in range(3):
			print("check params #%d" % i)
			self.assertEqual(result['params_correct'][i], 1)
		self.assertEqual(result['default_case'], 1)

	def test_mockup_function(self):
		arch = mozz.system.architecture()
		if arch != mozz.system.ARCH_X86_64:
			return #this test not yet supported on non x86_64 systems


		s = mozz.Session(abs_path(__file__, "function_test.bin"))