OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [libtests/] [malloctest/] [task1.c] - Blame information for rev 507

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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-1999.
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.OARcorp.com/rtems/license.html.
12
 *
13
 *  $Id: task1.c,v 1.2 2001-09-27 12:02:12 chris Exp $
14
 */
15
 
16
#include "system.h"
17
#include <libcsupport.h>    /* for malloc_dump, malloc_walk */
18
#include <string.h>         /* for memset */
19
#include <stdlib.h>
20
 
21
#define NUM_PASSES 100
22
 
23
rtems_task Task_1_through_5(
24
  rtems_task_argument argument
25
)
26
{
27
  int i;
28
  unsigned int passes = 0;
29
  rtems_id          tid;
30
  rtems_time_of_day time;
31
  rtems_status_code status;
32
  unsigned char *mem_ptr;
33
  int mem_amt;
34
 
35
  status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
36
  directive_failed( status, "rtems_task_ident" );
37
 
38
  while (TRUE)
39
  {
40
    if ( passes++ > NUM_PASSES ) {
41
        puts("*** END OF MALLOC TEST ***");
42
        exit(0);
43
    }
44
 
45
    status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
46
    directive_failed( status, "rtems_clock_get" );
47
 
48
    put_name( Task_name[ task_number( tid ) ], FALSE );
49
    print_time( " - rtems_clock_get - ", &time, "\n" );
50
 
51
    mem_amt = ((int)((float)rand()*1000.0/(float)RAND_MAX));
52
    while (!(mem_ptr = malloc ( mem_amt))) {
53
        printf("out of memory... trying again.\n");
54
        mem_amt = ((int)((float)rand()*1000.0/(float)RAND_MAX));
55
    }
56
    printf("mallocing %d bytes\n",mem_amt);
57
    memset( mem_ptr, mem_amt, mem_amt );
58
    malloc_dump();
59
    malloc_walk(1,FALSE);
60
    status = rtems_task_wake_after( task_number( tid ) * 1 * TICKS_PER_SECOND/4 );
61
    for (i=0; i < mem_amt; i++)
62
    {
63
       if ( mem_ptr[i] != (mem_amt & 0xff))
64
       {
65
          printf("failed %d, %d, 0x%x, 0x%x\n",i,mem_amt,mem_ptr[i],mem_amt&0xff);
66
          exit(1);
67
       }
68
    }
69
    directive_failed( status, "rtems_task_wake_after" );
70
    free( mem_ptr );
71
  }
72
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.