Exemple #1
0
def run_test(binary, test_files, test_name, test_directory, setup, logger,
             ocd):
    """
    Runs a given test from the test cases file
    """

    logger.log("-" * 80 + "\n")
    logger.log(f"Test Timestamp: {datetime.datetime.now()}\n")
    logger.log(f"Test Name:      {test_name}\n")
    logger.log(f"Test Directory: {test_directory}\n")

    # The net time is initially zero
    net_time = datetime.timedelta(0)

    # Change the current working directory to the test directory
    os.chdir(test_directory)

    # Run the setup, if any
    if setup:
        if re.match("^python", setup, flags=re.IGNORECASE):
            call_args = [sys.executable, *setup.split()[1:]]
            print(call_args)
            subprocess.call(call_args)
        else:
            subprocess.call(setup.split())

    for (base_name, expected_results) in test_files:

        # Get the name of the input file from the base name
        input_file = f"{base_name}.in"

        logger.message("-" * 80 + "\n")
        # If the expected results is 'forces', do a forces test on the input
        if expected_results == "forces":
            logger.message(f"Testing forces from {input_file}\n\n")
            logger.log(f"Testing forces from {input_file}\n")
            start_time = datetime.datetime.now()
            check_forces(input_file, "polarforces", "apolarforces", logger)
        else:
            logger.message(f"Testing input file {input_file}\n\n")
            logger.log(f"Testing {input_file}\n")

            # Record the start time before the test runs
            start_time = datetime.datetime.now()

            computed_results = None

            # Determine if this is a parallel run
            match = re.search(r"\s*pdime((\s+\d+)+)",
                              open(input_file, "r").read())

            # If it is parallel, get the number of procs and do a parallel run
            if match:
                procs = reduce(operator.mul,
                               [int(p) for p in match.group(1).split()])
                computed_results = process_parallel(binary, input_file, procs,
                                                    logger)
            # Otherwise, just do a serial run
            else:
                computed_results = process_serial(binary, input_file)

            # Split the expected results into a list of text values
            print(f"EXPECTED COMPUTED: {len(computed_results)}")
            print(f"EXPECTED EXPECTED: {len(expected_results)}")
            print(f"COMPUTED: {computed_results}")
            print(f"EXPECTED: {expected_results}")
            expected_results = expected_results.split()
            for result in computed_results:
                print(f"COMPUTED RESULT {result}")
            for i in range(len(expected_results)):
                # If the expected result is a star, it means ignore that result
                if expected_results[i] == "*":
                    continue

                # Compare the expected to computed results
                computed_result = 0
                try:
                    computed_result = computed_results[i]
                except IndexError as error:
                    logger.message(
                        f"Computed result for index, {i}, does not " +
                        f"exist: {error}")
                expected_result = float(expected_results[i])
                logger.message("Testing computed result against " +
                               f"expected result ({computed_result:.12e}, " +
                               f"{expected_result:.12e})\n")
                check_results(computed_result, expected_result, input_file,
                              logger, ocd)

        # Record the end time after the test
        end_time = datetime.datetime.now()
        elapsed_time = end_time - start_time
        net_time += elapsed_time
        stopwatch = elapsed_time.seconds + elapsed_time.microseconds / 1e6

        # Log the elapsed time for this test
        logger.message(f"Elapsed time: {stopwatch} seconds\n")
        logger.message("-" * 80 + "\n")

    stopwatch = net_time.seconds + net_time.microseconds / 1e6

    # Log the elapsed time for all tests that were run
    logger.message(f"Total elapsed time: {stopwatch} seconds\n")
    logger.message("Test results have been logged\n")
    logger.message("-" * 80 + "\n")
    logger.log(f"Time:           {stopwatch} seconds\n")

    os.chdir("../../tests")
Exemple #2
0
def run_test( binary, test_files, test_name, test_directory, logger, ocd ):
    """
    Runs a given test from the test cases file
    """
    
    logger.log( '=' * 80 )
    logger.log( "Test Timestamp: %s" % str( datetime.datetime.now() ) )
    logger.log( "Test Name:      %s" % test_name )
    logger.log( "Test Directory: %s" % test_directory )

    # The net time is initially zero
    net_time = datetime.timedelta( 0 )

    # Change the current working directory to the test directory
    os.chdir( test_directory )

    for ( base_name, expected_results ) in test_files:

        # Get the name of the input file from the base name
        input_file = '%s.in' % base_name

        # If the expected results is 'forces', do a forces test on the input
        if expected_results == 'forces':
            logger.message( '-' * 80 )
            logger.message( 'Testing forces from %s' % input_file )
            logger.message( '' )
            logger.log( 'Testing forces from %s' % input_file )
            start_time = datetime.datetime.now()
            check_forces( input_file, 'polarforces', 'apolarforces', logger )
            
        else:
            logger.message( '-' * 80 )
            logger.message( 'Testing input file %s' % input_file )
            logger.message( '' )
            logger.log( 'Testing %s' % input_file )
            
            # Record the start time before the test runs
            start_time = datetime.datetime.now()

            computed_results = None
            
            # Determine if this is a parallel run
            match = re.search( r'\s*pdime((\s+\d+)+)', open( input_file, 'r' ).read() )
            
            # If it is parallel, get the number of procs and do a parallel run
            if match:
                procs = reduce( operator.mul, [ int(p) for p in match.group( 1 ).split() ] )
                computed_results = process_parallel( binary, input_file, procs, logger )
            
            # Otherwise, just do a serial run
            else:
                computed_results = process_serial( binary, input_file )
                
            # Split the expected results into a list of text values
            expected_results = expected_results.split()
            for i in range( len( expected_results ) ):
            
                # If the expected result is a star, it means ignore that result
                if expected_results[i] == '*':
                    continue
                    
                # Compare the expected to computed results
                computed_result = computed_results[i]
                expected_result = float( expected_results[i] )
                logger.message( "Testing computed result %.12E against expected result %12E" % ( computed_result, expected_result ) )
                check_results( computed_result, expected_result, input_file, logger, ocd )

        # Record the end time after the test
        end_time = datetime.datetime.now()
        elapsed_time = end_time - start_time
        net_time += elapsed_time
        stopwatch = elapsed_time.seconds + elapsed_time.microseconds / 1e6
        
        # Log the elapsed time for this test
        logger.message( "Elapsed time: %f seconds" % stopwatch )
        logger.message( '-' * 80 )

    stopwatch = net_time.seconds + net_time.microseconds / 1e6
    
    # Log the elapsed time for all tests that were run
    logger.message( "Total elapsed time: %f seconds" % stopwatch )
    logger.message( "Test results have been logged" )
    logger.message( '-' * 80 )
    logger.log( "Time:           %d seconds" % stopwatch )

    os.chdir( '../../tests' )
Exemple #3
0
def run_test( binary, test_files, test_name, test_directory, logger, ocd ):
    """
    Runs a given test from the test cases file
    """
    
    logger.log( '=' * 80 )
    logger.log( "Test Timestamp: %s" % str( datetime.datetime.now() ) )
    logger.log( "Test Name:      %s" % test_name )
    logger.log( "Test Directory: %s" % test_directory )

    # The net time is initially zero
    net_time = datetime.timedelta( 0 )

    # Change the current working directory to the test directory
    os.chdir( test_directory )

    for ( base_name, expected_results ) in test_files:

        # Get the name of the input file from the base name
        input_file = '%s.in' % base_name

        # If the expected results is 'forces', do a forces test on the input
        if expected_results == 'forces':
            logger.message( '-' * 80 )
            logger.message( 'Testing forces from %s' % input_file )
            logger.message( '' )
            logger.log( 'Testing forces from %s' % input_file )
            start_time = datetime.datetime.now()
            check_forces( input_file, 'polarforces', 'apolarforces', logger )
            
        else:
            logger.message( '-' * 80 )
            logger.message( 'Testing input file %s' % input_file )
            logger.message( '' )
            logger.log( 'Testing %s' % input_file )
            
            # Record the start time before the test runs
            start_time = datetime.datetime.now()

            computed_results = None
            
            # Determine if this is a parallel run
            match = re.search( r'\s*pdime((\s+\d+)+)', open( input_file, 'r' ).read() )
            
            # If it is parallel, get the number of procs and do a parallel run
            if match:
                procs = reduce( operator.mul, [ int(p) for p in match.group( 1 ).split() ] )
                computed_results = process_parallel( binary, input_file, procs, logger )
            
            # Otherwise, just do a serial run
            else:
                computed_results = process_serial( binary, input_file )
                
            # Split the expected results into a list of text values
            expected_results = expected_results.split()
            for i in range( len( expected_results ) ):
            
                # If the expected result is a star, it means ignore that result
                if expected_results[i] == '*':
                    continue
                    
                # Compare the expected to computed results
                
                computed_result = computed_results[i]
                expected_result = float( expected_results[i] )
                logger.message( "Testing computed result %.12E against expected result %12E" % ( computed_result, expected_result ) )
                check_results( computed_result, expected_result, input_file, logger, ocd )

        # Record the end time after the test
        end_time = datetime.datetime.now()
        elapsed_time = end_time - start_time
        net_time += elapsed_time
        stopwatch = elapsed_time.seconds + elapsed_time.microseconds / 1e6
        
        # Log the elapsed time for this test
        logger.message( "Elapsed time: %f seconds" % stopwatch )
        logger.message( '-' * 80 )

    stopwatch = net_time.seconds + net_time.microseconds / 1e6
    
    # Log the elapsed time for all tests that were run
    logger.message( "Total elapsed time: %f seconds" % stopwatch )
    logger.message( "Test results have been logged" )
    logger.message( '-' * 80 )
    logger.log( "Time:           %d seconds" % stopwatch )

    os.chdir( '../../tests' )