示例#1
0
    //read from file, write to csv
    int log_file_csv(FILE* lf, FILE* csv)
    {
       if (lf == NULL || csv == NULL)
       {
            return CS1_NULL_FILE_POINTER;
       };

        string priority;
        string process;
	string message;
	string date;

      	char line[256];
      	size_t bin_s = sizeof(time_t) + 2*sizeof(uint8_t) + sizeof(uint16_t);
	size_t read;
       while ((read = fread(line, sizeof(char), 2 * bin_s , lf))){
	    if (binary_ascii_check(line)) {
		memset(line, '0', 256);
		fseek(lf, -1 * read, SEEK_CUR);
		fgets(line, sizeof(line), lf);
		ascii_log_check(string(line), date, priority,process,message);			
	   }
            else {
		fseek(lf, -1 * read, SEEK_CUR);
		memset(line, '0', 256); 
		if (fread(line, sizeof(char), bin_s, lf)){
			binary_log_check(line, date, priority, process, message);
		}
		else {
			return CS1_FAILURE;
		}
            }
	    memset(line, '0', 256);
            log_csv(csv, date, priority, process, message);
	 }
       return CS1_SUCCESS;     
    }
示例#2
0
void loopback_run(const char *test_name, int size, int iteration_max,
		  const char *sys_prefix, const char *dbgfs_prefix,
		  uint32_t mask)
{
	char buf[MAX_SYSFS_PATH];
	char inotify_buf[0x800];
	char *sys_pfx = (char*)sys_prefix;
	extern int errno;
	fd_set fds;
	int test_id = 0;
	int i;
	int previous, err, iteration_count;
	int fd, wd, ret;
	struct timeval tv;

	if (construct_paths(sys_prefix, dbgfs_prefix)) {
		fprintf(stderr, "unable to construct sysfs/dbgfs path names\n");
		usage();
		return;
	}
	sys_pfx = ctrl_path;

	for (i = 0; i < sizeof(dict) / sizeof(struct dict); i++) {
		if (strstr(dict[i].name, test_name))
			test_id = dict[i].type;
	}
	if (!test_id) {
		fprintf(stderr, "invalid test %s\n", test_name);
		usage();
		return;
	}

	/* Terminate any currently running test */
	write_sysfs_val(sys_pfx, NULL, "type", 0);

	/* Set parameter for no wait between messages */
	write_sysfs_val(sys_pfx, NULL, "ms_wait", 0);

	/* Set operation size */
	write_sysfs_val(sys_pfx, NULL, "size", size);

	/* Set iterations */
	write_sysfs_val(sys_pfx, NULL, "iteration_max", iteration_max);

	/* Set mask of connections to include */
	write_sysfs_val(sys_pfx, NULL, "mask", mask);

	/* Initiate by setting loopback operation type */
	write_sysfs_val(sys_pfx, NULL, "type", test_id);
	sleep(1);

	if (iteration_max == 0) {
		printf("Infinite test initiated CSV won't be logged\n");
		return;
	}

	/* Setup for inotify on the sysfs entry */
	fd = inotify_init();
	if (fd < 0) {
		fprintf(stderr, "inotify_init fail %s\n", strerror(errno));
		abort();
	}
	snprintf(buf, sizeof(buf), "%s%s", sys_pfx, "iteration_count");
	wd = inotify_add_watch(fd, buf, IN_MODIFY);
	if (wd < 0) {
		fprintf(stderr, "inotify_add_watch %s fail %s\n",
			buf, strerror(errno));
		close(fd);
		abort();
	}

	previous = 0;
	err = 0;
	while (1) {
		/* Wait for change */
		tv.tv_sec = 1;
		tv.tv_usec = 0;
		FD_ZERO(&fds);
		FD_SET(fd, &fds);
		ret = select(fd + 1, &fds, NULL, NULL, &tv);

		if (ret > 0) {
			if (!FD_ISSET(fd, &fds)) {
				fprintf(stderr, "error - FD_ISSET fd=%d flase!\n",
					fd);
				break;
			}
			/* Read to clear the event */
			ret = read(fd, inotify_buf, sizeof(inotify_buf));
		}

		/* Grab the data */
		iteration_count = read_sysfs_int(sys_pfx, NULL, "iteration_count");

		/* Validate data value is different */
		if (previous == iteration_count) {
			err = 1;
			break;
		} else if (iteration_count == iteration_max) {
			break;
		}
		previous = iteration_count;
		if (verbose) {
			printf("%02d%% complete %d of %d\r",
				100 * iteration_count / iteration_max,
				iteration_count, iteration_max);
			fflush(stdout);
		}
	}
	inotify_rm_watch(fd, wd);
	close(fd);

	if (err)
		printf("\nError executing test\n");
	else
		log_csv(test_name, size, iteration_max, sys_pfx, mask);
}