|
Packit Service |
7f3b24 |
// SPDX-License-Identifier: BSD-2-Clause
|
|
Packit Service |
7f3b24 |
/* Copyright (C) 2019 - 2020 Intel Corporation. */
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include <memkind.h>
|
|
Packit |
345191 |
#include "memkind/internal/memkind_dax_kmem.h"
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include <numa.h>
|
|
Packit |
345191 |
#include <numaif.h>
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include "common.h"
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* This test is run with overridden MEMKIND_DAX_KMEM_NODES environment variable
|
|
Packit |
345191 |
* and tries to perform allocation on DRAM using memkind_malloc()
|
|
Packit |
345191 |
*/
|
|
Packit |
345191 |
int main()
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
struct bitmask *expected_nodemask = nullptr;
|
|
Packit |
345191 |
struct bitmask *returned_nodemask = nullptr;
|
|
Packit |
345191 |
void *ptr = nullptr;
|
|
Packit |
345191 |
int ret = 0;
|
|
Packit |
345191 |
int status = 0;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
ptr = memkind_malloc(MEMKIND_DAX_KMEM, KB);
|
|
Packit |
345191 |
if (ptr != nullptr) {
|
|
Packit |
345191 |
printf("Error: allocation to DAX_KMEM should fail\n");
|
|
Packit |
345191 |
goto exit;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
ptr = memkind_malloc(MEMKIND_DEFAULT, KB);
|
|
Packit |
345191 |
if (ptr == nullptr) {
|
|
Packit |
345191 |
printf("Error: allocation failed\n");
|
|
Packit |
345191 |
goto exit;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
expected_nodemask = numa_allocate_nodemask();
|
|
Packit |
345191 |
status = memkind_dax_kmem_all_get_mbind_nodemask(nullptr,
|
|
Packit |
345191 |
expected_nodemask->maskp,
|
|
Packit |
345191 |
expected_nodemask->size);
|
|
Packit |
345191 |
if (status != MEMKIND_ERROR_ENVIRON) {
|
|
Packit |
345191 |
printf("Error: wrong return value from memkind_dax_kmem_all_get_mbind_nodemask()\n");
|
|
Packit |
345191 |
printf("Expected: %d\n", MEMKIND_ERROR_ENVIRON);
|
|
Packit |
345191 |
printf("Actual: %d\n", status);
|
|
Packit |
345191 |
goto exit;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
returned_nodemask = numa_allocate_nodemask();
|
|
Packit |
345191 |
status = get_mempolicy(nullptr, returned_nodemask->maskp,
|
|
Packit |
345191 |
returned_nodemask->size,
|
|
Packit |
345191 |
ptr, MPOL_F_ADDR);
|
|
Packit |
345191 |
if (status) {
|
|
Packit |
345191 |
printf("Error: get_mempolicy() returned %d\n", status);
|
|
Packit |
345191 |
goto exit;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
ret = numa_bitmask_equal(returned_nodemask, expected_nodemask);
|
|
Packit |
345191 |
if (!ret) {
|
|
Packit |
345191 |
printf("Error: Memkind dax kmem and allocated pointer nodemasks are not equal\n");
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
exit:
|
|
Packit |
345191 |
if (expected_nodemask) {
|
|
Packit |
345191 |
numa_free_nodemask(expected_nodemask);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
if (returned_nodemask) {
|
|
Packit |
345191 |
numa_free_nodemask(returned_nodemask);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
if (ptr) {
|
|
Packit |
345191 |
memkind_free(nullptr, ptr);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
return ret;
|
|
Packit |
345191 |
}
|