<commit_before>/*******************************************************************************
 * tests/mem/page_mapper_test.cpp
 *
 * Part of Project Thrill.
 *
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This file has no license. Only Chuck Norris can compile it.
 ******************************************************************************/

#include <gtest/gtest.h>
#include <thrill/common/logger.hpp>
#include <thrill/mem/page_mapper.hpp>

using namespace thrill;

TEST(PageMapper, AllocateReturnsAccessibleMemoryArea) {
    mem::PageMapper mapper;

    int* array = reinterpret_cast<int*>(mapper.Allocate());

    //write into memory area to see if we get a segfault
    for(unsigned int i = 0; i * sizeof(int) < mapper.object_size() ; i++) {
        array[i] = i;
    }

    mapper.Free(reinterpret_cast<char*>(array));
}

TEST(PageMapper, FreeMakesMemoryAreaInaccessible) {
    mem::PageMapper mapper;

    int* array = reinterpret_cast<int*>(mapper.Allocate());
    mapper.Free(reinterpret_cast<char*>(array));

    ASSERT_DEATH({ array[1] = 42; }, "Segfault");
}

TEST(PageMapper, SwapOutLeavesAreaAccessible) {
    mem::PageMapper mapper;

    int* array = reinterpret_cast<int*>(mapper.Allocate());
    mapper.SwapOut(reinterpret_cast<char*>(array));

    //write into memory area to see if we get a segfault
    for(unsigned int i = 0; i < mapper.object_size(); i += sizeof(int)) {
        array[i] = i;
    }

    mapper.Free(reinterpret_cast<char*>(array));
}

TEST(PageMapper, PrefetchLeavesAreaAccessible) {
    mem::PageMapper mapper;

    int* array = reinterpret_cast<int*>(mapper.Allocate());
    mapper.Prefetch(reinterpret_cast<char*>(array));

    //write into memory area to see if we get a segfault
    for(unsigned int i = 0; i < mapper.object_size(); i += sizeof(int)) {
        array[i] = i;
    }

    mapper.Free(reinterpret_cast<char*>(array));
}

namespace thrill {
namespace mem {

// forced instantiations
template class FixedAllocator<int, g_bypass_manager>;
template class Allocator<int>;

} // namespace mem
} // namespace thrill

/******************************************************************************/<commit_msg>fix memory_pager testcases (wrong loop range)<commit_after>/*******************************************************************************
 * tests/mem/page_mapper_test.cpp
 *
 * Part of Project Thrill.
 *
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This file has no license. Only Chuck Norris can compile it.
 ******************************************************************************/

#include <gtest/gtest.h>
#include <thrill/common/logger.hpp>
#include <thrill/mem/page_mapper.hpp>

using namespace thrill;

TEST(PageMapper, AllocateReturnsAccessibleMemoryArea) {
    mem::PageMapper mapper;

    int* array = reinterpret_cast<int*>(mapper.Allocate());

    //write into memory area to see if we get a segfault
    for(unsigned int i = 0; i * sizeof(int) < mapper.object_size() ; i++) {
        array[i] = i;
    }

    mapper.Free(reinterpret_cast<char*>(array));
}

TEST(PageMapper, FreeMakesMemoryAreaInaccessible) {
    mem::PageMapper mapper;

    int* array = reinterpret_cast<int*>(mapper.Allocate());
    mapper.Free(reinterpret_cast<char*>(array));

    ASSERT_DEATH({ array[1] = 42; }, "");
}

TEST(PageMapper, SwapOutLeavesAreaAccessible) {
    mem::PageMapper mapper;

    int* array = reinterpret_cast<int*>(mapper.Allocate());
    mapper.SwapOut(reinterpret_cast<char*>(array));

    //write into memory area to see if we get a segfault
    for(unsigned int i = 0; i * sizeof(int) < mapper.object_size() ; i++) {
        array[i] = i;
    }

    mapper.Free(reinterpret_cast<char*>(array));
}

TEST(PageMapper, PrefetchLeavesAreaAccessible) {
    mem::PageMapper mapper;

    int* array = reinterpret_cast<int*>(mapper.Allocate());
    mapper.Prefetch(reinterpret_cast<char*>(array));

    //write into memory area to see if we get a segfault
    for(unsigned int i = 0; i * sizeof(int) < mapper.object_size() ; i++) {
        array[i] = i;
    }

    mapper.Free(reinterpret_cast<char*>(array));
}

namespace thrill {
namespace mem {

// forced instantiations
template class FixedAllocator<int, g_bypass_manager>;
template class Allocator<int>;

} // namespace mem
} // namespace thrill

/******************************************************************************/
{'fraction_non_alphanumeric': 0.23211009174311928, 'fraction_numerical': 0.0045871559633027525, 'mean_word_length': 4.548346055979644, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1983030', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1292, 'n_words': 302}