-
Notifications
You must be signed in to change notification settings - Fork 508
/
Copy pathobj_memops.c
736 lines (588 loc) · 17.9 KB
/
obj_memops.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018-2023, Intel Corporation */
/* Copyright 2025 Hewlett Packard Enterprise Development LP */
/*
* obj_memops.c -- basic memory operations tests
*
*/
#include <stddef.h>
#include "obj.h"
#include "memops.h"
#include "ulog.h"
#include "unittest.h"
#define TEST_ENTRIES 256
#define TEST_VALUES TEST_ENTRIES
enum fail_types {
FAIL_NONE,
FAIL_CHECKSUM,
FAIL_MODIFY_NEXT,
FAIL_MODIFY_VALUE,
};
struct test_object {
struct ULOG(TEST_ENTRIES) redo;
struct ULOG(TEST_ENTRIES) undo;
uint64_t values[TEST_VALUES];
};
static void
clear_test_values(struct test_object *object)
{
memset(object->values, 0, sizeof(uint64_t) * TEST_VALUES);
}
static int
redo_log_constructor(void *ctx, void *ptr, size_t usable_size, void *arg)
{
PMEMobjpool *pop = ctx;
const struct pmem_ops *p_ops = &pop->p_ops;
size_t capacity = ALIGN_DOWN(usable_size - sizeof(struct ulog),
CACHELINE_SIZE);
ulog_construct(OBJ_PTR_TO_OFF(ctx, ptr), capacity,
*(uint64_t *)arg, 1, 0, p_ops);
return 0;
}
static int
pmalloc_redo_extend(void *base, uint64_t *redo, uint64_t gen_num)
{
size_t s = SIZEOF_ALIGNED_ULOG(TEST_ENTRIES);
return pmalloc_construct(base, redo, s, redo_log_constructor, &gen_num,
0, OBJ_INTERNAL_OBJECT_MASK, 0);
}
static void
test_free_entry(void *base, uint64_t *next)
{
*next = 0;
VALGRIND_DO_PERSIST(next, sizeof(next));
/* noop for fake ulog entries */
}
static void
test_set_entries(PMEMobjpool *pop,
struct operation_context *ctx, struct test_object *object,
size_t nentries, enum fail_types fail, enum operation_log_type type)
{
operation_start(ctx);
UT_ASSERT(nentries <= ARRAY_SIZE(object->values));
for (size_t i = 0; i < nentries; ++i) {
operation_add_typed_entry(ctx,
&object->values[i], i + 1,
ULOG_OPERATION_SET, type);
}
operation_reserve(ctx, nentries * 16);
if (fail != FAIL_NONE) {
operation_cancel(ctx);
switch (fail) {
case FAIL_CHECKSUM:
object->redo.checksum += 1;
break;
case FAIL_MODIFY_NEXT:
pmalloc_redo_extend(pop,
&object->redo.next, 0);
break;
case FAIL_MODIFY_VALUE:
object->redo.data[16] += 8;
break;
default:
UT_ASSERT(0);
}
ulog_recover((struct ulog *)&object->redo,
OBJ_OFF_IS_VALID_FROM_CTX, &pop->p_ops);
for (size_t i = 0; i < nentries; ++i)
UT_ASSERTeq(object->values[i], 0);
} else {
operation_process(ctx);
operation_finish(ctx, 0);
for (size_t i = 0; i < nentries; ++i)
UT_ASSERTeq(object->values[i], i + 1);
}
}
static void
test_merge_op(struct operation_context *ctx, struct test_object *object)
{
operation_start(ctx);
operation_add_typed_entry(ctx,
&object->values[0], 0b10,
ULOG_OPERATION_OR, LOG_PERSISTENT);
operation_add_typed_entry(ctx,
&object->values[0], 0b01,
ULOG_OPERATION_OR, LOG_PERSISTENT);
operation_add_typed_entry(ctx,
&object->values[0], 0b00,
ULOG_OPERATION_AND, LOG_PERSISTENT);
operation_add_typed_entry(ctx,
&object->values[0], 0b01,
ULOG_OPERATION_OR, LOG_PERSISTENT);
operation_process(ctx);
operation_finish(ctx, 0);
UT_ASSERTeq(object->values[0], 0b01);
}
static void
test_same_twice(struct operation_context *ctx, struct test_object *object)
{
operation_start(ctx);
operation_add_typed_entry(ctx,
&object->values[0], 5,
ULOG_OPERATION_SET, LOG_PERSISTENT);
operation_add_typed_entry(ctx,
&object->values[0], 10,
ULOG_OPERATION_SET, LOG_PERSISTENT);
operation_process(ctx);
UT_ASSERTeq(object->values[0], 10);
operation_cancel(ctx);
}
static void
test_redo(PMEMobjpool *pop, struct test_object *object)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
struct operation_context *ctx = operation_new(
(struct ulog *)&object->redo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_REDO);
#pragma GCC diagnostic pop
/*
* Keep this test first.
* It tests a situation where the number of objects being added
* is equal to the capacity of the log.
*/
test_set_entries(pop, ctx, object, TEST_ENTRIES - 1,
FAIL_NONE, LOG_PERSISTENT);
clear_test_values(object);
test_set_entries(pop, ctx, object, 100, FAIL_NONE, LOG_TRANSIENT);
clear_test_values(object);
test_set_entries(pop, ctx, object, 10, FAIL_NONE, LOG_PERSISTENT);
clear_test_values(object);
test_merge_op(ctx, object);
clear_test_values(object);
test_set_entries(pop, ctx, object, 100, FAIL_NONE, LOG_PERSISTENT);
clear_test_values(object);
test_set_entries(pop, ctx, object, 100, FAIL_CHECKSUM, LOG_PERSISTENT);
clear_test_values(object);
test_set_entries(pop, ctx, object, 10, FAIL_CHECKSUM, LOG_PERSISTENT);
clear_test_values(object);
test_set_entries(pop, ctx, object, 100, FAIL_MODIFY_VALUE,
LOG_PERSISTENT);
clear_test_values(object);
test_set_entries(pop, ctx, object, 10, FAIL_MODIFY_VALUE,
LOG_PERSISTENT);
clear_test_values(object);
test_same_twice(ctx, object);
clear_test_values(object);
operation_delete(ctx);
/*
* Verify that rebuilding redo_next works. This requires that
* object->redo->next is != 0 - to achieve that, this test must
* be preceded by a test that fails to finish the ulog's operation.
*/
ctx = operation_new(
(struct ulog *)&object->redo, TEST_ENTRIES,
NULL, test_free_entry, &pop->p_ops, LOG_TYPE_REDO);
test_set_entries(pop, ctx, object, 100, 0, LOG_PERSISTENT);
clear_test_values(object);
/* FAIL_MODIFY_NEXT tests can only happen after redo_next test */
test_set_entries(pop, ctx, object, 100, FAIL_MODIFY_NEXT,
LOG_PERSISTENT);
clear_test_values(object);
test_set_entries(pop, ctx, object, 10, FAIL_MODIFY_NEXT,
LOG_PERSISTENT);
clear_test_values(object);
operation_delete(ctx);
}
static void
test_undo_small_single_copy(struct operation_context *ctx,
struct test_object *object)
{
operation_start(ctx);
object->values[0] = 1;
object->values[1] = 2;
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(*object->values) * 2,
ULOG_OPERATION_BUF_CPY);
object->values[0] = 2;
object->values[1] = 1;
operation_process(ctx);
operation_finish(ctx, ULOG_INC_FIRST_GEN_NUM);
operation_start(ctx);
UT_ASSERTeq(object->values[0], 1);
UT_ASSERTeq(object->values[1], 2);
object->values[0] = 2;
object->values[1] = 1;
operation_process(ctx);
UT_ASSERTeq(object->values[0], 2);
UT_ASSERTeq(object->values[1], 1);
operation_finish(ctx, ULOG_INC_FIRST_GEN_NUM);
}
static void
test_undo_small_single_set(struct operation_context *ctx,
struct test_object *object)
{
operation_start(ctx);
object->values[0] = 1;
object->values[1] = 2;
int c = 0;
operation_add_buffer(ctx,
&object->values, &c, sizeof(*object->values) * 2,
ULOG_OPERATION_BUF_SET);
operation_process(ctx);
UT_ASSERTeq(object->values[0], 0);
UT_ASSERTeq(object->values[1], 0);
operation_finish(ctx, ULOG_INC_FIRST_GEN_NUM);
}
static void
test_undo_small_multiple_set(struct operation_context *ctx,
struct test_object *object)
{
operation_start(ctx);
object->values[0] = 1;
object->values[1] = 2;
int c = 0;
operation_add_buffer(ctx,
&object->values[0], &c, sizeof(*object->values),
ULOG_OPERATION_BUF_SET);
operation_add_buffer(ctx,
&object->values[1], &c, sizeof(*object->values),
ULOG_OPERATION_BUF_SET);
operation_process(ctx);
UT_ASSERTeq(object->values[0], 0);
UT_ASSERTeq(object->values[1], 0);
operation_finish(ctx, ULOG_INC_FIRST_GEN_NUM);
}
static void
test_undo_large_single_copy(struct operation_context *ctx,
struct test_object *object)
{
operation_start(ctx);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 1;
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(object->values),
ULOG_OPERATION_BUF_CPY);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 2;
operation_process(ctx);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
UT_ASSERTeq(object->values[i], i + 1);
operation_finish(ctx, ULOG_INC_FIRST_GEN_NUM);
}
static void
test_undo_checksum_mismatch(PMEMobjpool *pop, struct operation_context *ctx,
struct test_object *object, struct ulog *log)
{
operation_start(ctx);
for (uint64_t i = 0; i < 20; ++i)
object->values[i] = i + 1;
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(*object->values) * 20,
ULOG_OPERATION_BUF_CPY);
for (uint64_t i = 0; i < 20; ++i)
object->values[i] = i + 2;
pmemobj_persist(pop, &object->values, sizeof(*object->values) * 20);
log->data[100] += 1; /* corrupt the log somewhere */
pmemobj_persist(pop, &log->data[100], sizeof(log->data[100]));
operation_process(ctx);
/* the log shouldn't get applied */
for (uint64_t i = 0; i < 20; ++i)
UT_ASSERTeq(object->values[i], i + 2);
operation_finish(ctx, ULOG_INC_FIRST_GEN_NUM);
}
static void
test_undo_large_copy(PMEMobjpool *pop, struct operation_context *ctx,
struct test_object *object)
{
operation_start(ctx);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 1;
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(object->values),
ULOG_OPERATION_BUF_CPY);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 2;
operation_process(ctx);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
UT_ASSERTeq(object->values[i], i + 1);
operation_finish(ctx, ULOG_INC_FIRST_GEN_NUM);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 3;
operation_start(ctx);
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(*object->values) * 26,
ULOG_OPERATION_BUF_CPY);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 4;
pmemobj_persist(pop, &object->values, sizeof(object->values));
operation_process(ctx);
for (uint64_t i = 0; i < 26; ++i)
UT_ASSERTeq(object->values[i], i + 3);
for (uint64_t i = 26; i < TEST_VALUES; ++i)
UT_ASSERTeq(object->values[i], i + 4);
operation_finish(ctx, ULOG_INC_FIRST_GEN_NUM);
}
static int
test_undo_foreach(struct ulog_entry_base *e, void *arg,
const struct pmem_ops *p_ops)
{
size_t *nentries = arg;
++(*nentries);
return 0;
}
/*
* drain_empty -- drain for pmem_ops
*/
static void
drain_empty(void *ctx)
{
/* do nothing */
}
/*
* persist_empty -- persist for pmem_ops
*/
static int
persist_empty(void *ctx, const void *addr, size_t len, unsigned flags)
{
return 0;
}
/*
* flush_empty -- flush for pmem_ops
*/
static int
flush_empty(void *ctx, const void *addr, size_t len, unsigned flags)
{
return 0;
}
/*
* memcpy_libc -- memcpy for pmem_ops
*/
static void *
memcpy_libc(void *ctx, void *dest, const void *src, size_t len, unsigned flags)
{
return memcpy(dest, src, len);
}
/*
* memset_libc -- memset for pmem_ops
*/
static void *
memset_libc(void *ctx, void *ptr, int c, size_t sz, unsigned flags)
{
return memset(ptr, c, sz);
}
/*
* test_undo_log_reuse -- test for correct reuse of log space
*/
static void
test_undo_log_reuse()
{
#define ULOG_SIZE 1024
struct pmem_ops ops = {
.persist = persist_empty,
.flush = flush_empty,
.drain = drain_empty,
.memcpy = memcpy_libc,
.memmove = NULL,
.memset = memset_libc,
.base = NULL,
};
struct ULOG(ULOG_SIZE) *first = util_aligned_malloc(CACHELINE_SIZE,
SIZEOF_ULOG(ULOG_SIZE));
struct ULOG(ULOG_SIZE) *second = util_aligned_malloc(CACHELINE_SIZE,
SIZEOF_ULOG(ULOG_SIZE));
ulog_construct((uint64_t)(first), ULOG_SIZE, 0, 0, 0, &ops);
ulog_construct((uint64_t)(second), ULOG_SIZE, 0, 0, 0, &ops);
first->next = (uint64_t)(second);
struct operation_context *ctx = operation_new(
(struct ulog *)first, ULOG_SIZE,
NULL, test_free_entry,
&ops, LOG_TYPE_UNDO);
size_t nentries = 0;
ulog_foreach_entry((struct ulog *)first,
test_undo_foreach, &nentries, &ops);
UT_ASSERTeq(nentries, 0);
/* first, let's populate the log with some valid entries */
size_t entry_size = (ULOG_SIZE / 2) - sizeof(struct ulog_entry_buf);
size_t total_entries = ((ULOG_SIZE * 2) / entry_size);
char *data = MALLOC(entry_size);
memset(data, 0xc, entry_size); /* fill it with something */
for (size_t i = 0; i < total_entries; ++i) {
operation_add_buffer(ctx, (void *)0x123, data,
entry_size,
ULOG_OPERATION_BUF_CPY);
nentries = 0;
ulog_foreach_entry((struct ulog *)first,
test_undo_foreach, &nentries, &ops);
UT_ASSERTeq(nentries, i + 1);
}
operation_init(ctx); /* initialize a new operation */
/* let's overwrite old entries and see if they are no longer visible */
for (size_t i = 0; i < total_entries; ++i) {
operation_add_buffer(ctx, (void *)0x123, data,
entry_size,
ULOG_OPERATION_BUF_CPY);
nentries = 0;
ulog_foreach_entry((struct ulog *)first,
test_undo_foreach, &nentries, &ops);
UT_ASSERTeq(nentries, i + 1);
}
FREE(data);
operation_delete(ctx);
util_aligned_free(first);
util_aligned_free(second);
#undef ULOG_SIZE
}
/*
* test_undo_log_reuse -- test for correct reuse of log space
*/
static void
test_undo_log_resume()
{
#define ULOG_SIZE 1024
struct pmem_ops ops = {
.persist = persist_empty,
.flush = flush_empty,
.drain = drain_empty,
.memcpy = memcpy_libc,
.memmove = NULL,
.memset = memset_libc,
.base = NULL,
};
struct ULOG(ULOG_SIZE) *first = util_aligned_malloc(CACHELINE_SIZE,
SIZEOF_ULOG(ULOG_SIZE));
struct ULOG(ULOG_SIZE) *second = util_aligned_malloc(CACHELINE_SIZE,
SIZEOF_ULOG(ULOG_SIZE));
ulog_construct((uint64_t)(first), ULOG_SIZE, 0, 0, 0, &ops);
ulog_construct((uint64_t)(second), ULOG_SIZE, 0, 0, 0, &ops);
first->next = (uint64_t)(second);
struct operation_context *ctx = operation_new(
(struct ulog *)first, ULOG_SIZE,
NULL, test_free_entry,
&ops, LOG_TYPE_UNDO);
/* first, let's populate the log with some valid entries */
size_t entry_size = (ULOG_SIZE / 2) - sizeof(struct ulog_entry_buf);
size_t total_entries = ((ULOG_SIZE * 2) / entry_size);
char *data = MALLOC(entry_size);
memset(data, 0xc, entry_size); /* fill it with something */
size_t nentries = 0;
for (size_t i = 0; i < total_entries; ++i) {
operation_add_buffer(ctx, (void *)0x123, data,
entry_size,
ULOG_OPERATION_BUF_CPY);
nentries = 0;
ulog_foreach_entry((struct ulog *)first,
test_undo_foreach, &nentries, &ops);
UT_ASSERTeq(nentries, i + 1);
}
/* break the log so that it can't be processed */
first->gen_num = 1;
/* resume and process the operation */
operation_resume(ctx);
operation_process(ctx);
operation_finish(ctx, ULOG_INC_FIRST_GEN_NUM |
ULOG_FREE_AFTER_FIRST);
/*
* The resumed log should continue to be functional, but with only
* the first log.
*/
for (size_t i = 0; i < total_entries / 2; ++i) {
operation_add_buffer(ctx, (void *)0x123, data,
entry_size,
ULOG_OPERATION_BUF_CPY);
nentries = 0;
ulog_foreach_entry((struct ulog *)first,
test_undo_foreach, &nentries, &ops);
UT_ASSERTeq(nentries, i + 1);
}
FREE(data);
operation_delete(ctx);
util_aligned_free(first);
util_aligned_free(second);
#undef ULOG_SIZE
}
/*
* test_undo_log_reuse -- test for correct reuse of log space
*/
static void
test_redo_cleanup_same_size(PMEMobjpool *pop, struct test_object *object)
{
#define ULOG_SIZE 1024
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
struct operation_context *ctx = operation_new(
(struct ulog *)&object->redo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_REDO);
#pragma GCC diagnostic pop
int ret = pmalloc(pop, &object->redo.next, ULOG_SIZE, 0, 0);
UT_ASSERTeq(ret, 0);
/* undo logs are clobbered at the end, which shrinks their size */
size_t capacity = ulog_capacity((struct ulog *)&object->undo,
TEST_ENTRIES, &pop->p_ops);
/* builtin log + one next */
UT_ASSERTeq(capacity, TEST_ENTRIES * 2 + CACHELINE_SIZE);
operation_start(ctx); /* initialize a new operation */
struct pobj_action act;
pmemobj_reserve(pop, &act, ULOG_SIZE, 0);
palloc_publish(&pop->heap, &act, 1, ctx);
operation_delete(ctx);
#undef ULOG_SIZE
}
static void
test_undo(PMEMobjpool *pop, struct test_object *object)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
struct operation_context *ctx = operation_new(
(struct ulog *)&object->undo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_UNDO);
#pragma GCC diagnostic pop
test_undo_small_single_copy(ctx, object);
test_undo_small_single_set(ctx, object);
test_undo_small_multiple_set(ctx, object);
test_undo_large_single_copy(ctx, object);
test_undo_large_copy(pop, ctx, object);
test_undo_checksum_mismatch(pop, ctx, object,
(struct ulog *)&object->undo);
/* undo logs are clobbered at the end, which shrinks their size */
size_t capacity = ulog_capacity((struct ulog *)&object->undo,
TEST_ENTRIES, &pop->p_ops);
/* builtin log + one next */
UT_ASSERTeq(capacity, TEST_ENTRIES * 2 + CACHELINE_SIZE);
operation_delete(ctx);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_memops");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, "obj_memops",
PMEMOBJ_MIN_POOL * 10, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
/*
* The ulog API requires cacheline alignment. A cacheline aligned new
* new allocator is created here to properly test the ulog api.
* A aligned object can then be allocated using pmemobj_xalloc.
*/
struct pobj_alloc_class_desc new_ac = {
.unit_size = sizeof(struct test_object),
.alignment = CACHELINE_SIZE,
.units_per_block = 1,
.header_type = POBJ_HEADER_NONE,
};
if (pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &new_ac) == -1)
UT_FATAL("Failed to set allocation class");
PMEMoid pobject;
if (pmemobj_xalloc(pop, &pobject, sizeof(struct test_object), 0,
POBJ_CLASS_ID(new_ac.class_id), NULL, NULL) == -1)
UT_FATAL("Failed to allocate object");
struct test_object *object = pmemobj_direct(pobject);
UT_ASSERTne(object, NULL);
ulog_construct(OBJ_PTR_TO_OFF(pop, &object->undo),
TEST_ENTRIES, 0, 0, 0, &pop->p_ops);
ulog_construct(OBJ_PTR_TO_OFF(pop, &object->redo),
TEST_ENTRIES, 0, 0, 0, &pop->p_ops);
test_redo(pop, object);
test_undo(pop, object);
test_redo_cleanup_same_size(pop, object);
test_undo_log_reuse();
test_undo_log_resume();
pmemobj_close(pop);
DONE(NULL);
}