Ejemplo n.º 1
0
void tc_fs_smartfs_procfs_main(void)
{
	int fd;
	int ret;
	struct stat st;

	fd = open(PROC_SMARTFS_PATH, O_RDONLY);
	TC_ASSERT_GEQ("open", fd, 0);

	ret = close(fd);
	TC_ASSERT_EQ("close", ret, OK);

	/* entry not found condition */

	fd = open(PROC_SMARTFS_FILE_PATH, O_RDWR | O_CREAT);
	TC_ASSERT_EQ("open", fd, ERROR);

	fd = open(INVALID_PATH, O_RDONLY);
	TC_ASSERT_EQ("open", fd, ERROR);

	ret = read_dir_entries(PROC_SMARTFS_PATH);
	TC_ASSERT_EQ("read_dir_entries", ret, OK);

	ret = stat(PROC_SMARTFS_PATH, &st);
	TC_ASSERT_EQ("stat", ret, OK);

	TC_SUCCESS_RESULT();
}
Ejemplo n.º 2
0
/* Read all files in the directory */
static int read_dir_entries(const char *dirpath)
{
	int fd;
	int ret;
	DIR *dirp;
	ssize_t nread;
	struct dirent *entryp;
	char path[PROC_FILEPATH_LEN];
	char buf[PROC_BUFFER_LEN];

	dirp = opendir(dirpath);
	if (!dirp) {
		printf("Failed to open directory %s\n", dirpath);
		return ERROR;
	}

	while ((entryp = readdir(dirp)) != NULL) {
		snprintf(path, PROC_FILEPATH_LEN, "%s/%s", dirpath, entryp->d_name);
		if (!DIRENT_ISDIRECTORY(entryp->d_type)) {
			/* If this entry is a file, open and read it. */
			printf("%s: \n", path);
			fd = open(path, O_RDONLY);
			if (fd < 0) {
				printf("Failed to open file %s\n", path);
				goto error;
			}
			nread = 0;
			do {
				nread = read(fd, buf, PROC_BUFFER_LEN - 1);
				if (nread < 0) {
					/* Read error */
					printf("Failed to read : %d\n", errno);
					goto error_with_fd;
				}
				buf[nread] = '\0';
				printf("%s", buf);
			} while (nread == PROC_BUFFER_LEN - 1);
			printf("\n");
			close(fd);
		} else {
			ret = read_dir_entries(path);
			if (ret != OK) {
				goto error;
			}
		}
	}
	closedir(dirp);

	return OK;
error_with_fd:
	close(fd);
error:
	closedir(dirp);

	return ERROR;
}
Ejemplo n.º 3
0
void tc_fs_procfs_main(void)
{
	int ret;

	ret = mount(NULL, PROC_MOUNTPOINT, "procfs", 0, NULL);
	TC_ASSERT("mount", ret == OK || errno == EEXIST);

	ret = read_dir_entries(PROC_MOUNTPOINT);
	TC_ASSERT_EQ("read_dir_entries", ret, OK);

	TC_SUCCESS_RESULT();
}
Ejemplo n.º 4
0
void tc_fs_procfs_main(void)
{
	int ret;
	struct stat st;
	bool procfs_mount_exist = false;

	ret = mount(NULL, PROCFS_TEST_MOUNTPOINT, "procfs", 0, NULL);
	if (ret < 0) {
		TC_ASSERT_EQ("mount", errno, EEXIST);
		procfs_mount_exist = true;
	}

	ret = read_dir_entries(PROCFS_TEST_MOUNTPOINT);
	TC_ASSERT_EQ("read_dir_entries", ret, OK);

	ret = procfs_rewind_tc(PROCFS_TEST_MOUNTPOINT);
	TC_ASSERT_EQ("procfs_rewind_tc", ret, OK);

#ifndef CONFIG_FS_PROCFS_EXCLUDE_UPTIME
	ret = procfs_uptime_ops(PROC_UPTIME_PATH);
	TC_ASSERT_EQ("procfs_uptime_ops", ret, OK);
#endif

	ret = stat(PROCFS_TEST_MOUNTPOINT, &st);
	TC_ASSERT_EQ("stat", ret, OK);

	ret = stat(PROC_INVALID_PATH, &st);
	TC_ASSERT_EQ("stat", ret, ERROR);

	ret = procfs_version_ops(PROC_UPTIME_PATH);
	TC_ASSERT_EQ("procfs_version_ops", ret, OK);
#ifndef CONFIG_FS_PROCFS_EXCLUDE_SMARTFS
	tc_fs_smartfs_procfs_main();
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MTD
	tc_driver_mtd_procfs_ops();
#endif

	if (false == procfs_mount_exist) {
		ret = umount(PROCFS_TEST_MOUNTPOINT);
		TC_ASSERT_EQ("umount", ret, OK);
	}

	TC_SUCCESS_RESULT();
}