source: rtems/testsuites/psxtests/psxgetrusage01/init.c @ c4b8b147

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 2.1 KB
Line 
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
19extern int getrusage(int who, struct rusage *usage);
20#endif
21
22#include <tmacros.h>
23#include "test_support.h"
24
25const char rtems_test_name[] = "PSXGETRUSAGE 1";
26
27/* configuration information */
28
29#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
30#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
31
32#define CONFIGURE_MAXIMUM_TASKS             1
33#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
34
35#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
36
37#define CONFIGURE_INIT
38
39#include <rtems/confdefs.h>
40
41rtems_task Init(
42  rtems_task_argument argument
43)
44{
45  int           sc;
46  struct rusage usage;
47
48  TEST_BEGIN();
49
50  puts( "getrusage( RUSAGE_SELF, NULL ) -- EFAULT" );
51  sc = getrusage( RUSAGE_SELF, NULL );
52  rtems_test_assert( sc == -1 );
53  rtems_test_assert( errno == EFAULT );
54
55  puts( "getrusage( RUSAGE_CHILDREN, &usage ) -- ENOSYS" );
56  sc = getrusage( RUSAGE_CHILDREN, &usage );
57  rtems_test_assert( sc == -1 );
58  rtems_test_assert( errno == ENOSYS );
59
60  puts( "getrusage( 77, &usage ) -- EINVAL" );
61  sc = getrusage( 77, &usage );
62  rtems_test_assert( sc == -1 );
63  rtems_test_assert( errno == EINVAL );
64
65  puts( "Consume CPU long enough to have non-zero usage" );
66  rtems_test_spin_for_ticks( 5 );
67 
68  puts( "getrusage( RUSAGE_SELF, &usage ) -- EINVAL" );
69  sc = getrusage( RUSAGE_SELF, &usage );
70  rtems_test_assert( sc == 0 );
71
72  /* CPU usage is non-zero */
73  rtems_test_assert( usage.ru_utime.tv_sec == 0 );
74  rtems_test_assert( usage.ru_utime.tv_usec != 0 );
75
76  /* System and user time is the same */
77  rtems_test_assert( usage.ru_utime.tv_sec == usage.ru_stime.tv_sec );
78  rtems_test_assert( usage.ru_utime.tv_usec == usage.ru_stime.tv_usec );
79 
80  TEST_END();
81
82  rtems_test_exit(0);
83}
Note: See TracBrowser for help on using the repository browser.