Skip to content

Commit

Permalink
Fixing trap test.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitenti committed Apr 13, 2024
1 parent 583cf25 commit e18e78c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 28 deletions.
37 changes: 29 additions & 8 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ numcosmo_libdir = join_paths(numcosmo_prefix, get_option('libdir'))
numcosmo_libexecdir = join_paths(numcosmo_prefix, get_option('libexecdir'))
numcosmo_datadir = join_paths(numcosmo_prefix, get_option('datadir'))
numcosmo_pkgdatadir = join_paths(numcosmo_datadir, numcosmo_fullname)
numcosmo_includedir = join_paths(numcosmo_prefix, get_option('includedir'), 'numcosmo')
numcosmo_includedir = join_paths(
numcosmo_prefix,
get_option('includedir'),
'numcosmo',
)

numcosmo_pkgconfigreldir = join_paths(numcosmo_libdir, 'pkgconfig')

Expand Down Expand Up @@ -140,9 +144,15 @@ numcosmo_conf.set('NUMCOSMO_MINOR_VERSION', minor_version)
numcosmo_conf.set('NUMCOSMO_MICRO_VERSION', micro_version)
numcosmo_conf.set('NUMCOSMO_INTERFACE_AGE', interface_age)
numcosmo_conf.set('NUMCOSMO_BINARY_AGE', binary_age)
numcosmo_conf.set_quoted('PACKAGE_BUGREPORT', 'https://github.com/NumCosmo/NumCosmo/issues')
numcosmo_conf.set_quoted(
'PACKAGE_BUGREPORT',
'https://github.com/NumCosmo/NumCosmo/issues',
)
numcosmo_conf.set_quoted('PACKAGE_NAME', 'numcosmo')
numcosmo_conf.set_quoted('PACKAGE_STRING', 'numcosmo @0@'.format(meson.project_version()))
numcosmo_conf.set_quoted(
'PACKAGE_STRING',
'numcosmo @0@'.format(meson.project_version()),
)
numcosmo_conf.set_quoted('PACKAGE_TARNAME', 'numcosmo')
numcosmo_conf.set_quoted('PACKAGE_URL', 'https://github.com/NumCosmo/NumCosmo')
numcosmo_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
Expand Down Expand Up @@ -184,7 +194,9 @@ if (
and (host_system == 'windows'
or host_system == 'cygwin')
)
error('On Windows default_library must be "shared" or "static" but not "both"')
error(
'On Windows default_library must be "shared" or "static" but not "both"',
)
endif

if numcosmo_build_static_only
Expand All @@ -203,9 +215,11 @@ numcosmo_debug_cflags = []
numcosmo_debug = get_option('numcosmo_debug')
if (
numcosmo_debug.enabled()
or (numcosmo_debug.auto()
and get_option('debug')
and get_option('optimization') in ['0', 'g'])
or (
numcosmo_debug.auto()
and get_option('debug')
and get_option('optimization') in ['0', 'g']
)
)
numcosmo_debug_cflags += ['-DG_ENABLE_DEBUG']
message('Enabling various debug infrastructure')
Expand Down Expand Up @@ -316,6 +330,10 @@ if cc.compiles(
cc_supports_c99_vla = true
endif

if get_option('b_coverage')
add_global_arguments('-DUSE_GCOV', language: 'c')
endif

#######################################################################################
# Types:
#######################################################################################
Expand Down Expand Up @@ -440,7 +458,10 @@ omp_fortran = dependency(
#######################################################################################
message('Checking for GObject introspection')

gir_scanner = find_program('g-ir-scanner', required: get_option('introspection'))
gir_scanner = find_program(
'g-ir-scanner',
required: get_option('introspection'),
)

enable_gir = false
if gir_scanner.found()
Expand Down
22 changes: 21 additions & 1 deletion numcosmo/math/ncm_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,26 @@ static gboolean _enable_msg = TRUE;
static gboolean _enable_msg_flush = TRUE;
static gsl_error_handler_t *gsl_err = NULL;

# if (defined (__GNUC__) \
&& ((__GNUC__ == 11 && __GNUC_MINOR__ >= 1) || (__GNUC__ >= 12))) \
|| (defined (__clang__) && (__clang_major__ >= 12))
extern void __gcov_dump (void);
extern void __gcov_reset (void);

# define __gcov_flush() \
do { \
__gcov_dump (); __gcov_reset (); \
} while (0)
# else
extern void __gcov_flush (void);

# endif

static void
_ncm_cfg_log_message (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
{
NCM_UNUSED (log_domain);

NCM_UNUSED (log_level);
NCM_UNUSED (user_data);

Expand Down Expand Up @@ -279,14 +295,18 @@ _ncm_cfg_log_error (const gchar *log_domain, GLogLevelFlags log_level, const gch
/* print out all the frames to stderr */
for (i = 0; i < size; i++)
{
fprintf (_log_stream_err, "# (%s): %s-BACKTRACE:[%02zd] %s\n", pname, log_domain, i, trace[i]);
fprintf (_log_stream_err, "# (%s): %s-BACKTRACEA:[%02zd] %s\n", pname, log_domain, i, trace[i]);
}

g_free (trace);
}
#endif
fflush (_log_stream_err);

#ifdef USE_GCOV
__gcov_flush ();
#endif

abort ();
}

Expand Down
36 changes: 20 additions & 16 deletions tests/test_nc_cluster_abundance.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ test_nc_cluster_abundance_free (TestNcClusterAbundance *test, gconstpointer pdat
void
test_nc_cluster_abundance_sanity (TestNcClusterAbundance *test, gconstpointer pdata)
{
NcmRNG *rng = ncm_rng_new (NULL);
NcHaloMassFunction *mfp = NC_HALO_MASS_FUNCTION(test->cad->mfp);
NcmRNG *rng = ncm_rng_new (NULL);
NcHaloMassFunction *mfp = NC_HALO_MASS_FUNCTION (test->cad->mfp);


nc_data_cluster_ncount_init_from_sampling (test->ncdata, test->mset, test->area, rng);
g_assert_true (nc_halo_mass_function_peek_survey_area(mfp) == test->area);
g_assert_true(nc_halo_mass_function_d2n_dzdlnM(mfp , test->cosmo ,100 , 1000) == mfp->mf_lb);
g_assert_true (nc_halo_mass_function_peek_survey_area (mfp) == test->area);
g_assert_true (nc_halo_mass_function_d2n_dzdlnM (mfp, test->cosmo, 100, 1000) == mfp->mf_lb);

{
gchar *desc = ncm_data_get_desc (NCM_DATA (test->ncdata));
Expand Down Expand Up @@ -291,22 +291,22 @@ void
test_nc_cluster_abundance_intp_bin_d2n (TestNcClusterAbundance *test, gconstpointer pdata)
{
test_nc_cluster_abundance_sanity (test, pdata);
const gdouble lnM_obs_bin_lower[1] = {0.0};
const gdouble lnM_obs_bin_upper[1] = {0.5};
const gdouble z_obs_bin_lower[1] = {0.1};
const gdouble z_obs_bin_upper[1] = {0.3};

gdouble d2n_bin1 = nc_cluster_abundance_intp_bin_d2n (test->cad, test->cosmo, test->clusterz, test->clusterm, lnM_obs_bin_lower, lnM_obs_bin_upper, NULL, z_obs_bin_lower, z_obs_bin_upper, NULL);
gdouble d2n_bin2 = nc_cluster_abundance_intp_bin_d2n (test->cad, test->cosmo, test->clusterz, test->clusterm, lnM_obs_bin_lower, lnM_obs_bin_upper, NULL, z_obs_bin_lower, z_obs_bin_upper, NULL);
const gdouble lnM_obs_bin_lower[1] = {0.0};
const gdouble lnM_obs_bin_upper[1] = {0.5};
const gdouble z_obs_bin_lower[1] = {0.1};
const gdouble z_obs_bin_upper[1] = {0.3};

gdouble d2n_bin1 = nc_cluster_abundance_intp_bin_d2n (test->cad, test->cosmo, test->clusterz, test->clusterm, lnM_obs_bin_lower, lnM_obs_bin_upper, NULL, z_obs_bin_lower, z_obs_bin_upper, NULL);
gdouble d2n_bin2 = nc_cluster_abundance_intp_bin_d2n (test->cad, test->cosmo, test->clusterz, test->clusterm, lnM_obs_bin_lower, lnM_obs_bin_upper, NULL, z_obs_bin_lower, z_obs_bin_upper, NULL);


g_assert_true (gsl_finite (d2n_bin1));
g_assert_true (gsl_finite (d2n_bin2));

ncm_assert_cmpdouble_e (d2n_bin1, ==, d2n_bin2, 1.0e-15, 0.0);
}
g_assert_true (gsl_finite (d2n_bin1));
g_assert_true (gsl_finite (d2n_bin2));

ncm_assert_cmpdouble_e (d2n_bin1, ==, d2n_bin2, 1.0e-15, 0.0);
}

void
test_nc_cluster_abundance_intp_d2n_bias (TestNcClusterAbundance *test, gconstpointer pdata)
Expand Down Expand Up @@ -364,6 +364,8 @@ test_nc_cluster_abundance_failing_intp_bin_d2n (TestNcClusterAbundance *test, gc
if (g_test_subprocess ())
{
/* Here we are in the subprocess, it is safe to die here. */
test_nc_cluster_abundance_sanity (test, pdata);

const gdouble lnM_obs_bin_lower[1] = {0.0};
const gdouble lnM_obs_bin_upper[1] = {0.5};
const gdouble z_obs_bin_lower[1] = {0.1};
Expand All @@ -377,5 +379,7 @@ test_nc_cluster_abundance_failing_intp_bin_d2n (TestNcClusterAbundance *test, gc

/* Reruns this same test in a subprocess */
g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_stderr ("*_nc_cluster_abundance_z_intp_lnM_intp_bin_N_integrand: negative integrand at*");
g_test_trap_assert_failed ();
}
}

7 changes: 4 additions & 3 deletions tests/test_nc_data_cluster_ncounts_gauss.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ test_nc_data_cluster_ncounts_gauss_serialize (TestNcClusterNCountsGauss *test, g
{
nc_data_cluster_ncounts_gauss_set_z_obs_params (test->ncounts_gauss, test->z_obs_params);
nc_data_cluster_ncounts_gauss_set_lnM_obs_params (test->ncounts_gauss, test->lnM_obs_params);
nc_data_cluster_ncounts_gauss_set_s_matrix (test->ncounts_gauss, test->s_matrix);
nc_data_cluster_ncounts_gauss_set_resample_s_matrix (test->ncounts_gauss, test->resample_s_matrix);
}
{
NcmSerialize *ser = ncm_serialize_new (NCM_SERIALIZE_OPT_CLEAN_DUP);
Expand Down Expand Up @@ -265,15 +267,14 @@ test_nc_data_cluster_ncounts_gauss_s_matrix (TestNcClusterNCountsGauss *test, gc
void
test_nc_data_cluster_ncounts_gauss_mean_func (TestNcClusterNCountsGauss *test, gconstpointer pdata)
{
guint i;
NcmVector *mean;
NcmDataGaussCov *gauss_cov = NCM_DATA_GAUSS_COV (test->ncounts_gauss);
NcmVector *mean;
guint i;

ncm_data_set_init (NCM_DATA (gauss_cov), TRUE);

mean = ncm_vector_dup (ncm_data_gauss_cov_compute_mean (gauss_cov, test->mset));


for (i = 0; i < ncm_vector_len (mean); i++)
{
g_assert_true (gsl_finite (ncm_vector_get (mean, i)));
Expand Down

0 comments on commit e18e78c

Please sign in to comment.