<commit_before>/**
 * @file
 * @brief TODO documentation for core_test.c -- <NAME>
 *
 * @date 09.04.2011
 * @author <NAME>
 */

#include <errno.h>
#include <embox/test.h>

#include <kernel/thread/api.h>

EMBOX_TEST_SUITE("test for thread API");

static void *arg_invert_run(void *arg) {
	return (void *) ~((unsigned long) arg);
}

TEST_CASE("thread_create with default flags should return -EINVAL if the "
		"first argument is NULL") {
	test_assert_equal(thread_create(NULL, 0, arg_invert_run, (void *) 1),
			-EINVAL);
}

TEST_CASE("thread_create should return -EINVAL if thread function is NULL") {
	struct thread *foo;

	test_assert_equal(-EINVAL, thread_create(&foo, 0, NULL, NULL));
}

TEST_CASE("thread_create with THREAD_FLAG_DETACHED should return zero and "
		"shouldn't touch the pointer") {
	struct thread *bar = (struct thread *) 0xa5a5a5a5;

	test_assert_zero(
			thread_create(&bar, THREAD_FLAG_DETACHED, arg_invert_run, NULL));
	test_assert_equal(bar, (struct thread *) 0xa5a5a5a5);
}

TEST_CASE("thread_create with THREAD_FLAG_DETACHED should return zero even if "
		"the pointer is NULL") {
	test_assert_zero(
			thread_create(NULL, THREAD_FLAG_DETACHED, arg_invert_run, NULL));
}

TEST_CASE("thread_join should retrieve the result of thread execution") {
	struct thread *foo;
	void *ret;

	test_assert_zero(thread_create(&foo, 0, arg_invert_run, (void *) 42UL));
	test_assert_zero(thread_join(foo, &ret));
	test_assert_equal(ret, (void *) ~42UL);
}

TEST_CASE("thread_resume should return 0 if the thread was created with "
		"THREAD_FLAG_SUSPENDED flag") {
	struct thread *foo;

	test_assert_zero(thread_create(&foo, THREAD_FLAG_SUSPENDED, arg_invert_run, NULL));
	test_assert_zero(thread_resume(foo));
}

TEST_CASE("thread_resume should return -EINVAL if the thread hasn't been "
		"suspended") {
	struct thread *foo;

	test_assert_zero(thread_create(&foo, 0, arg_invert_run, NULL));
	test_assert_equal(thread_resume(foo), -EINVAL);
}

<commit_msg>A little fix and GET2500!!!<commit_after>/**
 * @file
 * @brief TODO documentation for core_test.c -- <NAME>
 *
 * @date 09.04.2011
 * @author <NAME>
 */

#include <errno.h>
#include <embox/test.h>

#include <kernel/thread/api.h>

EMBOX_TEST_SUITE("test for thread API");

static void *arg_invert_run(void *arg) {
	return (void *) ~((unsigned long) arg);
}

TEST_CASE("thread_create with default flags should return -EINVAL if the "
		"first argument is NULL") {
	test_assert_equal(thread_create(NULL, 0, arg_invert_run, (void *) 1),
			-EINVAL);
}

TEST_CASE("thread_create should return -EINVAL if thread function is NULL") {
	struct thread *foo;

	test_assert_equal(-EINVAL, thread_create(&foo, 0, NULL, NULL));
}

TEST_CASE("thread_create with THREAD_FLAG_DETACHED should return zero and "
		"shouldn't touch the pointer") {
	struct thread *bar = (struct thread *) 0xa5a5a5a5;

	test_assert_zero(
			thread_create(&bar, THREAD_FLAG_DETACHED, arg_invert_run, NULL));
	test_assert_equal(bar, (struct thread *) 0xa5a5a5a5);
}

TEST_CASE("thread_create with THREAD_FLAG_DETACHED should return zero even if "
		"the pointer is NULL") {
	test_assert_zero(
			thread_create(NULL, THREAD_FLAG_DETACHED, arg_invert_run, NULL));
}

TEST_CASE("thread_join should retrieve the result of thread execution") {
	struct thread *foo;
	void *ret;

	test_assert_zero(thread_create(&foo, 0, arg_invert_run, (void *) 42UL));
	test_assert_zero(thread_join(foo, &ret));
	test_assert_equal(ret, (void *) ~42UL);
}

TEST_CASE("thread_resume should return 0 if the thread was created with "
		"THREAD_FLAG_SUSPENDED flag") {
	struct thread *foo;

	test_assert_zero(thread_create(&foo, THREAD_FLAG_SUSPENDED, arg_invert_run, NULL));
	test_assert_zero(thread_resume(foo));
}

TEST_CASE("thread_resume should return an error if the thread hasn't been "
		"initially suspended") {
	struct thread *foo;

	test_assert_zero(thread_create(&foo, 0, arg_invert_run, NULL));
	test_assert_not_zero(thread_resume(foo));
}


{'fraction_non_alphanumeric': 0.12079858478645439, 'fraction_numerical': 0.015163002274450341, 'mean_word_length': 5.8477508650519034, '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': '3934917', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1397, 'n_words': 349}