Skip to content

Commit

Permalink
make enc2 tester optionally work with checked enc2 API.
Browse files Browse the repository at this point in the history
  * fixed one bug in gpr8 enumeration. SIL/DIL/SPL/BPL are only
    available in m64.

  * had to guard includes in test.c for the config being built

Change-Id: Ia2b2d670e156a5245499666a695006452f4c7d00
(cherry picked from commit 7c89a78212f2b56d3dc5d0d96000ee38c685b8fd)
  • Loading branch information
mjcharne authored and markcharney committed Aug 9, 2019
1 parent 5c84dc4 commit 4e50d6a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
14 changes: 11 additions & 3 deletions pysrc/enc2gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4781,10 +4781,12 @@ def gather_stats(db):

# object used for the env we pass to the generator
class enc_env_t(object):
def __init__(self, mode, asz):
def __init__(self, mode, asz, test_checked_interface=False):
self.mode = mode
self.asz = asz
self.function_names = {}
self.test_checked_interface = test_checked_interface
self.tests_per_form = 1
def __str__(self):
s = []
s.append("mode {}".format(self.mode))
Expand Down Expand Up @@ -4866,6 +4868,10 @@ def work():
action="store_true",
default=False,
help='all modes and addressing')
arg_parser.add_argument('-chk',
action="store_true",
default=False,
help='Test checked interface')
arg_parser.add_argument('--gendir',
help='output directory, default: "obj"',
default='obj')
Expand Down Expand Up @@ -4940,6 +4946,7 @@ def prune_asz_list_for_mode(mode,alist):
env = enc_env_t(mode, asz)
enc2test.set_test_gen_counters(env)
env.tests_per_form = 1
env.test_checked_interface = args.chk

msge("Generating encoder functions for {}".format(env))
for ii in xeddb.recs:
Expand Down Expand Up @@ -4984,7 +4991,8 @@ def prune_asz_list_for_mode(mode,alist):
config_descriptor = 'enc2-m{}-a{}'.format(mode,asz)
fn_prefix = 'xed-test-{}'.format(config_descriptor)
test_fn_hdr='{}.h'.format(fn_prefix)
enc2_fn_hdr='xed/xed-{}.h'.format(config_descriptor)
enc2_fn_hdr='xed/xed-{}.h'.format(config_descriptor)
enc2_chk_fn_hdr='xed/xed-chk-{}.h'.format(config_descriptor)
gen_src_dir = os.path.join(args.gendir, config_descriptor, 'test', 'src')
gen_hdr_dir = os.path.join(args.gendir, config_descriptor, 'test', 'hdr')
mbuild.cmkdir(gen_src_dir)
Expand All @@ -4995,7 +5003,7 @@ def prune_asz_list_for_mode(mode,alist):
args.xeddir,
gen_src_dir,
gen_hdr_dir,
other_headers = [enc2_fn_hdr],
other_headers = [enc2_fn_hdr, enc2_chk_fn_hdr],
max_lines_per_file=15000)

output_file_emitters.extend(file_emitters)
Expand Down
11 changes: 8 additions & 3 deletions pysrc/enc2test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def _make_test_function_object(env, enc_fn):
encoder_fn = enc_fn.get_function_name()
versions = env.test_function_names[encoder_fn]
fname = 'test_{}_{}'.format(versions, encoder_fn)
if env.test_checked_interface:
fname = '{}_chk'.format(fname)
env.test_function_names[encoder_fn] += 1

fo = codegen.function_object_t(fname, return_type='xed_uint32_t')
Expand All @@ -61,12 +63,12 @@ def _add_test_function(ii,fo):

gpr16_not64 = "AX CX DX BX SI DI BP SP".split()
gpr16_index = "SI DI".split()
gpr8_not64 = "AL CL DL BL SIL DIL BPL SPL".split()
gpr8_not64 = "AL CL DL BL".split()

gpr32_index_m64 = gpr32_index_not64 + "R8D R9D R10D R11D R12D R13D R14D R15D".split()
gpr32_m64 = gpr32_not64 + "R8D R9D R10D R11D R12D R13D R14D R15D".split()
gpr16_m64 = gpr16_not64 + "R8W R9W R10W R11W R12W R13W R14W R15W".split()
gpr8_m64 = gpr8_not64 + "R8B R9B R10B R11B R12B R13B R14B R15B".split()
gpr8_m64 = gpr8_not64 + "SIL DIL BPL SPL R8B R9B R10B R11B R12B R13B R14B R15B".split()

gpr8h = "AH CH DH BH".split()

Expand Down Expand Up @@ -372,7 +374,10 @@ def _create_enc_test_functions(env, ii, encfn):

# test function call
s = []
s.append( encfn.get_function_name() )
fname = encfn.get_function_name()
if env.test_checked_interface:
fname = '{}_chk'.format(fname)
s.append( fname )
s.append( '(' )
for i,(argtype,argname,arginfo) in enumerate(args):
if i>0:
Expand Down
11 changes: 7 additions & 4 deletions src/enc2test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@ END_LEGAL */

#include "xed-interface.h"
#include "xed-get-time.h"
#include "enc2-m64-a64/hdr/xed/xed-enc2-m64-a64.h"
#if defined(XED_ENC2_CONFIG_M64_A64)
# include "enc2-m64-a64/hdr/xed/xed-enc2-m64-a64.h"
#elif defined(XED_ENC2_CONFIG_M32_A32)
#include "enc2-m32-a32/hdr/xed/xed-enc2-m32-a32.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include "xed-histogram.h"

typedef xed_uint32_t (*test_func_t)(xed_uint8_t* output_buffer);

#if defined(XED_ENC2_CONFIG_M64_A64)
extern test_func_t test_functions_m64_a64[];
extern char const* test_functions_m64_a64_str[];
extern const xed_iclass_enum_t test_functions_m64_a64_iclass[];

#elif defined(XED_ENC2_CONFIG_M32_A32)
extern test_func_t test_functions_m32_a32[];
extern char const* test_functions_m32_a32_str[];
extern const xed_iclass_enum_t test_functions_m32_a32_iclass[];

#endif

xed_state_t dstate;

Expand Down
22 changes: 17 additions & 5 deletions xed_mbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def decode_command(self, xedsrc, extra_args=None):
return ' '.join(s)

def encode_command(self, xedsrc, extra_args=None, amd_enabled=True):
"""Produce a encoder generator command"""
"""Produce an encoder generator command"""
s = []
s.append( '%(pythonarg)s' )
# s.append("-3") # python3.0 compliance checking using python2.6
Expand Down Expand Up @@ -365,13 +365,15 @@ def run_encode_generator(gc, env):
return (retval, [] )

def _encode_command2(args):
"""Produce a encoder2 generator command"""
"""Produce an encoder2 generator command."""
s = []
s.append( '%(pythonarg)s' )
s.append( aq(mbuild.join(args.xeddir, 'pysrc', 'enc2gen.py')))
s.append('--xeddir %s' % aq(args.xeddir))
s.append('--gendir %s' % aq(args.gendir))
s.extend( args.config.as_args() )
s.extend( args.config.as_args() )
if args.test_checked_interface:
s.append('-chk' )
s.append('--output-file-list %s' % aq(args.enc2_output_file))
return ' '.join(s)

Expand Down Expand Up @@ -643,6 +645,7 @@ def mkenv():
asan=False,
enc2=False,
enc2_test=False,
enc2_test_checked=False,
first_lib=None,
last_lib=None)

Expand Down Expand Up @@ -940,6 +943,10 @@ def xed_args(env):
action="store_true",
dest="enc2_test",
help="Build the enc2 fast encoder *tests*. Longer build.")
env.parser.add_option("--enc2-test-checked",
action="store_true",
dest="enc2_test_checked",
help="Build the enc2 fast encoder *tests*. Test the checked interface. Longer build.")

env.parse_args(env['xed_defaults'])

Expand Down Expand Up @@ -1501,6 +1508,7 @@ def add_encoder2_command(env, dag, input_files, config):
enc2args.enc2_hash_file = env.build_dir_join('.mbuild.hash.xedencgen2-{}'.format(config))
enc2args.enc2_output_file = env.build_dir_join('ENCGEN2-OUTPUT-FILES-{}.txt'.format(config))
enc2args.config = config
enc2args.test_checked_interface = env['enc2_test_checked']
if os.path.exists(enc2args.enc2_output_file):
need_to_rebuild_enc = need_to_rebuild(enc2args.enc2_output_file,
enc2args.enc2_hash_file)
Expand Down Expand Up @@ -1807,7 +1815,7 @@ def build_libxedenc2(arg_env, work_queue, input_files, config):
mbuild.msgb("LIBRARY", "XED ENC2 build succeeded")

if env['enc2_test']:
build_enc2_test(env,work_queue, config)
build_enc2_test(env, work_queue, config)

return (env['shd_enc2_lib'], env['link_enc2_lib'],
env['shd_chk_lib'], env['link_chk_lib'] )
Expand All @@ -1833,7 +1841,7 @@ def build_enc2_test(arg_env, work_queue, config):
if env.on_linux() and env['shared']:
env['LINKFLAGS'] += " -Wl,-rpath,'$ORIGIN/../wkit/lib'"

lc = env.link(objs + [env['link_enc2_lib'], env['link_libxed']], exe)
lc = env.link(objs + [ env['link_chk_lib'], env['link_enc2_lib'], env['link_libxed']], exe)
cmd = dag.add(env,lc)
if mbuild.verbose(2):
mbuild.msgb('BUILDING', "ENC2 config {} test program".format(config))
Expand Down Expand Up @@ -2660,7 +2668,11 @@ def macro_args(env):
env.add_to_var('CXXFLAGS', fcmd)
env.add_to_var('CCFLAGS', fcmd)
env.add_to_var('LINKFLAGS', fcmd)

if env['enc2_test_checked']:
env['enc2_test']=True
if env['enc2_test']:
env['enc2']=True
env['enc']=True

def work(env):
Expand Down

0 comments on commit 4e50d6a

Please sign in to comment.