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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [cc/] [testbench.cc] - Diff between revs 107 and 125

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 107 Rev 125
Line 1... Line 1...
 
/* $Id: testbench.cc,v 1.2 2008-04-21 12:13:12 sybreon Exp $
 
**
 
** AEMB Function Verification C++ Testbench
 
** Copyright (C) 2004-2008 Shawn Tan <shawn.tan@aeste.net>
 
**
 
** This file is part of AEMB.
 
**
 
** AEMB is free software: you can redistribute it and/or modify it
 
** under the terms of the GNU General Public License as published by
 
** the Free Software Foundation, either version 3 of the License, or
 
** (at your option) any later version.
 
**
 
** AEMB is distributed in the hope that it will be useful, but WITHOUT
 
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
 
** License for more details.
 
**
 
** You should have received a copy of the GNU General Public License
 
** along with AEMB.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 
 
//#include <iostream>
 
#include <cstdio>
#include <cstdio>
#include <cstdlib>
#include <cstdlib>
#include "aemb/core.hh"
#include "aemb/core.hh"
 
#include "literate.hh"
 
#include "simboard.hh"
 
#include <vector>
 
 
volatile int *STDO = (int *) 0xFFFFFF00;
#define MAX_TEST 5
 
 
#define FIFO_SIZE 4
int thread1() // runs math tests
int fifo[FIFO_SIZE];
 
int ridx = 0;
 
int widx = 0;
 
 
 
// Push numbers into the FIFO (if it is not full)
 
void fifoProduce()
 
{
 
  for (int i=0; i<100; ++i)
 
    {
    {
      int wnxt = widx + 1;
  // *** 1. FIBONACCI *** //
      while (wnxt == ridx); // block if full
  outword (0xF1B07357);
      fifo[widx] = i;
  if (fibonacciTest(MAX_TEST) != EXIT_SUCCESS) trap(-1);
      widx = (widx + 1) % FIFO_SIZE;
 
    }
 
}
 
 
 
// Pull stuff from the FIFO (if there is any)
  // *** 2. EUCLIDEAN *** //
void fifoConsume()
  outword (0xEC1D7357);
{
  if (euclideanTest(MAX_TEST) != EXIT_SUCCESS) trap(-2);
  for (int i=0; i<100; ++i)
 
    {
 
      int rnxt = ridx + 1;
 
      while (rnxt == widx); // block if empty
 
      *STDO = fifo[ridx];
 
      ridx = (ridx + 1) % FIFO_SIZE;
 
    }
 
}
 
 
 
aemb::Semaphore amutex(0), bmutex(0);
 
 
 
int count = 0;
  // *** 3. NEWTON-RHAPSON *** //
 
  outword (0xF10A7357);
 
  if (newtonTest(MAX_TEST) != EXIT_SUCCESS) trap(-3);
 
 
int thread0() // runs for Thread 0
  outword (0xAAAAAAAA);
{
  aemb::rendezvous(); // Wait for other thread
  *STDO = ++count;
  return 0;
  amutex.signal();
 
  bmutex.wait();
 
  *STDO = ++count;
 
}
}
 
 
 
 
int thread1() // main for Thread 1
int thread0() // runs core tests
{
{
  std::printf("HELLO WORLD\n");
  // *** 1. MALLOC TEST ***/
  bmutex.signal();
  //if (memoryTest(100) != EXIT_SUCCESS) trap(1);
  amutex.wait();
 
  *STDO = ++count;
 
}
 
 
 
int nothreads() // for single threaded case
 
{
 
  return EXIT_SUCCESS;
 
}
 
 
 
 
  // *** 2. INTERRUPT TEST *** //
 
  //if (interruptTest(10000) != EXIT_SUCCESS) trap(2);
 
 
void outbyte(char c) {
  // *** 3. XSL *** //
  char *LCDO = (char *)0xFFFFFF10;
  //if (xslTest(0xBADCAB1E) != EXIT_SUCCESS) trap(3);
  *LCDO = c;
 
}
 
 
 
char inbyte() {
  outword (0xBBBBBBBB);
 
  aemb::rendezvous(); // Wait for other thread
  return 0;
  return 0;
}
}
 
 
 
int threads()
 
{
 
  if (aemb::isThread1())
 
    return thread1();
 
  else
 
    return thread0();
 
}
 
 
// run tests
// run tests
int main()
int main()
{
{
  if (aemb::isThread0()) return thread0(); else // split thread1
  threads();
    if (aemb::isThread1()) return thread1(); else // split thread0
  return EXIT_SUCCESS;
      return (nothreads()); // run both threads    
 
}
}
 
 
 No newline at end of file
 No newline at end of file
 
/*
 
$Log: not supported by cvs2svn $
 
*/
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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