Changeset 5886


Ignore:
Timestamp:
Mar 1, 2018, 2:23:35 PM (19 months ago)
Author:
xwa163
Message:

Add test cases for lz4d_ext_dep with -extract-and-deposit-only option

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/QA/lz4d_ext_dep/main.py

    r5864 r5886  
    1010failure_count = 0
    1111
     12# TODO Only test extract-only and extract-and-deposit-only now
     13test_options = [
     14    ('extract_only', '-extract-only', {'extract_only' : True}),
     15    ('extract_and_deposit', '-extract-and-deposit-only', {'extract_and_deposit_only': True}),
     16    # ('normal', '', {}),
     17]
     18
     19def run_test(test_file, lz4_option, python_lz4_option, test_file_full_path, output_file_full_path, python_output_file_full_path):
     20    global failure_count
     21    lz4d_cmd = "%s %s --thread-num=1 -segment-size=8 -f %s %s" % (
     22    lz4d_program_under_test, lz4_option, test_file_full_path, output_file_full_path, )
     23
     24    if options.verbose:
     25        print("Doing: " + lz4d_cmd)
     26    try:
     27        lz4d_out = subprocess.check_output(lz4d_cmd.encode('utf-8'), cwd=options.exec_dir, shell=True)
     28    except subprocess.CalledProcessError as e:
     29        lz4d_out = e.output
     30
     31    lz4Decoder = lz4d.LZ4Decoder()
     32
     33    lz4Decoder.decode(test_file_full_path, python_output_file_full_path, python_lz4_option)
     34
     35    with codecs.open(output_file_full_path, mode='rb') as inf:
     36        output_content = inf.read()
     37    with codecs.open(python_output_file_full_path, mode='rb') as inf:
     38        expected_output_content = inf.read()
     39
     40    if output_content != expected_output_content:
     41        print("Test failure: datafile {%s} option:{%s}" % (test_file, lz4_option))
     42        failure_count += 1
     43    else:
     44        if options.verbose:
     45            print("Test success: datafile {%s} option:{%s}" % (test_file, lz4_option))
     46
     47
    1248def run_tests(test_dir, output_dir, python_output_dir):
    1349    global options
     
    1551
    1652    test_files = os.listdir(test_dir)
     53
    1754    for test_file in test_files:
    1855        if test_file.endswith('.lz4'):
    1956            output_file = test_file.replace('.lz4', '')
    20 
    2157            test_file_full_path = os.path.join(test_dir, test_file)
    22             output_file_full_path = os.path.join(output_dir, output_file)
    23             python_output_file_full_path = os.path.join(python_output_dir, output_file)
    24 
    25             # TODO Only test extract-only now
    26             #-EnableCycleCounter --thread-num=1 -segment-size=8 -f /Users/wxy325/developer/lz4-dev/e.txt.lz4 /Users/wxy325/developer/lz4-dev/e_txt/parallel_e_d_test.txt
    27             lz4d_cmd = "%s -extract-only --thread-num=1 -segment-size=8 -f %s %s" % (lz4d_program_under_test, test_file_full_path, output_file_full_path)
    28 
    29             if options.verbose:
    30                 print("Doing: " + lz4d_cmd)
    31 
    32             try:
    33                 lz4d_out = subprocess.check_output(lz4d_cmd.encode('utf-8'), cwd=options.exec_dir, shell=True)
    34             except subprocess.CalledProcessError as e:
    35                 lz4d_out = e.output
    36 
    37             lz4Decoder = lz4d.LZ4Decoder()
    38             # lz4Decoder.decode(test_file_full_path, python_output_file_full_path, {'extract_only' : True})
    39             lz4Decoder.decode(test_file_full_path, python_output_file_full_path, {'extract_only': True})
    40             # lz4Decoder.decode(test_file_full_path, python_output_file_full_path, {})
    41 
    42             # with codecs.open(output_file_full_path, encoding='utf-8', mode='r') as inf:
    43             with codecs.open(output_file_full_path, mode='rb') as inf:
    44                 output_content = inf.read()
    45             # with codecs.open(python_output_file_full_path, encoding='utf-8', mode='r') as inf:
    46             with codecs.open(python_output_file_full_path, mode='rb') as inf:
    47                 expected_output_content = inf.read()
    48 
    49             if output_content != expected_output_content:
    50                 print("Test failure: datafile {%s}" % test_file)
    51                 failure_count += 1
    52             else:
    53                 if options.verbose:
    54                     print("Test success: datafile {%s}" % test_file)
     58            for test_opt in test_options:
     59                output_file_full_path = os.path.join(output_dir, test_opt[0], output_file)
     60                python_output_file_full_path = os.path.join(python_output_dir, test_opt[0], output_file)
     61                run_test(test_file, test_opt[1], test_opt[2], test_file_full_path, output_file_full_path, python_output_file_full_path)
    5562
    5663    if failure_count > 0:
     
    93100        shutil.rmtree(options.output_dir)
    94101    os.mkdir(options.output_dir)
    95 
     102    for opt in test_options:
     103        os.mkdir(os.path.join(options.output_dir, opt[0]))
    96104
    97105    if os.path.exists(options.python_output_dir):
    98106        shutil.rmtree(options.python_output_dir)
     107
    99108    os.mkdir(options.python_output_dir)
     109    for opt in test_options:
     110        os.mkdir(os.path.join(options.python_output_dir, opt[0]))
    100111
    101112    lz4d_program_under_test = args[0]
Note: See TracChangeset for help on using the changeset viewer.