<commit_before>#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <crpcut.hpp>
#include <stdio.h>

#include <coincident/coincident.h>

using namespace testing;


/*
 * The code below is not stupid, but VERY stupid.
 *
 * However, it's just for testing coincident.
 */
int global;

int add_val(int v)
{
	global += v;

	return global;
}

static int test_race(void *params)
{
	global = 1;

	ASSERT_TRUE(global == 1);

	int v = add_val(1);
	ASSERT_TRUE(v == 2);

	ASSERT_TRUE(v == global);

	return 0;
}


// Same as above, but without races (stack allocated stuff)
int add_val_non_race(int *src, int v)
{
	*src += v;

	return *src;
}

static int test_non_race(void *params)
{
	int src = 1;

	ASSERT_TRUE(src == 1);

	int v = add_val_non_race(&src, 1);
	ASSERT_TRUE(v == 2);

	ASSERT_TRUE(v == src);

	return 0;
}


TESTSUITE(coincident)
{
	TEST(basic_race)
	{
		// We use random scheduling here, so this actually affects
		// the result
		srand(time(NULL));

		coincident_add_thread(test_race, NULL);
		coincident_add_thread(test_race, NULL);

		coincident_set_run_limit(10);

		int result = coincident_run();
		ASSERT_TRUE(result == 0);
	}

	TEST(basic_non_race)
	{
		srand(time(NULL));

		coincident_add_thread(test_non_race, NULL);
		coincident_add_thread(test_non_race, NULL);

		// Stop after 500 ms<commit_msg>self-test: One more thread in the non-racy test<commit_after>#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <crpcut.hpp>
#include <stdio.h>

#include <coincident/coincident.h>

using namespace testing;


/*
 * The code below is not stupid, but VERY stupid.
 *
 * However, it's just for testing coincident.
 */
int global;

int add_val(int v)
{
	global += v;

	return global;
}

static int test_race(void *params)
{
	global = 1;

	ASSERT_TRUE(global == 1);

	int v = add_val(1);
	ASSERT_TRUE(v == 2);

	ASSERT_TRUE(v == global);

	return 0;
}


// Same as above, but without races (stack allocated stuff)
int add_val_non_race(int *src, int v)
{
	*src += v;

	return *src;
}

static int test_non_race(void *params)
{
	int src = 1;

	ASSERT_TRUE(src == 1);

	int v = add_val_non_race(&src, 1);
	ASSERT_TRUE(v == 2);

	ASSERT_TRUE(v == src);

	return 0;
}


TESTSUITE(coincident)
{
	TEST(basic_race)
	{
		// We use random scheduling here, so this actually affects
		// the result
		srand(time(NULL));

		coincident_add_thread(test_race, NULL);
		coincident_add_thread(test_race, NULL);

		coincident_set_run_limit(10);

		int result = coincident_run();
		ASSERT_TRUE(result == 0);
	}

	TEST(basic_non_race)
	{
		srand(time(NULL));

		coincident_add_thread(test_race, NULL);
		coincident_add_thread(test_non_race, NULL);
		coincident_add_thread(test_non_race, NULL);

		// Stop after 500 ms
{'fraction_non_alphanumeric': 0.13208241353936717, 'fraction_numerical': 0.01177336276674025, 'mean_word_length': 4.188931297709924, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2049609', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1047, 'n_words': 258}