source: rtems/testsuites/libtests/malloctest/task1.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*  task1.c
2 *
3 *  This set of three tasks do some simple task switching for about
4 *  15 seconds and then call a routine to "blow the stack".
5 *
6 *  COPYRIGHT (c) 1989-2009.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include "system.h"
19#include <rtems/malloc.h>
20#include <string.h>
21#include <stdlib.h>
22
23#define NUM_PASSES 100
24
25rtems_task Task_1_through_5(
26  rtems_task_argument argument
27)
28{
29  int i;
30  unsigned int passes = 0;
31  rtems_id          tid;
32  rtems_time_of_day time;
33  rtems_status_code status;
34  unsigned char *mem_ptr;
35  int mem_amt;
36
37  status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
38  directive_failed( status, "rtems_task_ident" );
39
40  while (TRUE)
41  {
42    bool malloc_walk_ok;
43
44    if ( passes++ > NUM_PASSES ) {
45        TEST_END();
46        rtems_test_exit(0);
47    }
48
49    status = rtems_clock_get_tod( &time );
50    directive_failed( status, "rtems_clock_get_tod" );
51
52    put_name( Task_name[ task_number( tid ) ], FALSE );
53    print_time( " - rtems_clock_get_tod - ", &time, "\n" );
54
55    mem_amt = ((int)((float)rand()*1000.0/(float)RAND_MAX));
56    while (!(mem_ptr = malloc ( mem_amt))) {
57        printf("out of memory... trying again.\n");
58        mem_amt = ((int)((float)rand()*1000.0/(float)RAND_MAX));
59    }
60    printf("mallocing %d bytes\n",mem_amt);
61    memset( mem_ptr, mem_amt, mem_amt );
62    malloc_report_statistics();
63    malloc_walk_ok = malloc_walk( 1, false );
64    rtems_test_assert( malloc_walk_ok );
65    status = rtems_task_wake_after(
66      task_number( tid ) * 1 * rtems_clock_get_ticks_per_second()/4 );
67    for (i=0; i < mem_amt; i++)
68    {
69       if ( mem_ptr[i] != (mem_amt & 0xff))
70       {
71          printf("failed %d, %d, 0x%x, 0x%x\n",i,mem_amt,mem_ptr[i],mem_amt&0xff);
72          rtems_test_exit(1);
73       }
74    }
75    directive_failed( status, "rtems_task_wake_after" );
76    free( mem_ptr );
77  }
78}
Note: See TracBrowser for help on using the repository browser.