Subversion Repositories HelenOS

Rev

Rev 4055 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2005 Ondrej Palkovsky
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. #include <print.h>
  30. #include <debug.h>
  31.  
  32. #include <test.h>
  33. #include <atomic.h>
  34. #include <proc/thread.h>
  35. #include <time/delay.h>
  36.  
  37. #include <arch.h>
  38.  
  39. #define THREADS   50
  40. #define DELAY     10000L
  41. #define ATTEMPTS  5
  42.  
  43. static atomic_t threads_ok;
  44. static atomic_t threads_fault;
  45. static waitq_t can_start;
  46.  
  47. static void testit1(void *data)
  48. {
  49.     int i;
  50.     int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
  51.     int after_arg __attribute__((aligned(16)));
  52.    
  53.     thread_detach(THREAD);
  54.    
  55.     waitq_sleep(&can_start);
  56.    
  57.     for (i = 0; i < ATTEMPTS; i++) {
  58.         asm volatile (
  59.             "mtc1 %0,$1"
  60.             : "=r" (arg)
  61.         );
  62.        
  63.         delay(DELAY);
  64.        
  65.         asm volatile (
  66.             "mfc1 %0, $1"
  67.             : "=r" (after_arg)
  68.         );
  69.        
  70.         if (arg != after_arg) {
  71.             TPRINTF("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
  72.             atomic_inc(&threads_fault);
  73.             break;
  74.         }
  75.     }
  76.     atomic_inc(&threads_ok);
  77. }
  78.  
  79. static void testit2(void *data)
  80. {
  81.     int i;
  82.     int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
  83.     int after_arg __attribute__((aligned(16)));
  84.    
  85.     thread_detach(THREAD);
  86.    
  87.     waitq_sleep(&can_start);
  88.    
  89.     for (i = 0; i < ATTEMPTS; i++) {
  90.         asm volatile (
  91.             "mtc1 %0,$1"
  92.             : "=r" (arg)
  93.         );
  94.        
  95.         scheduler();
  96.         asm volatile (
  97.             "mfc1 %0,$1"
  98.             : "=r" (after_arg)
  99.         );
  100.        
  101.         if (arg != after_arg) {
  102.             TPRINTF("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
  103.             atomic_inc(&threads_fault);
  104.             break;
  105.         }
  106.     }
  107.     atomic_inc(&threads_ok);
  108. }
  109.  
  110.  
  111. char *test_mips2(void)
  112. {
  113.     unsigned int i, total = 0;
  114.    
  115.     waitq_initialize(&can_start);
  116.     atomic_set(&threads_ok, 0);
  117.     atomic_set(&threads_fault, 0);
  118.    
  119.     TPRINTF("Creating %u threads... ", 2 * THREADS);
  120.    
  121.     for (i = 0; i < THREADS; i++) {
  122.         thread_t *t;
  123.        
  124.         if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
  125.             TPRINTF("could not create thread %u\n", 2 * i);
  126.             break;
  127.         }
  128.         thread_ready(t);
  129.         total++;
  130.        
  131.         if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
  132.             TPRINTF("could not create thread %u\n", 2 * i + 1);
  133.             break;
  134.         }
  135.         thread_ready(t);
  136.         total++;
  137.     }
  138.    
  139.     TPRINTF("ok\n");
  140.        
  141.     thread_sleep(1);
  142.     waitq_wakeup(&can_start, WAKEUP_ALL);
  143.    
  144.     while (atomic_get(&threads_ok) != (long) total) {
  145.         TPRINTF("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";
  153. }
  154.