Skip to content

Commit

Permalink
test: fix CodeQL issues
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gromadzki <tomasz.gromadzki@intel.com>
  • Loading branch information
grom72 committed Mar 30, 2023
1 parent 4b74cbf commit 4036eb3
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/test/obj_pmalloc_mt/obj_pmalloc_mt.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ run_worker(void *(worker_func)(void *arg), struct worker_args args[])
THREAD_JOIN(&t[i], NULL);
}

static inline size_t
allocation_inc(size_t base)
{
size_t result = ((base / 128) + 1) * 128;
result *= Ops_per_thread;
result *= Threads;
return result;
}

int
main(int argc, char *argv[])
{
Expand Down Expand Up @@ -390,17 +399,14 @@ main(int argc, char *argv[])

alloc = allocPre;
if (enable_stats)
alloc += Ops_per_thread * Threads * ((ALLOC_SIZE / 128) + 1)
* 128;
alloc += allocation_inc(ALLOC_SIZE);
run_worker(alloc_worker, args);
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocPost);
UT_ASSERTeq(alloc, allocPost);

if (enable_stats) {
alloc -= Ops_per_thread * Threads * ((ALLOC_SIZE / 128) + 1)
* 128;
alloc += Ops_per_thread * Threads * ((REALLOC_SIZE / 128) + 1)
* 128;
alloc -= allocation_inc(ALLOC_SIZE);
alloc += allocation_inc(REALLOC_SIZE);
}
run_worker(realloc_worker, args);
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocPost);
Expand All @@ -424,16 +430,14 @@ main(int argc, char *argv[])
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocPost);
UT_ASSERTeq(alloc, allocPost);
if (enable_stats && Threads > 1)
alloc += Ops_per_thread / 2 * Threads
* ((ALLOC_SIZE / 128) + 1) * 128;
alloc += allocation_inc(ALLOC_SIZE) / 2;
run_worker(action_publish_worker, args);
actions_clear(pop, r);
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocPost);
UT_ASSERTeq(alloc, allocPost);

if (enable_stats && Threads > 1)
alloc += Ops_per_thread / 4 * Threads
* ((ALLOC_SIZE / 128) + 1) * 128;
alloc += allocation_inc(ALLOC_SIZE) / 4;
run_worker(action_mix_worker, args);
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocPost);
UT_ASSERTeq(alloc, allocPost);
Expand Down

0 comments on commit 4036eb3

Please sign in to comment.