File: environ_err_dax_kmem_malloc_test.cpp

package info (click to toggle)
memkind 1.14.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,508 kB
  • sloc: ansic: 72,572; cpp: 39,493; sh: 4,594; perl: 4,250; xml: 2,044; python: 1,753; makefile: 1,393; csh: 7
file content (72 lines) | stat: -rw-r--r-- 2,032 bytes parent folder | download
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
// SPDX-License-Identifier: BSD-2-Clause
/* Copyright (C) 2019 - 2021 Intel Corporation. */

#include "memkind/internal/memkind_dax_kmem.h"
#include <memkind.h>

#include <numa.h>
#include <numaif.h>

#include "common.h"

/* This test is run with overridden MEMKIND_DAX_KMEM_NODES environment variable
 * and tries to perform allocation on DRAM using memkind_malloc()
 */
int main()
{
    struct bitmask *expected_nodemask = nullptr;
    struct bitmask *returned_nodemask = nullptr;
    void *ptr = nullptr;
    int ret = 0;
    int status = 0;

    ptr = memkind_malloc(MEMKIND_DAX_KMEM, KB);
    if (ptr != nullptr) {
        printf("Error: allocation to DAX_KMEM should fail\n");
        goto exit;
    }

    ptr = memkind_malloc(MEMKIND_DEFAULT, KB);
    if (ptr == nullptr) {
        printf("Error: allocation failed\n");
        goto exit;
    }

    expected_nodemask = numa_allocate_nodemask();
    status = memkind_dax_kmem_all_get_mbind_nodemask(
        nullptr, expected_nodemask->maskp, expected_nodemask->size);
    if (status != MEMKIND_ERROR_ENVIRON) {
        printf(
            "Error: wrong return value from memkind_dax_kmem_all_get_mbind_nodemask()\n");
        printf("Expected: %d\n", MEMKIND_ERROR_ENVIRON);
        printf("Actual: %d\n", status);
        goto exit;
    }

    returned_nodemask = numa_allocate_nodemask();
    status = get_mempolicy(nullptr, returned_nodemask->maskp,
                           returned_nodemask->size, ptr, MPOL_F_ADDR);
    if (status) {
        printf("Error: get_mempolicy() returned %d\n", status);
        goto exit;
    }

    ret = numa_bitmask_equal(returned_nodemask, expected_nodemask);
    if (!ret) {
        printf(
            "Error: Memkind dax kmem and allocated pointer nodemasks are not equal\n");
    }

exit:
    if (expected_nodemask) {
        numa_free_nodemask(expected_nodemask);
    }
    if (returned_nodemask) {
        numa_free_nodemask(returned_nodemask);
    }
    if (ptr) {
        memkind_free(nullptr, ptr);
    }

    return ret;
}