Ignore:
Timestamp:
May 28, 2013, 11:17:14 AM (11 years ago)
Author:
meunier
Message:

Tried to clean the test_regression directory:

  • Code formatting
  • Supressed warnings
  • Made comprehensible outputs
  • Factorized Makefiles

There's still a lot to do (many tests don't pass for either good or bad reasons)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/test_regression/19122005/system2.cpp

    r1 r55  
    1 #include <systemc.h>
    21
    3 #define ASSERT(x) \
    4   { errnum++; \
    5     if (!(x)) \
    6     { \
    7     cerr << "ASSERT : " #x "\n"; \
    8     exit (errnum); \
    9     } \
    10   }
     2#include "systemc.h"
     3#include "test.h"
     4
    115
    126using namespace std;
    137
     8
    149struct inner : sc_module {
    15         sc_in_clk      clk;
    16   sc_in<int>      i1;
    17   int reg;
     10    sc_in_clk clk;
     11    sc_in<int> i1;
     12    int reg;
    1813
    19   void save (ostream &o)
    20   {
    21     o << reg << endl;
    22   }
     14    void save(ostream & o) {
     15        o << reg << endl;
     16    }
    2317
    24   void save_state (FILE *fic)
    25   {
    26     cerr << "saving " << name () << "\n";
    27     fprintf (fic, "%d\n", reg);
    28   }
     18    void save_state(FILE * fic) {
     19        cerr << "saving " << name() << "\n";
     20        fprintf (fic, "%d\n", reg);
     21    }
    2922
    30   void restore_state (FILE *fic)
    31   {
    32     cerr << "restoring " << name () << "\n";
    33     int i;
    34     fscanf (fic, "%d\n", &i);
    35     reg = i;
    36   }
     23    void restore_state(FILE * fic) {
     24        cerr << "restoring " << name () << "\n";
     25        int i;
     26        fscanf (fic, "%d\n", &i);
     27        reg = i;
     28    }
    3729
    38   void trans ()
    39   {
    40     reg = i1.read();
    41   }
     30    void trans() {
     31        reg = i1.read();
     32    }
    4233
    43   SC_HAS_PROCESS(inner);
    44         inner (sc_module_name n) : sc_module (n),
     34    SC_HAS_PROCESS(inner);
     35    inner(sc_module_name n) : sc_module(n),
    4536    clk("clk"),
    46     i1("i1")
    47   {
    48                 SC_METHOD(trans);
    49                 sensitive << clk.pos();
    50     dont_initialize();
     37    i1("i1") {
     38        SC_METHOD(trans);
     39        sensitive << clk.pos();
     40        dont_initialize();
    5141#ifdef SYSTEMCASS_SPECIFIC
    52     //SAVE_HANDLER(save);
    53     SAVE_HANDLER(save_state);
     42        SAVE_HANDLER(save_state);
    5443#endif
    55         };
     44    }
     45
    5646};
    5747
     48
    5849struct test : sc_module {
    59         sc_in_clk      clk;
    60         sc_in<bool>    i1;
    61         sc_in<int>      i2;
    62         sc_in<int>      i3;
    63   inner          inner1;
     50    sc_in_clk clk;
     51    sc_in<bool> i1;
     52    sc_in<int> i2;
     53    sc_in<int> i3;
     54    inner inner1;
    6455
    65   int  tab[16];
    66   bool b;
     56    int  tab[16];
     57    bool b;
    6758
    68   void trans ()
    69   {
    70     b = i1.read() ^ b;
    71     tab[i3.read() % 16] = i2;
    72   }
     59    void trans() {
     60        b = i1.read() ^ b;
     61        tab[i3.read() % 16] = i2;
     62    }
    7363
    7464
    75   void save (ostream &o)
    76   {
    77     o << ((b)?1:0) << endl;
    78     int i;
    79     for (i = 0; i < 16; ++i)
    80       o << tab[i] << endl;
    81   }
     65    void save(ostream & o) {
     66        o << ((b) ? 1 : 0) << endl;
     67        int i;
     68        for (i = 0; i < 16; ++i) {
     69            o << tab[i] << endl;
     70        }
     71    }
    8272
    83   void save_state (FILE *fic)
    84   {
    85     cerr << "saving " << name () << "\n";
    86     fprintf (fic, "%c\n", ((b)?'1':'0'));
    87     int i;
    88     for (i = 0; i < 16; ++i)
    89     {
    90       fprintf (fic, "%d\n", tab[i]);
     73    void save_state(FILE * fic) {
     74        cerr << "saving " << name() << "\n";
     75        fprintf (fic, "%c\n", ((b) ? '1' : '0'));
     76        int i;
     77        for (i = 0; i < 16; ++i) {
     78            fprintf(fic, "%d\n", tab[i]);
     79        }
    9180    }
    92   }
    9381
    94   void restore_state (FILE *fic)
    95   {
    96     cerr << "restoring " << name () << "\n";
    97     int j;
    98     fscanf (fic, "%d\n", &j);
    99     b = (j > 0);
    100     int i;
    101     for (i = 0; i < 16; ++i)
    102     {
    103       fscanf (fic, "%d\n", &j);
    104       tab[i] = j;
     82    void restore_state(FILE * fic) {
     83        cerr << "restoring " << name() << "\n";
     84        int j;
     85        fscanf (fic, "%d\n", &j);
     86        b = (j > 0);
     87        int i;
     88        for (i = 0; i < 16; ++i) {
     89            fscanf(fic, "%d\n", &j);
     90            tab[i] = j;
     91        }
    10592    }
    106   }
    10793
    108   SC_HAS_PROCESS(test);
    109         test (sc_module_name n) : sc_module (n),
     94    SC_HAS_PROCESS(test);
     95    test (sc_module_name n) : sc_module (n),
    11096    clk("clk"),
    11197    i1("i1"), i2("i2"), i3("i3"),
    112     inner1 ("inner1")
    113   {
    114                 SC_METHOD(trans);
    115                 sensitive << clk.pos();
    116     dont_initialize();
     98    inner1 ("inner1") {
     99        SC_METHOD(trans);
     100        sensitive << clk.pos();
     101        dont_initialize();
    117102#ifdef SYSTEMCASS_SPECIFIC
    118     //SAVE_HANDLER(save);
    119     SAVE_HANDLER(save_state);
     103        SAVE_HANDLER(save_state);
    120104#endif
    121         };
     105    }
     106
    122107};
    123108
    124 int
    125 usage (const char *com)
    126 {
    127   cout << "Usage :\n" << com << " [#cycles]\n";
    128   return EXIT_FAILURE;
     109
     110int usage (const char * com) {
     111    cout << "Usage :\n" << com << " [#cycles]\n";
     112    return EXIT_FAILURE;
    129113}
    130114
    131 sc_signal<bool>              s01 ("bool");
    132 sc_signal<int>               s02 ("tab_index"),
    133                              s03 ("value_to_write_in_tab");
    134115
    135 void*
    136 func ()
    137 {
    138   cerr << "func () at #" << sc_time_stamp () << endl;
    139   int i = (int)(sc_time_stamp ().to_double ()) / 1000;
    140   s01  = (i & 1) > 0;
    141   s02  = (i + (i << 1)) << 6;
    142   s03  = i;
    143   ++i;
    144   return 0;
     116sc_signal<bool> s01("bool");
     117sc_signal<int> s02("tab_index"),
     118s03 ("value_to_write_in_tab");
     119
     120
     121void * func() {
     122    cerr << "func () at #" << sc_time_stamp() << endl;
     123    int i = (int) (sc_time_stamp().to_double()) / 1000;
     124    s01  = (i & 1) > 0;
     125    s02  = (i + (i << 1)) << 6;
     126    s03  = i;
     127    ++i;
     128    return 0;
    145129}
    146130
    147 void
    148 save ()
    149 {
     131
     132void save() {
    150133#ifdef SYSTEMCASS_SPECIFIC
    151   int current_cycle = ((int)sc_time_stamp().to_double() / 1000);
    152   if (current_cycle != 20)
    153     return;
    154   char name[256];
    155   sprintf (name,"test2_systemcass_%d.dat",current_cycle);
    156   sc_save_simulation (name);
     134    int current_cycle = ((int) sc_time_stamp().to_double() / 1000);
     135    if (current_cycle != 20) {
     136        return;
     137    }
     138    char name[256];
     139    sprintf(name, "test2_systemcass_%d.dat", current_cycle);
     140    sc_save_simulation(name);
    157141#endif
    158142}
    159143
    160 int sc_main (int argc, char *argv[])
    161 {
    162   int errnum = 0;
    163         sc_clock                     signal_clk("my_clock",1, 0.5);
    164144
    165   test test1("test1");
    166   test1.clk (signal_clk);
    167   test1.i1 (s01);
    168   test1.i2 (s02);
    169   test1.i3 (s03);
    170   test1.inner1.clk (signal_clk);
    171   test1.inner1.i1 (s02);
     145int sc_main (int argc, char * argv[]) {
     146    sc_clock signal_clk("my_clock",1, 0.5);
    172147
    173         // Init & run
    174         sc_start (0);
     148    test test1("test1");
     149    test1.clk(signal_clk);
     150    test1.i1(s01);
     151    test1.i2(s02);
     152    test1.i3(s03);
     153    test1.inner1.clk(signal_clk);
     154    test1.inner1.i1(s02);
     155
     156    // Init & run
     157    sc_start(sc_time(0, sc_core::SC_NS));
    175158
    176159#ifndef SOCVIEW
    177   if (argc != 2)
    178   {
    179     return usage (argv[0]);
    180   }
     160    if (argc != 2) {
     161        return usage(argv[0]);
     162    }
    181163
    182         int nb = atoi(argv[1]);
     164    int nb = atoi(argv[1]);
    183165
    184   if (nb == 0)
    185   {
    186     return usage (argv[0]);
    187   }
     166    if (nb == 0) {
     167        return usage(argv[0]);
     168    }
    188169
    189   int i = 0;
    190   while (i++ < nb)
    191   {
    192     func ();
    193     sc_start (1);
    194     save ();
    195   }
     170    int i = 0;
     171    while (i++ < nb) {
     172        func();
     173        sc_start(sc_time(1, sc_core::SC_NS));
     174        save();
     175    }
    196176#else
    197   debug(&func);
     177    debug(&func);
    198178#endif
    199179
    200         return EXIT_SUCCESS;
     180    return EXIT_SUCCESS;
    201181}
    202182
     183
     184/*
     185# Local Variables:
     186# tab-width: 4;
     187# c-basic-offset: 4;
     188# c-file-offsets:((innamespace . 0)(inline-open . 0));
     189# indent-tabs-mode: nil;
     190# End:
     191#
     192# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     193*/
     194
Note: See TracChangeset for help on using the changeset viewer.