GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / testrootfs / init.c
blob9c3bbdf9df0b76ba8a845140dd7926ad157bbaa5
1 /*
2 * Simple user-land program instead of real "init"
3 */
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <string.h>
9 #include <asm/ioctls.h>
10 #include <sys/wait.h>
12 #include <linux/reboot.h>
15 static volatile unsigned long long counter ;
17 void
18 main_test_speed(unsigned sec, unsigned n)
20 int pfd[2];
21 unsigned long start ;
22 unsigned i;
24 printf("Testing speed with %d threads\n", n );
25 start = time(NULL);
26 counter = 0;
27 pipe( pfd );
29 for(i = 0; i < n; i ++ )
31 int pid ;
32 if( (pid = fork()) != 0 )
33 continue;
34 /* Child process */
35 close(pfd[0]);
36 while( time(NULL) < (start + sec ) )
37 counter ++ ;
38 printf("Counter %llu\n", counter );
39 write( pfd[1], (void *) &counter, sizeof(counter) );
40 exit(0);
42 /* Children running, parent waits */
43 close(pfd[1]);
44 while( time(NULL) < (start + sec ) )
45 sleep(1);
47 /* Retreive child exist status */
48 for(counter = i = 0; i < n; i ++ )
50 unsigned long long cnt ;
51 int res;
52 if( read(pfd[0], &cnt, sizeof(cnt)) == sizeof(cnt))
53 counter += cnt ;
54 wait( &res );
55 printf("child %d status %d\n", i, WEXITSTATUS(res));
57 printf("Average count %llu, or %d per sec \n",
58 counter / n, (int) (counter / n / sec) );
62 int
63 main(int argc, char ** argv )
65 unsigned i, j;
66 const unsigned seconds = 60;
67 const unsigned dt = 5;
68 char buf[128];
70 printf("Howdy from user-land! ! ! !\n");
72 for(j = i = 0; i < seconds; i += dt )
74 sleep(dt);
75 printf("Time is %d sec\n", time(NULL) );
76 ioctl(0, FIONREAD, &j);
77 if(j > 0 )
79 memset(buf, 0, sizeof(buf));
80 j = read(0, buf, sizeof(buf));
81 printf("Received %d characters from input:\n", j);
82 printf("'%s'\n", buf );
86 sleep(2);
87 main_test_speed( 30, 1 );
88 sleep(2);
89 main_test_speed( 30, 2 );
90 sleep(2);
91 main_test_speed( 30, 3 );
92 sleep(2);
93 main_test_speed( 30, 4 );
95 ioctl(0, FIONREAD, &j);
96 if(j > 0 )
98 memset(buf, 0, sizeof(buf));
99 j = read(0, buf, sizeof(buf));
100 printf("Received %d characters from input:\n", j);
101 printf("'%s'\n", buf );
103 sleep(1);
104 printf("Done couning, commiting suicide...\n");
105 sleep(3);
106 reboot( LINUX_REBOOT_CMD_RESTART );
107 sleep(5);
108 printf("reboot failed: %s\n", strerror(errno) );