'Build and run a small program to test the installed HDF5 Blosc plugin'

def check_install(self, spec):

    print('Checking    HDF5-Blosc    plugin...')
    checkdir = 'spack-check'
    with working_dir(checkdir, create=True):
        source = '\\\n#include    <hdf5.h>\n#include    <assert.h>\n#include    <stdio.h>\n#include    <stdlib.h>\n\n#define    FILTER_BLOSC    32001    /*    Blosc    filter    ID    registered    with    the    HDF    group    */\n\nint    main(int    argc,    char    **argv)    {\n        herr_t    herr;\n        hid_t    file    =    H5Fcreate("file.h5",    H5F_ACC_TRUNC,    H5P_DEFAULT,    H5P_DEFAULT);\n        assert(file    >=    0);\n        hsize_t    dims[3]    =    {10,    10,    10};\n        hid_t    space    =    H5Screate_simple(3,    dims,    NULL);\n        assert(space    >=    0);\n        hid_t    create_proplist    =    H5Pcreate(H5P_DATASET_CREATE);\n        assert(create_proplist    >=    0);\n        herr    =    H5Pset_chunk(create_proplist,    3,    dims);\n        assert(herr    >=    0);\n        herr    =    H5Pset_filter(create_proplist,    FILTER_BLOSC,    H5Z_FLAG_OPTIONAL,    0,\n                                                                                            NULL);\n        assert(herr    >=    0);\n        htri_t    all_filters_avail    =    H5Pall_filters_avail(create_proplist);\n        assert(all_filters_avail    >    0);\n        hid_t    dataset    =    H5Dcreate(file,    "dataset",    H5T_NATIVE_DOUBLE,    space,\n                                                                                                                H5P_DEFAULT,    create_proplist,    H5P_DEFAULT);\n        assert(dataset    >=    0);\n        double    data[10][10][10];\n        for    (int    k=0;    k<10;    ++k)    {\n                for    (int    j=0;    j<10;    ++j)    {\n                        for    (int    i=0;    i<10;    ++i)    {\n                                data[k][j][i]    =    1.0    /    (1.0    +    i    +    j    +    k);\n                        }\n                }\n        }\n        herr    =    H5Dwrite(dataset,    H5T_NATIVE_DOUBLE,    space,    space,    H5P_DEFAULT,\n                                                                        &data[0][0][0]);\n        assert(herr    >=    0);\n        herr    =    H5Pclose(create_proplist);\n        assert(herr    >=    0);\n        herr    =    H5Dclose(dataset);\n        assert(herr    >=    0);\n        herr    =    H5Sclose(space);\n        assert(herr    >=    0);\n        herr    =    H5Fclose(file);\n        assert(herr    >=    0);\n        printf("Done.\\n");\n        return    0;\n}\n'
        expected = 'Done.\n'
        with open('check.c', 'w') as f:
            f.write(source)
        if ('+mpi' in spec['hdf5']):
            cc = Executable(spec['mpi'].mpicc)
        else:
            cc = Executable(self.compiler.cc)
        cc('-c', ('-I%s' % spec['hdf5'].prefix.include), 'check.c')
        cc('-o', 'check', 'check.o', ('-L%s' % spec['hdf5'].prefix.lib), '-lhdf5')
        try:
            check = Executable('./check')
            output = check(output=str)
        except:
            output = ''
        success = (output == expected)
        if (not success):
            print('Produced    output    does    not    match    expected    output.')
            print('Expected    output:')
            print(('-' * 80))
            print(expected)
            print(('-' * 80))
            print('Produced    output:')
            print(('-' * 80))
            print(output)
            print(('-' * 80))
            print('Environment:')
            env = which('env')
            env()
            raise RuntimeError('HDF5    Blosc    plugin    check    failed')
    shutil.rmtree(checkdir)
