Ignore:
Timestamp:
Apr 15, 2008, 8:40:01 PM (17 years ago)
Author:
rosiere
Message:
  • Finish Environment (and test)
  • Continue predictor_unit
  • Add external tools
  • svn keyword "Id" set
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/IPs/systemC/Environment/Cache/selftest/main.cpp

    • Property svn:keywords set to Id
    r80 r81  
     1#include "../include/Cache.h"
    12#include <iostream>
    2 #include "../include/Cache.h"
    33
    44using namespace std;
     
    66using namespace environment::cache;
    77
    8 #define TEST(x,y)                               \
    9   {                                             \
    10     cout << "Line " << __LINE__ << " : ";       \
    11     if (x==y)                                   \
    12       {                                         \
    13         cout << "Test OK" << endl;              \
    14       }                                         \
    15     else                                        \
    16       {                                         \
    17         cout << "Test KO" << endl;              \
    18         exit (EXIT_FAILURE);                    \
    19       }                                         \
     8#define TEST(x,y)                                                       \
     9  {                                                                     \
     10    if (x==y)                                                           \
     11      {                                                                 \
     12        cout << "Line " << __LINE__ << " : " << "Test OK" << endl;      \
     13      }                                                                 \
     14    else                                                                \
     15      {                                                                 \
     16        cout << "Line " << __LINE__ << " : " << "Test KO" << endl;      \
     17        exit (EXIT_FAILURE);                                            \
     18      }                                                                 \
    2019  } while (0)
    2120   
    2221
    2322
    24 int main (void)
     23#ifdef SYSTEMC
     24int sc_main (int argc, char * argv[])
     25#else
     26int    main (int argc, char * argv[])
     27#endif
    2528{
    2629  cout << "<main> Begin" << endl;
     
    3841       );
    3942
    40     cout << *param << endl;
     43//     cout << *param << endl;
    4144
    4245    cache_onelevel::Cache_OneLevel * cache = new cache_onelevel::Cache_OneLevel ("my_cache",param);
    4346    cache->reset();
    4447   
    45     cout << *cache << endl;
     48//     cout << *cache << endl;
    4649   
    4750    cache->transition();
    4851    cache->transition();
    4952
    50     cout << *cache << endl;
     53//     cout << *cache << endl;
    5154
    5255    TEST(cache->access(0, 0x100, 0, CACHED, WRITE), MISS);
     
    8992
    9093    cache->transition(); // miss cycle 1
    91     cout << *cache << endl;
     94//     cout << *cache << endl;
    9295
    9396    TEST(cache->access(0, 0x200, 0, CACHED, WRITE), MISS      );
     
    99102    cache->transition(); // miss cycle 2
    100103    cache->transition(); // miss cycle 3
    101     cout << *cache << endl;
     104//     cout << *cache << endl;
    102105
    103106    // line 0 : all way is use
     
    113116
    114117    cache->transition();
    115     cout << *cache << endl;
     118//     cout << *cache << endl;
    116119   
    117120    TEST(cache->access(0, 0x500, 0,  CACHED, WRITE), MISS      );
     
    141144    TEST(cache->latence(3), 5);
    142145   
    143     cout << *cache << endl;
     146//     cout << *cache << endl;
    144147
    145148    delete cache;
     
    174177       );
    175178
    176     cout << *param << endl;
     179//     cout << *param << endl;
    177180 
    178181    cache_multilevel::Cache_MultiLevel * cache = new cache_multilevel::Cache_MultiLevel ("my_cache",param);
    179182
    180     cout << *cache << endl;
    181183    cache->reset();
    182     cout << *cache << endl;
     184//     cout << *cache << endl;
    183185 
    184186    cache_multilevel::Access access;
     
    202204    cache->transition(); //11
    203205    cache->transition(); //10
    204     cout << *cache << endl;
     206//     cout << *cache << endl;
    205207
    206208    access = cache->access (0, 0x100, 0, CACHED, WRITE);
     
    238240    TEST(access.latence      , 1);
    239241    TEST(access.last_nb_level, 0);
    240     cout << *cache << endl;
     242//     cout << *cache << endl;
    241243
    242244    cache->transition();
     
    303305    cache->transition(); //11
    304306    cache->transition(); //10
    305     cout << *cache << endl;
     307//     cout << *cache << endl;
    306308
    307309    access = cache->access (0, 0x100, 0, CACHED, WRITE);
     
    358360
    359361    access = cache->access (1, 0x100, 0, CACHED, WRITE);
    360     cout << access<< endl;
     362//     cout << access<< endl;
    361363   
    362364    cache->update_access(access);
     
    367369    TEST(access.last_nb_level, 1);
    368370
    369     cout << *cache << endl;
     371//     cout << *cache << endl;
    370372    delete cache;
    371373    delete param;
     
    389391    cache_shared_size_line     [0] = 8 ;
    390392    cache_shared_size_word     [0] = 4 ;
    391     cache_shared_associativity [0] = 4 ;
     393    cache_shared_associativity [0] = 8 ;
    392394    cache_shared_hit_latence   [0] = 2 ;
    393395    cache_shared_miss_penality [0] = 5 ;
     
    467469
    468470    dcache_nb_level      [1]    = 2;
    469     dcache_nb_port       [1]    = 2;
     471    dcache_nb_port       [1]    = 8; // to test
    470472    dcache_nb_line       [1]    = new uint32_t [2];
    471473    dcache_size_line     [1]    = new uint32_t [2];
     
    519521       );
    520522
    521     cout << *param << endl;
     523//     cout << *param << endl;
    522524
    523525    cache::Cache * cache = new cache::Cache ("my_cache",param);
    524526
     527    cache->reset();
     528//     cout << *cache << endl;
     529
     530    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 16);
     531    cache->transition();
     532    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 15);
     533    cache->transition();
     534    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 14);
     535    cache->transition();
     536    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 13);
     537    cache->transition();
     538    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 12);
     539    cache->transition();
     540    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 11);
     541    cache->transition();
     542    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 10);
     543    cache->transition();
     544    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  9);
     545    cache->transition();
     546    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  8);
     547    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE), 16); // miss thread !=
     548    TEST(cache->latence (DATA_CACHE, 0, 0, 0x100, 0, CACHED, WRITE),  6); // miss L1, hit L2
     549    cache->transition();
     550    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  7);
     551    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE), 15);
     552    cache->transition();
     553    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  6);
     554    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE), 14);
     555    cache->transition();
     556    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  5);
     557    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE), 13);
     558    cache->transition();
     559    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  4);
     560    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE), 12);
     561    cache->transition();
     562    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  3);
     563    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE), 11);
     564    cache->transition();
     565    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  2);
     566    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE), 10);
     567    cache->transition();
     568    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     569    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  9);
     570    cache->transition();
     571    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     572    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  8);
     573    cache->transition();
     574    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     575    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  7);
     576    cache->transition();
     577    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     578    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  6);
     579    cache->transition();
     580    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     581    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  5);
     582    cache->transition();
     583    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     584    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  4);
     585    cache->transition();
     586    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     587    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  3);
     588    cache->transition();
     589    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     590    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  2);
     591    cache->transition();
     592
     593    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  5); // L1 is direct map, hit L2
     594    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  1); // write in L1
     595    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE), 16);
     596    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE), 16);
     597    cache->transition();
     598
     599    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  4);
     600    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  1);
     601    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE), 15);
     602    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE), 15);
     603    cache->transition();
     604    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  3);
     605    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  1);
     606    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE), 14);
     607    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE), 14);
     608    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE), 16);
     609    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE), 16);
     610    cache->transition();
     611    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  2);
     612    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  1);
     613    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE), 13);
     614    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE), 13);
     615    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE), 15);
     616    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE), 15);
     617
     618
     619    cache->transition();
     620    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     621    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  5);
     622    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE), 12);
     623    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE), 12);
     624    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE), 14);
     625    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE), 14);
     626
     627
     628    cache->transition();
     629    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     630    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  4);
     631    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE), 11);
     632    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE), 11);
     633    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE), 13);
     634    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE), 13);
     635
     636    // in cache L2 : context 0,1,2,3
     637
     638    cache->transition();
     639    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     640    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  3);
     641    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE), 10);
     642    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE), 10);
     643    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE), 12);
     644    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE), 12);
     645
     646    cache->transition();
     647    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     648    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  2);
     649    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  9);
     650    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE),  9);
     651    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE), 11);
     652    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE), 11);
     653
     654    cache->transition();
     655    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  5);
     656    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  1);
     657    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  8);
     658    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE),  8);
     659    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE), 10); // write in L2
     660    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE), 10); // write in L2
     661
     662    cache->transition();
     663    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  4);
     664    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  1);
     665    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  7);
     666    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE),  7);
     667    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE),  9);
     668    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE),  9);
     669
     670    cache->transition();
     671    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  3);
     672    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  1);
     673    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  6);
     674    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE),  6);
     675    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE),  8);
     676    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE),  8);
     677
     678    cache->transition();
     679    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  2);
     680    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  1);
     681    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  5);
     682    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE),  5);
     683    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE),  7);
     684    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE),  7);
     685
     686    cache->transition();
     687    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     688    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  5);
     689    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  4);
     690    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE),  4);
     691    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE),  6);
     692    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE),  6);
     693
     694    cache->transition();
     695    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     696    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  4);
     697    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  3);
     698    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE),  3);
     699    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE),  5);
     700    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE),  5);
     701
     702    cache->transition();
     703    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE),  1);
     704    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  3);
     705    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  2);
     706    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE),  2);
     707    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE),  4);
     708    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE),  4);
     709
    525710    cout << *cache << endl;
    526     cache->reset();
    527     cout << *cache << endl;
    528 
    529     TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 16);
    530     cache->transition();
    531     TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 15);
    532     cache->transition();
    533 
    534     cout << *cache << endl;
    535 
     711
     712    cache->transition();
     713    // In L2 : context 1,2,4,5 : also context 0 and 3 miss L1 and L2, hit L3
     714    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 11);
     715    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  2);
     716    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  1);
     717    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE), 11);
     718    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE),  3);
     719    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE),  3);
     720
     721    cache->transition();
     722    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 10);
     723    TEST(cache->latence (DATA_CACHE, 1, 1, 0x100, 1, CACHED, WRITE),  1);
     724    TEST(cache->latence (DATA_CACHE, 1, 2, 0x100, 2, CACHED, WRITE),  5);
     725    TEST(cache->latence (DATA_CACHE, 1, 3, 0x100, 3, CACHED, WRITE), 10);
     726    TEST(cache->latence (DATA_CACHE, 1, 4, 0x100, 4, CACHED, WRITE),  2);
     727    TEST(cache->latence (DATA_CACHE, 1, 5, 0x100, 5, CACHED, WRITE),  2);
     728
     729// //     cout << *cache << endl;
    536730
    537731    delete    cache;
     732
    538733    delete    param;
    539734    delete [] cache_shared_nb_line      ;
Note: See TracChangeset for help on using the changeset viewer.