int main() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(Semihost file system); MBED_HOSTTEST_START("MBED_A2"); pc.printf("Test the Stream class\n"); printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No")); char mac[16]; mbed_mac_address(mac); printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); LocalFileSystem local("local"); FILE *f; char *str = TEST_STRING; char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); // Write f = test_open("w"); test_write(f, str, str_len); test_close(f); // Read f = test_open("r"); test_read(f, buffer, str_len); test_close(f); // Check the two strings are equal MBED_HOSTTEST_RESULT((strncmp(buffer, str, str_len) == 0)); }
int main() { pc.printf("Test the Stream class\n"); printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No")); char mac[16]; mbed_mac_address(mac); printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); LocalFileSystem local("local"); FILE *f; char* str = TEST_STRING; char* buffer = (char*) malloc(sizeof(unsigned char)*strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); // Write f = test_open("w"); test_write(f, str, str_len); test_close(f); // Read f = test_open("r"); test_read(f, buffer, str_len); test_close(f); // Check the two strings are equal notify_completion((strncmp(buffer, str, str_len) == 0)); }
int main (void) { int result; /* Basic checks. */ result = test_open (do_open, false); dfd = open (".", O_RDONLY); ASSERT (0 <= dfd); ASSERT (test_open (do_open, false) == result); ASSERT (close (dfd) == 0); /* Check that even when *-safer modules are in use, plain openat can land in fd 0. Do this test last, since it is destructive to stdin. */ ASSERT (close (STDIN_FILENO) == 0); ASSERT (openat (AT_FDCWD, ".", O_RDONLY) == STDIN_FILENO); { dfd = open (".", O_RDONLY); ASSERT (STDIN_FILENO < dfd); ASSERT (chdir ("..") == 0); ASSERT (close (STDIN_FILENO) == 0); ASSERT (openat (dfd, ".", O_RDONLY) == STDIN_FILENO); ASSERT (close (dfd) == 0); } return result; }
static void setup_interleaved(void) { JournalFile *one, *two; one = test_open("one.journal"); two = test_open("two.journal"); append_number(one, 1, NULL); append_number(two, 2, NULL); append_number(one, 3, NULL); append_number(two, 4, NULL); test_close(one); test_close(two); }
int main() { SDFileSystem sd(p11, p12, p13, p14, "sd"); FILE *f; char* str = TEST_STRING; char* buffer = (char*) malloc(sizeof(unsigned char)*strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); printf("Write files\n"); char filename[32]; for (int i=0; i<10; i++) { sprintf(filename, "/sd/test_%d.txt", i); printf("Creating file: %s\n", filename); f = test_open(filename, "w"); test_write(f, str); test_close(f); } printf("List files:\n"); DIR *d = opendir("/sd"); if (d == NULL) { printf("Error opening directory\n"); notify_completion(false); } struct dirent *p; while((p = readdir(d)) != NULL) { printf("%s\n", p->d_name); } closedir(d); notify_completion(true); }
static int test_packet_table(hid_t fid) { if( test_create_close(fid) < 0 ) return -1; if( test_open(fid) < 0 ) return -1; /* test_append must be run before test_count and test_read, as it */ /* creates the packet table they use. */ if( test_append(fid) < 0 ) return -1; /* These tests will not necessarily cause failures in each other, so we don't abort the other tests if one fails. */ test_read(fid); test_get_next(fid); test_big_table(fid); test_rw_nonnative_dt(fid); #ifdef VLPT_REMOVED test_varlen(fid); #endif /* VLPT_REMOVED */ test_opaque(fid); test_compress(); test_error(fid); return 0; }
void * run_open_test(const char * path, int flags, int mode, int expected_errno, const char * condition){ void * f; printf("testing open()..."); printf("%s", condition); printf("..."); fflush(stdout); f = test_open(path, flags, mode); if ( f == NULL ){ if ( expected_errno == 0 ){ fflush(stdout); perror("unexpected error"); return NULL; } else if ( errno == expected_errno ){ printf("passed\n"); return NULL; } else { printf("should have failed with %d not %d\n", expected_errno, errno); return NULL; } } else { if ( expected_errno == 0 ){ printf("passed\n"); return f; } else { printf("should have failed with %d not %d\n", expected_errno, errno); return f; } } return NULL; }
void ft_reclass(char **argv, int argc, int flag, int compt) { int j; DIR *dip; char **tab; int k; j = place(argv, argc); k = 0; if ((tab = (char**)malloc(sizeof(char*) * (argc - j + 1))) == NULL) exit(1); while (j < argc) { if (((dip = opendir(argv[j])) != NULL) && test_open(argv[j]) == 0) { tab[k] = argv[j]; k++; } if (dip != NULL) (void)closedir(dip); j++; } tab[k] = NULL; if (tab[0] != NULL && k > 1) class_elem(tab, flag); ft_args(tab, flag, compt); }
void multiple_args(int argc, char **argv, int i, int flag) { t_car_list *debut; t_car_list *temp; DIR *dip; int compt[2]; debut = NULL; compt[0] = 0; class_args(argc, argv, i); while (i < argc) { if (((dip = opendir(argv[i])) == NULL) || (test_open(argv[i]) == 1)) if ((compt[1] = analyse_error(argv[i])) == 1) { compt[0]++; temp = scan(&debut, argv[i]); ft_inspect_file(&temp, argv[i]); } if (dip != NULL) closedir(dip); i++; } if (debut != NULL) ft_print_list(debut, flag); if (compt[0] != argc) ft_reclass(argv, argc, flag, compt[0]); }
int main(int argc, char *argv[]) { char *pool_desc, *log_file; char root_dir[PATH_MAX]; START(argc, argv, "rpmemd_db"); if (argc != 4) UT_FATAL("usage: %s <root_dir> <pool_desc> <log-file>", argv[0]); if (realpath(argv[1], root_dir) == NULL) UT_FATAL("!realpath(%s)", argv[1]); pool_desc = argv[2]; log_file = argv[3]; if (rpmemd_log_init("rpmemd error: ", log_file, 0)) FAILED_FUNC("rpmemd_log_init"); test_init(root_dir); test_check_dir(root_dir); test_create(root_dir, pool_desc); test_open(root_dir, pool_desc); rpmemd_log_close(); DONE(NULL); }
int main(int argc, char *argv[]) { progname = get_progname(argv[0]); handle_args(argc, argv); prepare_buf(); test_open(); /* Test using 1 XLOG_BLCKSZ write */ test_sync(1); /* Test using 2 XLOG_BLCKSZ writes */ test_sync(2); test_open_syncs(); test_file_descriptor_sync(); test_non_sync(); unlink(filename); return 0; }
/** @tested: open file, write file, read file, close_file */ void test_read_write() { // open a file and get fd int fd = test_open(first_doc); test_write_read(fd); int res = test_close(fd); assert(res == fd); test_std_rw(); }
void TestFSFH_Run_IMP(TestFSFileHandle *self, TestBatchRunner *runner) { TestBatchRunner_Plan(runner, (TestBatch*)self, 46); test_open(runner); test_Read_Write(runner); test_Close(runner); test_Window(runner); }
int main () { struct parport_list pl; ieee1284_find_ports (&pl, 0); test_deviceid (&pl); test_open (&pl); ieee1284_free_ports (&pl); return 0; }
static void test_safe_httpreq(void) { IXMLHttpRequest *xhr; xhr = create_xhr(); set_safety_opt((IUnknown*)xhr, INTERFACESAFE_FOR_UNTRUSTED_DATA, -1); set_xhr_site(xhr); /* different scheme */ test_open(xhr, "GET", "https://test.winehq.org/tests/hello.html", E_ACCESSDENIED); /* different host */ test_open(xhr, "GET", "http://tests.winehq.org/tests/hello.html", E_ACCESSDENIED); test_open(xhr, "GET", "http://www.test.winehq.org/tests/hello.html", E_ACCESSDENIED); IXMLHttpRequest_Release(xhr); }
int main() { #if defined(TARGET_KL25Z) SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); #elif defined(TARGET_nRF51822) //SDFileSystem sd(p20, p22, p25, p24, "sd"); SDFileSystem sd(p12, p13, p15, p14, "sd"); #elif defined(TARGET_NUCLEO_F030R8) || \ defined(TARGET_NUCLEO_F072RB) || \ defined(TARGET_NUCLEO_F091RC) || \ defined(TARGET_NUCLEO_F103RB) || \ defined(TARGET_NUCLEO_F302R8) || \ defined(TARGET_NUCLEO_F303RE) || \ defined(TARGET_NUCLEO_F334R8) || \ defined(TARGET_NUCLEO_F401RE) || \ defined(TARGET_NUCLEO_F411RE) || \ defined(TARGET_NUCLEO_L053R8) || \ defined(TARGET_NUCLEO_L152RE) SDFileSystem sd(D11, D12, D13, D10, "sd"); #elif defined(TARGET_LPC1768_MINI_DK2) SDFileSystem sd(SD_SDI, SD_SDO, SD_SCK, SD_CS, "sd"); #else SDFileSystem sd(p11, p12, p13, p14, "sd"); #endif led2 = 1; wait(0.5); FILE *f; char *str = TEST_STRING; char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); printf("Write files\n"); char filename[32]; for (int i = 0; i < 10; i++) { sprintf(filename, "/sd/test_%d.txt", i); printf("Creating file: %s\n", filename); f = test_open(filename, "w"); led2 = 0; test_write(f, str); test_close(f); } printf("List files:\n"); DIR *d = opendir("/sd"); if (d == NULL) { printf("Error opening directory\n"); notify_completion(false); } struct dirent *p; while ((p = readdir(d)) != NULL) printf("%s\n", p->d_name); closedir(d); notify_completion(true); }
int main (int argc _GL_UNUSED, char *argv[]) { int result; set_program_name (argv[0]); /* Test behaviour for invalid file descriptors. */ { errno = 0; ASSERT (openat (-1, "foo", O_RDONLY) == -1); ASSERT (errno == EBADF); } { close (99); errno = 0; ASSERT (openat (99, "foo", O_RDONLY) == -1); ASSERT (errno == EBADF); } /* Basic checks. */ result = test_open (do_open, false); dfd = open (".", O_RDONLY); ASSERT (0 <= dfd); ASSERT (test_open (do_open, false) == result); ASSERT (close (dfd) == 0); /* Check that even when *-safer modules are in use, plain openat can land in fd 0. Do this test last, since it is destructive to stdin. */ ASSERT (close (STDIN_FILENO) == 0); ASSERT (openat (AT_FDCWD, ".", O_RDONLY) == STDIN_FILENO); { dfd = open (".", O_RDONLY); ASSERT (STDIN_FILENO < dfd); ASSERT (chdir ("..") == 0); ASSERT (close (STDIN_FILENO) == 0); ASSERT (openat (dfd, ".", O_RDONLY) == STDIN_FILENO); ASSERT (close (dfd) == 0); } return result; }
int main(int argc, char * const argv[]) { int i; char str[100]; test_open(DEV0, "test0.ts"); test_open(DEV1, "test1.ts"); test_open(DEV2, "test2.ts"); test_open(DEV3, "test3.ts"); /* for (i = 0; i < 36; i++) { sprintf(str, "rec0-%02d.ts", i); rec_open(DEV0, str, i); } rec_open(DEV1, "rec1.ts", 21); rec_open(DEV2, "rec2.ts", 99); rec_open(DEV3, "rec3.ts", 76); */ }
void TestCFReader_Run_IMP(TestCompoundFileReader *self, TestBatchRunner *runner) { TestBatchRunner_Plan(runner, (TestBatch*)self, 48); S_init_strings(); test_open(runner); test_Local_MkDir_and_Find_Folder(runner); test_Local_Delete_and_Exists(runner); test_Local_Open_Dir(runner); test_Local_Open_FileHandle(runner); test_Local_Open_In(runner); test_Close(runner); S_destroy_strings(); }
int main (int argc, char **argv) { printf("argc: %d, argv[0]: %s, &optind: %x\n", argc, argv[0], &optind); while( getopt(argc, argv, "h?ABC:DEFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz") != -1) {printf("bleh\n");} printf("optind: %d\n", optind); printf ("Syscall test starting...\n"); test_open (); return 0; }
/* * Main routine */ int main(int argc, char *argv[]) { char test_str[] = "test stdout...\n\n"; syslog(LOG_INFO, "\nfileio: fs test program\n"); /* Wait 1 sec until loading fs server */ timer_sleep(1000, 0); /* * Prepare to use a file system. */ fslib_init(); /* * Mount file systems */ mount("", "/", "ramfs", 0, NULL); mkdir("/dev", 0); mount("", "/dev", "devfs", 0, NULL); /* device */ mkdir("/boot", 0); mount("/dev/ram0", "/boot", "arfs", 0, NULL); /* archive */ mkdir("/tmp", 0); /* * Prepare stdio */ open("/dev/tty", O_RDWR); /* stdin */ dup(0); /* stdout */ dup(0); /* stderr */ /* Test device write */ write(STDOUT_FILENO, test_str, strlen(test_str)); test_write(); cat_file(); /* test read/write */ test_invalid(); /* test invalid request */ test_read(); /* test read loop */ test_open(); /* test open/close loop */ /* * Disconnect from a file system. */ fslib_exit(); return 0; }
int main () { /* Don't change the order of the calls. They partly depend on each other */ test_open (); test_write (); test_read (); test_lseek (); test_close (); test_stat (); test_fstat (); test_isatty (); test_system (); test_rename (); test_unlink (); test_time (); return 0; }
int main(int argc, char * argv[]) { (void) argc; (void) argv; printf("\n**************************\n"); printf("Errno Handling Test\n"); printf("***************************\n"); test_open(); test_close(); test_write(); test_read(); test_lseek(); test_dup2(); return 0; }
int main(int argc, char *argv[]) { START(argc, argv, "obj_zones"); if (argc != 3) UT_FATAL("usage: %s file-name [open|create]", argv[0]); const char *path = argv[1]; char op = argv[2][0]; if (op == 'c') test_create(path); else if (op == 'o') test_open(path); else UT_FATAL("invalid operation"); DONE(NULL); }
/** @tested: open file, dup_file, dup2_file, close_file */ void test_open_close() { int dup_fd; int fd = test_open(first_doc); // fd should be 4 // 0 -- stdin, 1 -- stdout, 2 -- stderr, 3 -- cwd assert(fd == CWD + 1); dup_fd = set_fd_msg(fd, dup_file); assert(dup_fd == fd + 1); int res; res = test_dup2(fd, dup_fd + 1); assert(res == dup_fd + 1); // do some operations: read and write to file // close the duplicated file descriptor res = test_close(dup_fd); assert(res == dup_fd); res = test_close(dup_fd + 1); assert(res == dup_fd + 1); res = test_close(fd); assert(res == fd); }
int stress_test2(){ int i; struct stat st; char buffer[64]; int len; int loc; void * f; printf("Starting stess test 2\n"); printf("appending..."); fflush(stdout); f = test_open("log.txt", O_APPEND | O_RDWR | O_CREAT, 0666); if ( f == NULL ){ perror("Failed to open file"); return -1; } test_fstat(f, &st); loc = st.st_size; strcpy(buffer, "123456789\n"); len = strlen(buffer); for(i = 0; i < 10000; i++){ if ( i % 100 == 0 ){ printf("."); fflush(stdout); } if ( test_write(f, loc, buffer, len) != len ){ perror("write failed"); break; } loc += len; } test_fstat(f, &st); printf("%d bytes\n", (int)st.st_size); test_close(f); return 0; }
static void create_read_write(const char *name, int ram_id) { int res; // create file res = set_name_msg(name, create_file); assert(res == SUCC); // open int fd = test_open(name); // read from ram // write to disk Msg m; // get executable file int len = -1; char *buf = (char *) get_a_ram_file(ram_id, &len); set_rw_msg(&m, fd, buf); m.i[4] = len; write_file(&m); // close file res = test_close(fd); assert(res == fd); }
int main(int argc, char *argv[]) { set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_test_fsync")); progname = get_progname(argv[0]); handle_args(argc, argv); /* Prevent leaving behind the test file */ pqsignal(SIGINT, signal_cleanup); pqsignal(SIGTERM, signal_cleanup); #ifndef WIN32 pqsignal(SIGALRM, process_alarm); #endif #ifdef SIGHUP /* Not defined on win32 */ pqsignal(SIGHUP, signal_cleanup); #endif prepare_buf(); test_open(); /* Test using 1 XLOG_BLCKSZ write */ test_sync(1); /* Test using 2 XLOG_BLCKSZ writes */ test_sync(2); test_open_syncs(); test_file_descriptor_sync(); test_non_sync(); unlink(filename); return 0; }
int main(int argc, char *argv[]) { START(argc, argv, "cto_multiple_pools"); if (argc < 4) UT_FATAL("usage: %s directory mode npools nthreads", argv[0]); Dir = argv[1]; char mode = argv[2][0]; Npools = ATOU(argv[3]); unsigned nthreads = ATOU(argv[4]); UT_OUT("create %d pools in %d thread(s)", Npools, nthreads); Pools = CALLOC(Npools * nthreads, sizeof(Pools[0])); Threads = CALLOC(nthreads, sizeof(Threads[0])); Pool_idx = CALLOC(nthreads, sizeof(Pool_idx[0])); switch (mode) { case 'o': test_open(nthreads); break; case 'c': test_create(nthreads); break; default: UT_FATAL("unknown mode"); } FREE(Pools); FREE(Threads); FREE(Pool_idx); DONE(NULL); }
static int ubi_volume_match(struct volume *v, char *name, int ubi_num, int volid) { char voldir[BUFLEN], volblkdev[BUFLEN], *volname; struct ubi_priv *p; snprintf(voldir, sizeof(voldir), "%s/ubi%u/ubi%u_%u", ubi_dir_name, ubi_num, ubi_num, volid); snprintf(volblkdev, sizeof(volblkdev), "/dev/ubiblock%u_%u", ubi_num, volid); /* skip if ubiblock device exists */ if (test_open(volblkdev)) return -1; /* todo: skip existing gluebi device for legacy support */ volname = read_string_from_file(voldir, "name"); if (!volname) { ULOG_ERR("Couldn't read %s/name\n", voldir); return -1; } if (strncmp(name, volname, strlen(volname) + 1)) return -1; p = calloc(1, sizeof(struct ubi_priv)); if (!p) return -1; v->priv = p; v->drv = &ubi_driver; p->ubi_num = ubi_num; p->ubi_volid = volid; return ubi_volume_init(v); }