@@ -15,21 +15,22 @@ using os_params_unique_handle_t =
1515 std::unique_ptr<umf_os_memory_provider_params_t ,
1616 decltype (&umfOsMemoryProviderParamsDestroy)>;
1717
18- os_params_unique_handle_t createOsMemoryProviderParams () {
18+ void * createOsMemoryProviderParams () {
1919 umf_os_memory_provider_params_handle_t params = nullptr ;
2020 umf_result_t res = umfOsMemoryProviderParamsCreate (¶ms);
2121 if (res != UMF_RESULT_SUCCESS) {
2222 throw std::runtime_error (" Failed to create os memory provider params" );
2323 }
2424
25- return os_params_unique_handle_t ( params, &umfOsMemoryProviderParamsDestroy) ;
25+ return params;
2626}
27- auto defaultParams = createOsMemoryProviderParams();
2827
29- INSTANTIATE_TEST_SUITE_P (jemallocPoolTest, umfPoolTest,
30- ::testing::Values (poolCreateExtParams{
31- umfJemallocPoolOps (), nullptr ,
32- umfOsMemoryProviderOps (), defaultParams.get ()}));
28+ INSTANTIATE_TEST_SUITE_P (
29+ jemallocPoolTest, umfPoolTest,
30+ ::testing::Values (poolCreateExtParams{
31+ umfJemallocPoolOps (), nullptr , nullptr , umfOsMemoryProviderOps (),
32+ createOsMemoryProviderParams,
33+ (pfnProviderParamsDestroy)umfOsMemoryProviderParamsDestroy}));
3334
3435// this test makes sure that jemalloc does not use
3536// memory provider to allocate metadata (and hence
@@ -41,17 +42,41 @@ TEST_F(test, metadataNotAllocatedUsingProvider) {
4142
4243 // set coarse grain allocations to PROT_NONE so that we can be sure
4344 // jemalloc does not touch any of the allocated memory
44- umf_os_memory_provider_params_handle_t params = nullptr ;
45- umf_result_t res = umfOsMemoryProviderParamsCreate (¶ms);
46- ASSERT_EQ (res, UMF_RESULT_SUCCESS);
47- res = umfOsMemoryProviderParamsSetProtection (params, UMF_PROTECTION_NONE);
48- ASSERT_EQ (res, UMF_RESULT_SUCCESS);
4945
50- auto pool = poolCreateExtUnique (
51- {umfJemallocPoolOps (), nullptr , umfOsMemoryProviderOps (), params});
46+ auto providerParamsCreate = []() {
47+ umf_os_memory_provider_params_handle_t params = nullptr ;
48+ umf_result_t res = umfOsMemoryProviderParamsCreate (¶ms);
49+ if (res != UMF_RESULT_SUCCESS) {
50+ throw std::runtime_error (
51+ " Failed to create OS Memory Provider params" );
52+ }
53+ res =
54+ umfOsMemoryProviderParamsSetProtection (params, UMF_PROTECTION_NONE);
55+ if (res != UMF_RESULT_SUCCESS) {
56+ throw std::runtime_error (
57+ " Failed to set OS Memory Provider params protection" );
58+ }
59+ return (void *)params;
60+ };
61+
62+ auto providerParamsDestroy = [](void *params) {
63+ umf_result_t res = umfOsMemoryProviderParamsDestroy (
64+ (umf_os_memory_provider_params_handle_t )params);
65+ if (res != UMF_RESULT_SUCCESS) {
66+ throw std::runtime_error (
67+ " Failed to destroy OS Memory Provider params" );
68+ }
69+ return res;
70+ };
5271
53- res = umfOsMemoryProviderParamsDestroy (params);
54- ASSERT_EQ (res, UMF_RESULT_SUCCESS);
72+ auto pool = poolCreateExtUnique ({
73+ umfJemallocPoolOps (),
74+ nullptr ,
75+ nullptr ,
76+ umfOsMemoryProviderOps (),
77+ (pfnProviderParamsCreate)providerParamsCreate,
78+ (pfnProviderParamsDestroy)providerParamsDestroy,
79+ });
5580
5681 std::vector<std::shared_ptr<void >> allocs;
5782 for (size_t i = 0 ; i < numAllocs; i++) {
0 commit comments