www.pudn.com > pebble.zip > app3.c


/*  
 * Copyright 1999, 2000, 2001, 2002 Lucent Technologies Inc. 
 * All Rights Reserved. 
 * Information Sciences Research Center, Bell Labs. 
 * 
 * LUCENT TECHNOLOGIES DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE  
 * OR THE SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The 
 * software is provided "as is" without expressed or implied warranty  
 * of any kind. 
 * 
 * These notices must be retained in any copies of any part of this 
 * software. 
 * 
 */ 
 
#include "string.h" 
#include "pebble.h" 
#include "unistd.h" 
#include "machine/cpu.h" 
 
#define	N	1024 
 
char *out = "The Quick Brown Fox Jumped Over the Lazy Dog"; 
 
int 
main(int argc, char *argv[]) 
{ 
	int i; 
	char buf[N]; 
	char msg[NAMELEN]; 
	int errcount = 0; 
 
	printf("test driver starting\n"); 
 
	msg[0] = '\0'; 
	i = get_error(msg); 
	printf("initial get_error returns %d msg=\"%s\"\n", i, msg); 
	 
 
	i = write(1, out, -1); 
	printf("system call write %08x,%d returns %d\n", (int)out, -1, i); 
	if (i < 0) { 
		get_error(msg); 
		printf("(expected) error string=\"%s\"\n", msg); 
	} else { 
		errcount++; 
		printf("got %d, which is not expected!", i); 
	} 
	 
	i = write(1, out, strlen(out)); 
	printf("\nsystem call write %d chars returns %d\n", strlen(out), i); 
	if (i < 0) { 
		errcount++; 
		get_error(msg); 
		printf("unexpected error string=\"%s\"\n", msg); 
	}  
	 
/* Uncomment this to see the expected failure */ 
#if 0 
	printf("calling read expected to fail (asid: %d, thread id: %08x)\n", 
			get_asid(), (int)get_thread()); 
	i = read(0, KSEG0_BASE, N); 
	printf("system call read %08x,%d returns %d\n", 
		(int)KSEG0_BASE, N, i); 
	if (i < 0) { 
		get_error(msg); 
		printf("error string=\"%s\"\n", msg); 
	} else { 
		errcount++; 
		printf("got %d, which is not expected!", i); 
	} 
#endif 
	 
	i = read(0, buf, 1000000); 
	printf("system call read %08x,%d returns %d\n", (int)buf, 1000000, i); 
	if (i < 0) { 
		get_error(msg); 
		printf("error string=\"%s\"\n", msg); 
	} else { 
		errcount++; 
		printf("got %d, which is not expected!", i); 
	} 
	 
	printf("Type a string and hit enter\n"); 
	i = read(0, buf, N); 
	printf("read(%08x,%d) returns %d\n", (int)buf, N, i); 
	if (i >= 0) 
		printf("returned value=\"%s\"\n", buf); 
	else	{ 
		errcount++; 
		get_error(msg); 
		printf("error string=\"%s\"\n", msg); 
	} 
 
/*	printf("driver_get()=%d\n", driver_get()); */ 
	printf("APP3 TEST ENDED, %d ERRORS\n", errcount); 
	return(1); 
}