<commit_before>//
// Copyright 2016 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include <stdio.h>
#include <nyuzi.h>

#define ALLOC_SIZE 0x40000
#define STRIDE 256
#define FNV_OFFSET_BASIS 2166136261
#define FNV_PRIME 16777619
#define RNG_MULTIPLIER 1664525
#define RNG_INCREMENT 1013904223

//
// This test ensures multiple threads can run in different address spaces
// and have their pages mapped properly. It writes a pseudorandom pattern
// across a chunk of memory, computing a checksum as it goes. It then reads
// it back to ensure the checksum matches. The random pattern is seeded by
// the thread ID so each one will have a different pattern. If it is successful,
// it prints '+', otherwise it prints '-'.
//

int main()
{
    unsigned int rand_seed = get_current_thread_id();
    unsigned int chksum1 = FNV_OFFSET_BASIS;    // FNV-1 hash
    unsigned int chksum2 = FNV_OFFSET_BASIS;
    unsigned char *area_base;
    int i;

    area_base = (unsigned char*) create_area(0x100000, ALLOC_SIZE, AREA_PLACE_EXACT,
                                             "alloc_area", AREA_WRITABLE);
    for (i = 0; i < ALLOC_SIZE; i += STRIDE)
    {
        rand_seed = rand_seed * RNG_MULTIPLIER + RNG_INCREMENT;
        area_base[i] = rand_seed & 0xff;
        chksum1 = (chksum1 ^ (rand_seed & 0xff)) * FNV_PRIME;
    }

    for (i = 0; i < ALLOC_SIZE; i += STRIDE)
        chksum2 = (chksum2 ^ area_base[i]) * FNV_PRIME;

    if (chksum1 == chksum2)
        printf("+");
    else
        printf("-");
}<commit_msg>tests: memtest kernel test was broken because test area collided with heap<commit_after>//
// Copyright 2016 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include <stdio.h>
#include <nyuzi.h>

#define ALLOC_SIZE 0x40000
#define STRIDE 256
#define FNV_OFFSET_BASIS 2166136261
#define FNV_PRIME 16777619
#define RNG_MULTIPLIER 1664525
#define RNG_INCREMENT 1013904223

//
// This test ensures multiple threads can run in different address spaces
// and have their pages mapped properly. It writes a pseudorandom pattern
// across a chunk of memory, computing a checksum as it goes. It then reads
// it back to ensure the checksum matches. The random pattern is seeded by
// the thread ID so each one will have a different pattern. If it is successful,
// it prints '+', otherwise it prints '-'.
//

int main()
{
    unsigned int rand_seed = get_current_thread_id();
    unsigned int chksum1 = FNV_OFFSET_BASIS;    // FNV-1 hash
    unsigned int chksum2 = FNV_OFFSET_BASIS;
    unsigned char *area_base;
    int i;

    area_base = (unsigned char*) create_area(0x10000000, ALLOC_SIZE, AREA_PLACE_EXACT,
                                             "alloc_area", AREA_WRITABLE);
    for (i = 0; i < ALLOC_SIZE; i += STRIDE)
    {
        rand_seed = rand_seed * RNG_MULTIPLIER + RNG_INCREMENT;
        area_base[i] = rand_seed & 0xff;
        chksum1 = (chksum1 ^ (rand_seed & 0xff)) * FNV_PRIME;
    }

    for (i = 0; i < ALLOC_SIZE; i += STRIDE)
        chksum2 = (chksum2 ^ area_base[i]) * FNV_PRIME;

    if (chksum1 == chksum2)
        printf("+");
    else
        printf("-");
}
{'fraction_non_alphanumeric': 0.09375753193540612, 'fraction_numerical': 0.03518920221740179, 'mean_word_length': 2.9903846153846154, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5611324', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1280, 'n_words': 487}