Annotation of driverkit/tests/acctest.m, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: /*
        !            25:  * acctest.c - test access violations
        !            26:  */
        !            27: 
        !            28: #import <bsd/sys/types.h> 
        !            29: #import <ansi/stdio.h>
        !            30: #import <bsd/libc.h>
        !            31: #import <driverkit/IOClient.h>
        !            32: #import "defaults.h"
        !            33: #import "buflib.h"
        !            34: 
        !            35: void usage(char **argv);
        !            36: void exit(int exitcode);
        !            37: 
        !            38: int main(int argc, char **argv) {
        !            39: 
        !            40:        char *hostname=HOST_DEFAULT;
        !            41:        char *devname=DEVICE_DEFAULT;
        !            42:        int arg;
        !            43:        char c;
        !            44:        id idClient;
        !            45:        IOReturn rtn;
        !            46:        char data[BYTE_COUNT_DEFAULT];
        !            47:        u_int query_resp;
        !            48:        u_int bytes_xfr;
        !            49:        char outstr[100];
        !            50:        
        !            51:        /*
        !            52:         * Get standard defaults from environment or defaults.h
        !            53:         */
        !            54:        get_default_t("hostname", &hostname, HOST_DEFAULT);
        !            55:        get_default_t("devname", &devname, DEVICE_DEFAULT);
        !            56:        
        !            57:        for(arg=1; arg<argc; arg++) {
        !            58:                c = argv[arg][0];
        !            59:                switch(c) {
        !            60:                    case 'h':
        !            61:                        hostname = &argv[arg][2];
        !            62:                        break;
        !            63:                    case 'd':
        !            64:                        devname = &argv[arg][2];
        !            65:                        break;
        !            66:                    default:
        !            67:                        usage(argv);
        !            68:                }
        !            69:        }
        !            70: 
        !            71:        /* 
        !            72:         * open for read access, test all 5 I/Os
        !            73:         */
        !            74:        rtn = [IOClient clientOpen:devname 
        !            75:                hostName:hostname
        !            76:                intentions:IO_INT_READ
        !            77:                idp:&idClient];
        !            78:        if(rtn) {
        !            79:                [IOClient ioError:rtn 
        !            80:                          logString:"clientOpen"
        !            81:                          outString:outstr];
        !            82:                printf(outstr);
        !            83:                exit(1);
        !            84:        }
        !            85:        rtn = [idClient ioQuery:&query_resp];
        !            86:        if(rtn) {
        !            87:                [IOClient ioError:rtn 
        !            88:                          logString:"ioQuery"
        !            89:                          outString:outstr];
        !            90:                printf(outstr);
        !            91:                exit(1);
        !            92:        }
        !            93:        rtn = [idClient ioRead:0
        !            94:                        bytesReq:BYTE_COUNT_DEFAULT
        !            95:                        buf:data
        !            96:                        bytesXfr:&bytes_xfr];
        !            97:        if(rtn) {
        !            98:                [IOClient ioError:rtn 
        !            99:                          logString:"ioRead"
        !           100:                          outString:outstr];
        !           101:                printf(outstr);
        !           102:                exit(1);
        !           103:        }
        !           104:        rtn = [idClient ioWrite:0
        !           105:                        bytesReq:BYTE_COUNT_DEFAULT
        !           106:                        buf:data
        !           107:                        bytesXfr:&bytes_xfr];
        !           108:        if(rtn != IO_R_PRIVILEGE) {
        !           109:                [IOClient ioError:rtn 
        !           110:                          logString:"ioWrite with read-only privileges"
        !           111:                          outString:outstr];
        !           112:                printf(outstr);
        !           113:                exit(1);
        !           114:        }
        !           115:        rtn = [idClient ioClose];
        !           116:        if(rtn) {
        !           117:                [IOClient ioError:rtn 
        !           118:                          logString:"ioClose"
        !           119:                          outString:outstr];
        !           120:                printf(outstr);
        !           121:                exit(1);
        !           122:        }
        !           123:        
        !           124:        /* 
        !           125:         * open for write access, test all 5 I/Os
        !           126:         */
        !           127:        rtn = [IOClient clientOpen:devname 
        !           128:                hostName:hostname
        !           129:                intentions:IO_INT_WRITE
        !           130:                idp:&idClient];
        !           131:        if(rtn) {
        !           132:                [IOClient ioError:rtn 
        !           133:                          logString:"clientOpen"
        !           134:                          outString:outstr];
        !           135:                printf(outstr);
        !           136:                exit(1);
        !           137:        }
        !           138:        rtn = [idClient ioQuery:&query_resp];
        !           139:        if(rtn != IO_R_PRIVILEGE) {
        !           140:                [IOClient ioError:rtn 
        !           141:                          logString:"ioQuery with write-only privileges"
        !           142:                          outString:outstr];
        !           143:                printf(outstr);
        !           144:                exit(1);
        !           145:        }
        !           146:        rtn = [idClient ioRead:0
        !           147:                        bytesReq:BYTE_COUNT_DEFAULT
        !           148:                        buf:data
        !           149:                        bytesXfr:&bytes_xfr];
        !           150:        if(rtn != IO_R_PRIVILEGE) {
        !           151:                [IOClient ioError:rtn 
        !           152:                          logString:"ioRead with write-only privileges"
        !           153:                          outString:outstr];
        !           154:                printf(outstr);
        !           155:                exit(1);
        !           156:        }
        !           157:        rtn = [idClient ioWrite:0
        !           158:                        bytesReq:BYTE_COUNT_DEFAULT
        !           159:                        buf:data
        !           160:                        bytesXfr:&bytes_xfr];
        !           161:        if(rtn) {
        !           162:                [IOClient ioError:rtn 
        !           163:                          logString:"ioWrite with write-only privileges"
        !           164:                          outString:outstr];
        !           165:                printf(outstr);
        !           166:                exit(1);
        !           167:        }
        !           168:        rtn = [idClient ioClose];
        !           169:        if(rtn) {
        !           170:                [IOClient ioError:rtn 
        !           171:                          logString:"ioClose"
        !           172:                          outString:outstr];
        !           173:                printf(outstr);
        !           174:                exit(1);
        !           175:        }
        !           176:        printf("acctest: passed\n");
        !           177:        exit(0);
        !           178: 
        !           179: } /* main() */
        !           180: 
        !           181: void usage(char **argv) {
        !           182:        printf("usage: %s [h=hostname] [d=devname]\n", argv[0]);
        !           183:        exit(1);
        !           184: }
        !           185: 
        !           186: 
        !           187: 
        !           188: 
        !           189: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.