Changeset cb01e1e in mainline for kernel/test/synch/semaphore1.c


Ignore:
Timestamp:
2009-04-04T00:26:27Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a85aebd
Parents:
171f9a1
Message:

use global variable and a macro for silencing tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/synch/semaphore1.c

    r171f9a1 rcb01e1e  
    3636#include <synch/semaphore.h>
    3737
    38 #define AT_ONCE                 3
    39 #define PRODUCERS               50
    40 #define CONSUMERS               50
     38#define AT_ONCE    3
     39#define PRODUCERS  50
     40#define CONSUMERS  50
    4141
    4242static semaphore_t sem;
     
    4848static void producer(void *arg)
    4949{
    50         thread_detach(THREAD); 
    51 
     50        thread_detach(THREAD);
     51       
    5252        waitq_sleep(&can_start);
    53            
     53       
    5454        semaphore_down(&sem);
    5555        atomic_inc(&items_produced);
     
    6060static void consumer(void *arg)
    6161{
    62         thread_detach(THREAD); 
     62        thread_detach(THREAD);
    6363       
    6464        waitq_sleep(&can_start);
     
    7070}
    7171
    72 char * test_semaphore1(bool quiet)
     72char *test_semaphore1(void)
    7373{
    7474        int i, j, k;
     
    7777        waitq_initialize(&can_start);
    7878        semaphore_initialize(&sem, AT_ONCE);
    79 
     79       
    8080        for (i = 1; i <= 3; i++) {
    8181                thread_t *thrd;
    82 
     82               
    8383                atomic_set(&items_produced, 0);
    8484                atomic_set(&items_consumed, 0);
     
    8787                producers = (4 - i) * PRODUCERS;
    8888               
    89                 printf("Creating %d consumers and %d producers...", consumers, producers);
    90        
     89                TPRINTF("Creating %d consumers and %d producers...", consumers, producers);
     90               
    9191                for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) {
    9292                        for (k = 0; k < i; k++) {
     
    9595                                        thread_ready(thrd);
    9696                                else
    97                                         printf("could not create consumer %d\n", i);
     97                                        TPRINTF("could not create consumer %d\n", i);
    9898                        }
    9999                        for (k = 0; k < (4 - i); k++) {
     
    102102                                        thread_ready(thrd);
    103103                                else
    104                                         printf("could not create producer %d\n", i);
     104                                        TPRINTF("could not create producer %d\n", i);
    105105                        }
    106106                }
    107 
    108                 printf("ok\n");
    109 
     107               
     108                TPRINTF("ok\n");
     109               
    110110                thread_sleep(1);
    111111                waitq_wakeup(&can_start, WAKEUP_ALL);
    112        
     112               
    113113                while ((items_consumed.count != consumers) || (items_produced.count != producers)) {
    114                         printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);
     114                        TPRINTF("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);
    115115                        thread_sleep(1);
    116116                }
Note: See TracChangeset for help on using the changeset viewer.