<commit_before>/****************************************************************************
 *
 * Copyright 2016 Samsung Electronics All Rights Reserved.
 *
 * 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.
 *
 ****************************************************************************/

/// @file semaphore.c
/// @brief Test Case Example for semaphore API
#include <tinyara/config.h>
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include "tc_internal.h"

#define HALF_SEC        500000
#define SEC_1           1

int g_pshared = 0;
int g_count = 1;

sem_t g_empty;
sem_t g_full;
sem_t g_mutex;
int g_loop_cnt = 5;

/**
* @fn                   :producer_func
* @description          :Function for tc_semaphore_sem_init_post_wait
* @return               :void*
*/
static void *producer_func(void *arg)
{
	int index;
	int ret_val;
	for (index = 0; index < g_loop_cnt; index++) {
		ret_val = sem_wait(&g_empty);
		if (ret_val == ERROR) {
			pthread_exit("sem_wait(&g_empty)");
		}

		ret_val = sem_wait(&g_mutex);
		if (ret_val == ERROR) {
			pthread_exit("sem_wait(&g_mutex)");
		}

		ret_val = sem_post(&g_mutex);
		if (ret_val == ERROR) {
			pthread_exit("sem_post(&g_mutex)");
		}

		ret_val = sem_post(&g_full);
		if (ret_val == ERROR) {
			pthread_exit("sem_post(&g_full)");
		}
	}
	pthread_exit(NULL);
	return NULL;
}

/**
* @fn                   :consumer_func
* @description          :Function for tc_semaphore_sem_init_post_wait
* @return               :void*
*/
static void *consumer_func(void *arg)
{
	int index;
	int ret_val;
	for (index = 0; index < g_loop_cnt; index++) {
		ret_val = sem_wait(&g_full);
		if (ret_val == ERROR) {
			pthread_exit("sem_wait(&g_full)");
		}

		ret_val = sem_wait(&g_mutex);
		if (ret_val == ERROR) {
			pthread_exit("sem_wait(&g_mutex)");
		}

		ret_val = sem_post(&g_mutex);
		if (ret_val == ERROR) {
			pthread_exit("sem_post(&g_mutex)");
		}

		ret_val = sem_post(&g_empty);
		if (ret_val == ERROR) {
			pthread_exit("sem_post(&g_empty)");
		}
	}
	pthread_exit(NULL);
	return NULL;
}

/**
* @fn                   :tc_semaphore_sem_init_post_wait
* @brief                :Unlocks the semaphore passed as argument.
* @scenario             :Unlocks the semaphore passed as argument.
* API's covered         :sem_init, sem_post, sem_wait
* Preconditions         :Semaphore should be initialised.
* Postconditions        :Semaphore should be destroyed.
* @return               :void
*/
static void tc_semaphore_sem_init_post_wait(void)
{
	int ret_val;
	pthread_addr_t *pexit_value = NULL;
	pthread_t pid;
	pthread_t cid;

	ret_val = sem_init(&g_empty, g_pshared, g_count);
	TC_ASSERT_NEQ("sem_init", ret_val, ERROR);

	ret_val = sem_init(&g_full, g_pshared, 0);
	TC_ASSERT_NEQ("sem_init", ret_val, ERROR);<commit_msg>change a variable from pointer to local<commit_after>/****************************************************************************
 *
 * Copyright 2016 Samsung Electronics All Rights Reserved.
 *
 * 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.
 *
 ****************************************************************************/

/// @file semaphore.c
/// @brief Test Case Example for semaphore API
#include <tinyara/config.h>
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include "tc_internal.h"

#define HALF_SEC        500000
#define SEC_1           1

int g_pshared = 0;
int g_count = 1;

sem_t g_empty;
sem_t g_full;
sem_t g_mutex;
int g_loop_cnt = 5;

/**
* @fn                   :producer_func
* @description          :Function for tc_semaphore_sem_init_post_wait
* @return               :void*
*/
static void *producer_func(void *arg)
{
	int index;
	int ret_val;
	for (index = 0; index < g_loop_cnt; index++) {
		ret_val = sem_wait(&g_empty);
		if (ret_val == ERROR) {
			pthread_exit("sem_wait(&g_empty)");
		}

		ret_val = sem_wait(&g_mutex);
		if (ret_val == ERROR) {
			pthread_exit("sem_wait(&g_mutex)");
		}

		ret_val = sem_post(&g_mutex);
		if (ret_val == ERROR) {
			pthread_exit("sem_post(&g_mutex)");
		}

		ret_val = sem_post(&g_full);
		if (ret_val == ERROR) {
			pthread_exit("sem_post(&g_full)");
		}
	}
	pthread_exit(NULL);
	return NULL;
}

/**
* @fn                   :consumer_func
* @description          :Function for tc_semaphore_sem_init_post_wait
* @return               :void*
*/
static void *consumer_func(void *arg)
{
	int index;
	int ret_val;
	for (index = 0; index < g_loop_cnt; index++) {
		ret_val = sem_wait(&g_full);
		if (ret_val == ERROR) {
			pthread_exit("sem_wait(&g_full)");
		}

		ret_val = sem_wait(&g_mutex);
		if (ret_val == ERROR) {
			pthread_exit("sem_wait(&g_mutex)");
		}

		ret_val = sem_post(&g_mutex);
		if (ret_val == ERROR) {
			pthread_exit("sem_post(&g_mutex)");
		}

		ret_val = sem_post(&g_empty);
		if (ret_val == ERROR) {
			pthread_exit("sem_post(&g_empty)");
		}
	}
	pthread_exit(NULL);
	return NULL;
}

/**
* @fn                   :tc_semaphore_sem_init_post_wait
* @brief                :Unlocks the semaphore passed as argument.
* @scenario             :Unlocks the semaphore passed as argument.
* API's covered         :sem_init, sem_post, sem_wait
* Preconditions         :Semaphore should be initialised.
* Postconditions        :Semaphore should be destroyed.
* @return               :void
*/
static void tc_semaphore_sem_init_post_wait(void)
{
	int ret_val;
	pthread_addr_t pexit_value = NULL;
	pthread_t pid;
	pthread_t cid;

	ret_val = sem_init(&g_empty, g_pshared, g_count);
	TC_ASSERT_NEQ("sem_init", ret_val, ERROR);

	ret_val = sem_init(&g_full, g_pshared, 0);
	TC_ASSERT_NEQ("sem_init", ret_val, ERROR);
{'fraction_non_alphanumeric': 0.16201117318435754, 'fraction_numerical': 0.0066435150234032915, 'mean_word_length': 3.5968077723802914, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5210872', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2281, 'n_words': 575}