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

Subversion Repositories openrisc

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

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 220 jeremybenn
  /* Dummy argv array to pass arguments to or1ksim_init. Varies depending on
73
     whether an image file is specified. */
74
  int   dummy_argc;
75
  char *dummy_argv[5];
76
 
77
  dummy_argv[0] = "libsim";
78
  dummy_argv[1] = "-q";
79
  dummy_argv[2] = "-f";
80
  dummy_argv[3] = argv[1];
81
  dummy_argv[4] = argv[2];
82
 
83
  dummy_argc = 5;
84
 
85 90 jeremybenn
  /* Put the initialization message afterwards, or it will get swamped by the
86
     Or1ksim header. */
87 220 jeremybenn
  if (0 == or1ksim_init (dummy_argc, dummy_argv, NULL, NULL, NULL))
88 90 jeremybenn
    {
89
      printf ("Initalization succeeded.\n");
90
    }
91
  else
92
    {
93
      printf ("Initalization failed.\n");
94
      return  1;
95
    }
96
 
97
  /* Test of running */
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
 
106
 
107
  /* Test of timing. Set a time point, run for the duration, then check the
108
     timing matches. */
109
  or1ksim_set_time_point ();
110
  printf ("Set time point.\n");
111
  printf ("Running code...");
112
  switch (or1ksim_run (duration))
113
    {
114
    case OR1KSIM_RC_OK:    printf ("done.\n");           break;
115
    case OR1KSIM_RC_BRKPT: printf ("hit breakpoint.\n"); break;
116
    default:               printf ("failed.\n");         return  1;
117
    }
118
  /* All done OK (within 1ps) */
119
  double measured_duration = or1ksim_get_time_period ();
120
 
121
  if (fabs (duration - measured_duration) < 1e-12)
122
    {
123
      printf ("Measured time period correctly.\n");
124
    }
125
  else
126
    {
127
      printf ("Failed. Requested period %.12f, but measured %.12f\n", duration,
128
              measured_duration);
129
      return  1;
130
    }
131
 
132
  /* Test endianness */
133
  if (or1ksim_is_le ())
134
    {
135
      printf ("Little endian architecture.\n");
136
    }
137
  else
138
    {
139
      printf ("Big endian architecture.\n");
140
    }
141
 
142
  /* Check for clock rate */
143
  unsigned long int  clock_rate = or1ksim_clock_rate ();
144
 
145
  if (clock_rate > 0)
146
    {
147
      printf ("Clock rate %ld Hz.\n", clock_rate);
148
    }
149
  else
150
    {
151
      printf ("Invalid clock rate %ld Hz.\n", clock_rate);
152
      return  1;
153
    }
154
 
155
  printf ("Test completed successfully.\n");
156
  return  0;
157
 
158
}       /* main () */

powered by: WebSVN 2.1.0

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