// Tests reading the stream across boundaries of what has been buffered so far and what // the total buffer size is. static void test_incremental_buffering(skiatest::Reporter* reporter, size_t bufferSize) { // NOTE: For this and other tests in this file, we cheat and continue to refer to the // wrapped stream, but that's okay because we know the wrapping stream has not been // deleted yet (and we only call const methods in it). SkMemoryStream* memStream = SkNEW_ARGS(SkMemoryStream, (gAbcs, strlen(gAbcs), false)); SkAutoTDelete<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); test_hasLength(reporter, *bufferedStream.get(), *memStream); // First, test reading less than the max buffer size. test_read(reporter, bufferedStream, gAbcs, bufferSize / 2); // Now test rewinding back to the beginning and reading less than what was // already buffered. test_rewind(reporter, bufferedStream, true); test_read(reporter, bufferedStream, gAbcs, bufferSize / 4); // Now test reading part of what was buffered, and buffering new data. test_read(reporter, bufferedStream, gAbcs + bufferedStream->getPosition(), bufferSize / 2); // Now test reading what was buffered, buffering new data, and // reading directly from the stream. test_rewind(reporter, bufferedStream, true); test_read(reporter, bufferedStream, gAbcs, bufferSize << 1); // We have reached the end of the buffer, so rewinding will fail. // This test assumes that the stream is larger than the buffer; otherwise the // result of rewind should be true. test_rewind(reporter, bufferedStream, false); }
int main(int argc, char** argv) { if (argc < 2) { cc::errln("Error: too few arguments."); return EXIT_FAILURE; } else if (argc > 2) { cc::errln("Error: too many arguments."); return EXIT_FAILURE; } auto path = argv[1]; auto fd = safe_open(path, O_RDONLY).get(); auto fs = file_size(fd).get(); safe_close(fd).get(); auto count = check(path); auto sizes = {4, 8, 12, 16, 24, 32, 40, 48, 56, 64, 256, 1024, 4096, 16384, 65536, 262144}; purge_cache().get(); print_header(); test_read_range(read_plain, path, "read_plain", sizes, fs, count); test_read_range(read_direct, path, "read_direct", sizes, fs, count); test_read_range(read_fadvise, path, "read_fadvise", sizes, fs, count); test_read_range(aio_read_direct, path, "aio_read_direct", sizes, fs, count); test_read_range(aio_read_fadvise, path, "aio_read_fadvise", sizes, fs, count); test_read_range(read_async_plain, path, "read_async_plain", sizes, fs, count); test_read_range(read_async_direct, path, "read_async_direct", sizes, fs, count); test_read_range(read_async_fadvise, path, "read_async_fadvise", sizes, fs, count); test_read(std::bind(read_mmap_plain, path), "mmap_plain", count, fs); test_read(std::bind(read_mmap_direct, path), "mmap_direct", count, fs); test_read(std::bind(read_mmap_fadvise, path), "mmap_fadvise", count, fs); }
int main() { arena = Arena_new(); start_socket_server(); start_socket_client(); test_unconnected_put(); //fatal, reconnect start_socket_client(); test_con(); test_con_2(); //fatal, reconnect start_socket_client(); test_con(); test_put(); test_read(); test_take(); test_upt(); //fatal, reconnect start_socket_client(); test_con(); test_upl(); stop_socket_server(); return 0; }
static void test_many(lzma_index *i) { test_copy(i); test_read(i); test_code(i); }
// Test using a stream with an initial offset. static void test_initial_offset(skiatest::Reporter* reporter, size_t bufferSize) { SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false); // Skip a few characters into the memStream, so that bufferedStream represents an offset into // the stream it wraps. const size_t arbitraryOffset = 17; memStream->skip(arbitraryOffset); std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); // Since SkMemoryStream has a length, bufferedStream must also. REPORTER_ASSERT(reporter, bufferedStream->hasLength()); const size_t amountToRead = 10; const size_t bufferedLength = bufferedStream->getLength(); size_t currentPosition = 0; // Read the stream in chunks. After each read, the position must match currentPosition, // which sums the amount attempted to read, unless the end of the stream has been reached. // Importantly, the end should not have been reached until currentPosition == bufferedLength. while (currentPosition < bufferedLength) { REPORTER_ASSERT(reporter, !bufferedStream->isAtEnd()); test_read(reporter, bufferedStream.get(), gAbcs + arbitraryOffset + currentPosition, amountToRead); currentPosition = SkTMin(currentPosition + amountToRead, bufferedLength); REPORTER_ASSERT(reporter, memStream->getPosition() - arbitraryOffset == currentPosition); } REPORTER_ASSERT(reporter, bufferedStream->isAtEnd()); REPORTER_ASSERT(reporter, bufferedLength == currentPosition); }
int main() { int32_t ret = 0; int fd = 0; int i = 0,j = 0; fd = open("/dev/dpram1",O_RDWR); if (-1 == fd) { perror("open /dev/dpram1 failed"); return -1; } for(i = 1; i < 0xffff; i += 0xff) { printf("i:%d\n",i); for(j = 0; j < 4; j++) { ret = test_read(fd,i); if(-1 == ret) { return -1; } } } return 0; }
// This test ensures that buffering the exact length of the stream and attempting to read beyond it // does not invalidate the buffer. static void test_read_beyond_buffer(skiatest::Reporter* reporter, size_t bufferSize) { // Use a stream that behaves like Android's stream. AndroidLikeMemoryStream* memStream = new AndroidLikeMemoryStream((void*)gAbcs, bufferSize, false); // Create a buffer that matches the length of the stream. std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); test_hasLength(reporter, *bufferedStream.get(), *memStream); // Attempt to read one more than the bufferSize test_read(reporter, bufferedStream.get(), gAbcs, bufferSize + 1); test_rewind(reporter, bufferedStream.get(), true); // Ensure that the initial read did not invalidate the buffer. test_read(reporter, bufferedStream.get(), gAbcs, bufferSize); }
int main(void) { board_init(); if (test_write_and_erase() == STATUS_OK) { /* Toggle LED to indicate success */ gpio_toggle_pin(LED_PIN_0); } if (test_write_no_erase() == STATUS_OK) { /* Toggle LED to indicate success */ gpio_toggle_pin(LED_PIN_1); } if (test_read() == STATUS_OK) { /* Toggle LED to indicate success */ gpio_toggle_pin(LED_PIN_2); } /* Toggle LED to indicate that we are done */ gpio_toggle_pin(LED_PIN_7); while (true) {} }
int main() { test_read(); test_write(); printf("\n \e[32m\u2713 \e[90mok\e[0m\n\n"); return 0; }
int main(int ac, char **av) { int afd, fd; aio_context_t ctx = 0; char const *testfn = "/tmp/eventfd-aio-test.data"; fprintf(stdout, "creating an eventfd ...\n"); if ((afd = eventfd(0)) == -1) { perror("eventfd"); return 2; } fprintf(stdout, "done! eventfd = %d\n", afd); if (io_setup(TESTFILE_SIZE / IORTX_SIZE + 256, &ctx)) { perror("io_setup"); return 3; } if ((fd = open(testfn, O_RDWR | O_CREAT, 0644)) == -1) { perror(testfn); return 4; } ftruncate(fd, TESTFILE_SIZE); fcntl(afd, F_SETFL, fcntl(afd, F_GETFL, 0) | O_NONBLOCK); test_write(ctx, fd, TESTFILE_SIZE, afd); test_read(ctx, fd, TESTFILE_SIZE, afd); io_destroy(ctx); close(fd); close(afd); remove(testfn); return 0; }
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(int argc, char* argv[]) { if (argc < 2) { goto help; } if (strcmp(argv[1], "create") == SHM_OK) { return test_creat(); } else if (strcmp(argv[1], "write") == SHM_OK) { return test_write(); } else if (strcmp(argv[1], "read") == SHM_OK) { return test_read(); } else if (strcmp(argv[1], "delete") == SHM_OK) { return test_delete(); } help: printf("Usage: shm COMMAND\n\n" "The most used commands are:\n" "create Create a share memory\n" "write Write something into the share memory\n" "read Read something from the share memory\n" "delete Delete the share memory\n" ); return SHM_FAILED; }
int main(int argc, char **argv) { int rval = 0; printf("Testing read functions ... "); rval = test_read(); if (rval != 0) { fprintf(stderr, "FAILED!\n"); return (-1); } else { printf("passed!\n"); } printf("Testing skip functions ... "); rval = test_skip(); if (rval != 0) { fprintf(stderr, "FAILED!\n"); return (-1); } else { printf("passed!\n"); } printf("Testing position functions ... "); rval = test_position(); if (rval != 0) { fprintf(stderr, "FAILED!\n"); return (-1); } else { printf("passed!\n"); } return (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) { fprintf(stderr, "%s\n", __FILE__); unlink("./data.lsmdb"); unlink("./data.lsmdb-lock"); LSMDB_env *env; chk( lsmdb_env_create(&env) ); chk( lsmdb_env_set_mapsize(env, MAP_SIZE) ); chk( lsmdb_env_open(env, "./data.lsmdb", MDB_NOSUBDIR | (!SYNC * MDB_NOSYNC), 0600) ); /* MDB_dbi dbi; { MDB_txn *txn; chk( mdb_txn_begin(env, NULL, MDB_RDWR, &txn) ); chk( mdb_dbi_open(txn, NULL, 0, &dbi) ); chk( mdb_txn_commit(txn) ); }*/ test_write(env); if(READ) test_read(env); lsmdb_env_close(env); return 0; }
int main() { pthread_t pid[MAX_THREAD]; struct table *T = init(); printf("init\n"); pthread_create(&pid[0], NULL, thread_write, T); int i; for (i=1;i<MAX_THREAD;i++) { pthread_create(&pid[i], NULL, thread_read, T); } for (i=0;i<MAX_THREAD;i++) { pthread_join(pid[i], NULL); } printf("main exit\n"); test_read(T); stable_release(T); return 0; }
int unittest_io_reader_filereader() { directory_t* tempdir = 0; char tmppath[128]; // prepare TEST(0 == newtemp_directory(&tempdir, "filereader", &(wbuffer_t) wbuffer_INIT_STATIC(sizeof(tmppath), (uint8_t*)tmppath))); if (test_initfree(tempdir)) goto ONERR; if (test_query()) goto ONERR; if (test_setter()) goto ONERR; if (test_read(tempdir)) goto ONERR; /* adapt log */ uint8_t *logbuffer; size_t logsize; GETBUFFER_ERRLOG(&logbuffer, &logsize); while (strstr((char*)logbuffer, "/filereader.")) { logbuffer = (uint8_t*)strstr((char*)logbuffer, "/filereader.")+12; if (logbuffer[6] == '/') { memcpy(logbuffer, "XXXXXX", 6); } } // unprepare TEST(0 == removedirectory_directory(0, tmppath)); TEST(0 == delete_directory(&tempdir)); return 0; ONERR: (void) delete_directory(&tempdir); return EINVAL; }
int main(int argc, const char* argv[]) { if (argc != 2) { usage(argv[0]); return 1; } if (!test_write(argv[1])) { return 1; } if (!test_read(argv[1])) { return 1; } if (!test_modify(argv[1])) { return 1; } return 0; }
int main(int argc, char *argv[]) { int opt; if((opt = getopt(argc, argv, "ar")) != -1) { switch(opt) { case 'a': test_add(); break; case 'r': test_read(); break; #if 0 case 'd': test_del(); break; case 't': test_alter(); break; #endif case '?': printf("unknown option: %c\n", optopt); break; } } return(0); }
int test_modify(const char* filename) { MXFFile* mxfFile = NULL; if (!mxf_disk_file_open_modify(filename, &mxfFile)) { mxf_log_error("Failed to open modify '%s'" LOG_LOC_FORMAT, filename, LOG_LOC_PARAMS); return 0; } /* TEST */ CHK_OFAIL(do_write(mxfFile)); mxf_file_close(&mxfFile); CHK_OFAIL(test_read(filename)); return 1; fail: mxf_file_close(&mxfFile); return 0; }
void start_test(int id) { uint i; int error,lock_type; MI_ISAMINFO isam_info; MI_INFO *file,*file1,*file2=0,*lock; if (use_log) mi_log(1); if (!(file1=mi_open(filename,O_RDWR,HA_OPEN_WAIT_IF_LOCKED)) || !(file2=mi_open(filename,O_RDWR,HA_OPEN_WAIT_IF_LOCKED))) { fprintf(stderr,"Can't open isam-file: %s\n",filename); exit(1); } if (key_cacheing && rnd(2) == 0) init_key_cache(dflt_key_cache, KEY_CACHE_BLOCK_SIZE, 65536L, 0, 0); printf("Process %d, pid: %d\n",id,getpid()); fflush(stdout); for (error=i=0 ; i < tests && !error; i++) { file= (rnd(2) == 1) ? file1 : file2; lock=0 ; lock_type=0; if (rnd(10) == 0) { if (mi_lock_database(lock=(rnd(2) ? file1 : file2), lock_type=(rnd(2) == 0 ? F_RDLCK : F_WRLCK))) { fprintf(stderr,"%2d: start: Can't lock table %d\n",id,my_errno); error=1; break; } } switch (rnd(4)) { case 0: error=test_read(file,id); break; case 1: error=test_rrnd(file,id); break; case 2: error=test_write(file,id,lock_type); break; case 3: error=test_update(file,id,lock_type); break; } if (lock) mi_lock_database(lock,F_UNLCK); } if (!error) { mi_status(file1,&isam_info,HA_STATUS_VARIABLE); printf("%2d: End of test. Records: %ld Deleted: %ld\n", id,(long) isam_info.records, (long) isam_info.deleted); fflush(stdout); } mi_close(file1); mi_close(file2); if (use_log) mi_log(0); if (error) { printf("%2d: Aborted\n",id); fflush(stdout); exit(1); } }
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; }
int main(int argc, char** argv) { vsipl init(argc, argv); test_write(); test_read(); }
int main() { try { test_read(); } catch (const std::exception& e) { std::cout << e.what() << std::endl; return 1; } return 0; }
static void test_perfectly_sized_buffer(skiatest::Reporter* reporter, size_t bufferSize) { SkMemoryStream* memStream = SkNEW_ARGS(SkMemoryStream, (gAbcs, strlen(gAbcs), false)); SkAutoTDelete<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); test_hasLength(reporter, *bufferedStream.get(), *memStream); // Read exactly the amount that fits in the buffer. test_read(reporter, bufferedStream, gAbcs, bufferSize); // Rewinding should succeed. test_rewind(reporter, bufferedStream, true); // Once again reading buffered info should succeed test_read(reporter, bufferedStream, gAbcs, bufferSize); // Read past the size of the buffer. At this point, we cannot return. test_read(reporter, bufferedStream, gAbcs + bufferedStream->getPosition(), 1); test_rewind(reporter, bufferedStream, false); }
int runTests() { int passed = 1; char newchar; passed &= lsTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= test_cat(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= test_read(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= test_write(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= cdTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= chmodTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= mkdirTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= touchTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= linkTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= rmdirTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= pwdTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= cpTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= mvTest(); printf("\nEnter a char to continue!\n"); scanf(" %c", &newchar); passed &= lseekTest(); if (passed == 1) { printf("\n\nEVERYTHING PASSED\n\n"); } else { printf("\n\nNOT EVERYTHING PASSED\n\n"); } }
/** * argv[1]: file operation * argv[2]: file to test (with path) * argv[3]: file to test (without path) */ int main(int argc, char *argv[]) { if (argc != 4) { fprintf(stderr, "wrong argument number\n"); return 1; } filepath = argv[2]; filename = argv[3]; /* create file and get the initial inode version */ fd = creat(argv[2], O_RDWR); if (fd == -1) { fprintf(stderr, "failed to create file: %s\n", argv[2]); return 1; } old_inode_version = get_inode_version(); if (strcmp(argv[1], "create") == 0) { printf("%d\n", old_inode_version); return 0; } else if (strcmp(argv[1], "chmod") == 0) { test_chmod(); } else if (strcmp(argv[1], "chown") == 0) { test_chown(); } else if (strcmp(argv[1], "read") == 0) { test_read(); } else if (strcmp(argv[1], "write") == 0) { test_write(); } else if (strcmp(argv[1], "mmap_read") == 0) { test_mmap_read(); } else if (strcmp(argv[1], "mmap_write") == 0) { test_mmap_write(); } else { fprintf(stderr, "wrong file operation: %s\n", argv[1]); return 1; } new_inode_version = get_inode_version(); #if 0 fprintf(stderr, "test_inode_version: old - %d\n", old_inode_version); fprintf(stderr, "test_inode_version: new - %d\n", new_inode_version); #endif /* wrong inode version, test failed */ if (new_inode_version <= old_inode_version) return 1; printf("%d\n", new_inode_version); close(fd); return 0; }
BOOST_FOREACH(Graph p, graphs){ test_edge_iterators(p); test_read(p); test_vertex_iterators(p); test_out_edges(p); test_in_edges(p); test_in_out_edges(p); test_edge_find(p); test_faces(p); test_halfedge_around_vertex_iterator(p); test_halfedge_around_face_iterator(p); }
static void test_skipping(skiatest::Reporter* reporter, size_t bufferSize) { SkMemoryStream* memStream = SkNEW_ARGS(SkMemoryStream, (gAbcs, strlen(gAbcs), false)); SkAutoTDelete<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); test_hasLength(reporter, *bufferedStream.get(), *memStream); // Skip half the buffer. bufferedStream->skip(bufferSize / 2); // Rewind, then read part of the buffer, which should have been read. test_rewind(reporter, bufferedStream, true); test_read(reporter, bufferedStream, gAbcs, bufferSize / 4); // Now skip beyond the buffered piece, but still within the total buffer. bufferedStream->skip(bufferSize / 2); // Test that reading will still work. test_read(reporter, bufferedStream, gAbcs + bufferedStream->getPosition(), bufferSize / 4); test_rewind(reporter, bufferedStream, true); test_read(reporter, bufferedStream, gAbcs, bufferSize); }
int main() { int fd; decoder = bert_decoder_create(); fd = test_open_file("files/big_int.bert"); bert_decoder_stream(decoder,fd); test_read(); bert_decoder_destroy(decoder); close(fd); return 0; }