/*
* linux and CPU test
*
* Copyright (c) 2003 Fabrice Bellard
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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/>.
*/
/*
* Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the General Public License version 2 (GPLv2) at this time for any software where
* a choice of GPL license versions is made available with the language indicating
* that GPLv2 or any later version may be used, or where a choice of which version
* of the GPL is applied is otherwise unspecified.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <inttypes.h>
#include <string.h>
#include <errno.h>
#include <utime.h>
#include <time.h>
#include <sched.h>
#include <dirent.h>
#include <setjmp.h>
{
exit(1);
}
{
if (ret < 0) {
}
return ret;
}
/*******************************************************/
void test_file(void)
{
/* clean up, just in case */
error("getcwd");
for(i=0;i < FILE_BUF_SIZE; i++)
buf[i] = i;
error("write");
error("writev");
if (len != FILE_BUF_SIZE)
error("read");
error("memcmp");
if (ret != 16)
error("lseek");
error("readv");
error("memcmp");
/* access */
error("stat size");
error("stat mode");
error("stat mode2");
error("stat time");
error("stat mode");
/* fstat */
error("stat size");
error("stat mode");
error("stat mode");
/* getdents */
if (!dir)
error("opendir");
len = 0;
for(;;) {
if (!de)
break;
error("readdir");
len++;
}
if (len != 4)
error("readdir");
}
void test_fork(void)
{
if (pid == 0) {
/* child */
exit(2);
}
}
void test_time(void)
{
int ti, i;
error("nanosleep");
if (ti >= 2)
error("gettimeofday");
for(i = 0;i < 10000; i++);
error("getrusage");
}
{
int c;
char *q = buf;
if (buf_size <= 0)
return;
for(;;) {
c = *str++;
break;
*q++ = c;
}
*q = '\0';
}
/* strcat and truncate. */
{
int len;
return buf;
}
int server_socket(void)
{
/* server socket */
val = 1;
return fd;
}
int client_socket(void)
{
int fd;
/* server socket */
return fd;
}
void test_socket(void)
{
server_fd = server_socket();
/* test a few socket options */
if (val != SOCK_STREAM)
error("getsockopt");
if (pid == 0) {
client_fd = client_socket();
exit(0);
}
if (ret != sizeof(socket_msg))
error("recv");
error("socket_msg");
}
void test_pipe(void)
{
wcount = 0;
rcount = 0;
for(;;) {
if (ret > 0) {
rcount++;
if (rcount >= WCOUNT_MAX)
break;
}
ch = 'a';
wcount++;
}
}
}
}
int thread1_res;
int thread2_res;
{
int i;
for(i=0;i<5;i++) {
thread1_res++;
}
return 0;
}
{
int i;
for(i=0;i<6;i++) {
thread2_res++;
}
return 0;
}
void test_clone(void)
{
if (thread1_res != 5 ||
thread2_res != 6)
error("clone");
}
/***********************************/
volatile int alarm_count;
{
error("signal");
alarm_count++;
}
{
error("signal");
}
void test_signal(void)
{
/* timer test */
alarm_count = 0;
error("itimer");
while (alarm_count < 5) {
}
error("setitimer");
/* SIGSEGV test */
*(uint8_t *)0 = 0;
}
}
void test_shm(void)
{
void *ptr;
int shmid;
if (!ptr)
error("shmat");
}
{
test_file();
test_fork();
test_time();
test_socket();
// test_clone();
test_signal();
test_shm();
return 0;
}