11// SPDX-License-Identifier: BSD-3-Clause
2- /* Copyright 2015-2020 , Intel Corporation */
2+ /* Copyright 2015-2021 , Intel Corporation */
33
44/*
55 * obj_cpp_pool.c -- cpp pool implementation test
@@ -23,6 +23,27 @@ struct root {
2323 nvobj::p<int > val;
2424};
2525
26+ /* emulate no more space in the memory */
27+ void *
28+ null_alloc_func (size_t s)
29+ {
30+ errno = ENOSPC;
31+ return nullptr ;
32+ }
33+
34+ void
35+ test_pool_exceptions ()
36+ {
37+ /* try catching pool_invalid_argument as a pool_error */
38+ try {
39+ throw pmem::pool_invalid_argument (" test" );
40+ } catch (pmem::pool_error &e) {
41+ return ;
42+ }
43+
44+ UT_ASSERT (0 );
45+ }
46+
2647/*
2748 * pool_create -- (internal) test pool create
2849 */
@@ -35,9 +56,12 @@ pool_create(const char *path, const char *layout, size_t poolsize,
3556 pop = nvobj::pool<root>::create (path, layout, poolsize, mode);
3657 nvobj::persistent_ptr<root> root = pop.root ();
3758 UT_ASSERT (root != nullptr );
38- } catch (pmem::pool_error &e) {
59+ } catch (pmem::pool_invalid_argument &e) {
3960 UT_OUT (" %s: pool::create: %s" , path, e.what ());
4061 return ;
62+ } catch (pmem::pool_error &e) {
63+ UT_OUT (" %s: pool::create: (pool_error) %s" , path, e.what ());
64+ return ;
4165 }
4266
4367 os_stat_t stbuf;
@@ -69,9 +93,12 @@ pool_open(const char *path, const char *layout)
6993 nvobj::pool<root> pop;
7094 try {
7195 pop = nvobj::pool<root>::open (path, layout);
72- } catch (pmem::pool_error &e) {
96+ } catch (pmem::pool_invalid_argument &e) {
7397 UT_OUT (" %s: pool::open: %s" , path, e.what ());
7498 return ;
99+ } catch (pmem::pool_error &e) {
100+ UT_OUT (" %s: pool::open: (pool_error) %s" , path, e.what ());
101+ return ;
75102 }
76103
77104 UT_OUT (" %s: pool::open: Success" , path);
@@ -142,6 +169,9 @@ test(int argc, char *argv[])
142169 layout = argv[3 ];
143170
144171 switch (argv[1 ][0 ]) {
172+ case ' n' :
173+ pmemobj_set_funcs (null_alloc_func, NULL , NULL , NULL );
174+ /* no break */
145175 case ' c' :
146176 poolsize = std::stoul (argv[4 ], nullptr , 0 ) *
147177 MB; /* in megabytes */
@@ -165,6 +195,8 @@ test(int argc, char *argv[])
165195 default :
166196 UT_FATAL (" unknown operation" );
167197 }
198+
199+ test_pool_exceptions ();
168200}
169201
170202int
0 commit comments