PROCESS_THREAD(example_coffee_process, ev, data) { PROCESS_BEGIN(); #define SDCARD #ifdef SDCARD uSDcard_init(); printf("sdcard initialised.\n"); #endif #if NEED_FORMATTING cfs_coffee_format(); #endif /* Ensure that we will be working with a new file. */ cfs_remove(FILENAME); if (file_test(FILENAME, "The first test") == 0) { printf("file test 1 failed\n"); } if (file_test(FILENAME, "The second test") == 0) { printf("file test 2 failed\n"); } if (dir_test() == 0) { printf("dir test failed\n"); } PROCESS_END(); }
void read_hz() { if(file_test("sys/HZK16")) HZK = SD.open("sys/HZK16"); if(file_test("sys/ASCII")) ASCII = SD.open("sys/ASCII"); return; }
int main(void) { int i; memset(null_data, 22, sizeof(null_data)); file_test(&my_data_1); file_test(&null_data[1000]); file_test(&my_data_2); while(1); return 0; }
void show_apimg(int x, int y, char* apimgname) { #ifndef DEBUG File apimg; unsigned char temp[2]; unsigned short width, height, i, j; unsigned char r, g, b, a; if(!file_test(apimgname)) return; apimg = SD.open(apimgname); temp[0] = apimg.read(); temp[1] = apimg.read(); width = *(unsigned short*)temp; //读取图片宽度 temp[0] = apimg.read(); temp[1] = apimg.read(); height = *(unsigned short*)temp; //读取图片高度 for(j = 0; j < height; j++) //逐行描点 for(i = 0; i < width; i++) { b = apimg.read(); g = apimg.read(); r = apimg.read(); a = apimg.read(); myGLCD.setColor(r, g, b); myGLCD.drawPixel(x + i, y + j); } apimg.close(); return; #endif }
int test(){ printf("test start!\n"); op_test(); mem_test(); stack_test(); file_test(); return 0; }
char * path_test(const char *file, unsigned int test) { char *cp, *ep; char *s, *p; unsigned int len, exelen; if (!file) return NULL; if (isabspath(file)) { if (file_test(file, test)) return Estrdup(file); return NULL; } cp = getenv("PATH"); if (!cp) return Estrdup(file); exelen = strlen(file); s = NULL; ep = cp; for (; ep; cp = ep + 1) { ep = strchr(cp, ':'); len = (ep) ? (unsigned int)(ep - cp) : strlen(cp); if (len == 0) continue; p = EREALLOC(char, s, len + exelen + 2); if (!p) break; s = p; memcpy(s, cp, len); s[len] = '/'; memcpy(s + len + 1, file, exelen + 1); if (file_test(s, test)) return s; } Efree(s); return NULL; }
void Desktop::read_desktop_folder(const char *dpath) { E_RETURN_IF_FAIL(dpath != NULL); String path; DIR *dir = opendir(dpath); E_RETURN_IF_FAIL(dir != NULL); DesktopConfig pos; pos.load(ICONS_POS_FILE); dirent *d; while((d = readdir(dir)) != NULL) { if(DOT_OR_DOTDOT(d->d_name)) continue; if(d->d_type > 0) { if(d->d_type != DT_REG && d->d_type != DT_LNK && d->d_type != DT_DIR) continue; path = dpath; path += E_DIR_SEPARATOR; path += d->d_name; } else { /* * If we got here, it means d_type isn't set and we must do it via file_test() which could be much slower. * By POSIX standard, only d_name must be set, but many modern *nixes set all dirent members correctly. Except Slackware ;) */ path = dpath; path += E_DIR_SEPARATOR; path += d->d_name; if(!(file_test(path.c_str(), FILE_TEST_IS_REGULAR) || file_test(path.c_str(), FILE_TEST_IS_DIR) || file_test(path.c_str(), FILE_TEST_IS_SYMLINK))) continue; } DesktopIcon *o = read_desktop_file(path.c_str(), (const char*)d->d_name, &pos); if(o) add(o); } closedir(dir); }
static void EDirCheck(const char *dir) { if (file_test(dir, EFILE_DIR | EPERM_RWX)) return; Alert(_("%s must be a directory in which you have\n" "read, write, and execute permission.\n"), dir); EExit(1); }
ustring SettingsManager::readProjectsDir() { ustring pdir(readStr(IDS_PROJECTS_DIR)); int p = pdir.find("%home%"); if(p != -1) pdir.replace(p, 6, g_get_home_dir()); if(!file_test(pdir, FILE_TEST_IS_DIR)) g_mkdir_with_parents(pdir.c_str(), 0777); return pdir; }
void StringList::loadFromFile(const ustring &fileName) { clear(); if(file_test(fileName, FILE_TEST_EXISTS)) { gchar *cont; gsize len; g_file_get_contents(fileName.c_str(), &cont, &len, NULL); loadFromChar(cont); g_free(cont); } }
static int upgrade_modem(const char *resource) { int ret; char update_wizard[1024]; pid_t pid; pthread_t usb_thread; text_path_cat(update_wizard, sizeof(update_wizard), resource, UPDATE_WIZARD_NAME); ret = chmod(update_wizard, 0777); if (ret < 0) { print_error("chmod \"%s\"", update_wizard); return ret; } pid = fork(); if (pid < 0) { print_error("fork"); return pid; } if (pid == 0) { if (file_test("/bin/sh", "x") == 0) { ret = system_command("%s %s | tee %s", update_wizard, resource, SWAN_CONSOLE_DEVICE); exit(ret); } else { ret = execl(update_wizard, update_wizard, resource, NULL); if (ret < 0) { error_msg("execl"); } exit(-1); } } pthread_create(&usb_thread, NULL, set_usb_power_handle, NULL); waitpid(pid, &ret, 0); if (!WIFEXITED(ret) || WEXITSTATUS(ret) != 0) { error_msg("upgrade modem failed"); return -1; } return 0; }
DesktopIcon *Desktop::read_desktop_file(const char *path, const char *base, DesktopConfig *pos) { DesktopIcon *ret = NULL; if(file_test(path, FILE_TEST_IS_DIR)) { ret = new DesktopIcon(_("No Name")); ret->set_icon_type(DESKTOP_ICON_TYPE_FOLDER); /* hardcoded */ ret->set_image("folder"); /* copy label explicitly, as DesktopIcon() will only store a pointer */ ret->copy_label(base); } else { /* * try to load it as plain .desktop file by looking only at extension * TODO: MimeType can be used here too */ if(!str_ends(path, EDE_DESKTOP_DESKTOP_EXT)) return ret; DesktopFile df; char buf[PATH_MAX]; E_RETURN_VAL_IF_FAIL(df.load(path), ret); E_RETURN_VAL_IF_FAIL(df.type() != DESK_FILE_TYPE_UNKNOWN, ret); ret = new DesktopIcon(_("No Name")); ret->set_icon_type(DESKTOP_ICON_TYPE_NORMAL); if(df.name(buf, sizeof(buf))) ret->copy_label(buf); ret->set_image(df.icon(buf, sizeof(buf)) ? buf : NULL); if(df.comment(buf, sizeof(buf))) ret->set_tooltip(buf); } /* try to put random icon position in the middle of the desktop, so it is easier to notice */ int X = (rand() % (w() / 4)) + (w() / 4); int Y = (rand() % (h() / 4)) + (h() / 4); /* lookup icons locations if possible */ if(base && pos && *pos) { pos->get(base, "X", X, X); pos->get(base, "Y", Y, Y); } E_DEBUG("Setting icon '%s' (%i,%i)\n", base, X, Y); ret->position(X, Y); /* use loaded icon options */ ret->set_options(icon_opts); ret->set_path(path); return ret; }
void load_artifacts(const std::string &artfilename, itypemap &itypes) { std::ifstream file_test(artfilename.c_str(), std::ifstream::in | std::ifstream::binary); if (!file_test.good()) { file_test.close(); return; } try { load_artifacts_from_ifstream(file_test, itypes); } catch (std::string e) { debugmsg("%s: %s", artfilename.c_str(), e.c_str()); } file_test.close(); }
// io commands static void cmd_io(void) { u08 cmd, res; u08 exit = 0; while((cmd = get_char()) != 0) { switch(cmd) { case 'd': file_dir(); break; case 's': { if(buffer_get_size()>0) { res = file_save_buffer(1); set_result(res); } else { set_result(0); } } break; case 'f': // find next disk name dir { u32 num = 0; res = file_find_disk_dir(&num); uart_send_hex_dword_crlf(num); set_result(res); } break; case 'm': // make disk dir { res = file_make_disk_dir(parse_hex_byte(0)); set_result(res); } break; case 't': // test file file_test(); break; default: set_result(ERROR_SYNTAX); case '.': exit = 1; break; } if(exit) break; } }
void test_run(void) { initialize(); #if TEST_CASE == LOGIC_TEST logic_test(); #elif TEST_CASE == TIMER_TEST timer_test(); #elif TEST_CASE == COMPONENT_TEST component_test(); #elif TEST_CASE == PROTOCOL_TEST protocol_test(); #elif TEST_CASE == POWER_TEST power_test(); #elif TEST_CASE == IDLE_TEST idle_test(); #elif TEST_CASE == STATE_TEST state_test(); #elif TEST_CASE == WORK_TEST work_test(); #elif TEST_CASE == FILE_TEST file_test(); #elif TEST_CASE == PICTURE_TEST picture_test(); #elif TEST_CASE == CONSUME_POWER consume_power(); #elif TEST_CASE == INIT_FILE init_file(); #elif TEST_CASE == FACTORY_TEST factory_test(); #elif TEST_CASE == MOBILE_STATE_TEST mobile_state_test(); #elif TEST_CASE == MESSAGE_REPLY_TEST message_reply_test(); #elif TEST_CASE == TF_TEST tf_test(); #elif TEST_CASE == SCREEN_TEST screen_test(); #elif TEST_CASE == UPGRADE_TEST upgrade_test(); #elif TEST_CASE == MOBILE_TEST mobile_test(); #endif }
int cavan_dd_base(const char *file_in, const char *file_out, off_t offset_in, off_t offset_out, off_t length, int flags) { int fd_in, fd_out; int ret; off_t size; println("%s [dd]-> %s", file_in, file_out); if (file_test(file_out, "b") < 0 || get_first_partition_offset(file_out, &size) < 0) { size = 0; } fd_in = open(file_in, O_RDONLY | O_BINARY); if (fd_in < 0) { print_error("open input file"); return -1; } fd_out = open(file_out, O_WRONLY | O_CREAT | O_SYNC | O_BINARY | flags, 0777); if (fd_out < 0) { print_error("open output file"); ret = -1; goto out_close_fd_in; } ret = fcavan_dd(fd_in, fd_out, offset_in, offset_out, length, size); if (ret < 0) { error_msg("fcavan_dd"); goto out_close_fd_out; } ret = 0; out_close_fd_out: close(fd_out); out_close_fd_in: close(fd_in); return ret; }
int main(int argc, char *argv[]) { int ret; struct uevent_desc udesc; ret = uevent_init(&udesc); if (ret < 0) { error_msg("uevent_init"); return ret; } while (1) { char devpath[1024]; ret = get_partition_add_uevent(&udesc); if (ret < 0) { error_msg("get_partition_add_uevent"); break; } if (uevent_get_propery_devname(&udesc, devpath) == NULL) { continue; } if (file_test(devpath, "b") < 0) { continue; } println("partition \"%s\" added", devpath); mount_main(devpath, NULL, NULL, NULL); } uevent_deinit(&udesc); return 0; }
/* * Largely stolen from GLib (kudos to the GLib team). * * This function can be simplified via strtok_r() or stringtok() where * tokenizers will normalize cases like "/foo///baz///foo". On other * hand, above path is valid to every mkdir() so this is not an issue * too much. */ bool dir_create_with_parents(const char* name, int perm) { E_ASSERT(name != NULL); char* fn = strdup(name); char* p = fn; // skip root if needed if(fn[0] == E_DIR_SEPARATOR) { p = fn; while(*p == E_DIR_SEPARATOR) p++; } else p = fn; do { while(*p && *p != E_DIR_SEPARATOR) p++; if(!*p) p = NULL; else *p = '\0'; /* FIXME: file_test() is needed here; can it be removed? */ if(!file_test(fn, FILE_TEST_IS_DIR) && !dir_create(fn, perm)) { free(fn); return false; } if(p) { *p = E_DIR_SEPARATOR; p++; while(*p && *p == E_DIR_SEPARATOR) p++; } } while(p); free(fn); return true; }
status_t driver_init_mode( vmi_instance_t vmi, unsigned long id, char *name) { unsigned long count = 0; /* see what systems are accessable */ if (VMI_SUCCESS == xen_test(id, name)) { dbprint("--found Xen\n"); vmi->mode = VMI_XEN; count++; } if (VMI_SUCCESS == kvm_test(id, name)) { dbprint("--found KVM\n"); vmi->mode = VMI_KVM; count++; } if (VMI_SUCCESS == file_test(id, name)) { dbprint("--found file\n"); vmi->mode = VMI_FILE; count++; } /* if we didn't see exactly one system, report error */ if (count == 0) { errprint("Could not find a VMM or file to use.\n"); errprint("Opening a live VMM requires root access.\n"); return VMI_FAILURE; } else if (count > 1) { errprint ("Found more than one VMM or file to use,\nplease specify what you want instead of using VMI_AUTO.\n"); return VMI_FAILURE; } else { // count == 1 return VMI_SUCCESS; } }
int main(int argc, char *argv[]) { int ret; const char *dev_path; char name[64]; struct cavan_input_service service; assert(argc < 3); if (argc > 1) { if (file_test(argv[1], "c") < 0 && text_is_number(argv[1])) { sprintf(name, "/dev/input/event%s", argv[1]); dev_path = name; } else { dev_path = argv[1]; } } else { dev_path = NULL; } cavan_input_service_init(&service, cavan_event_simple_matcher); service.lcd_width = service.lcd_height = 100; ret = cavan_input_service_start(&service, (void *) dev_path); if (ret < 0) { pr_error_info("cavan_input_service_start"); return ret; } cavan_input_service_join(&service); cavan_input_service_stop(&service); return 0; }
int main(int argc, char *argv[]) { int ret; const char *ramdisk_path; const char *dev_path; if (argc < 2) { ramdisk_path = DEFAULT_RAMDISK_PATH; dev_path = DEFAULT_DEVICE_PATH; } else if (argc < 3) { if (file_test(argv[1], "b") >= 0) { ramdisk_path = DEFAULT_RAMDISK_PATH; dev_path = argv[1]; } else { ramdisk_path = argv[1]; dev_path = DEFAULT_DEVICE_PATH; } } else { ramdisk_path = argv[1]; dev_path = argv[2]; adjust_image_device(&ramdisk_path, &dev_path); } if (file_test(ramdisk_path, "d") >= 0) { if (image_is(ramdisk_path, "ramdisk")) { ret = burn_directory(ramdisk_path, dev_path, 0); } else { ret = burn_directory(ramdisk_path, dev_path, 1); } } else if (image_is(ramdisk_path, "uramdisk.img")) { ret = burn_uramdisk(ramdisk_path, dev_path, 0); } else if (image_is(ramdisk_path, "busybox.img")) { ret = burn_uramdisk(ramdisk_path, dev_path, 1); } else { ret = burn_ramdisk(ramdisk_path, dev_path, 0); } if (ret < 0) { error_msg("Burn ramdisk failed"); return ret; } return 0; }
bool gdb_output_generate(const char *path, TempFile &t, int pid) { E_RETURN_VAL_IF_FAIL(path != NULL, false); int tfd = -1; TempFile scr; if(!scr.create("/tmp/.ecrash-script")) { E_WARNING(E_STRLOC ": Unable to create temporary file for debugger script: (%i) %s", scr.status(), strerror(scr.status())); return false; } if(!t.create("/tmp/.ecrash-output")) { E_WARNING(E_STRLOC ": Unable to create temporary file for debugger output: (%i) %s", t.status(), strerror(t.status())); return false; } tfd = t.handle(); /* write script */ ::write(scr.handle(), "bt\nquit\n", 8); scr.set_auto_delete(true); scr.close(); String gdb_path = file_path("gdb"); if(gdb_path.empty()) { /* write straight to the file, so dialog could show it */ write_str(tfd, "Unable to find gdb. Please install it first"); /* see it as valid, so dialog could be shown */ return true; } /* * to find core file, we will try these strategies: first try to open 'core.PID' if * we got PID (default on linux); if does not exists, try to open 'core'; everything is * assumed current folder, whatever it was set */ bool core_found = false; String core_path; if(pid > -1) { core_path.printf("%s.%i", CORE_FILE, pid); if(file_test(core_path.c_str(), FILE_TEST_IS_REGULAR)) core_found = true; } if(!core_found) { core_path = CORE_FILE; if(file_test(core_path.c_str(), FILE_TEST_IS_REGULAR)) core_found = true; } if(!core_found) { write_str(tfd, "Unable to find core file. Backtrace will not be done."); /* see it as valid, so dialog could be shown */ return true; } pid_t gdb_pid = fork(); if(gdb_pid == -1) { E_WARNING(E_STRLOC ": Unable to fork the process\n"); return false; } else if(gdb_pid == 0) { /* child; redirect to the file */ dup2(tfd, 1); t.close(); ::write(1, " ", 1); char* argv[8]; argv[0] = (char*)gdb_path.c_str(); argv[1] = (char*)"--quiet"; argv[2] = (char*)"--batch"; argv[3] = (char*)"-x"; argv[4] = (char*)scr.name(); argv[5] = (char*)path; argv[6] = (char*)core_path.c_str(); argv[7] = 0; execvp(argv[0], argv); return false; } else { int status; if(waitpid(gdb_pid, &status, 0) != gdb_pid) { E_WARNING(E_STRLOC ": Failed to execute waitpid() properly\n"); return false; } } file_remove(core_path.c_str()); return true; }
int package(const char *pkg_name, const char *dir_name) { int ret; int pkg_fd; struct swan_package_info pkg_info; struct swan_file_info file_info; char tmp_path[1024], *name_p; int shrink_image_table[] = { SWAN_IMAGE_SYSTEM, SWAN_IMAGE_RECOVERY, SWAN_IMAGE_USERDATA, SWAN_IMAGE_VENDOR, }; struct swan_image_info *p, *p_end; name_p = text_path_cat(tmp_path, sizeof(tmp_path), dir_name, NULL); if (swan_machine_type == SWAN_BOARD_UNKNOWN) { text_copy(name_p, "system.img"); swan_machine_type = get_swan_board_type_by_system_img(tmp_path); } if (swan_machine_type == SWAN_BOARD_UNKNOWN) { pr_err_info("Machine type no set"); } else { struct swan_image_info *img_info; img_info = get_swan_image_info_by_type(SWAN_IMAGE_LOGO); if (img_info) { text_copy(img_info->filename, get_logo_name_by_board_type(swan_machine_type)); } img_info = get_swan_image_info_by_type(SWAN_IMAGE_BUSYBOX); if (img_info) { text_copy(img_info->filename, get_busybox_name_by_board_type(swan_machine_type)); } } pkg_fd = open(pkg_name, O_RDWR | O_CREAT | O_SYNC | O_TRUNC | O_BINARY, 0777); if (pkg_fd < 0) { pr_err_info("open file \"%s\"", pkg_name); return -1; } text_copy(name_p, HEADER_BIN_NAME); ret = write_upgrade_program(pkg_fd, &file_info, tmp_path); if (ret < 0) { pr_err_info("write_upgrade_program"); goto out_close_pkg; } ret = lseek(pkg_fd, sizeof(pkg_info), SEEK_CUR); if (ret < 0) { pr_err_info("lseek"); goto out_close_pkg; } ret = write_resource_image(pkg_fd, &pkg_info, dir_name, get_resource_name_by_board_type(swan_machine_type), RESOURCE_IMAGE_NAME, I600_RESOURCE_NAME, I200_RESOURCE_NAME, MODEM_RESOURCE_NAME, NULL); if (ret < 0) { pr_err_info("write_resource_image"); goto out_close_pkg; } pkg_info.image_count = 0; for (p = swan_images, p_end = p + ARRAY_SIZE(swan_images); p < p_end; p++) { text_copy(name_p, p->filename); if (array_has_element(p->type, (int *) swan_exclude_images, swan_exclude_image_count) || file_test(tmp_path, "r") < 0) { println_cyan("exclude image \"%s\"", tmp_path); continue; } if (swan_need_shrink && array_has_element(p->type, shrink_image_table, ARRAY_SIZE(shrink_image_table))) { ret = swan_shrink_image(dir_name, p); if (ret < 0) { pr_err_info("image_shrink"); goto out_close_pkg; } } ret = write_simple_image(pkg_fd, dir_name, p, &swan_emmc_part_table); if (ret < 0) { pr_err_info("write_image"); goto out_close_pkg; } pkg_info.image_count++; } pkg_info.crc32 = 0; ret = ffile_crc32_seek(pkg_fd, sizeof(file_info) + file_info.header_size + sizeof(pkg_info), 0, &pkg_info.crc32); if (ret < 0) { pr_err_info("ffile_crc32"); goto out_close_pkg; } strncpy(pkg_info.volume, swan_vfat_volume, sizeof(pkg_info.volume)); pkg_info.mkfs_mask = swan_mkfs_mask; pkg_info.board_type = swan_machine_type; pkg_info.upgrade_flags = swan_upgrade_flags; pkg_info.part_table = swan_emmc_part_table; show_package_info(&pkg_info); ret = lseek(pkg_fd, sizeof(file_info) + file_info.header_size, SEEK_SET); if (ret < 0) { pr_err_info("lseek"); goto out_close_pkg; } ret = write_package_info(pkg_fd, &pkg_info); if (ret < 0) { pr_err_info("write_package_info"); goto out_close_pkg; } ret = swan_set_md5sum(pkg_name); if (ret < 0) { pr_err_info("swan_set_md5sum"); } out_close_pkg: close(pkg_fd); if (ret < 0) { remove(pkg_name); return ret; } return 0; }
int main(int argc, char** argv) { if (argc > 3) { // get list of PCD-files for training int num_files = atoi(argv[1]); std::string pcd_dir = argv[2]; std::vector<std::string> files; if (num_files == 0) { std::string file_name = pcd_dir + "files.txt"; std::ifstream file(file_name.c_str()); std::string str; while (std::getline(file, str)) { files.push_back(pcd_dir + str); std::cout << files.at(files.size()-1) << "\n"; } } else { for (int i=0; i < num_files; i++) files.push_back(pcd_dir + boost::lexical_cast<std::string>(i)); } // get list of workspace dimensions if available std::string file_name = pcd_dir + "workspace.txt"; boost::filesystem::path file_test(file_name); Eigen::MatrixXd workspace_mat(files.size(), 6); if( !boost::filesystem::exists(file_test) ) { std::cout << "No workspace.txt file found in pcd directory\n"; std::cout << " Using standard workspace limits\n"; Eigen::VectorXd ws(6); ws << 0.65, 0.9, -0.1, 0.1, -0.2, 1.0; for (int i=0; i < files.size(); i++) workspace_mat.row(i) = ws; } else { std::ifstream file_ws(file_name.c_str()); std::string str; int t = 0; while (std::getline(file_ws, str)) { for (int i = 0; i < 6; ++i) { int idx = str.find(" "); workspace_mat(t,i) = atof(str.substr(0, idx).c_str()); str = str.substr(idx + 1); } t++; } } std::cout << "workspace_mat:\n" << workspace_mat << "\n"; std::string svm_file_name = argv[3]; bool plots_hands = false; if (argc > 4) plots_hands = atoi(argv[4]); int num_samples = 1000; if (argc > 5) num_samples = atoi(argv[5]); int num_threads = 4; if (argc > 6) num_threads = atoi(argv[6]); // camera poses for 2-camera Baxter setup Eigen::Matrix4d base_tf, sqrt_tf; base_tf << 0, 0.445417, 0.895323, 0.21, 1, 0, 0, -0.02, 0, 0.895323, -0.445417, 0.24, 0, 0, 0, 1; sqrt_tf << 0.9366, -0.0162, 0.3500, -0.2863, 0.0151, 0.9999, 0.0058, 0.0058, -0.3501, -0.0002, 0.9367, 0.0554, 0, 0, 0, 1; // set-up parameters for the hand search Localization loc(num_threads, false, plots_hands); loc.setCameraTransforms(base_tf * sqrt_tf.inverse(), base_tf * sqrt_tf); loc.setNumSamples(num_samples); loc.setNeighborhoodRadiusTaubin(0.03); loc.setNeighborhoodRadiusHands(0.08); double finger_width = 0.01; double hand_outer_diameter = 0.09; double hand_depth = 0.06; double init_bite = 0.015; double hand_height = 0.02; loc.setFingerHand(new ParallelHand(finger_width, hand_outer_diameter, hand_depth)); loc.setInitBite(0.015); loc.setHandHeight(0.02); // collect training data for the SVM from each PCD file std::cout << "Acquiring training data ...\n"; std::vector<GraspHypothesis> hand_list; std::vector<int> hand_list_sizes(files.size()); for (int i = 0; i < files.size(); i++) { std::cout << " Creating training data from file " << files[i] << " ...\n"; std::string file_left = files[i] + "l_reg.pcd"; std::string file_right = files[i] + "r_reg.pcd"; loc.setWorkspace(workspace_mat.row(i)); std::vector<GraspHypothesis> hands = loc.localizeHands(file_left, file_right, true, true); hand_list.insert(hand_list.end(), hands.begin(), hands.end()); hand_list_sizes[i] = hand_list.size(); std::cout << i << ") # hands: " << hands.size() << std::endl; } // use the collected data for training the SVM std::cout << "Training the SVM ...\n"; Learning learn; Eigen::Matrix<double,3,2> cam_pos; cam_pos.col(0) = loc.getCameraTransform(true).block<3,1>(0,3); cam_pos.col(1) = loc.getCameraTransform(false).block<3,1>(0,3); int max_positives = 20; // learn.trainBalanced(hand_list, hand_list_sizes, svm_file_name, cam_pos, max_positives); learn.train(hand_list, hand_list_sizes, svm_file_name, cam_pos, max_positives); // learn.train(hand_list, svm_file_name, cam_pos, false); return 0; } std::cout << "No PCD filenames given!\n"; std::cout << "Usage: train_svm num_files pcd_directory svm_filename [plots_hands] [num_samples] [num_threads]\n"; std::cout << "Train an SVM to localize grasps in point clouds.\n\n"; std::cout << "The standard way is to create a directory that contains *.pcd files for " << "training. Each file needs to be called obji.pcd where i goes from 0 to <num_files>. " << "<pcd_directory> is the location and the root name of the files, for example, " << "/home/userA/data/obj.\n"; std::cout << "Alternatively, if <num_files> is set to 0, there needs to be a files.txt " << "within pcd_directory that lists all filenames that should be used for training, and " << "a workspace.txt that lists the workspace dimensions for each file.\n"; return (-1); }
int main(int argc, char *argv[]) { ext2_filsys fs; struct ext2_super_block param; errcode_t retval; int i; /* setup */ initialize_ext2_error_table(); memset(¶m, 0, sizeof(param)); ext2fs_blocks_count_set(¶m, 32768); param.s_inodes_count = 100; param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_INLINE_DATA; param.s_rev_level = EXT2_DYNAMIC_REV; param.s_inode_size = 256; retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, ¶m, test_io_manager, &fs); if (retval) { com_err("setup", retval, "while initializing filesystem"); exit(1); } retval = ext2fs_allocate_tables(fs); if (retval) { com_err("setup", retval, "while allocating tables for test filesysmte"); exit(1); } /* initialize inode cache */ if (!fs->icache) { struct ext2_inode inode; ext2_ino_t first_ino = EXT2_FIRST_INO(fs->super); int i; /* we just want to init inode cache. So ignore error */ ext2fs_create_inode_cache(fs, 16); if (!fs->icache) { fprintf(stderr, "tst_inline_data: init inode cache failed\n"); exit(1); } /* setup inode cache */ for (i = 0; i < fs->icache->cache_size; i++) fs->icache->cache[i].ino = first_ino++; } /* test */ if (file_test(fs)) { fprintf(stderr, "tst_inline_data(FILE): FAILED\n"); return 1; } printf("tst_inline_data(FILE): OK\n"); if (dir_test(fs)) { fprintf(stderr, "tst_inline_data(DIR): FAILED\n"); return 1; } printf("tst_inline_data(DIR): OK\n"); return 0; }
void Splash::run(void) { E_ASSERT(slist != NULL); if(!show_splash) { while(next_client_nosplash()) ; return; } fl_register_images(); String path, splash_theme_path; #ifdef USE_LOCAL_CONFIG splash_theme_path = "splash-themes/"; #else splash_theme_path = Resource::find_data("themes/splash-themes", RES_SYS_ONLY); if(splash_theme_path.empty()) { E_WARNING(E_STRLOC ": Unable to locate splash themes in $XDG_DATA_DIRS directories\n"); return; } #endif splash_theme_path += E_DIR_SEPARATOR; splash_theme_path += *splash_theme; if(!file_test(splash_theme_path.c_str(), FILE_TEST_IS_DIR)) { E_WARNING(E_STRLOC ": Unable to locate '%s' in '%s' theme directory\n", splash_theme->c_str(), splash_theme_path.c_str()); return; } /* setup widgets */ begin(); Fl_Box* bimg = new Fl_Box(0, 0, w(), h()); Fl_Image* splash_img = 0; path = build_filename(splash_theme_path.c_str(), "background.png"); splash_img = Fl_Shared_Image::get(path.c_str()); if(splash_img) { int W = splash_img->w(); int H = splash_img->h(); /* update window and Box sizes */ size(W, H); bimg->size(W, H); bimg->image(splash_img); } /* * place message box at the bottom with * nice offset (10 px) from window borders */ msgbox = new Fl_Box(10, h() - 25 - 10, w() - 20, 25); /* * Setup icons positions, based on position of msgbox assuming someone * will not abuse splash to start hundrets of programs, since icons will * be placed only in horizontal order, one line, so in case their large * number, some of them will go out of window borders. * * Icon box will be 64x64 so larger icons can fit too. * * This code will use Fl_Group (moving group, later, will move all icons * saving me from code mess), but will not update it's w() for two reasons: * icons does not use it, and will be drawn correctly, and second, setting * width will initiate fltk layout engine which will mess everything up. */ Fl_Group* icon_group = new Fl_Group(10, msgbox->y() - 10 - 64, 0, 64); int X = icon_group->x(); int Y = icon_group->y(); /* offset between icons */ int ioffset = 5; /* FIXME: use malloc/something instead this */ icons = new Fl_Box*[slist->size()]; icon_group->begin(); int i = 0; const char* imgpath; Fl_Image* iconimg = 0; for(StartupItemListIter it = slist->begin(); it != slist->end(); ++it, ++i) { Fl_Box* bb = new Fl_Box(X, Y, 64, 64); path = build_filename(splash_theme_path.c_str(), (*it)->icon.c_str()); imgpath = path.c_str(); iconimg = Fl_Shared_Image::get(imgpath); if(!iconimg) { bb->label(_("No image")); bb->align(FL_ALIGN_INSIDE | FL_ALIGN_WRAP); } else bb->image(iconimg); bb->hide(); X += bb->w() + ioffset; icons[i] = bb; } icon_group->end(); /* see X as width of all icons */ int gx = w()/2 - X/2; /* gx can be negative */ gx = (gx > 10) ? gx : 10; icon_group->position(gx, Y); end(); clear_border(); /* * If set_override() is used, message boxes will be * popped behind splash. Using it or not ??? */ set_override(); // make sure window is centered int sw = DisplayWidth(fl_display, fl_screen); int sh = DisplayHeight(fl_display, fl_screen); position(sw/2 - w()/2, sh/2 - h()/2); show(); Fl::add_timeout(TIMEOUT_START, runner_cb, this); // to keep splash at the top #ifndef EDEWM_HAVE_NET_SPLASH global_splash = this; XSelectInput(fl_display, RootWindow(fl_display, fl_screen), SubstructureNotifyMask); Fl::add_handler(splash_xmessage_handler); #endif while(shown()) Fl::wait(); #ifndef EDEWM_HAVE_NET_SPLASH Fl::remove_handler(splash_xmessage_handler); #endif }
int main(int argc, char **argv) { badblocks_list bb1, bb2, bb3, bb4, bb5; int equal; errcode_t retval; bb1 = bb2 = bb3 = bb4 = bb5 = 0; printf("test1: "); retval = create_test_list(test1, &bb1); if (retval == 0) print_list(bb1, 1); printf("\n"); printf("test2: "); retval = create_test_list(test2, &bb2); if (retval == 0) print_list(bb2, 1); printf("\n"); printf("test3: "); retval = create_test_list(test3, &bb3); if (retval == 0) print_list(bb3, 1); printf("\n"); printf("test4: "); retval = create_test_list(test4, &bb4); if (retval == 0) { print_list(bb4, 0); printf("\n"); validate_test_seq(bb4, test4a); } printf("\n"); printf("test5: "); retval = create_test_list(test5, &bb5); if (retval == 0) { print_list(bb5, 0); printf("\n"); do_test_seq(bb5, test5a); printf("After test5 sequence: "); print_list(bb5, 0); printf("\n"); } printf("\n"); if (bb1 && bb2 && bb3 && bb4 && bb5) { printf("Comparison tests:\n"); equal = ext2fs_badblocks_equal(bb1, bb2); printf("bb1 and bb2 are %sequal.\n", equal ? "" : "NOT "); if (equal) test_fail++; equal = ext2fs_badblocks_equal(bb1, bb3); printf("bb1 and bb3 are %sequal.\n", equal ? "" : "NOT "); if (!equal) test_fail++; equal = ext2fs_badblocks_equal(bb1, bb4); printf("bb1 and bb4 are %sequal.\n", equal ? "" : "NOT "); if (equal) test_fail++; equal = ext2fs_badblocks_equal(bb4, bb5); printf("bb4 and bb5 are %sequal.\n", equal ? "" : "NOT "); if (!equal) test_fail++; printf("\n"); } file_test(bb4); if (test_fail == 0) printf("ext2fs library badblocks tests checks out OK!\n"); if (bb1) ext2fs_badblocks_list_free(bb1); if (bb2) ext2fs_badblocks_list_free(bb2); if (bb3) ext2fs_badblocks_list_free(bb3); if (bb4) ext2fs_badblocks_list_free(bb4); return test_fail; }
int main(void) { int fd; int rx_data; int ret; pid_t pid1, pid2; int i; struct sched_param param; printf("Main Start(pid:%d)!!\n", getpid()); pid1 = fork(); switch(pid1) { case -1 : printf("fork_1 error!!\n"); exit(-1); case 0 : execl("./task1", "task1", NULL); exit(0); } pid2 = fork(); switch(pid2) { case -1 : printf("fork_2 error!!\n"); exit(-1); case 0 : execl("./task2", "task2", NULL); exit(0); } setpriority(PRIO_PROCESS, 0, -10); //setpriority(PRIO_PROCESS, pid1, -10); setpriority(PRIO_PROCESS, pid2, -10); #if 1 for(i=1; ; i++) { printf("Parent_%d!!\n", i); //SCHED_OTHER:0, SCHED_FIFO:1, SCHED_RR:2 ............. printf("-------------->Parent_Policy:%d, prio:%d\n", ............. ); sched_getparam(pid1, ¶m); printf("-------------->Child1_Policy:%d, prio:%d\n", sched_getscheduler(pid1), param.sched_priority); sched_getparam(pid2, ¶m); printf("-------------->Child2_Policy:%d, prio:%d\n", sched_getscheduler(pid2), param.sched_priority); #if 1 param.sched_priority = i%100; //0~99, big val : high priority ........... (pid1, ¶m); #endif file_test(); sleep(1); } #endif close(fd); kill(pid1, SIGKILL); kill(pid2, SIGKILL); return 0; }
#include <edelib/TempFile.h> #include <edelib/FileTest.h> #include "UnitTest.h" EDELIB_NS_USE UT_FUNC(TempFileTest, "Test TempFile") { TempFile t, t2, t3; UT_VERIFY(t.create("foo-temp.XXXXXX") == true); UT_VERIFY(t == true); UT_VERIFY(file_test(t.name(), FILE_TEST_IS_REGULAR | FILE_TEST_IS_WRITEABLE)); t.unlink(); UT_VERIFY(file_test(t.name(), FILE_TEST_IS_REGULAR) == false); UT_VERIFY(t2.create("baz-tmp") == true); UT_VERIFY(t2 == true); UT_VERIFY(file_test(t2.name(), FILE_TEST_IS_REGULAR | FILE_TEST_IS_WRITEABLE)); UT_VERIFY(t2.fstream() != 0); t2.set_auto_delete(true); UT_VERIFY(t3.create("/this/file/should/not/exists") == false); UT_VERIFY(t3 == false); }
int test_inner(void) { pj_caching_pool caching_pool; const char *filename; int line; int rc = 0; mem = &caching_pool.factory; pj_log_set_level(3); pj_log_set_decor(param_log_decor); rc = pj_init(); if (rc != 0) { app_perror("pj_init() error!!", rc); return rc; } //pj_dump_config(); pj_caching_pool_init( &caching_pool, NULL, 0 ); #if INCLUDE_ERRNO_TEST DO_TEST( errno_test() ); #endif #if INCLUDE_EXCEPTION_TEST DO_TEST( exception_test() ); #endif #if INCLUDE_OS_TEST DO_TEST( os_test() ); #endif #if INCLUDE_RAND_TEST DO_TEST( rand_test() ); #endif #if INCLUDE_LIST_TEST DO_TEST( list_test() ); #endif #if INCLUDE_POOL_TEST DO_TEST( pool_test() ); #endif #if INCLUDE_POOL_PERF_TEST DO_TEST( pool_perf_test() ); #endif #if INCLUDE_STRING_TEST DO_TEST( string_test() ); #endif #if INCLUDE_FIFOBUF_TEST DO_TEST( fifobuf_test() ); #endif #if INCLUDE_RBTREE_TEST DO_TEST( rbtree_test() ); #endif #if INCLUDE_HASH_TEST DO_TEST( hash_test() ); #endif #if INCLUDE_TIMESTAMP_TEST DO_TEST( timestamp_test() ); #endif #if INCLUDE_ATOMIC_TEST DO_TEST( atomic_test() ); #endif #if INCLUDE_MUTEX_TEST DO_TEST( mutex_test() ); #endif #if INCLUDE_TIMER_TEST DO_TEST( timer_test() ); #endif #if INCLUDE_SLEEP_TEST DO_TEST( sleep_test() ); #endif #if INCLUDE_THREAD_TEST DO_TEST( thread_test() ); #endif #if INCLUDE_SOCK_TEST DO_TEST( sock_test() ); #endif #if INCLUDE_SOCK_PERF_TEST DO_TEST( sock_perf_test() ); #endif #if INCLUDE_SELECT_TEST DO_TEST( select_test() ); #endif #if INCLUDE_UDP_IOQUEUE_TEST DO_TEST( udp_ioqueue_test() ); #endif #if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST DO_TEST( tcp_ioqueue_test() ); #endif #if INCLUDE_IOQUEUE_PERF_TEST DO_TEST( ioqueue_perf_test() ); #endif #if INCLUDE_IOQUEUE_UNREG_TEST DO_TEST( udp_ioqueue_unreg_test() ); #endif #if INCLUDE_ACTIVESOCK_TEST DO_TEST( activesock_test() ); #endif #if INCLUDE_FILE_TEST DO_TEST( file_test() ); #endif #if INCLUDE_SSLSOCK_TEST DO_TEST( ssl_sock_test() ); #endif #if INCLUDE_ECHO_SERVER //echo_server(); //echo_srv_sync(); udp_echo_srv_ioqueue(); #elif INCLUDE_ECHO_CLIENT if (param_echo_sock_type == 0) param_echo_sock_type = pj_SOCK_DGRAM(); echo_client( param_echo_sock_type, param_echo_server, param_echo_port); #endif goto on_return; on_return: pj_caching_pool_destroy( &caching_pool ); PJ_LOG(3,("test", "")); pj_thread_get_stack_info(pj_thread_this(), &filename, &line); PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u", pj_thread_get_stack_max_usage(pj_thread_this()), filename, line)); if (rc == 0) PJ_LOG(3,("test", "Looks like everything is okay!..")); else PJ_LOG(3,("test", "Test completed with error(s)")); pj_shutdown(); return 0; }