示例#1
0
int main(int argc, char *argv[])
{
    int result[4] = {0,0};
    int resultCount = 2;
    int num = 0;

    if( 1 != preEnvironment())
        return 0;

    fprintf(stderr, "************Begin to test ***************\n");
    result[0] = GetStats_basic_check1();
    result[1] = GetStats_basic_check2();
    
    CleanEnvironment();
    fprintf(stderr, "************test result as below***************\n");

    for(int j = 0; j < 2; j++){
        if(result[j] == 1){
            num++;
            fprintf( stderr, "ZSGetStats test %drd success.\n",j+1);
        }
        else fprintf( stderr, "ZSGetStats test %drd failed.\n",j+1);
    }
    if(resultCount == num){
        fprintf(stderr, "************ test pass!******************\n");
	fprintf(stderr, "#The related test script is ZS_GetStats.c\n");
        return 0;
    }
    else 
        fprintf(stderr, "************%d test failed!******************\n",resultCount-num);
	fprintf(stderr, "#The related test script is ZS_GetStats.c\n");
        return 1;
}
示例#2
0
/**********************************************************************
 *%FUNCTION: main
 *%ARGUMENTS:
 * argc, argv -- usual suspects
 * Usage: pppoe-wrapper {start|stop|status} {connection_name}
 *%RETURNS:
 * Whatever pppoe-start, pppoe-stop or pppoe-status returns.
 *%DESCRIPTION:
 * Runs pppoe-start, pppoe-stop or pppoe-status on given connection if
 * non-root users are allowed to do it.
 **********************************************************************/
int
main(int argc, char *argv[])
{
    int amRoot;
    char *cp;
    char fname[64+CONN_NAME_LEN];
    char line[LINELEN+1];
    int allowed = 0;

    FILE *fp;

    extern char **environ;

    /* Clean out environment */
    CleanEnvironment(environ);
    
    /* Are we root? */
    amRoot = (getuid() == 0);

    /* Validate arguments */
    if (argc != 3) {
	fprintf(stderr, "Usage: %s {start|stop|status} connection_name\n",
		argv[0]);
	exit(1);
    }

    if (strcmp(argv[1], "start") &&
	strcmp(argv[1], "stop") &&
	strcmp(argv[1], "status")) {
	fprintf(stderr, "Usage: %s {start|stop|status} connection_name\n",
		argv[0]);
	exit(1);
    }

    /* Connection name can be at most CONN_NAME_LEN chars; alpha, num, underscore */
    if (strlen(argv[2]) > CONN_NAME_LEN) {
	fprintf(stderr, "%s: Connection name '%s' too long.\n",
		argv[0], argv[2]);
	exit(1);
    }

    for (cp = argv[2]; *cp; cp++) {
	if (!strchr("abcdefghijklmnopqrstuvwxyz"
		    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		    "0123456789_-", *cp)) {
	    fprintf(stderr, "%s: Connection name '%s' contains illegal character '%c'\n", argv[0], argv[2], *cp);
	    exit(1);
	}
    }

    /* Open the connection file */
    sprintf(fname, "/etc/ppp/rp-pppoe-gui/conf.%s", argv[2]);
    /* Check path sanity */
    if (!PathOK(fname)) {
	exit(1);
    }

    fp = fopen(fname, "r");
    if (!fp) {
	fprintf(stderr, "%s: Could not open '%s': %s\n",
		argv[0], fname, strerror(errno));
	exit(1);
    }

    /* Check if non-root users can control it */
    if (amRoot) {
	allowed = 1;
    } else {
	while (!feof(fp)) {
	    if (!fgets(line, LINELEN, fp)) {
		break;
	    }
	    if (!strcmp(line, "NONROOT=OK\n")) {
		allowed = 1;
		break;
	    }
	}
    }
    fclose(fp);

    if (!allowed) {
	fprintf(stderr, "%s: Non-root users are not permitted to control connection '%s'\n", argv[0], argv[2]);
	exit(1);
    }

    /* Become root with setuid() to defeat is-root checks in shell scripts */
    if (setreuid(0, 0) < 0) {
	perror("setreuid");
	exit(1);
    }
       
    /* It's OK -- do it.  */
    if (!strcmp(argv[1], "start")) {
	if (!PathOK(pppoe_start)) exit(1);
	execl(pppoe_start, "pppoe-start", fname, NULL);
    } else if (!strcmp(argv[1], "stop")) {
	if (!PathOK(pppoe_stop)) exit(1);
	execl(pppoe_stop, "pppoe-stop", fname, NULL);
    } else {
	if (!PathOK(pppoe_status)) exit(1);
	execl(pppoe_status, "pppoe-status", fname, NULL);
    }
    fprintf(stderr, "%s: execl: %s\n", argv[0], strerror(errno));
    exit(1);
}
示例#3
0
int main(int argc, char *argv[])
{
    int result[3][2][5] = {{{0,0}}};
    ZS_boolean_t eviction[] = {0,0,0};
    ZS_boolean_t persistent[] = {1,1,1};
    ZS_boolean_t fifo[] = {0,0,0};
    ZS_boolean_t writethru[] = {1,1,1};
    ZS_boolean_t async_writes[] = {0,1};
    ZS_durability_level_t durability[] = {0,1,2};
    char          property[] = "SDF_REFORMAT";
    char          value[][4] = {"1","0"};
    int     resultCount = 12;
    int     num = 0;

    if((fp = fopen("ZS_SetProperty.log", "w+")) == 0){
        fprintf(stderr, " open failed!.\n");
        return -1;
    }
    if( 1 != preEnvironment())
        return 0;
    fprintf(fp, "************Begin to test ***************\n");

    for(int j = 0 ;j < 1;j++){
    for(int i = 0 ;  i < 3;i++){

        ZSSetProperty(property,value[i]);
        testCount = 0;
        SetPropMode(eviction[i],persistent[i],fifo[i],writethru[i],async_writes[j],durability[i]);
        OpenContainer("x",ZS_CTNR_CREATE,&cguid);

        result[j][i][0] = ZSSetProperty_basic_check();
        result[j][i][1] = ZSSetProperty_Open_CreateObj_close(2);
//        result[j][i][2] = ZSSetProperty_MoreObject1(6);
//        result[j][i][3] = ZSSetProperty_MoreObject2(5);

        CloseContainer(cguid );
        DeleteContainer(cguid);
    }
    }
    CleanEnvironment();
    
    for(int k = 0; k < 1; k++){
    for(int j = 0;j < 3;j++){
        fprintf(stderr, "test mode:eviction=%d,persistent=%d,fifo=%d,writethru=%d,async_writes=%d,durability=%d.SDF_REFORMAT=%d\n",eviction[j],persistent[j],fifo[j],writethru[j],async_writes[k],durability[j],(j+1)%2);
        for(int i = 0; i < 4; i++){
            if(result[k][j][i] == 1){
                num++;
                fprintf(stderr, "ZSSetProperty %drd success.\n",i+1);
            }
            else if(result[k][j][i] == -2)
                fprintf(stderr, "ZSSetProperty test %drd fail to test.\n",i+1);
            else if(result[k][j][i] == 0)
                fprintf(stderr, "ZSSetProperty test %drd failed.\n",i+1);
            else if(result[k][j][i] == -1)
                fprintf(stderr, "ZSSetProperty test %drd return failed.\n",i+1);
            else fprintf(stderr, "ZSSetProperty test %drd hit wrong.\n",i+1);
        }
    }
    }
    if(resultCount == num){
        fprintf(stderr, "************ test pass!******************\n");
	fprintf(stderr, "#The related test script is ZS_SetProperty.c\n");
	fprintf(stderr, "#If you want, you can check test details in ZS_SetProperty.log\n");
        return 0;
    }
    else 
        fprintf(stderr, "************%d test fail!******************\n",resultCount-num);
        fprintf(stderr, "#The related test script is ZS_SetProperty.c\n");
	fprintf(stderr, "#If you want, you can check test details in ZS_SetProperty.log\n");
	return 1;
}
int main(int argc, char *argv[])
{
    int result[3][2][7] = {{{0,0}}};
    ZS_boolean_t eviction[] = {0,0,0};
    ZS_boolean_t persistent[] = {1,1,1};
    ZS_boolean_t fifo[] = {0,0,0};
    ZS_boolean_t writethru[] = {1,1,1};
    int resultCount = 12;
    int num = 0;
    ZS_boolean_t async_writes[] = {0,1};
    ZS_durability_level_t durability[] = {0,1,2};

    if((fp = fopen("ZS_NextEnumeratedObject.log", "w+")) == 0){
        fprintf(stderr, " open failed!.\n");
        return -1;
    }
    if( 1 != preEnvironment())
        return 0;
    fprintf(fp, "************Begin to test ***************\n");

    for(int j = 0; j < 1; j++){
    for(int i = 0 ;  i < 3;i++){
        testCount = 0;
        SetPropMode(eviction[i],persistent[i],fifo[i],writethru[i],async_writes[j],durability[i]);

        result[j][i][0] = ZSNextEnumeratedObject_basic_check1();
        result[j][i][1] = ZSNextEnumeratedObject_basic_check2();
//        result[j][i][2] = ZSNextEnumeratedObject_Open_CreateObj_close(3);
        result[j][i][3] = ZSNextEnumeratedObject_MoreObject1(2);
//        result[j][i][4] = ZSNextEnumeratedObject_MoreObject2(2);
        result[j][i][5] = ZSNextEnumeratedObject_MoreObject3(1025);
    }
    }
    CleanEnvironment();
    
    for(int k = 0;k < 1;k++){
    for(int j = 0;j < 3;j++){
        fprintf(stderr, "test mode:eviction=%d,persistent=%d,fifo=%d,async=%d,durability=%d.\n",eviction[j],persistent[j],fifo[j],async_writes[k],durability[j]);
        for(int i = 0; i < 6; i++){
            if(result[k][j][i] == 1){
                num++;
                fprintf(stderr, "ZSNextEnumeratedObject %drd success.\n",i+1);
            }
            else if(result[k][j][i] == -2)
                fprintf(stderr, "ZSNextEnumeratedObject test %drd fail to test.\n",i+1);
            else if(result[k][j][i] == 0)
                fprintf(stderr, "ZSNextEnumeratedObject test %drd failed.\n",i+1);
            else if(result[k][j][i] == -1)
                fprintf(stderr, "ZSNextEnumeratedObject test %drd return failed.\n",i+1);
            else fprintf(stderr, "ZSNextEnumeratedObject test %drd hit wrong.\n",i+1);
        }
    }
    }
    if(resultCount == num){
        fprintf(stderr, "************ test pass!******************\n");
	fprintf(stderr, "#The related test script is ZS_NextEnumeratedObject.c\n");
	fprintf(stderr, "#If you want, you can check test details in ZS_NextEnumeratedObject.log\n");
        return 0;
    }
    else 
        fprintf(stderr, "************%d test fail!******************\n",resultCount-num);
	fprintf(stderr, "#The related test script is ZS_NextEnumeratedObject.c\n");
	fprintf(stderr, "#If you want, you can check test details in ZS_NextEnumeratedObject.log\n");
    	return 1;
}
int main(int argc, char *argv[])
{
    int result[2][3][20] = {{{0,0}}};
    int                  num = 0,totalNum = 90;
    ZS_boolean_t eviction[3] = {0,0,0};
    ZS_boolean_t persistent[3] = {1,1,1};
    ZS_boolean_t fifo[3] = {0,0,0};
    ZS_boolean_t writethru[3]={1,1,1};
    ZS_boolean_t async_write[2]={0,1};
    ZS_durability_level_t durability[3] = {0,1,2/*ZS_DURABILITY_PERIODIC,ZS_DURABILITY_SW_CRASH_SAFE,
     ZS_DURABILITY_HW_CRASH_SAFE*/};

    if((fp = fopen("ZS_OpenContainer.log", "w+")) == 0){
        fprintf(stderr, " open failed!.\n");
        return -1;
    }
    
    if( 1 != preEnvironment())
        return 0;

    fprintf(fp, "************Begin to test ***************\n");
     for(int i = 0; i < 2; i++){
        p.async_writes = async_write[i];
        for(int j = 0; j< 3 ; j++){
            testCount = 0;
            SetProps(1024*1024,eviction[j],persistent[j],fifo[j],writethru[j],durability[j]);
            result[i][j][0] = ZSOpenContainer_basic_check1();
            result[i][j][1] = ZSOpenContainer_basic_check_size();
            result[i][j][2] = ZSOpenContainer_openCloseMore1(5);
            result[i][j][3] = ZSOpenContainer_openCloseMore2(5);
            result[i][j][4] = ZSOpenContainer_openCloseMore_createObj(5);
            result[i][j][5] = ZSOpenContainer_openMore(5);
            result[i][j][6] = ZSOpenContainer_createDeletedMore(5);
            result[i][j][7] = ZSOpenContainer_createMore(2);
            result[i][j][8] = ZSOpenContainer_invalid_cguid();
            result[i][j][9] = ZSOpenContainer_invalid_flags();
            result[i][j][10] = ZSOpenContainer_flags_check();
            result[i][j][11] = ZSOpenContainer_invalid_cname1();
            result[i][j][12] = ZSOpenContainer_invalid_cname2();
            result[i][j][13] = ZSOpenContainer_invalid_cname3();
            result[i][j][14] = ZSOpenContainer_invalid_props();
       }
    }

    CleanEnvironment();
     
    for(int j = 0; j < 2; j++){
        for(int k =0; k < 3; k++){
            fprintf(stderr, "when async_write = %d.\n",async_write[j]);
            fprintf(stderr, "test mode:eviction=%d,persistent=%d,fifo=%d,durability=%d.\n",eviction[k],persistent[k],fifo[k],k+1);
            for(int i = 0; i < 15; i++){
                if(result[j][k][i] == 1){
                    fprintf(stderr, "ZSOpenContainer test %drd success.\n",i+1);
                    num++;
                }
                else if(result[j][k][i] == -1)
                    fprintf(stderr, "ZSOpenContainer test %drd fail to test.\n",i+1);
                else if(result[j][k][i] == 0)
                    fprintf(stderr, "ZSOpenContainer test %drd failed.\n",i+1);
                else fprintf(stderr, "ZSOpenContainer test %drd hit wrong.\n",i+1);
           }
        }
    }
    
    if(totalNum == num){
        fprintf(stderr,"************ test pass!******************\n");
	fprintf(stderr, "#The related test script is ZS_OpenContainer.c\n");
	fprintf(stderr, "#If you want, you can check test details in ZS_OpenContainer.log\n");
        return 0;
    }
    else 
        fprintf(stderr, "************%d test fail!******************\n",totalNum-num);
	fprintf(stderr, "#The related test script is ZS_OpenContainer.c\n");
	fprintf(stderr, "#If you want, you can check test details in ZS_OpenContainer.log\n");
        return -1;
}