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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [common/] [v2_0/] [tests/] [vaargs.c] - Blame information for rev 561

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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