1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2010. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <sys/time.h> |
---|
15 | #include <sys/resource.h> |
---|
16 | #include <errno.h> |
---|
17 | |
---|
18 | #if !HAVE_DECL_GETRUSAGE |
---|
19 | extern int getrusage(int who, struct rusage *usage); |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <tmacros.h> |
---|
23 | #include "test_support.h" |
---|
24 | |
---|
25 | /* configuration information */ |
---|
26 | |
---|
27 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
28 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
29 | |
---|
30 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
31 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
32 | |
---|
33 | #define CONFIGURE_INIT |
---|
34 | |
---|
35 | #include <rtems/confdefs.h> |
---|
36 | |
---|
37 | rtems_task Init( |
---|
38 | rtems_task_argument argument |
---|
39 | ) |
---|
40 | { |
---|
41 | int sc; |
---|
42 | struct rusage usage; |
---|
43 | |
---|
44 | puts( "\n\n*** TEST GETRUSAGE 01 ***" ); |
---|
45 | |
---|
46 | puts( "getrusage( RUSAGE_SELF, NULL ) -- EFAULT" ); |
---|
47 | sc = getrusage( RUSAGE_SELF, NULL ); |
---|
48 | rtems_test_assert( sc == -1 ); |
---|
49 | rtems_test_assert( errno == EFAULT ); |
---|
50 | |
---|
51 | puts( "getrusage( RUSAGE_CHILDREN, &usage ) -- ENOSYS" ); |
---|
52 | sc = getrusage( RUSAGE_CHILDREN, &usage ); |
---|
53 | rtems_test_assert( sc == -1 ); |
---|
54 | rtems_test_assert( errno == ENOSYS ); |
---|
55 | |
---|
56 | puts( "getrusage( 77, &usage ) -- EINVAL" ); |
---|
57 | sc = getrusage( 77, &usage ); |
---|
58 | rtems_test_assert( sc == -1 ); |
---|
59 | rtems_test_assert( errno == EINVAL ); |
---|
60 | |
---|
61 | puts( "Consume CPU long enough to have non-zero usage" ); |
---|
62 | rtems_test_spin_for_ticks( 5 ); |
---|
63 | |
---|
64 | puts( "getrusage( RUSAGE_SELF, &usage ) -- EINVAL" ); |
---|
65 | sc = getrusage( RUSAGE_SELF, &usage ); |
---|
66 | rtems_test_assert( sc == 0 ); |
---|
67 | |
---|
68 | /* CPU usage is non-zero */ |
---|
69 | rtems_test_assert( usage.ru_utime.tv_sec == 0 ); |
---|
70 | rtems_test_assert( usage.ru_utime.tv_usec != 0 ); |
---|
71 | |
---|
72 | /* System and user time is the same */ |
---|
73 | rtems_test_assert( usage.ru_utime.tv_sec == usage.ru_stime.tv_sec ); |
---|
74 | rtems_test_assert( usage.ru_utime.tv_usec == usage.ru_stime.tv_usec ); |
---|
75 | |
---|
76 | puts( "*** END OF TEST GETRUSAGE 01 ***" ); |
---|
77 | |
---|
78 | rtems_test_exit(0); |
---|
79 | } |
---|