<commit_before>/* $Id$ */
/* Copyright (c) 2013 <NAME> <<EMAIL>> */
/* This file is part of DeforaOS System libc */
/* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. */



#include <sys/wait.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "../src/unistd.c"


/* fork */
static int _fork(char const * progname)
{
	pid_t pid;
	int res = 42;
	pid_t p;
	int status;

	printf("%s: Testing fork()\n", progname);
	if((pid = fork()) == -1)
		return -1;
	if(pid == 0)
		/* child process */
		_exit(res);
	/* parent process */
	for(;;)
	{
		if((p = waitpid(pid, &status, 0)) == -1)
			break;
		if(p != pid)
			continue;
		if(WIFEXITED(status) && WEXITSTATUS(status) == res)
			return 0;
	}
	return -1;
}


/* sleep */
static int _sleep(char const * progname)
{
	time_t before;
	time_t after;

	printf("%s: Testing sleep()\n", progname);
	before = time(NULL);
	sleep(1);
	after = time(NULL);
	return (after == before + 1) ? 0 : -1;
}


/* main */
int main(int argc, char * argv[])
{
	int ret = 0;

	ret += _fork(argv[0]);
	ret += _sleep(argv[0]);
	return (ret == 0) ? 0 : 2;
}
<commit_msg>More exhaustive test for sleep()<commit_after>/* $Id$ */
/* Copyright (c) 2013 <NAME> <<EMAIL>> */
/* This file is part of DeforaOS System libc */
/* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. */



#include <sys/wait.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "../src/unistd.c"


/* fork */
static int _fork(char const * progname)
{
	pid_t pid;
	int res = 42;
	pid_t p;
	int status;

	printf("%s: Testing fork()\n", progname);
	if((pid = fork()) == -1)
		return -1;
	if(pid == 0)
		/* child process */
		_exit(res);
	/* parent process */
	for(;;)
	{
		if((p = waitpid(pid, &status, 0)) == -1)
			break;
		if(p != pid)
			continue;
		if(WIFEXITED(status) && WEXITSTATUS(status) == res)
			return 0;
	}
	return -1;
}


/* sleep */
static int _sleep(char const * progname, unsigned int t)
{
	time_t before;
	time_t after;
	int res;

	printf("%s: Testing sleep()\n", progname);
	before = time(NULL);
	res = sleep(t);
	after = time(NULL);
	if(res == 0)
		return (after - before == t) ? 0 : -1;
	/* XXX ignore other cases (signal deliveries...) */
	return 0;
}


/* main */
int main(int argc, char * argv[])
{
	int ret = 0;

	ret += _fork(argv[0]);
	ret += _sleep(argv[0], 0);
	ret += _sleep(argv[0], 1);
	return (ret == 0) ? 0 : 2;
}

{'fraction_non_alphanumeric': 0.15348971908485376, 'fraction_numerical': 0.014769765421372719, 'mean_word_length': 3.2960199004975124, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '2524431', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1188, 'n_words': 438}