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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code/] [lib-iftest/] [lib-iftest.c] - Blame information for rev 178

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

Line No. Rev Author Line
1 90 jeremybenn
/* lib-iftest.c. Test of Or1ksim library interface functions.
2
 
3
   Copyright (C) 1999-2006 OpenCores
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributors various OpenCores participants
7
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
   This file is part of OpenRISC 1000 Architectural Simulator.
10
 
11
   This program is free software; you can redistribute it and/or modify it
12
   under the terms of the GNU General Public License as published by the Free
13
   Software Foundation; either version 3 of the License, or (at your option)
14
   any later version.
15
 
16
   This program is distributed in the hope that it will be useful, but WITHOUT
17
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
   more details.
20
 
21
   You should have received a copy of the GNU General Public License along
22
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
23
 
24
/* ----------------------------------------------------------------------------
25
   This code is commented throughout for use with Doxygen.
26
   --------------------------------------------------------------------------*/
27
 
28
#include <math.h>
29
#include <stdlib.h>
30
#include <stdio.h>
31
 
32
#include "or1ksim.h"
33
 
34
 
35
/* --------------------------------------------------------------------------*/
36
/*!Main program
37
 
38
   Build an or1ksim program using the library which loads a program and config
39
   from the command line. Usage:
40
 
41
   lib-iftest <config-file> <image> <duration_ms>
42
 
43
   Run that test for a <duration_ms> milliseconds of simulated time. The test
44
   the various interface functions.
45
 
46
   @param[in] argc  Number of elements in argv
47
   @param[in] argv  Vector of program name and arguments
48
 
49
   @return  Return code for the program.                                     */
50
/* --------------------------------------------------------------------------*/
51
int
52
main (int   argc,
53
      char *argv[])
54
{
55
  /* Parse args */
56
  if (4 != argc)
57
    {
58
      fprintf (stderr,
59
               "usage: lib-iftest <config-file> <image> <duration_ms>\n");
60
      return  1;
61
    }
62
 
63
  int     duration_ms = atoi (argv[3]);
64
  double  duration    = (double) duration_ms / 1.0e3;
65
 
66
  if (duration_ms <= 0)
67
    {
68
      fprintf (stderr, "ERROR. Duration must be positive number of ms\n");
69
      return  1;
70
    }
71
 
72
  /* Put the initialization message afterwards, or it will get swamped by the
73
     Or1ksim header. */
74
  if (0 == or1ksim_init (argv[1], argv[2], NULL, NULL, NULL))
75
    {
76
      printf ("Initalization succeeded.\n");
77
    }
78
  else
79
    {
80
      printf ("Initalization failed.\n");
81
      return  1;
82
    }
83
 
84
  /* Test of running */
85
  printf ("Running code...");
86
  switch (or1ksim_run (duration))
87
    {
88
    case OR1KSIM_RC_OK:    printf ("done.\n");           break;
89
    case OR1KSIM_RC_BRKPT: printf ("hit breakpoint.\n"); break;
90
    default:               printf ("failed.\n");         return  1;
91
    }
92
 
93
 
94
  /* Test of timing. Set a time point, run for the duration, then check the
95
     timing matches. */
96
  or1ksim_set_time_point ();
97
  printf ("Set time point.\n");
98
  printf ("Running code...");
99
  switch (or1ksim_run (duration))
100
    {
101
    case OR1KSIM_RC_OK:    printf ("done.\n");           break;
102
    case OR1KSIM_RC_BRKPT: printf ("hit breakpoint.\n"); break;
103
    default:               printf ("failed.\n");         return  1;
104
    }
105
  /* All done OK (within 1ps) */
106
  double measured_duration = or1ksim_get_time_period ();
107
 
108
  if (fabs (duration - measured_duration) < 1e-12)
109
    {
110
      printf ("Measured time period correctly.\n");
111
    }
112
  else
113
    {
114
      printf ("Failed. Requested period %.12f, but measured %.12f\n", duration,
115
              measured_duration);
116
      return  1;
117
    }
118
 
119
  /* Test endianness */
120
  if (or1ksim_is_le ())
121
    {
122
      printf ("Little endian architecture.\n");
123
    }
124
  else
125
    {
126
      printf ("Big endian architecture.\n");
127
    }
128
 
129
  /* Check for clock rate */
130
  unsigned long int  clock_rate = or1ksim_clock_rate ();
131
 
132
  if (clock_rate > 0)
133
    {
134
      printf ("Clock rate %ld Hz.\n", clock_rate);
135
    }
136
  else
137
    {
138
      printf ("Invalid clock rate %ld Hz.\n", clock_rate);
139
      return  1;
140
    }
141
 
142
  printf ("Test completed successfully.\n");
143
  return  0;
144
 
145
}       /* main () */

powered by: WebSVN 2.1.0

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