OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [common/] [current/] [tests/] [vaargs.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//=================================================================
2
//
3
//        vaargs.c
4
//
5
//        HAL variable argument calls test
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     jskov
43
// Contributors:  jskov
44
// Date:          2001-08-03
45
//####DESCRIPTIONEND####
46
//==========================================================================
47
 
48
#include <cyg/infra/testcase.h>         // test case macros
49
#include <cyg/infra/diag.h>             // diag_printf
50
#include <cyg/infra/cyg_ass.h>          // assertions
51
 
52
#include <cyg/hal/hal_arch.h>           // context macros
53
 
54
#include <stdarg.h>                     // vaargs magic
55
 
56
// -------------------------------------------------------------------------
57
 
58
int
59
function(int n, ...)
60
{
61
    va_list args;
62
    int c = 11 * n;
63
    int i = 1;
64
    int res = 1;
65
 
66
    CYG_ASSERT(n >= 0 && n < 8, "Invalid count argument");
67
 
68
    va_start(args, n);
69
 
70
    for (i = 1; i <= n; c++, i++) {
71
        int v = va_arg(args, int);
72
        if (v != c) {
73
            diag_printf("FAIL:<Bad argument: index %d expected %d got %d>\n", i, c, v);
74
            res = 0;
75
        }
76
    }
77
 
78
    va_end(args);
79
 
80
    return res;
81
}
82
 
83
int
84
function_proxy(int n, va_list args)
85
{
86
    int c = 11 * n;
87
    int i = 1;
88
    int res = 1;
89
 
90
    CYG_ASSERT(n >= 0 && n < 8, "Invalid count argument");
91
 
92
    for (i = 1; i <= n; c++, i++) {
93
        int v = va_arg(args, int);
94
        if (v != c) {
95
            diag_printf("FAIL:<Bad argument: index %d expected %d got %d>\n", i, c, v);
96
            res = 0;
97
        }
98
    }
99
 
100
    return res;
101
}
102
 
103
int
104
proxy(int n, ...)
105
{
106
    int res;
107
    va_list args;
108
 
109
    va_start(args, n);
110
    res = function_proxy(n, args);
111
    va_end(args);
112
 
113
    return res;
114
}
115
 
116
 
117
void
118
entry(void)
119
{
120
    int res;
121
 
122
    res =  function(0);
123
    res &= function(1, 11);
124
    res &= function(2, 22, 23);
125
    res &= function(3, 33, 34, 35);
126
    res &= function(4, 44, 45, 46, 47);
127
    res &= function(5, 55, 56, 57, 58, 59);
128
    res &= function(6, 66, 67, 68, 69, 70, 71);
129
    res &= function(7, 77, 78, 79, 80, 81, 82, 83);
130
    CYG_TEST_PASS_FAIL(res, "Direct vaargs calls");
131
 
132
    res =  proxy(0);
133
    res &= proxy(1, 11);
134
    res &= proxy(2, 22, 23);
135
    res &= proxy(3, 33, 34, 35);
136
    res &= proxy(4, 44, 45, 46, 47);
137
    res &= proxy(5, 55, 56, 57, 58, 59);
138
    res &= proxy(6, 66, 67, 68, 69, 70, 71);
139
    res &= proxy(7, 77, 78, 79, 80, 81, 82, 83);
140
    CYG_TEST_PASS_FAIL(res, "Proxy vaargs calls");
141
 
142
    CYG_TEST_FINISH("HAL vaargs test");
143
}
144
 
145
// -------------------------------------------------------------------------
146
 
147
externC void
148
cyg_start( void )
149
{
150
    CYG_TEST_INIT();
151
 
152
    entry();
153
}
154
 
155
// -------------------------------------------------------------------------
156
// EOF vaargs.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.