예제 #1
0
int
main (int argc _GL_UNUSED, char *argv[])
{
  int result;

  set_program_name (argv[0]);

  /* Clean up any trash from prior testsuite runs.  */
  ignore_value (system ("rm -rf " BASE "*"));

  /* Test behaviour for invalid file descriptors.  */
  {
    errno = 0;
    ASSERT (mkdirat (-1, "foo", 0700) == -1);
    ASSERT (errno == EBADF);
  }
  {
    close (99);
    errno = 0;
    ASSERT (mkdirat (99, "foo", 0700) == -1);
    ASSERT (errno == EBADF);
  }

  /* Test basic mkdir functionality.  */
  result = test_mkdir (do_mkdir, false);
  dfd = open (".", O_RDONLY);
  ASSERT (0 <= dfd);
  ASSERT (test_mkdir (do_mkdir, false) == result);

  /* Tests specific to mkdirat.  */
  ASSERT (mkdirat (dfd, BASE "dir1", 0700) == 0);
  ASSERT (chdir (BASE "dir1") == 0);
  ASSERT (close (dfd) == 0);
  dfd = open ("..", O_RDONLY);
  ASSERT (0 <= dfd);
  ASSERT (mkdirat (dfd, BASE "dir2", 0700) == 0);
  ASSERT (close (dfd) == 0);
  errno = 0;
  ASSERT (mkdirat (dfd, BASE "dir3", 0700) == -1);
  ASSERT (errno == EBADF);
  dfd = open ("/dev/null", O_RDONLY);
  ASSERT (0 <= dfd);
  errno = 0;
  ASSERT (mkdirat (dfd, "dir3", 0700) == -1);
  ASSERT (errno == ENOTDIR);
  ASSERT (close (dfd) == 0);
  ASSERT (chdir ("..") == 0);
  ASSERT (rmdir (BASE "dir1") == 0);
  ASSERT (rmdir (BASE "dir2") == 0);

  return result;
}
예제 #2
0
static void test_setup_dirs(void **state) {
    const char *basepath = *state;
    char path[255];

    strcpy( path, basepath );
    strcat( path, "/t1" );
    assert_int_equal( test_mkdir( path ), 0 );

    strcpy( path, basepath );
    strcat( path, "/t2");
    assert_int_equal( test_mkdir( path ), 0 );
    strcat( path, "/Übergröße");
    assert_int_equal( test_mkdir( path ), 0 );
}
예제 #3
0
int
main (void)
{
  /* Clean up any trash from prior testsuite runs.  */
  ignore_value (system ("rm -rf " BASE "*"));

  return test_mkdir (mkdir, true);
}
예제 #4
0
static void setup_toplevel_dir( void **state ) {
    char basepath[255];

    strcpy( basepath, "tXXXXXX");
    assert_int_equal( c_tmpname(basepath), 0 );
    printf("Using top testing dir %s\n", basepath);
    assert_int_equal( test_mkdir( basepath ), 0 );
    *state = (void*) c_strdup(basepath);
}
예제 #5
0
int main(void)
{
    int ret;

    ret = toku_fs_mount(MOUNT_PATH);
    assert(ret == 0);

    test_mkdir();
    test_rmdir();

    ret = toku_fs_unmount();
    assert(ret == 0);

    return 0;
}
예제 #6
0
파일: test.c 프로젝트: codeliuer/learn-code
int
main(int argc, char* argv[])
{
    file_info(STDIN_FILENO);
    file_info(STDOUT_FILENO);

    test_access();
    test_faccessat();
    test_mode();
    test_chown();
    test_write_test();
    test_unlink();
    test_link();
    test_mkdir();
    test_readdir();
    test_openat();
    test_ln();

    return EXIT_SUCCESS;
}
예제 #7
0
파일: init.c 프로젝트: Avanznow/rtems
static rtems_task Init(rtems_task_argument argument)
{
  mode_t omode = S_IRWXU | S_IRWXG | S_IRWXO;
  int rv = 0;

  TEST_BEGIN();

  puts( "rtems_mkdir a - OK" );
  test_mkdir("a", omode, 0);
  puts( "rtems_mkdir a/b - OK" );
  test_mkdir("a/b", omode, 0);
  puts( "rtems_mkdir a/b/c/d/e/f/g/h/i - OK" );
  test_mkdir("a/b/c/d/e/f/g/h/i", omode, 0);
  puts( "rtems_mkdir a/b/c - OK" );
  test_mkdir("a/b/c", omode, 0);
  puts( "rtems_mkdir a/b/c/1 - OK" );
  test_mkdir("a/b/c/1", 0, 0);
  puts( "rtems_mkdir a/b/c/2 - OK" );
  test_mkdir("a/b/c/2", S_IRWXU, 0);
  puts( "rtems_mkdir a/b/c/3 - OK" );
  test_mkdir("a/b/c/3", S_IRWXG, 0);
  puts( "rtems_mkdir a/b/c/4 - OK" );
  test_mkdir("a/b/c/4", S_IRWXO, 0);
  puts( "rtems_mkdir a/b - OK" );
  test_mkdir("a/b", omode, 0);
  puts( "rtems_mkdir a - OK" );
  test_mkdir("a", omode, 0);
  puts( "rtems_mkdir a/b/x - OK" );
  test_mkdir("a/b/x", S_IRUSR, 0);
  puts( "rtems_mkdir a/b/x/y - expect failure" );
  test_mkdir("a/b/x/y", S_IRUSR, -1);
  puts( "mknod regular file a/n - OK" );  
  rv = mknod("a/n", S_IRWXU | S_IFREG, 0LL);
  puts( "rtems_mkdir a/n/b - expect failure" );
  test_mkdir("a/n/b", S_IRUSR, -1);

  puts( "Create node b and open in RDONLY mode - OK" );
  rv = open ("b", O_CREAT | O_RDONLY, omode);
  rtems_test_assert(rv >= 0);

  puts( "Closing b - OK" );
  rv = close(rv);
  rtems_test_assert(rv == 0);

  puts( "rtems_mkdir b - expect failure" );
  test_mkdir("b", omode, -1);
  rtems_test_assert(errno == EEXIST);

  TEST_END();

  exit(0);
}
예제 #8
0
파일: save.c 프로젝트: Felipeasg/rpilogger
//--------------------------------------------------------------------------------------------------
void saveit(void){
//--------------------------------------------------------------------------------------------------
	struct tm t1;
	char tms[430*60][25]; //worst case 1.2MB
	int i,n;
	char *sql;
	//float 8 byte: (7 digits+comma), datetime 24 byte (2015-02-07, 15:22:21.1234) + sample times 3bytes (),;
	int storsize=(sampl*(4*16+26+4) + 200) *sizeof(char);
	char str[430*60*100];
	for (i=0;i<sampl;i++){ //convert timespec to string
		t1 = *gmtime(&dst.ts[piter+i].tv_sec);
		sprintf(tms[i],"%d-%02d-%02d %02d:%02d:%02d.%04ld",t1.tm_year+1900,t1.tm_mon+1, t1.tm_mday, t1.tm_hour,t1.tm_min,t1.tm_sec, dst.ts[piter+i].tv_nsec/100000L);
	}

	if (websocket){ // --------------------------------------------------------------------------------------
		//printf("{\"x\":%ld.%09ld, \"y\":%.9g}\n",dst.ts[piter].tv_sec,dst.ts[piter].tv_nsec,dst.data[piter][0]);
		sprintf(str,"[");
		for(i=0;i<sampl;i++)
			sprintf(str,"%s{\"x\":%ld%03ld, \"a\":%.9g, \"b\":%.9g, \"c\":%.9g, \"d\":%.9g},",str,dst.ts[piter+i].tv_sec,dst.ts[piter+i].tv_nsec/1000000, dst.data[piter+i][0],dst.data[piter+i][1],dst.data[piter+i][2],dst.data[piter+i][3]);
		*(str+strlen(str)-1)=']';
		if (!nopoll_conn_send_text(conn, str, strlen(str)))
			printf("ERROR sending data to websocket server!\n");

	}
	if (savesql){ //-----------------------------------------------------------------------------------------
		if (PQstatus(pg_conn) != CONNECTION_OK){
		    pg_conn = PQconnectdb("dbname = postgres");
			printf("INFO: connected to database postgres\n");
			// Check to see that the backend pg_connection was successfully made 
    		if (PQstatus(pg_conn) != CONNECTION_OK)    {
		        printf("ERROR: pg_connection to database failed: %s",PQerrorMessage(pg_conn));
			    PQfinish(pg_conn);
				exit(-1);
		    }
		}
		sql = (char *) malloc(storsize); 
		sprintf(sql,"INSERT INTO data VALUES ");
		for (i=0;i<sampl;i++){
			n=sprintf(sql,"%s('%s',%.9g,%.9g,%.9g,%.9g),",sql,tms[i], dst.data[piter+i][0],dst.data[piter+i][1],dst.data[piter+i][2], dst.data[piter+i][3]);
		}
		*(sql+n-1)=';';
		//printf("(%i characters of reserved %i)\n",n,storsize);

		pg_res = PQexec(pg_conn, sql);
		if (PQresultStatus(pg_res) != PGRES_COMMAND_OK) {
		    printf("ERROR: SQL command failed: %s", PQerrorMessage(pg_conn));
		    PQclear(pg_res);
			PQfinish(pg_conn);
			exit(-1);
		}
		PQclear(pg_res);

		sprintf(sql,"insert into spsinfo (datetime, sps) select '%s', %g where not exists (select * from spsinfo where datetime = (select max(datetime) from spsinfo) and sps = %g);",tms[0],sps,sps);
		pg_res = PQexec(pg_conn, sql);
		if (PQresultStatus(pg_res) != PGRES_COMMAND_OK) {
		    printf("ERROR: SQL command failed: %s", PQerrorMessage(pg_conn));
		    PQclear(pg_res);
			PQfinish(pg_conn);
			exit(-1);
		}
		PQclear(pg_res);

		free(sql);
		//printf("\tSQL inserted %i records!\n",sampl);

	}

	char dirn[100], fn[40], filen[150];
    FILE *nc=NULL;
	int j;

	if (saveascii || savebin){ //------------------------------------------------------------------------------
		t1 = *gmtime(&dst.ts[piter].tv_sec); //first sample of batch
		test_mkdir(savedirbase);	//home/piter/data
		sprintf(dirn,"%s/%d",savedirbase,t1.tm_year + 1900);
		test_mkdir(dirn);			//home/piter/data/2014
		sprintf(dirn,"%s/%02d", dirn, t1.tm_mon + 1);
		test_mkdir(dirn);			//home/piter/data/2014/12
		sprintf(dirn,"%s/%02d", dirn, t1.tm_mday); 
		test_mkdir(dirn);			//home/piter/data/2014/12/14
		sprintf(fn,"%02d%02d%02d.%04ld",t1.tm_hour,t1.tm_min,t1.tm_sec, dst.ts[piter].tv_nsec/100000L); //file name only
	}	

	if (saveascii){ 	// generate ASCII file: *.cdl (netCDF)
		sprintf(filen,"%s/%s.cdl",dirn,fn);								//path to ASCII file (.cdl)
		nc = fopen(filen, "w");
		if (nc==NULL){
			printf("savefile: Could not open file %s to write!\n",filen);
			//printf("File will be omitted!\n");
			exit(-1);
		}
		fprintf(nc,
			"netcdf %s{\n"
			"dimensions:\n"
			"	a = %i ;\n"
			"	b = %i ;\n"
			"	c = %i ;\n"
			"	d = %i ;\n"
			"variables:\n"
			"	float a(a) ;\n"
			"		a:units = \"mV\" ;\n"
			"	float b(b) ;\n"
			"		b:units = \"mV\" ;\n"
			"	float c(c) ;\n"
			"		c:units = \"mV\" ;\n"
			"	float d(d) ;\n"
			"		d:units = \"mV\" ;\n"
			"     :start=\"%s\";\n"
			"     :sps=%g.f;\n"
			"data:\n", fn,sampl, sampl, sampl, sampl,tms[0],sps);

		const char *s[4];
		s[0] = " a = ";
		s[1] = " b = ";
		s[2] = " c = ";
		s[3] = " d = ";
		for (i=0;i<4;i++){
			fprintf(nc,"%s",s[i]);
			for (j=0;j<sampl;j++)
				fprintf(nc,"%f,",dst.data[piter+j][i]);
			fseek(nc,-1,SEEK_CUR); //del last comma
			fprintf(nc,";\n");
		}
		fprintf(nc,	"}\n");
		if (!fclose(nc))
#ifdef DEBUG
			printf("ASCII file %s written with %i samples each channel.\n",filen, sampl);
#else
			;
#endif
		else
			printf("savefile: Error while writing file %s!\n",filen);
	}
예제 #9
0
int test_mkdir(const tchar* path, unsigned) {
    return test_mkdir(path);
}
예제 #10
0
int main(int argc, char *argv[])
{
	const char *basepath;
	int err = 0;

	umask(0);
	if (argc < 2 || argc > 3) {
		fprintf(stderr, "usage: %s testdir [test#]\n", argv[0]);
		return 1;
	}
	basepath = argv[1];
	if (argc == 3) {
		char *endptr;
		char *arg = argv[2];
		if (arg[0] == '-') {
			arg++;
			skip_test = strtoul(arg, &endptr, 10);
		} else {
			select_test = strtoul(argv[2], &endptr, 10);
		}
		if (arg[0] == '\0' || *endptr != '\0') {
			fprintf(stderr, "invalid number: '%s'\n", arg);
			return 1;
		}
	}
	assert(strlen(basepath) < 512);
	if (basepath[0] != '/') {
		fprintf(stderr, "testdir must be an absolute path\n");
		return 1;
	}

	sprintf(testfile, "%s/testfile", basepath);
	sprintf(testfile2, "%s/testfile2", basepath);
	sprintf(testdir, "%s/testdir", basepath);
	sprintf(testdir2, "%s/testdir2", basepath);
	sprintf(subfile, "%s/subfile", testdir2);
	err += test_create();
	err += test_create_unlink();
	err += test_mknod();
	err += test_symlink();
	err += test_link();
	err += test_link2();
	err += test_mkfifo();
	err += test_mkdir();
	err += test_rename_file();
	err += test_rename_dir();
	err += test_utime();
	err += test_truncate(0);
	err += test_truncate(testdatalen / 2);
	err += test_truncate(testdatalen);
	err += test_truncate(testdatalen + 100);
	err += test_ftruncate(0, 0600);
	err += test_ftruncate(testdatalen / 2, 0600);
	err += test_ftruncate(testdatalen, 0600);
	err += test_ftruncate(testdatalen + 100, 0600);
	err += test_ftruncate(0, 0400);
	err += test_ftruncate(0, 0200);
	err += test_ftruncate(0, 0000);
	err += test_open(0, O_RDONLY, 0);
	err += test_open(1, O_RDONLY, 0);
	err += test_open(1, O_RDWR, 0);
	err += test_open(1, O_WRONLY, 0);
	err += test_open(0, O_RDWR | O_CREAT, 0600);
	err += test_open(1, O_RDWR | O_CREAT, 0600);
	err += test_open(0, O_RDWR | O_CREAT | O_TRUNC, 0600);
	err += test_open(1, O_RDWR | O_CREAT | O_TRUNC, 0600);
	err += test_open(0, O_RDONLY | O_CREAT, 0600);
	err += test_open(0, O_RDONLY | O_CREAT, 0400);
	err += test_open(0, O_RDONLY | O_CREAT, 0200);
	err += test_open(0, O_RDONLY | O_CREAT, 0000);
	err += test_open(0, O_WRONLY | O_CREAT, 0600);
	err += test_open(0, O_WRONLY | O_CREAT, 0400);
	err += test_open(0, O_WRONLY | O_CREAT, 0200);
	err += test_open(0, O_WRONLY | O_CREAT, 0000);
	err += test_open(0, O_RDWR | O_CREAT, 0400);
	err += test_open(0, O_RDWR | O_CREAT, 0200);
	err += test_open(0, O_RDWR | O_CREAT, 0000);
	err += test_open(0, O_RDWR | O_CREAT | O_EXCL, 0600);
	err += test_open(1, O_RDWR | O_CREAT | O_EXCL, 0600);
	err += test_open(0, O_RDWR | O_CREAT | O_EXCL, 0000);
	err += test_open(1, O_RDWR | O_CREAT | O_EXCL, 0000);
	err += test_open_acc(O_RDONLY, 0600, 0);
	err += test_open_acc(O_WRONLY, 0600, 0);
	err += test_open_acc(O_RDWR,   0600, 0);
	err += test_open_acc(O_RDONLY, 0400, 0);
	err += test_open_acc(O_RDONLY | O_TRUNC, 0400, EACCES);
	err += test_open_acc(O_WRONLY, 0400, EACCES);
	err += test_open_acc(O_RDWR,   0400, EACCES);
	err += test_open_acc(O_RDONLY, 0200, EACCES);
	err += test_open_acc(O_WRONLY, 0200, 0);
	err += test_open_acc(O_RDWR,   0200, EACCES);
	err += test_open_acc(O_RDONLY, 0000, EACCES);
	err += test_open_acc(O_WRONLY, 0000, EACCES);
	err += test_open_acc(O_RDWR,   0000, EACCES);
	err += test_create_ro_dir(O_CREAT);
	err += test_create_ro_dir(O_CREAT | O_EXCL);
	err += test_create_ro_dir(O_CREAT | O_WRONLY);
	err += test_create_ro_dir(O_CREAT | O_TRUNC);

	unlink(testfile);
	unlink(testfile2);
	rmdir(testdir);
	rmdir(testdir2);

	if (err) {
		fprintf(stderr, "%i tests failed\n", -err);
		return 1;
	}

	return 0;
}
예제 #11
0
파일: testnfs.c 프로젝트: john-peterson/nfs
int main(int argc, char **argv) {
    char workdir[1024];
    char workdirbasename[1024];
    char *nfsdir, *nfshost, *hosttemp=DEFAULT_HOSTTEMP;
    int c;
    int skipread=0, skipwrite=0, skipdir=0;

    while (1) {
        c=getopt(argc, argv, "o:t:l:f:c:");
        if (c == -1)
            break;

        switch(c) {
        case '?':
            usage(argv[0]);
        /* notreached */
        case 'o':
            if (!strcmp(optarg, "skipread")) {
                skipread=1;
            } else if (!strcmp(optarg, "skipwrite")) {
                skipwrite=1;
            } else if (!strcmp(optarg, "skipdir")) {
                skipdir=1;
            } else {
                printf("Unrecognized -o option: %s\n", optarg);
                usage(argv[0]);
            }
            break;
        case 't':
            hosttemp=strdup(optarg);
            break;
        case 'l':
            localtemp=strdup(optarg);
            break;
        case 'f':
            testfile=strdup(optarg);
            break;
        case 'c':
            testfiles=atoi(optarg);
            break;
        }
    }

    if (argc-optind != 2) {
        printf("Invalid number of required arguments\n");
        usage(argv[0]);
    }

    nfshost=argv[optind++];
    nfsdir=argv[optind++];

    /* Begin */

    test_statfs(nfsdir);

    /* Start with a fresh work area */
    sprintf(workdirbasename, "tmp%d", getpid());
    sprintf(workdir, "%s/%s", nfsdir, workdirbasename);
    printf("workdir is %s\n", workdir);

    test_mkdir(workdir);

    test_create(workdir);

    test_setattr(workdir);

    test_link(workdir);

    if (!skipread)
        test_read(nfsdir);

    if (!skipwrite)
        test_write(workdir, nfshost, hosttemp, workdirbasename);

    test_rename(workdir);

    if (!skipdir)
        test_readdir(workdir);

    test_remove(workdir);

    test_rmdir(workdir);

    return 0;

}