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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [bsd_tcpip/] [current/] [tests/] [sysctl1.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tests/sysctl1.c
4
//
5
//      Simple test of sysclt API
6
//
7
//==========================================================================
8
// ####BSDALTCOPYRIGHTBEGIN####                                             
9
// -------------------------------------------                              
10
// Portions of this software may have been derived from FreeBSD             
11
// or other sources, and if so are covered by the appropriate copyright     
12
// and license included herein.                                             
13
// -------------------------------------------                              
14
// ####BSDALTCOPYRIGHTEND####                                               
15
//==========================================================================
16
//#####DESCRIPTIONBEGIN####
17
//
18
// Author(s):    andrew lunn
19
// Contributors: andrew lunn
20
// Date:         2003-06-28
21
// Purpose:      
22
// Description:  
23
//              
24
//
25
//####DESCRIPTIONEND####
26
//
27
//==========================================================================
28
 
29
#include <network.h>
30
#include <sys/sysctl.h>
31
 
32
#include <cyg/infra/testcase.h>
33
 
34
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
35
static char stack[STACK_SIZE];
36
static cyg_thread thread_data;
37
static cyg_handle_t thread_handle;
38
 
39
static int mib_name[] =     { CTL_DEBUG, 1 };
40
static int mib_next[] =     { CTL_DEBUG, 2 };
41
static int mib_name2oid[] = { CTL_DEBUG, 3 };
42
static int mib_oidfmt[] =   { CTL_DEBUG, 4 };
43
static int mib_name_debug_name[] = { CTL_DEBUG, 1, CTL_DEBUG, 1 };
44
static int mib[10];
45
static char name2oid[] = "sysctl.name2oid";
46
void
47
net_test(cyg_addrword_t q)
48
{
49
    char oldbuff[128];
50
    size_t oldbuffsize;
51
    char pbuff[128], name[64], *p;
52
    int *new_oid;
53
    size_t num_elem;
54
    int ret, i, oid_kind;
55
 
56
    diag_printf("Start sysctl1 test\n");
57
 
58
    //    init_all_network_interfaces();
59
 
60
    /* Test the OID to name function of sysctl*/
61
    oldbuffsize = sizeof(oldbuff);
62
    ret = sysctl(mib_name_debug_name, CYG_NELEM(mib_name_debug_name),
63
                 oldbuff, &oldbuffsize, NULL, 0);
64
    if (ret == -1) CYG_TEST_FAIL("sysclt(mib_name) failed");
65
    CYG_TEST_INFO(oldbuff);
66
    CYG_TEST_PASS_FAIL(!strcmp(oldbuff, "sysctl.name"), "sysctl.name");
67
 
68
    /* Test the name to OID function of sysclt */
69
    oldbuffsize = sizeof(oldbuff);
70
    ret = sysctl(mib_name2oid, CYG_NELEM(mib_name2oid), oldbuff, &oldbuffsize,
71
                 name2oid, sizeof(name2oid));
72
    if (ret == -1) CYG_TEST_FAIL("sysclt(mib_name) failed");
73
    CYG_TEST_PASS_FAIL(((ret == 8 ) &&
74
                        (((int *)&oldbuff)[0] == CTL_DEBUG) &&
75
                        (((int *)&oldbuff)[1] == 3)),
76
                       "sysctl.name2oid");
77
 
78
    /* Walk the table using the next function of sysclt */
79
    num_elem = CYG_NELEM(mib_next)+1;
80
    new_oid = mib + CYG_NELEM(mib_next);
81
    mib[2] = 0;
82
    do {
83
      memcpy(mib,mib_next,sizeof(mib_next));
84
      oldbuffsize = sizeof(mib) - sizeof(mib_next);
85
      ret = sysctl(mib, num_elem, new_oid, &oldbuffsize, NULL, 0);
86
      if (ret == -1) {
87
        if (errno != ENOENT) {
88
          CYG_TEST_FAIL_FINISH("sysclt(mib_name) failed");
89
        } else {
90
          break;
91
        }
92
      }
93
      p = pbuff;
94
      num_elem = CYG_NELEM(mib_next) + (ret / 4);
95
      i=0;
96
      while (ret > 0) {
97
        p+=diag_sprintf(p, "%d ",new_oid[i++]);
98
        ret -= sizeof(int);
99
      }
100
      /* Get the name of this oid */
101
      oldbuffsize = sizeof(name);
102
      memcpy(mib,mib_name,sizeof(mib_name));
103
      ret = sysctl(mib, num_elem, name, &oldbuffsize, NULL, 0);
104
      if (ret == -1) CYG_TEST_FAIL("sysclt(mib2name) failed");
105
      name[ret] = 0;
106
      p += diag_sprintf(p, "= %s (", name);
107
 
108
      /* Get the find and format */
109
      memcpy(mib,mib_oidfmt,sizeof(mib_oidfmt));
110
      ret = sysctl(mib, num_elem, name, &oldbuffsize, NULL, 0);
111
      if (ret == -1) CYG_TEST_FAIL("sysclt(mib2name) failed");
112
      oid_kind = *(int *)name;
113
      switch (oid_kind & CTLTYPE) {
114
      case CTLTYPE_NODE:
115
        p += diag_sprintf(p, "NODE");
116
        break;
117
      case CTLTYPE_INT:
118
        p += diag_sprintf(p, "INT");
119
        break;
120
      case CTLTYPE_STRING:
121
        p += diag_sprintf(p, "STRING");
122
        break;
123
      case CTLTYPE_QUAD:
124
        p += diag_sprintf(p, "QUAD");
125
        break;
126
      case CTLTYPE_STRUCT:
127
        p += diag_sprintf(p, "STRUCT");
128
        break;
129
      case CTLTYPE_UINT:
130
        p += diag_sprintf(p, "UINT");
131
        break;
132
      case CTLTYPE_LONG:
133
        p += diag_sprintf(p, "LONG");
134
        break;
135
      case CTLTYPE_ULONG:
136
        p += diag_sprintf(p, "ULONG");
137
        break;
138
      default:
139
        p += diag_sprintf(p,"Unknown type! (%d)", oid_kind & CTLTYPE);
140
      }
141
      if (oid_kind & CTLFLAG_RD)
142
        p += diag_sprintf(p," Read");
143
      if (oid_kind & CTLFLAG_WR)
144
        p += diag_sprintf(p," Write");
145
      if (oid_kind & CTLFLAG_NOLOCK)
146
        p += diag_sprintf(p," Nolock");
147
      if (oid_kind & CTLFLAG_ANYBODY)
148
        p += diag_sprintf(p," Anybody");
149
      if (oid_kind & CTLFLAG_SECURE)
150
        p += diag_sprintf(p," Secure");
151
      if (oid_kind & CTLFLAG_PRISON)
152
        p += diag_sprintf(p," Prison");
153
      if (oid_kind & CTLFLAG_DYN)
154
        p += diag_sprintf(p," Dynamic");
155
 
156
      p += diag_sprintf(p," )");
157
 
158
      p += diag_sprintf(p,"{%d}", num_elem);
159
      CYG_TEST_INFO(pbuff);
160
    } while (ret != -1);
161
 
162
    /* Tests for sysctlnametomib */
163
    num_elem = CYG_NELEM(mib);
164
    ret = sysctlnametomib(name2oid, mib,&num_elem);
165
    if (ret == -1) CYG_TEST_FAIL("sysctlnametomib failed");
166
    CYG_TEST_PASS_FAIL(((num_elem == 2 ) &&
167
                        (((int *)&oldbuff)[0] == CTL_DEBUG) &&
168
                        (((int *)&oldbuff)[1] == 3)),
169
                       "sysctlnametooid1");
170
 
171
    /* This time with too small a results buffer */
172
    num_elem = 1;
173
    ret = sysctlnametomib(name2oid, mib,&num_elem);
174
    CYG_TEST_PASS_FAIL((ret == -1) && (errno = ENOMEM),
175
                       "sysctlnametooid2");
176
    /* This time with an unknown name */
177
    num_elem = CYG_NELEM(mib);
178
    ret = sysctlnametomib("unknown.unknown", mib,&num_elem);
179
    CYG_TEST_PASS_FAIL((ret == -1) && (errno = ENOENT),
180
                       "sysctlnametooid3");
181
 
182
    /* Tests for sysctlbyname */
183
    oldbuffsize = sizeof(oldbuff);
184
    ret = sysctlbyname("sysctl.name2oid", oldbuff, &oldbuffsize,
185
                 name2oid, sizeof(name2oid));
186
    if (ret == -1) CYG_TEST_FAIL("sysclt(mib_name) failed");
187
    CYG_TEST_PASS_FAIL(((ret == 8 ) &&
188
                        (((int *)&oldbuff)[0] == CTL_DEBUG) &&
189
                        (((int *)&oldbuff)[1] == 3)),
190
                       "sysctlbyname");
191
 
192
    CYG_TEST_EXIT ("sysctl1 exit");
193
}
194
 
195
void
196
cyg_start(void)
197
{
198
    CYG_TEST_INIT();
199
 
200
    // Create a main thread, so we can run the scheduler and have time 'pass'
201
    cyg_thread_create(CYGPKG_NET_THREAD_PRIORITY-4,// Priority - just a number
202
                      net_test,                 // entry
203
                      0,                        // entry parameter
204
                      "Loopback ping  test",    // Name
205
                      &stack[0],                // Stack
206
                      STACK_SIZE,               // Size
207
                      &thread_handle,           // Handle
208
                      &thread_data              // Thread data structure
209
            );
210
    cyg_thread_resume(thread_handle);           // Start it
211
    cyg_scheduler_start();
212
}
213
 

powered by: WebSVN 2.1.0

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