int main() { test_short(); test_long(); return 0; }
void histogram(void) { long maxcount = BLOCKS; intptr_t sc[PRIORITIES]; intptr_t total = 0; long x,y; for (y = 0; y < PRIORITIES; ++y) { sc[y] = counts[y].count; } for (y = 0; y < PRIORITIES; ++y) { double fraction; double value; printf("%s: %ld\n", labels[y], sc[y]); total += sc[y]; fraction = (double)sc[y] / (double)maxcount; value = fraction * (double)80; for (x = 0; x < 80; ++x) { printf("%s", (value > x) ? "*" : " "); } printf("\n"); } test_long("blocks completed", (long)total, ITERATIONS); test_long_less_than("high priority precedence", (long)sc[0], (long)sc[2]); }
void test_stop_after_delay(void *delay) { #if HAVE_LEAKS int res; pid_t pid; char pidstr[10]; #endif if (delay != NULL) { Sleep((DWORD)(SIZE_T)delay * 1000); } #if HAVE_LEAKS if (getenv("NOLEAKS")) _exit(EXIT_SUCCESS); /* leaks doesn't work against debug variant malloc */ if (getenv("DYLD_IMAGE_SUFFIX")) _exit(EXIT_SUCCESS); snprintf(pidstr, sizeof(pidstr), "%d", getpid()); char* args[] = { "./leaks-wrapper", pidstr, NULL }; res = posix_spawnp(&pid, args[0], NULL, NULL, args, environ); if (res == 0 && pid > 0) { int status; waitpid(pid, &status, 0); test_long("Leaks", status, 0); } else { perror(args[0]); } #endif _exit(EXIT_SUCCESS); }
int main(int, char*[]) { test_quick(); test_short_messages(); test_long(); return boost::report_errors(); }
int main(void) { const char *path = "/usr/share/dict/words"; struct stat sb; dispatch_test_start("Dispatch Source Read"); int infd = open(path, O_RDONLY); if (infd == -1) { perror(path); exit(EXIT_FAILURE); } if (fstat(infd, &sb) == -1) { perror(path); exit(EXIT_FAILURE); } bytes_total = sb.st_size; if (fcntl(infd, F_SETFL, O_NONBLOCK) != 0) { perror(path); exit(EXIT_FAILURE); } if (!dispatch_test_check_evfilt_read_for_fd(infd)) { test_skip("EVFILT_READ kevent not firing for test file"); test_fin(NULL); } dispatch_queue_t main_q = dispatch_get_main_queue(); test_ptr_notnull("dispatch_get_main_queue", main_q); dispatch_source_t reader = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, infd, 0, main_q); test_ptr_notnull("dispatch_source_create", reader); assert(reader); dispatch_source_set_event_handler(reader, ^{ size_t estimated = dispatch_source_get_data(reader); fprintf(stderr, "bytes available: %zu\n", estimated); test_double_less_than_or_equal("estimated", estimated, bytes_total - bytes_read); const ssize_t bufsiz = 1024*500; // 500 KB buffer static char buffer[1024*500]; // 500 KB buffer ssize_t actual = read(infd, buffer, sizeof(buffer)); bytes_read += actual; printf("bytes read: %zd\n", actual); if (actual < bufsiz) { actual = read(infd, buffer, sizeof(buffer)); bytes_read += actual; // confirm EOF condition test_long("EOF", actual, 0); dispatch_source_cancel(reader); } });
void test_proc(pid_t bad_pid) { dispatch_source_t proc_s[PID_CNT], proc; int res; pid_t pid, monitor_pid; event_cnt = 0; // Creates a process and register multiple observers. Send a signal, // exit the process, etc., and verify all observers were notified. posix_spawnattr_t attr; res = posix_spawnattr_init(&attr); assert(res == 0); #if HAVE_DECL_POSIX_SPAWN_START_SUSPENDED res = posix_spawnattr_setflags(&attr, POSIX_SPAWN_START_SUSPENDED); assert(res == 0); #endif char* args[] = { "/bin/sleep", "2", NULL }; res = posix_spawnp(&pid, args[0], NULL, &attr, args, NULL); if (res < 0) { perror(args[0]); exit(127); } res = posix_spawnattr_destroy(&attr); assert(res == 0); dispatch_group_t group = dispatch_group_create(); assert(pid > 0); monitor_pid = bad_pid ? bad_pid : pid; // rdar://problem/8090801 int i; for (i = 0; i < PID_CNT; ++i) { dispatch_group_enter(group); proc = proc_s[i] = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, monitor_pid, DISPATCH_PROC_EXIT, dispatch_get_global_queue(0, 0)); test_ptr_notnull("dispatch_source_proc_create", proc); dispatch_source_set_event_handler(proc, ^{ long flags = dispatch_source_get_data(proc); test_long("DISPATCH_PROC_EXIT", flags, DISPATCH_PROC_EXIT); event_cnt++; dispatch_source_cancel(proc); }); dispatch_source_set_cancel_handler(proc, ^{ dispatch_group_leave(group); });
int main() { test_char(); test_uchar(); test_short(); test_ushort(); test_int(); test_uint(); test_long(); test_ulong(); test_float(); test_double(); return 0; }
int main() { test_cpy(); test_int(); test_long(); test_real(); test_idx(); test_trim(); test_split(); test_match(); return 0; }
int main(int argc, char** argv) { wlog("testing creating, get, set and iteration\n"); test_create_and_access(); wlog("testing realloc resize clear and freedata\n"); test_realloc_resize(); wlog("testing push pop and extend\n"); test_pushpop(); wlog("testing sort\n"); test_sort(); wlog("testing basic type long\n"); test_long(); wlog("testing pointer\n"); test_ptr(); }
int main(int argc, char *argv[]) { test_long(); test_int(); test_short(); test_char(); test_unsigned_long(); test_unsigned_int(); test_unsigned_short(); test_unsigned_char(); #if 0 test_unsigned_long_long(); test_long_long(); #endif return 0; }
static void test_concat(void) { dispatch_group_enter(g); dispatch_async(dispatch_get_main_queue(), ^{ char* buffer1 = "This is buffer1 "; size_t size1 = 17; char* buffer2 = "This is buffer2 "; size_t size2 = 17; __block bool buffer2_destroyed = false; dispatch_data_t data1 = dispatch_data_create(buffer1, size1, NULL, NULL); dispatch_data_t data2 = dispatch_data_create(buffer2, size2, dispatch_get_main_queue(), ^{ buffer2_destroyed = true; }); dispatch_data_t concat = dispatch_data_create_concat(data1, data2); dispatch_release(data1); dispatch_release(data2); test_long("Data size of concatenated dispatch data", dispatch_data_get_size(concat), 34); const void* contig; size_t contig_size; dispatch_data_t contig_data = dispatch_data_create_map(concat, &contig, &contig_size); dispatch_release(concat); dispatch_release(contig_data); test_long("Contiguous memory size", contig_size, 34); dispatch_async(dispatch_get_main_queue(), ^{ test_long("buffer2 destroyed", buffer2_destroyed, true); dispatch_group_leave(g); });
int main(int argc, char *argv[]) { dispatch_source_t tmp_ds; int res; pid_t pid; if (argc < 2) { fprintf(stderr, "usage: harness [...]\n"); exit(1); } posix_spawnattr_t attr; res = posix_spawnattr_init(&attr); assert(res == 0); res = posix_spawnattr_setflags(&attr, POSIX_SPAWN_START_SUSPENDED); assert(res == 0); int i; char** newargv = calloc(argc, sizeof(void*)); for (i = 1; i < argc; ++i) { newargv[i-1] = argv[i]; } newargv[i-1] = NULL; res = posix_spawnp(&pid, newargv[0], NULL, &attr, newargv, environ); if (res) { errno = res; perror(newargv[0]); exit(EXIT_FAILURE); } //fprintf(stderr, "pid = %d\n", pid); assert(pid > 0); dispatch_queue_t main_q = dispatch_get_main_queue(); tmp_ds = dispatch_source_proc_create(pid, DISPATCH_PROC_EXIT, NULL, main_q, ^(dispatch_event_t ev __attribute__((unused))) { int status; int res2 = waitpid(pid, &status, 0); assert(res2 != -1); //int passed = (WIFEXITED(status) && WEXITSTATUS(status) == 0); test_long("Process exited", WEXITSTATUS(status) | WTERMSIG(status), 0); exit(0); });
/*------------------------------------------------------------------------- * Function: main * * Purpose: Test groups * * Return: Success: zero * * Failure: non-zero * * Programmer: Robb Matzke * Tuesday, November 24, 1998 * * Modifications: * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl, fcpl, file; int nerrors=0; char filename[1024]; /* Reset library */ h5_reset(); fapl = h5_fileaccess(); /* * Use larger symbol table data structures to be more efficient, use * defaults to bang harder on the library for testing. */ fcpl = H5Pcreate(H5P_FILE_CREATE); #if 0 H5Pset_sym_k(fcpl, 16, 16); #endif /* Open the file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl))<0) goto error; /* Perform tests */ nerrors += test_misc(file); nerrors += test_long(file); nerrors += test_large(file); nerrors += read_new(fapl); if (nerrors) goto error; /* Cleanup */ H5Fclose(file); puts("All symbol table tests passed."); h5_cleanup(FILENAME, fapl); return 0; error: puts("*** TESTS FAILED ***"); return 1; }
void run() { test_zero(); test_zero_white(); test_hundred(); test_minus_hundred(); test_large(); test_max(); fail_minus(); fail_minus_white(); fail_minus_alpha(); fail_too_large(); fail_as_float(); fail_as_string(); test_short(); test_int(); test_long(); test_intmax(); test_unsigned(); fail_unsigned_negative(); }
int main(void) { dispatch_test_start("Dispatch VM Pressure test"); // rdar://problem/7000945 if (!dispatch_test_check_evfilt_vm()) { test_skip("EVFILT_VM not supported"); test_stop(); return 0; } initial = time(NULL); uint64_t memsize = _dispatch_get_memory_size(); max_page_count = MIN(memsize, MAXMEM) / ALLOC_SIZE; pages = calloc(max_page_count, sizeof(char*)); vm_queue = dispatch_queue_create("VM Pressure", NULL); vm_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VM, 0, DISPATCH_VM_PRESSURE, vm_queue); dispatch_source_set_event_handler(vm_source, ^{ if (!page_count) { // Too much memory pressure already to start the test test_skip("Memory pressure at start of test"); cleanup(); } if (__sync_add_and_fetch(&handler_call_count, 1) != NOTIFICATIONS) { log_msg("Ignoring vm pressure notification\n"); interval = 1; return; } test_long("dispatch_source_get_data()", dispatch_source_get_data(vm_source), NOTE_VM_PRESSURE); int32_t i, pc = page_count + 1; for (i = 0; i < pc && pages[i]; ++i) { free(pages[i]); pages[i] = NULL; } log_msg("Freed %ldMB\n", pg2mb(i)); });
int main(void) { char *hello; int *i; struct node n[2]; void *p; strcpy(n[0].hello, "123456"); strcpy(n[1].hello, "abcdef"); p = n; printf("%s\n", p); p +=1; printf("%s\n", p); i = p; test_long(); return 0; }
int main(int argc, char** argv) { struct hostent *he; int sockfd, clientfd; struct sockaddr_in addr1, addr2, server; socklen_t addr2len; socklen_t addr1len; pid_t clientid; const char *path = "/usr/share/dict/words"; int read_fd, fd; if (argc == 2) { // Client dispatch_test_start(NULL); if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { test_errno("Client-socket()", errno, 0); test_stop(); } if ((he = gethostbyname("localhost")) == NULL) { fprintf(stderr, "Client-gethostbyname() failed\n"); test_stop(); } memcpy(&server.sin_addr, he->h_addr_list[0], he->h_length); server.sin_family = AF_INET; server.sin_port = atoi(argv[1]); fprintf(stderr, "Client-connecting on port ... %d\n", server.sin_port); if (connect(sockfd, (struct sockaddr *)&server, sizeof(server))) { test_errno("client-connect()", errno, 0); test_stop(); } // Read from the socket and compare the contents are what we expect fd = open(path, O_RDONLY); if (fd == -1) { test_errno("client-open", errno, 0); test_stop(); } #ifdef F_NOCACHE if (fcntl(fd, F_NOCACHE, 1)) { test_errno("client-fcntl F_NOCACHE", errno, 0); test_stop(); } #else // investigate what the impact of lack of file cache disabling has // for this test #endif struct stat sb; if (fstat(fd, &sb)) { test_errno("client-fstat", errno, 0); test_stop(); } size_t size = sb.st_size; __block dispatch_data_t g_d1 = dispatch_data_empty; __block dispatch_data_t g_d2 = dispatch_data_empty; __block int g_error = 0; dispatch_group_t g = dispatch_group_create(); dispatch_group_enter(g); dispatch_read(fd, size, dispatch_get_global_queue(0, 0), ^(dispatch_data_t d1, int error) { test_errno("Client-dict-read error", error, 0); test_long("Client-dict-dispatch data size", dispatch_data_get_size(d1), size); dispatch_retain(d1); g_d1 = d1; dispatch_group_leave(g); });
int main(int argc, char *argv[]) { dispatch_source_t tmp_ds; int res; pid_t pid = 0; if (argc < 2) { fprintf(stderr, "usage: %s [...]\n", argv[0]); exit(1); } #if HAVE_DECL_POSIX_SPAWN_START_SUSPENDED short spawnflags = POSIX_SPAWN_START_SUSPENDED; #endif #if TARGET_OS_EMBEDDED spawnflags |= POSIX_SPAWN_SETEXEC; #endif posix_spawnattr_t attr; res = posix_spawnattr_init(&attr); assert(res == 0); #if HAVE_DECL_POSIX_SPAWN_START_SUSPENDED res = posix_spawnattr_setflags(&attr, spawnflags); assert(res == 0); #endif uint64_t to = 0; char *tos = getenv("BSDTEST_TIMEOUT"); if (tos) { to = strtoul(tos, NULL, 0); to *= NSEC_PER_SEC; } #if __APPLE__ char *arch = getenv("BSDTEST_ARCH"); if (arch) { const NXArchInfo *ai = NXGetArchInfoFromName(arch); if (ai) { res = posix_spawnattr_setbinpref_np(&attr, 1, (cpu_type_t*)&ai->cputype, NULL); assert(res == 0); } } #endif int i; char** newargv = calloc(argc, sizeof(void*)); for (i = 1; i < argc; ++i) { newargv[i-1] = argv[i]; } newargv[i-1] = NULL; struct timeval tv_start; gettimeofday(&tv_start, NULL); #if HAVE_POSIX_SPAWN_SETEXEC if (spawnflags & POSIX_SPAWN_SETEXEC) { pid = fork(); } #endif if (!pid) { res = posix_spawnp(&pid, newargv[0], NULL, &attr, newargv, environ); if (res) { errno = res; perror(newargv[0]); exit(EXIT_FAILURE); } } //fprintf(stderr, "pid = %d\n", pid); assert(pid > 0); dispatch_queue_t main_q = dispatch_get_main_queue(); tmp_ds = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, pid, DISPATCH_PROC_EXIT, main_q); assert(tmp_ds); dispatch_source_set_event_handler(tmp_ds, ^{ int status; struct rusage usage; struct timeval tv_stop, tv_wall; gettimeofday(&tv_stop, NULL); tv_wall.tv_sec = tv_stop.tv_sec - tv_start.tv_sec; tv_wall.tv_sec -= (tv_stop.tv_usec < tv_start.tv_usec); tv_wall.tv_usec = abs(tv_stop.tv_usec - tv_start.tv_usec); int res2 = wait4(pid, &status, 0, &usage); assert(res2 != -1); test_long("Process exited", (WIFEXITED(status) && WEXITSTATUS(status) && WEXITSTATUS(status) != 0xff) || WIFSIGNALED(status), 0); printf("[PERF]\twall time: %ld.%06d\n", tv_wall.tv_sec, tv_wall.tv_usec); printf("[PERF]\tuser time: %ld.%06d\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec); printf("[PERF]\tsystem time: %ld.%06d\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec); printf("[PERF]\tmax resident set size: %ld\n", usage.ru_maxrss); printf("[PERF]\tpage faults: %ld\n", usage.ru_majflt); printf("[PERF]\tswaps: %ld\n", usage.ru_nswap); printf("[PERF]\tvoluntary context switches: %ld\n", usage.ru_nvcsw); printf("[PERF]\tinvoluntary context switches: %ld\n", usage.ru_nivcsw); exit((WIFEXITED(status) && WEXITSTATUS(status)) || WIFSIGNALED(status)); });
static ERL_NIF_TERM type_test(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { int i; int sint; unsigned uint; long slong; unsigned long ulong; ErlNifSInt64 sint64; ErlNifUInt64 uint64; double d; ERL_NIF_TERM atom, ref1, ref2; sint = INT_MIN; do { if (!test_int(env,sint)) { goto error; } sint += ~sint / 3 + 1; } while (sint < 0); sint = INT_MAX; do { if (!test_int(env,sint)) { goto error; } sint -= sint / 3 + 1; } while (sint >= 0); slong = LONG_MIN; do { if (!test_long(env,slong)) { goto error; } slong += ~slong / 3 + 1; } while (slong < 0); slong = LONG_MAX; do { if (!test_long(env,slong)) { goto error; } slong -= slong / 3 + 1; } while (slong >= 0); sint64 = ((ErlNifSInt64)1 << 63); /* INT64_MIN */ do { if (!test_int64(env,sint64)) { goto error; } sint64 += ~sint64 / 3 + 1; } while (sint64 < 0); sint64 = ((ErlNifUInt64)1 << 63) - 1; /* INT64_MAX */ do { if (!test_int64(env,sint64)) { goto error; } sint64 -= sint64 / 3 + 1; } while (sint64 >= 0); uint = UINT_MAX; for (;;) { if (!test_uint(env,uint)) { goto error; } if (uint == 0) break; uint -= uint / 3 + 1; } ulong = ULONG_MAX; for (;;) { if (!test_ulong(env,ulong)) { goto error; } if (ulong == 0) break; ulong -= ulong / 3 + 1; } uint64 = (ErlNifUInt64)-1; /* UINT64_MAX */ for (;;) { if (!test_uint64(env,uint64)) { goto error; } if (uint64 == 0) break; uint64 -= uint64 / 3 + 1; } if (MAX_SMALL < INT_MAX) { /* 32-bit */ for (i=-10 ; i <= 10; i++) { if (!test_int(env,MAX_SMALL+i)) { goto error; } } for (i=-10 ; i <= 10; i++) { if (!test_int(env,MIN_SMALL+i)) { goto error; } } for (i=-10 ; i <= 10; i++) { if (!test_uint(env,MAX_SMALL+i)) { goto error; } } } assert((MAX_SMALL < INT_MAX) == (MIN_SMALL > INT_MIN)); for (i=-10 ; i < 10; i++) { if (!test_long(env,MAX_SMALL+i) || !test_ulong(env,MAX_SMALL+i) || !test_long(env,MIN_SMALL+i) || !test_int64(env,MAX_SMALL+i) || !test_uint64(env,MAX_SMALL+i) || !test_int64(env,MIN_SMALL+i)) { goto error; } if (MAX_SMALL < INT_MAX) { if (!test_int(env,MAX_SMALL+i) || !test_uint(env,MAX_SMALL+i) || !test_int(env,MIN_SMALL+i)) { goto error; } } } for (d=3.141592e-100 ; d < 1e100 ; d *= 9.97) { if (!test_double(env,d) || !test_double(env,-d)) { goto error; } } if (!enif_make_existing_atom(env,"nif_SUITE", &atom, ERL_NIF_LATIN1) || !enif_is_identical(atom,enif_make_atom(env,"nif_SUITE"))) { fprintf(stderr, "nif_SUITE not an atom?\r\n"); goto error; } for (i=2; i; i--) { if (enif_make_existing_atom(env,"nif_SUITE_pink_unicorn", &atom, ERL_NIF_LATIN1)) { fprintf(stderr, "pink unicorn exist?\r\n"); goto error; } } ref1 = enif_make_ref(env); ref2 = enif_make_ref(env); if (!enif_is_ref(env,ref1) || !enif_is_ref(env,ref2) || enif_is_identical(ref1,ref2) || enif_compare(ref1,ref2)==0) { fprintf(stderr, "strange refs?\r\n"); goto error; } return enif_make_atom(env,"ok"); error: return enif_make_atom(env,"error"); }