static void stop_tests(struct loopback_test *t) { int i; for (i = 0; i < t->device_count; i++) { if (!device_enabled(t, i)) continue; write_sysfs_val(t->devices[i].sysfs_entry, "type", 0); } }
static int start(struct loopback_test *t) { int i; /* the test starts by writing test_id to the type file. */ for (i = 0; i < t->device_count; i++) { if (!device_enabled(t, i)) continue; write_sysfs_val(t->devices[i].sysfs_entry, "type", t->test_id); } return 0; }
static void prepare_devices(struct loopback_test *t) { int i; /* * Cancel any running tests on enabled devices. If * stop_all option is given, stop test on all devices. */ for (i = 0; i < t->device_count; i++) if (t->stop_all || device_enabled(t, i)) write_sysfs_val(t->devices[i].sysfs_entry, "type", 0); for (i = 0; i < t->device_count; i++) { if (!device_enabled(t, i)) continue; write_sysfs_val(t->devices[i].sysfs_entry, "us_wait", t->us_wait); /* Set operation size */ write_sysfs_val(t->devices[i].sysfs_entry, "size", t->size); /* Set iterations */ write_sysfs_val(t->devices[i].sysfs_entry, "iteration_max", t->iteration_max); if (t->use_async) { write_sysfs_val(t->devices[i].sysfs_entry, "async", 1); write_sysfs_val(t->devices[i].sysfs_entry, "timeout", t->async_timeout); write_sysfs_val(t->devices[i].sysfs_entry, "outstanding_operations_max", t->async_outstanding_operations); } else write_sysfs_val(t->devices[i].sysfs_entry, "async", 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); }