linux-test.c revision 4af48bf7c72ef1e201c64bd475377b5af9d8e8a1
/*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
/*
* 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>
#define TESTPATH "/tmp/linux-test.tmp"
#define TESTPORT 7654
#define STACK_SIZE 16384
{
exit(1);
}
{
if (ret < 0) {
}
return ret;
}
/*******************************************************/
#define FILE_BUF_SIZE 300
void test_file(void)
{
char cur_dir[1024];
/* 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");
#define FOFFSET 16
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)
{
struct sockaddr_in sockaddr;
/* server socket */
val = 1;
return fd;
}
int client_socket(void)
{
int fd;
struct sockaddr_in sockaddr;
/* server socket */
return fd;
}
const char socket_msg[] = "hello socket\n";
void test_socket(void)
{
struct sockaddr_in sockaddr;
char buf[512];
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");
}
#define WCOUNT_MAX 512
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 thread1_func(void *arg)
{
int i;
for(i=0;i<5;i++) {
thread1_res++;
}
return 0;
}
int thread2_func(void *arg)
{
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;
}
}
#define SHM_SIZE 32768
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;
}