Changeset 34db7fa in mainline for kernel/test/fpu


Ignore:
Timestamp:
2006-12-12T12:32:02Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
96348adc
Parents:
df496c5
Message:

cleanup kernel tests infrastructure

Location:
kernel/test/fpu
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/fpu/fpu1.c

    rdf496c5 r34db7fa  
    2828 */
    2929
     30#if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen))
     31
    3032#include <print.h>
    3133#include <debug.h>
     
    3941#include <arch/arch.h>
    4042
    41 #ifdef CONFIG_BENCH
    42 #include <arch/cycle.h>
    43 #endif
    44 
    45 #if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen))
    46 
    47 #define THREADS         150*2
     43
     44#define THREADS         150
    4845#define ATTEMPTS        100
    4946
     
    5350
    5451#ifdef KERN_ia32_ARCH_H_
    55 static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
     52static inline double sqrt(double x)
     53{
     54        double v;
     55       
     56        asm (
     57                "fsqrt\n"
     58                : "=t" (v)
     59                : "0" (x)
     60        );
     61       
     62        return v;
     63}
    5664#endif
    5765
    5866#ifdef KERN_amd64_ARCH_H_
    59 static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
     67static inline double sqrt(double x)
     68{
     69        double v;
     70       
     71        asm (
     72                "fsqrt\n"
     73                : "=t" (v)
     74                : "0" (x)
     75        );
     76       
     77        return v;
     78}
    6079#endif
    6180
    6281#ifdef KERN_ia64_ARCH_H_
     82
     83#undef PI_10e8 
     84#define PI_10e8 3141592
     85
    6386static inline long double sqrt(long double a)
    6487{   
     
    6689        long double lx = 0;
    6790
    68         if(a<0.00000000000000001) return 0;
     91        if (a < 0.00000000000000001)
     92                return 0;
    6993               
    70         while(x!=lx)
    71         {
    72                 lx=x;
    73                 x=(x+(a/x))/2;
    74         }
     94        while(x != lx) {
     95                lx = x;
     96                x = (x + (a / x)) / 2;
     97        }
     98       
    7599        return x;
    76100}
     
    78102
    79103
    80 
    81104static atomic_t threads_ok;
     105static atomic_t threads_fault;
    82106static waitq_t can_start;
    83107
     
    92116
    93117        for (i = 0; i<ATTEMPTS; i++) {
    94                 le=-1;
    95                 e=0;
    96                 f=1;
    97 
    98                 for(d=1;e!=le;d*=f,f+=1) {
    99                         le=e;
    100                         e=e+1/d;
    101                 }
    102 
    103                 if((int)(100000000*e)!=E_10e8)
    104                         panic("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8);
    105         }
    106 
    107         printf("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8);
     118                le = -1;
     119                e = 0;
     120                f = 1;
     121
     122                for (d = 1; e != le; d *= f, f += 1) {
     123                        le = e;
     124                        e = e + 1 / d;
     125                }
     126
     127                if ((int) (100000000 * e) != E_10e8) {
     128                        printf("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8);
     129                        atomic_inc(&threads_fault);
     130                        break;
     131                }
     132        }
    108133        atomic_inc(&threads_ok);
    109134}
     
    111136static void pi(void *data)
    112137{
    113 
    114 #ifdef KERN_ia64_ARCH_H_
    115 #undef PI_10e8 
    116 #define PI_10e8 3141592
    117 #endif
    118 
    119 
    120138        int i;
    121139        double lpi, pi;
     
    126144        waitq_sleep(&can_start);
    127145
    128 
    129         for (i = 0; i<ATTEMPTS; i++) {
     146        for (i = 0; i < ATTEMPTS; i++) {
    130147                lpi = -1;
    131148                pi = 0;
    132149
    133                 for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
     150                for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
    134151                        double sc, cd;
    135152
    136                         sc = sqrt(1 - (ab*ab/4));
     153                        sc = sqrt(1 - (ab * ab / 4));
    137154                        cd = 1 - sc;
    138                         ad = sqrt(ab*ab/4 + cd*cd);
     155                        ad = sqrt(ab * ab / 4 + cd * cd);
    139156                        lpi = pi;
    140157                        pi = 2 * n * ad;
     
    142159
    143160#ifdef KERN_ia64_ARCH_H_
    144                 if((int)(1000000*pi)!=PI_10e8)
    145                         panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000*pi),(unative_t) (PI_10e8/100));
     161                if ((int) (1000000 * pi) != PI_10e8) {
     162                        printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100));
     163                        atomic_inc(&threads_fault);
     164                        break;
     165                }
    146166#else
    147                 if((int)(100000000*pi)!=PI_10e8)
    148                         panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8);
    149 #endif
    150 
    151         }
    152 
    153         printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8);
     167                if ((int) (100000000 * pi) != PI_10e8) {
     168                        printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8);
     169                        atomic_inc(&threads_fault);
     170                        break;
     171                }
     172#endif
     173        }
    154174        atomic_inc(&threads_ok);
    155175}
    156176
    157 void test_fpu1(void)
    158 {
    159 #ifdef CONFIG_BENCH
    160         uint64_t t0 = get_cycle();
    161 #endif
    162         thread_t *t;
    163         int i;
     177char * test_fpu1(void)
     178{
     179        unsigned int i, total = 0;
    164180
    165181        waitq_initialize(&can_start);
    166 
    167         printf("FPU test #1\n");
    168         printf("Creating %d threads... ", THREADS);
    169 
    170         for (i=0; i<THREADS/2; i++) { 
    171                 if (!(t = thread_create(e, NULL, TASK, 0, "e")))
    172                         panic("could not create thread\n");
     182        atomic_set(&threads_ok, 0);
     183        atomic_set(&threads_fault, 0);
     184        printf("Creating %d threads... ", 2 * THREADS);
     185
     186        for (i = 0; i < THREADS; i++) { 
     187                thread_t *t;
     188               
     189                if (!(t = thread_create(e, NULL, TASK, 0, "e"))) {
     190                        printf("could not create thread %d\n", 2 * i);
     191                        break;
     192                }
    173193                thread_ready(t);
    174                 if (!(t = thread_create(pi, NULL, TASK, 0, "pi")))
    175                         panic("could not create thread\n");
     194                total++;
     195               
     196                if (!(t = thread_create(pi, NULL, TASK, 0, "pi"))) {
     197                        printf("could not create thread %d\n", 2 * i + 1);
     198                        break;
     199                }
    176200                thread_ready(t);
     201                total++;
    177202        }
    178203        printf("ok\n");
     
    180205        thread_sleep(1);
    181206        waitq_wakeup(&can_start, WAKEUP_ALL);
    182 
    183         while (atomic_get(&threads_ok) != THREADS)
    184                 ;
    185                
    186         printf("Test passed.\n");
    187 #ifdef CONFIG_BENCH
    188         uint64_t dt = get_cycle() - t0;
    189         printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
    190 #endif
    191 }
    192 
    193 #else
    194 
    195 void test_fpu1(void)
    196 {
    197         printf("This test is available only on Intel/AMD platforms.");
    198 }
    199 
    200 #endif
     207       
     208        while (atomic_get(&threads_ok) != total) {
     209                printf("Threads left: %d\n", total - atomic_get(&threads_ok));
     210                thread_sleep(1);
     211        }
     212       
     213        if (atomic_get(&threads_fault) == 0)
     214                return NULL;
     215       
     216        return "Test failed";
     217}
     218
     219#endif
  • kernel/test/fpu/mips2.c

    rdf496c5 r34db7fa  
    2727 */
    2828
     29#ifdef mips32
     30
    2931#include <print.h>
    3032#include <debug.h>
     
    3840#include <arch.h>
    3941
    40 #ifdef mips32
    41 
    4242#define THREADS         50
    4343#define DELAY           10000L
     
    4545
    4646static atomic_t threads_ok;
     47static atomic_t threads_fault;
    4748static waitq_t can_start;
    4849
     
    5051{
    5152        int i;
    52         int arg __attribute__((aligned(16))) = (int)((unative_t) data);
     53        int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
    5354        int after_arg __attribute__((aligned(16)));
    54 
     55       
    5556        thread_detach(THREAD);
    5657       
    5758        waitq_sleep(&can_start);
    5859
    59         for (i = 0; i<ATTEMPTS; i++) {
    60                 __asm__ volatile (
     60        for (i = 0; i < ATTEMPTS; i++) {
     61                asm volatile (
    6162                        "mtc1 %0,$1"
    62                         :"=r"(arg)
    63                         );
    64 
     63                        : "=r" (arg)
     64                );
     65               
    6566                delay(DELAY);
    66                 __asm__ volatile (
     67               
     68                asm volatile (
    6769                        "mfc1 %0, $1"
    68                         :"=r"(after_arg)
    69                         );
     70                        : "=r" (after_arg)
     71                );
    7072               
    71                 if(arg != after_arg)
    72                         panic("General reg tid%d: arg(%d) != %d\n",
    73                               THREAD->tid, arg, after_arg);
     73                if (arg != after_arg) {
     74                        printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
     75                        atomic_inc(&threads_fault);
     76                        break;
     77                }
    7478        }
    75 
    7679        atomic_inc(&threads_ok);
    7780}
     
    8083{
    8184        int i;
    82         int arg __attribute__((aligned(16))) = (int)((unative_t) data);
     85        int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
    8386        int after_arg __attribute__((aligned(16)));
    84 
     87       
    8588        thread_detach(THREAD);
    86 
     89       
    8790        waitq_sleep(&can_start);
    8891
    89         for (i = 0; i<ATTEMPTS; i++) {
    90                 __asm__ volatile (
     92        for (i = 0; i < ATTEMPTS; i++) {
     93                asm volatile (
    9194                        "mtc1 %0,$1"
    92                         :"=r"(arg)
    93                         );
     95                        : "=r" (arg)
     96                );
    9497
    9598                scheduler();
    96                 __asm__ volatile (
     99                asm volatile (
    97100                        "mfc1 %0,$1"
    98                         :"=r"(after_arg)
    99                         );
     101                        : "=r" (after_arg)
     102                );
    100103               
    101                 if(arg != after_arg)
    102                         panic("General reg tid%d: arg(%d) != %d\n",
    103                               THREAD->tid, arg, after_arg);
     104                if (arg != after_arg) {
     105                        panic("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
     106                        atomic_inc(&threads_fault);
     107                        break;
     108                }
    104109        }
    105 
    106110        atomic_inc(&threads_ok);
    107111}
    108112
    109113
    110 void test_mips2(void)
     114char * test_mips2(void)
    111115{
    112         thread_t *t;
    113         int i;
     116        unsigned int i, total = 0;
     117       
     118        waitq_initialize(&can_start);
     119        atomic_set(&threads_ok, 0);
     120        atomic_set(&threads_fault, 0);
     121        printf("Creating %d threads... ", 2 * THREADS);
    114122
    115         waitq_initialize(&can_start);
    116 
    117         printf("MIPS test #1\n");
    118         printf("Creating %d threads... ", THREADS);
    119 
    120         for (i=0; i<THREADS/2; i++) { 
    121                 if (!(t = thread_create(testit1, (void *)((unative_t)i*2), TASK, 0, "testit1")))
    122                         panic("could not create thread\n");
     123        for (i = 0; i < THREADS; i++) {
     124                thread_t *t;
     125               
     126                if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1"))) {
     127                        printf("could not create thread %d\n", 2 * i);
     128                        break;
     129                }
    123130                thread_ready(t);
    124                 if (!(t = thread_create(testit2, (void *)((unative_t)i*2+1), TASK, 0, "testit2")))
    125                         panic("could not create thread\n");
     131                total++;
     132               
     133                if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2"))) {
     134                        printf("could not create thread %d\n", 2 * i + 1);
     135                        break;
     136                }
    126137                thread_ready(t);
     138                total++;
    127139        }
    128 
    129140        printf("ok\n");
    130        
     141               
    131142        thread_sleep(1);
    132143        waitq_wakeup(&can_start, WAKEUP_ALL);
    133 
    134         while (atomic_get(&threads_ok) != THREADS)
    135                 ;
    136                
    137         printf("Test passed.\n");
    138 }
    139 
    140 #else
    141 
    142 void test_mips2(void)
    143 {
    144         printf("This test is availaible only on MIPS32 platform.\n");
     144       
     145        while (atomic_get(&threads_ok) != total) {
     146                printf("Threads left: %d\n", total - atomic_get(&threads_ok));
     147                thread_sleep(1);
     148        }
     149       
     150        if (atomic_get(&threads_fault) == 0)
     151                return NULL;
     152       
     153        return "Test failed";
    145154}
    146155
  • kernel/test/fpu/sse1.c

    rdf496c5 r34db7fa  
    2727 */
    2828
     29#if (defined(ia32) || defined(amd64) || defined(ia32xen))
     30
    2931#include <print.h>
    3032#include <debug.h>
     
    3840#include <arch.h>
    3941
    40 #ifdef CONFIG_BENCH
    41 #include <arch/cycle.h>
    42 #endif
    43 
    44 #if (defined(ia32) || defined(amd64) || defined(ia32xen))
    45 
    46 #define THREADS         50
     42#define THREADS         25
    4743#define DELAY           10000L
    4844#define ATTEMPTS        5
    4945
    5046static atomic_t threads_ok;
     47static atomic_t threads_fault;
    5148static waitq_t can_start;
    5249
     
    5451{
    5552        int i;
    56         int arg __attribute__((aligned(16))) = (int)((unative_t) data);
     53        int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
    5754        int after_arg __attribute__((aligned(16)));
    5855
     
    6158        waitq_sleep(&can_start);
    6259
    63         for (i = 0; i<ATTEMPTS; i++) {
    64                 __asm__ volatile (
    65                         "movlpd %0, %%xmm2"
    66                         :"=m"(arg)
    67                         );
     60        for (i = 0; i < ATTEMPTS; i++) {
     61                asm volatile (
     62                        "movlpd %0, %%xmm2\n"
     63                        : "=m" (arg)
     64                );
    6865
    6966                delay(DELAY);
    70                 __asm__ volatile (
    71                         "movlpd %%xmm2, %0"
    72                         :"=m"(after_arg)
    73                         );
     67                asm volatile (
     68                        "movlpd %%xmm2, %0\n"
     69                        : "=m" (after_arg)
     70                );
    7471               
    75                 if(arg != after_arg)
    76                         panic("tid%d: arg(%d) != %d\n",
    77                               THREAD->tid, arg, after_arg);
     72                if (arg != after_arg) {
     73                        printf("tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
     74                        atomic_inc(&threads_fault);
     75                        break;
     76                }
    7877        }
    79 
    8078        atomic_inc(&threads_ok);
    8179}
     
    8482{
    8583        int i;
    86         int arg __attribute__((aligned(16))) = (int)((unative_t) data);
     84        int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
    8785        int after_arg __attribute__((aligned(16)));
    88 
     86       
    8987        thread_detach(THREAD);
    9088       
    9189        waitq_sleep(&can_start);
    9290
    93         for (i = 0; i<ATTEMPTS; i++) {
    94                 __asm__ volatile (
    95                         "movlpd %0, %%xmm2"
    96                         :"=m"(arg)
    97                         );
     91        for (i = 0; i < ATTEMPTS; i++) {
     92                asm volatile (
     93                        "movlpd %0, %%xmm2\n"
     94                        : "=m" (arg)
     95                );
    9896
    9997                scheduler();
    100                 __asm__ volatile (
    101                         "movlpd %%xmm2, %0"
    102                         :"=m"(after_arg)
    103                         );
     98                asm volatile (
     99                        "movlpd %%xmm2, %0\n"
     100                        : "=m" (after_arg)
     101                );
    104102               
    105                 if(arg != after_arg)
    106                         panic("tid%d: arg(%d) != %d\n",
    107                               THREAD->tid, arg, after_arg);
     103                if (arg != after_arg) {
     104                        printf("tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
     105                        atomic_inc(&threads_fault);
     106                        break;
     107                }
    108108        }
    109 
    110109        atomic_inc(&threads_ok);
    111110}
    112111
    113112
    114 void test_sse1(void)
     113char * test_sse1(void)
    115114{
    116 #ifdef CONFIG_BENCH
    117         uint64_t t0 = get_cycle();
    118 #endif
    119         thread_t *t;
    120         int i;
     115        unsigned int i, total = 0;
    121116
    122117        waitq_initialize(&can_start);
     118        atomic_set(&threads_ok, 0);
     119        atomic_set(&threads_fault, 0);
     120        printf("Creating %d threads... ", 2 * THREADS);
    123121
    124         printf("SSE test #1\n");
    125         printf("Creating %d threads... ", THREADS);
    126 
    127         for (i=0; i<THREADS/2; i++) { 
    128                 if (!(t = thread_create(testit1, (void *)((unative_t)i*2), TASK, 0, "testit1")))
    129                         panic("could not create thread\n");
     122        for (i = 0; i < THREADS; i++) {
     123                thread_t *t;
     124               
     125                if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1"))) {
     126                        printf("could not create thread %d\n", 2 * i);
     127                        break;
     128                }
    130129                thread_ready(t);
    131                 if (!(t = thread_create(testit2, (void *)((unative_t)i*2+1), TASK, 0, "testit2")))
    132                         panic("could not create thread\n");
     130                total++;
     131               
     132                if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2"))) {
     133                        printf("could not create thread %d\n", 2 * i + 1);
     134                        break;
     135                }
    133136                thread_ready(t);
     137                total++;
    134138        }
    135 
    136139        printf("ok\n");
    137        
     140               
    138141        thread_sleep(1);
    139142        waitq_wakeup(&can_start, WAKEUP_ALL);
    140 
    141         while (atomic_get(&threads_ok) != THREADS)
    142                 ;
    143                
    144         printf("Test passed.\n");
    145 #ifdef CONFIG_BENCH
    146         uint64_t dt = get_cycle() - t0;
    147         printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
    148 #endif
    149 }
    150 
    151 #else
    152 
    153 void test_sse1(void)
    154 {
    155         printf("This test is available only on SSE enabled platforms.");
     143       
     144        while (atomic_get(&threads_ok) != total) {
     145                printf("Threads left: %d\n", total - atomic_get(&threads_ok));
     146                thread_sleep(1);
     147        }
     148       
     149        if (atomic_get(&threads_fault) == 0)
     150                return NULL;
     151       
     152        return "Test failed";
    156153}
    157154
Note: See TracChangeset for help on using the changeset viewer.