Ejemplo n.º 1
0
def main(argv):
    # define return code const value
    const.RunTestFail = 1
    const.RunTestOK = 0
    const.GeneralError = -1
    const.UnknownArguments = -2
    const.NormalizationFail = -3
    const.WrongRunDir = -4

    # Parse the command line
    parser = argparse.ArgumentParser()
    parser.add_argument('-a',
                        '--arch',
                        type=str,
                        choices={'x86', 'x64'},
                        default='x64',
                        help='the target architure')
    parser.add_argument('-b',
                        '--build',
                        type=str,
                        choices={'release', 'debug'},
                        default='debug',
                        help='release or debug build of CoreCLR run-time used')
    parser.add_argument('-d',
                        '--dump-level',
                        type=str,
                        choices={'summary', 'verbose'},
                        help='the dump level: summary, or verbose')
    parser.add_argument('-r',
                        '--result-path',
                        type=str,
                        default=DefaultResultPath(),
                        help='the path to runtest result output directory')
    required = parser.add_argument_group('required arguments')
    required.add_argument('-j',
                          '--jit-path',
                          required=True,
                          help='full path to jit .dll')
    required.add_argument(
        '-c',
        '--coreclr-runtime-path',
        required=True,
        help='full path to CoreCLR run-time binary directory')
    args, unknown = parser.parse_known_args(argv)

    if unknown:
        print('Unknown argument(s): ', ', '.join(unknown))
        return const.UnknowArguments

    # Ensure the command run from a CoreCLR tests directory
    current_work_directory = os.getcwd()
    path, folder = os.path.split(current_work_directory)
    parent_path, parent_folder = os.path.split(path)
    if (not folder == 'tests' or not parent_folder == 'coreclr'):
        print(
            'This script is required to run from tests directory in a CoreCLR repository.'
        )
        return const.WrongRunDir

    try:
        # Determine the built test location
        build_test_path = BuiltTestPath(str(args.arch), str(args.build))

        # Determine time stamp
        time_stamp = str(time.time()).split('.')[0]

        # Copy in llilcjit.dll with time stamp
        time_stamped_jit_name = 'LLILCJit' + time_stamp + '.dll'
        time_stamped_jit_path = os.path.join(args.coreclr_runtime_path,
                                             time_stamped_jit_name)
        shutil.copy2(args.jit_path, time_stamped_jit_path)

        # Create llilctestenv.cmd with time stamp
        time_stamped_test_env_name = 'LLILCTestEnv' + time_stamp + '.cmd'
        time_stamped_test_env_path = os.path.join(args.coreclr_runtime_path,
                                                  time_stamped_test_env_name)

        # Todo: Test Env is right now only for Windows. Will expand when cross platform
        with open(time_stamped_test_env_path, 'w') as test_env:
            test_env.write('set COMPlus_AltJit=*\n')
            test_env.write('set COMPlus_AltJitName=' + time_stamped_jit_name +
                           '\n')
            test_env.write('set COMPlus_GCConservative=1\n')
            test_env.write('chcp 65001\n')
            if args.dump_level is not None:
                test_env.write('set COMPlus_DumpLLVMIR=' + args.dump_level +
                               '\n')

        # Exclude undesired tests from running
        ExcludeTopLevelTestDirectories()
        ExcludeIndividualTestCases(build_test_path)
    except:
        e = sys.exc_info()[0]
        print('Error: RunTest failed due to ', e)
        return const.GeneralError

    # Run the test
    return_code = const.RunTestOK
    runtest_command = 'runtest ' + args.arch + ' ' + args.build
    runtest_command = runtest_command + ' Testenv ' + time_stamped_test_env_path
    runtest_command = runtest_command + ' ' + args.coreclr_runtime_path
    print(runtest_command)
    error_level = subprocess.call(runtest_command, shell=True)
    if error_level == 1:
        return_code = const.RunTestFail

    # Remove temporary time-stamped jit and test env files
    try:
        os.remove(time_stamped_jit_path)
        os.remove(time_stamped_test_env_path)
    except:
        e = sys.exc_info()[0]
        print('Error: RunTest failed due to ', e)
        return const.GeneralError

    # Copy out result if there is one, clean up undesired files,
    # In case of verbose result, normalize it and extract out summary.
    # In case of summary result, rename all result file name.
    if args.dump_level is not None:
        try:
            coreclr_result_path = os.path.join(build_test_path, 'Reports')
            if os.path.exists(args.result_path):
                shutil.rmtree(args.result_path, onerror=del_rw)
            shutil.copytree(coreclr_result_path, args.result_path)
            ExcludeIndividualTestCases(args.result_path)
            CleanUpResultFiles(args.result_path)
            total = CountFiles(args.result_path, 'error.txt')
            if args.dump_level == 'verbose':
                print('Verbose-mode post-processing started')
                print('found ', total,
                      'valid raw test outputs (error.txt) under ',
                      str(coreclr_result_path))
                print('creating normalized outputs (error.txt) under ',
                      str(args.result_path))
                print('creating summary outputs (sum.txt) under ',
                      str(args.result_path))
                applyfilter.ApplyAll(args.result_path)
                print('Verbose-mode post-processing finished')
            if args.dump_level == 'summary':
                print('Summary-mode post-processing started')
                print('found ', total,
                      'valid raw test outputs (error.txt) under ',
                      os.path.abspath(coreclr_result_path))
                print('creating summary outputs (sum.txt) under ',
                      str(args.result_path))
                applyfilter.SummaryRenameAll(args.result_path)
                print('Summary-mode post-processing finished')
        except:
            e = sys.exc_info()[0]
            print('Error: Test result normalization failed due to ', e)
            return const.NormalizationFail
    else:
        print('No post-processing needed.')

    return return_code
Ejemplo n.º 2
0
def main(argv):
    # define return code const value
    const.RunTestFail = 1
    const.RunTestOK = 0
    const.GeneralError = -1
    const.UnknownArguments = -2
    const.NormalizationFail = -3
    const.InvalidPath = -4

    # Parse the command line    
    parser = argparse.ArgumentParser()
    parser.add_argument('-a', '--arch', type=str, choices={'x86', 'x64'},
                        default='x64', help='the target architure')
    parser.add_argument('-b', '--build', type=str, choices={'release', 'debug'}, 
                        default='debug', help='release or debug build of CoreCLR run-time used')
    parser.add_argument('-d', '--dump-level', type=str, choices={'summary', 'verbose'}, 
                        help='the dump level: summary, or verbose')
    parser.add_argument('-r', '--result-path', type=str, 
                        default=DefaultResultPath(), help='the path to runtest result output directory')
    parser.add_argument('-t', '--runtest-path', type=str,
                        default=None, help='the full path to the CoreCLR\\tests directory')
    parser.add_argument('-n', '--ngen', help='use ngened mscorlib', default=False, action="store_true")
    parser.add_argument('-s', '--insert-statepoints', help='Insert GC Statepoints',
                         default=False, action="store_true")
    parser.add_argument('-p', '--precise-gc', help='test with precise gc', default=False, action="store_true")
    parser.add_argument('-e', '--eh', help='enable exception handlers to run (as opposed to failfast)', default=False, action="store_true")
    required = parser.add_argument_group('required arguments')
    required.add_argument('-j', '--jit-path', required=True, 
                        help='full path to jit .dll')
    required.add_argument('-c', '--coreclr-runtime-path', required=True, 
                        help='full path to CoreCLR run-time binary directory')
    args, unknown = parser.parse_known_args(argv)

    if unknown:
        print('Unknown argument(s): ', ', '.join(unknown))
        return const.UnknowArguments

    coreclr_runtime_full_path = expandPath(args.coreclr_runtime_path)
    if (not os.path.isdir(coreclr_runtime_full_path)):
        print('Please specify valid --coreclr-runtime-path to CoreCLR run-time binary directory')
        return const.InvalidPath

    jit_full_path = expandPath(args.jit_path)
    if (not os.path.isfile(jit_full_path)):
        print('Please specify valid --jit-path to the jit .dll')
        return const.InvalidPath
    print('path',args.result_path)

    result_full_path = expandPath(args.result_path)
    print('Result path: ', result_full_path);

    # Ensure the command run from a CoreCLR tests directory
    runtest_dir = args.runtest_path
    if (args.runtest_path is None):
        runtest_dir = os.getcwd()

    # All platforms other than Windows run runtest.sh
    runtest_full_path = os.path.join(runtest_dir, 'runtest.sh')

    # On Windows, we will run runtest.cmd
    if sys.platform == "win32":
      runtest_full_path = os.path.join(runtest_dir, 'runtest.cmd')

    if (not os.path.isfile(runtest_full_path)):
        print('Please specify --runtest-path or run from theests directory in a CoreCLR repository')
        return const.InvalidPath

    try:
        # Determine the built test location
        build_test_path = BuiltTestPath(str(args.arch), str(args.build))

        # Determine time stamp
        time_stamp = str(time.time()).split('.')[0]

        # Copy in llilcjit.dll with time stamp
        time_stamped_jit_name = 'LLILCJit' + time_stamp + '.dll'
        time_stamped_jit_path = os.path.join(coreclr_runtime_full_path, time_stamped_jit_name)
        shutil.copy2(jit_full_path, time_stamped_jit_path)

        # Create llilctestenv.cmd with time stamp
        time_stamped_test_env_name = 'LLILCTestEnv' + time_stamp + '.cmd'
        time_stamped_test_env_path = os.path.join(coreclr_runtime_full_path, time_stamped_test_env_name)

        # Todo: Test Env is right now only for Windows. Will expand when cross platform
        with open(time_stamped_test_env_path, 'w') as test_env:
            test_env.write('set COMPlus_AltJit=*\n')
            test_env.write('set COMPlus_AltJitNgen=*\n')
            test_env.write('set COMPlus_AltJitName=' + time_stamped_jit_name + '\n')
            if (args.precise_gc):
                test_env.write('set COMPlus_InsertStatepoints=1\n')
            else:
                test_env.write('set COMPlus_GCConservative=1\n')
            if (args.insert_statepoints):
                test_env.write('set COMPlus_InsertStatepoints=1\n')
            if (not args.ngen):
              test_env.write('set COMPlus_ZapDisable=1\n')
            test_env.write('chcp 65001\n')
            if args.dump_level is not None:
                test_env.write('set COMPlus_DumpLLVMIR=' + args.dump_level + '\n')
            if args.eh:
                os.environ["COMPlus_ExecuteHandlers"]="1"

        # Exclude undesired tests from running
        ExcludeTopLevelTestDirectories()
    except:
        e = sys.exc_info()[0]
        print('Error: RunTest failed due to ', e)
        return const.GeneralError

    # Run the test
    return_code = const.RunTestOK
    exclusion = os.path.join(os.path.dirname(__file__), 'exclusion.targets')
    runtest_command = runtest_full_path + ' ' + args.arch + ' ' + args.build 
    runtest_command = runtest_command + ' Exclude ' + exclusion
    runtest_command = runtest_command + ' Testenv ' + time_stamped_test_env_path
    runtest_command = runtest_command + ' ' + coreclr_runtime_full_path
    print(runtest_command)
    error_level = subprocess.call(runtest_command, shell=True)
    if error_level == 1:
        return_code = const.RunTestFail

    # Remove temporary time-stamped jit and test env files
    try:
        os.remove(time_stamped_jit_path)
        os.remove(time_stamped_test_env_path)
    except:
        e = sys.exc_info()[0]
        print('Error: RunTest failed due to ', e)
        return const.GeneralError

    # Copy out result if there is one, clean up undesired files, 
    # In case of verbose result, normalize it and extract out summary.
    # In case of summary result, rename all result file name.
    if args.dump_level is not None:
        try:
            coreclr_result_path = os.path.join(build_test_path, 'Reports')
            if os.path.exists(result_full_path):
                shutil.rmtree(result_full_path, onerror=del_rw)
            shutil.copytree(coreclr_result_path, result_full_path)
            CleanUpResultFiles(result_full_path)
            total = CountFiles(result_full_path, 'error.txt')
            if args.dump_level == 'verbose':
                print('Verbose-mode post-processing started')
                print('found ', total, 'valid raw test outputs (error.txt) under ', str(coreclr_result_path))
                print('creating normalized outputs (error.txt) under ', str(result_full_path))
                print('creating summary outputs (sum.txt) under ', str(result_full_path))
                applyfilter.ApplyAll(result_full_path)
                print('Verbose-mode post-processing finished')
            if args.dump_level == 'summary':
                print('Summary-mode post-processing started')
                print('found ', total, 'valid raw test outputs (error.txt) under ', os.path.abspath(coreclr_result_path))
                print('creating summary outputs (sum.txt) under ', str(result_full_path))
                applyfilter.SummaryRenameAll(result_full_path)
                print('Summary-mode post-processing finished')
        except:
            e = sys.exc_info()[0]
            print('Error: Test result normalization failed due to ', e)
            return const.NormalizationFail
    else:
        print('No post-processing needed.')

    return return_code