~ubuntu-branches/ubuntu/vivid/ffc/vivid

« back to all changes in this revision

Viewing changes to test/regression/test.py

  • Committer: Package Import Robot
  • Author(s): Johannes Ring
  • Date: 2014-01-10 13:56:45 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20140110135645-4ozcd71y1oggj44z
Tags: 1.3.0-1
* New upstream release.
* debian/watch: Update URL for move to Bitbucket.
* debian/docs: README -> README.rst and remove TODO.
* debian/control:
  - Add python-numpy to Build-Depends.
  - Replace python-all with python-all-dev in Build-Depends.
  - Add ${shlibs:Depends} to Depends.
  - Change to Architecture: any.
  - Bump Standards-Version to 3.9.5 (no changes needed).
* debian/rules: Call dh_numpy in override_dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
This script can also be used for benchmarking tabulate_tensor for all
8
8
form files found in the 'bench' directory. To run benchmarks, use the
9
9
option --bench.
 
10
 
10
11
"""
11
12
 
12
13
# Copyright (C) 2010-2013 Anders Logg, Kristian B. Oelgaard and Marie E. Rognes
27
28
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
28
29
#
29
30
# Modified by Martin Alnaes, 2013
 
31
# Modified by Johannes Ring, 2013
 
32
# Modified by Kristian B. Oelgaard, 2013
 
33
# Modified by Garth N. Wells, 2014
30
34
#
31
35
# First added:  2010-01-21
32
 
# Last changed: 2013-02-14
33
36
 
34
37
# FIXME: Need to add many more test cases. Quite a few DOLFIN forms
35
38
# failed after the FFC tests passed.
42
45
import time
43
46
 
44
47
# Parameters
 
48
debug = False # TODO: Can make this a cmdline argument, and start crashing programs in debugger automatically?
45
49
output_tolerance = 1.e-6
46
50
demo_directory = "../../../../demo"
47
51
bench_directory = "../../../../bench"
67
71
_command_timings = []
68
72
def run_command(command):
69
73
    "Run command and collect errors in log file."
 
74
    # Debugging:
 
75
    #print "IN DIRECTORY:", os.path.abspath(os.curdir)
 
76
    #print "RUNNING COMMAND:", command
70
77
    t1 = time.time()
71
78
    (status, output) = get_status_output(command)
72
79
    t2 = time.time()
138
145
 
139
146
    begin("Generating code (%d form files found)" % len(form_files))
140
147
 
141
 
    # TODO: Parse additional options from .ufl file? I.e. grep for some sort of tag like '#ffc: <flags>'.
 
148
    # TODO: Parse additional options from .ufl file? I.e. grep for
 
149
    # some sort of tag like '#ffc: <flags>'.
142
150
    special = {
143
151
        "AdaptivePoisson.ufl": "-e",
144
152
        }
227
235
        if os.path.isfile(os.path.join(boost_dir, inc_dir, "boost", "version.hpp")):
228
236
            boost_inc_dir = os.path.join(boost_dir, inc_dir)
229
237
            break
230
 
    for lib_dir in ["", "lib"]:
 
238
    for lib_dir in ["", "lib", "lib/x86_64-linux-gnu"]:
231
239
        for ext in [".so", "-mt.so", ".dylib", "-mt.dylib"]:
232
240
            _lib = os.path.join(boost_dir, lib_dir, "lib" + boost_math_tr1_lib + ext)
233
241
            if os.path.isfile(_lib):
249
257
    # Set compiler options
250
258
    compiler_options = "%s -Wall" % ufc_cflags
251
259
    if not permissive:
252
 
        compiler_options += " -Werror"
 
260
        compiler_options += " -Werror -pedantic"
253
261
    if bench:
254
262
        info("Benchmarking activated")
255
263
        # Takes too long to build with -O2
256
264
        #compiler_options += " -O2"
 
265
        compiler_options += " -O3"
 
266
        #compiler_options += " -O3 -fno-math-errno -march=native"
 
267
    if debug:
 
268
        info("Debugging activated")
 
269
        compiler_options += " -g -O0"
257
270
    info("Compiler options: %s" % compiler_options)
258
271
 
259
272
    # Iterate over all files
311
324
    "Validate generated programs against references."
312
325
 
313
326
    # Get a list of all files
314
 
    output_files = [f for f in os.listdir(".") if f.endswith(".out")]
 
327
    output_files = [f for f in os.listdir(".") if f.endswith(".json")]
315
328
    output_files.sort()
316
329
 
317
330
    begin("Validating generated programs (%d programs found)" % len(output_files))
396
409
            info_blue("Missing reference for %s" % reference_json_file)
397
410
            reference_json_output = "{}"
398
411
 
399
 
        # Compare json with reference using recursive diff algorithm # TODO: Write to different error file?
 
412
        # Compare json with reference using recursive diff algorithm
 
413
        # TODO: Write to different error file?
400
414
        from recdiff import recdiff, print_recdiff, DiffEqual
401
415
        # Assuming reference is well formed
402
416
        reference_json_output = eval(reference_json_output)
415
429
            info_green("%s OK" % fj)
416
430
        else:
417
431
            info_red("%s differs" % fj)
418
 
            log_error("Json output differs for %s, diff follows (reference first, generated second)"
 
432
            log_error("Json output differs for %s, diff follows (generated first, reference second)"
419
433
                      % os.path.join(*reference_json_file.split(os.path.sep)[-3:]))
420
434
            print_recdiff(json_diff, printer=log_error)
421
435
 
428
442
    generate_only  = "--generate-only" in args
429
443
    fast           = "--fast" in args
430
444
    bench          = "--bench" in args
431
 
    use_quad       = "--skip_quad" not in args
432
 
    use_ext_quad   = "--ext_quad" in args
433
 
    use_ext_uflacs = "--ext_uflacs" in args
 
445
    use_quad       = "--skip-quad" not in args
 
446
    use_ext_quad   = "--ext-quad" in args
 
447
    use_ext_uflacs = "--ext-uflacs" in args
434
448
    permissive     = "--permissive" in args
435
449
    tolerant       = "--tolerant" in args
436
450
    print_timing   = "--print-timing" in args
 
451
    skip_download  = "--skip-download" in args
437
452
 
438
453
    flags = (
439
454
        "--generate-only",
440
455
        "--fast",
441
456
        "--bench",
442
 
        "--skip_quad",
443
 
        "--ext_quad",
444
 
        "--ext_uflacs",
 
457
        "--skip-quad",
 
458
        "--ext-quad",
 
459
        "--ext-uflacs",
445
460
        "--permissive",
446
461
        "--tolerant",
447
462
        "--print-timing",
 
463
        "--skip-download",
448
464
        )
449
465
    args = [arg for arg in args if not arg in flags]
450
466
 
452
468
    only_forms = set([arg for arg in args if arg.endswith(".ufl")])
453
469
    args = [arg for arg in args if arg not in only_forms]
454
470
 
 
471
    # Download reference data
 
472
    if skip_download:
 
473
        info_blue("Skipping reference data download")
 
474
    else:
 
475
        failure, output = get_status_output("./scripts/download")
 
476
        print output
 
477
        if failure:
 
478
            info_red("Download reference data failed")
 
479
        else:
 
480
            info_green("Download reference data ok")
 
481
 
455
482
    if tolerant:
456
483
        global output_tolerance
457
484
        output_tolerance = 1e-3
470
497
        test_cases += ext_quad
471
498
    if use_ext_uflacs:
472
499
        test_cases = ext_uflacs
473
 
        #test_cases += ["-r quadrature -O"]
 
500
        test_cases += ["-r quadrature -O"]
474
501
 
475
502
    for argument in test_cases:
476
503
 
488
515
        generate_code(args + [argument], only_forms)
489
516
 
490
517
        # Location of reference directories
491
 
        reference_directory =  os.path.abspath("../../references/")
 
518
        reference_directory =  os.path.abspath("../../ffc-reference-data/")
492
519
        code_reference_dir = os.path.join(reference_directory, sub_directory)
493
 
        output_reference_dir = os.path.join(reference_directory, "output")
 
520
 
 
521
        # Note: We use the r_auto references for all test cases. This
 
522
        # ensures that we continously test that the codes generated by
 
523
        # all different representations are equivalent.
 
524
        output_reference_dir = os.path.join(reference_directory, "r_auto")
494
525
 
495
526
        # Validate code by comparing to code generated with this set
496
527
        # of compiler parameters