uint8_t validate_bin_nvic(const uint8_t *buf) { // test for known required NVIC entries // 00 is stack pointer (RAM address) // 04 is Reset vector (FLASH address) // 08 NMI_Handler (FLASH address) // 12 HardFault_Handler(FLASH address) uint32_t i = 4, nvic_val = 0; // test the initial SP value memcpy(&nvic_val, buf+0, sizeof(nvic_val)); if (0 == test_range(nvic_val, target_device.ram_start, target_device.ram_end)) { return 0; } // Reset_Handler // NMI_Handler // HardFault_Handler for ( ; i <=12; i+=4) { memcpy(&nvic_val, buf+i, sizeof(nvic_val)); if (0 == test_range(nvic_val, target_device.flash_start, target_device.flash_end)) { return 0; } } return 1; }
void piglit_init(int argc, char **argv) { GLuint bo[2]; int size = 1024; GLint max_bindings; GLint junk; GLint alignment; piglit_require_extension("GL_ARB_uniform_buffer_object"); test_range(__LINE__, 0, 0, -1, -1); glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment); glGenBuffers(2, bo); glBindBuffer(GL_UNIFORM_BUFFER, bo[0]); glBufferData(GL_UNIFORM_BUFFER, size, NULL, GL_STATIC_READ); glBindBuffer(GL_UNIFORM_BUFFER, bo[1]); glBufferData(GL_UNIFORM_BUFFER, size, NULL, GL_STATIC_READ); glBindBufferRange(GL_UNIFORM_BUFFER, 0, bo[0], 0, 1); glBindBufferRange(GL_UNIFORM_BUFFER, 1, bo[1], 2 * alignment, 3); test_range(__LINE__, 0, bo[0], 0, 1); test_range(__LINE__, 1, bo[1], 2 * alignment, 3); /* There's a bit of a contradiction in the spec. On the one * hand, "BindBufferBase is equivalent to calling * BindBufferRange with offset zero and size equal to the size * of buffer", but on the other hand, " If the parameter * (starting offset or size) was not specified when the buffer * object was bound, zero is returned". This is clarified by * the GL 4.2 specification, which says that "BindBufferBase * binds the entire buffer, even when the size of the buffer * is changed after the binding is established.", so the zero * return for the size makes sense since it's effectively * computed at render time. */ glBindBufferBase(GL_UNIFORM_BUFFER, 1, bo[1]); test_range(__LINE__, 1, bo[1], 0, 0); /* Is binding a BO of 0 valid? It's not clear to me from the * spec ("The error INVALID_OPERATION is generated by * BindBufferRange and BindBufferBase if <buffer> is not the * name of a valid buffer object.", and glIsBuffer returns * false for 0), but it seems obviously parallel to the rest * of the GL API, including glBindBuffer(), to allow it */ glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0); test_range(__LINE__, 0, 0, -1, -1); /* Test the error condition. */ glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_bindings); glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, max_bindings, &junk); if (!piglit_check_gl_error(GL_INVALID_VALUE)) pass = false; piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
void test_isalpha_t::run() { constexpr auto char_max = 1 << sizeof(char) * 8; assert(test_range(0, char_max), "int from 0 to " + std::to_string(char_max)); assert(test_range(char_max, char_max * 2), "int from " + std::to_string(char_max) + " to " + std::to_string(char_max * 2)); assert(test_range(-char_max, 0), "int from " + std::to_string(-char_max) + " to 0"); }
/** * The get_any function cannot be fully tested on its own, so the basics are here and some more * hacking is done in test_return_function(). * * Tests to some extent that the different ranges do not interfere with each other during gets. */ static bool test_get_any_function(void) { if (!test_range(0, PORT_RANGE1_MAX, "Even low ports")) return false; if (!test_range(1, PORT_RANGE1_MAX, "Odd low ports")) return false; if (!test_range(1024, PORT_RANGE2_MAX, "Even high ports")) return false; if (!test_range(1025, PORT_RANGE2_MAX, "Odd high ports")) return false; return true; }
int main(void) { struct xkb_context *context = test_get_context(0); struct xkb_keymap *keymap; assert(context); /* Make sure these are allowed. */ xkb_context_unref(NULL); xkb_keymap_unref(NULL); xkb_state_unref(NULL); keymap = test_compile_rules(context, "evdev", "pc104", "us,ru", NULL, "grp:menu_toggle"); assert(keymap); test_update_key(keymap); test_serialisation(keymap); test_repeat(keymap); test_consume(keymap); test_range(keymap); test_get_utf8_utf32(keymap); test_ctrl_string_transformation(keymap); xkb_keymap_unref(keymap); keymap = test_compile_rules(context, "evdev", NULL, "ch", "fr", NULL); assert(keymap); test_caps_keysym_transformation(keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); }
int check_if_redirect( lsi_cb_param_t * rec ) { const char *uri; const char *qs; int action = LSI_URI_REWRITE; int useHandler = 0; int len; uri = g_api->get_req_uri(rec->_session, &len); if ( len >= strlen(TEST_URL) && strncasecmp(uri, TEST_URL, strlen(TEST_URL)) == 0 ) { qs = g_api->get_req_query_string(rec->_session, NULL ); if ( parse_qs( qs, &action, &useHandler ) < 0 ) { report_error( rec->_session, qs ); return LSI_RET_OK; } if ( test_range( action ) < 0 ) report_error( rec->_session, qs ); else if ( !useHandler ) g_api->set_uri_qs(rec->_session, action, DEST_URL, sizeof(DEST_URL) -1, "", 0 ); else if ( action > 1 ) g_api->register_req_handler(rec->_session, &MNAME, TEST_URL_LEN); else report_error( rec->_session, qs ); } return LSI_RET_OK; }
int main() { test_basic(); test_capacity(); test_comparison(); test_composite_key(); test_conv_iterators(); test_copy_assignment(); test_hash_ops(); test_iterators(); test_key_extractors(); test_list_ops(); test_modifiers(); test_mpl_ops(); test_observers(); test_projection(); test_range(); test_rank_ops(); test_rearrange(); test_safe_mode(); test_serialization(); test_set_ops(); test_special_set_ops(); test_update(); return boost::report_errors(); }
int main(void) { int res; res = test_begin(); test_updown(); test_range(); return res; }
uint8_t validate_bin_nvic(uint8_t *buf) { // test for known required NVIC entries // 0 is stack pointer (RAM address) // 1 is Reset vector (FLASH address) uint32_t nvic_sp = 0; uint32_t nvic_rv = 0; // test the initial SP value memcpy(&nvic_sp, buf, sizeof(nvic_sp)); if (0 == test_range(nvic_sp, target_device.ram_start, target_device.ram_end)) { return 0; } // test the initial reset vector memcpy(&nvic_rv, buf+4, sizeof(nvic_rv)); if (0 == test_range(nvic_rv, target_device.flash_start, target_device.flash_end)) { return 0; } return 1; }
void piglit_init(int argc, char **argv) { GLuint bo[2]; int size = 1024; GLint max_bindings; GLint junk; GLint alignment; piglit_require_extension("GL_ARB_shader_storage_buffer_object"); /* If no buffer object is bound to index, zero is returned. */ test_range(__LINE__, 1, 0, 0, 0); glGetIntegerv(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, &alignment); glGenBuffers(2, bo); glBindBuffer(GL_SHADER_STORAGE_BUFFER, bo[0]); glBufferData(GL_SHADER_STORAGE_BUFFER, size, NULL, GL_STATIC_READ); glBindBuffer(GL_SHADER_STORAGE_BUFFER, bo[1]); glBufferData(GL_SHADER_STORAGE_BUFFER, size, NULL, GL_STATIC_READ); glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, bo[0], 0, 1); glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 1, bo[1], 2 * alignment, 3); test_range(__LINE__, 0, bo[0], 0, 1); test_range(__LINE__, 1, bo[1], 2 * alignment, 3); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, bo[1]); test_range(__LINE__, 1, bo[1], 0, 0); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, 0); test_range(__LINE__, 0, 0, 0, 0); /* Test the error condition. */ glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &max_bindings); glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_BINDING, max_bindings, &junk); if (!piglit_check_gl_error(GL_INVALID_VALUE)) pass = false; piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
int main(int argc, char** argv) { if (!parse_args(argc,argv)) { return 0; } plan_tests(16); Waypoints waypoints; ok(setup_waypoints(waypoints),"waypoint setup",0); unsigned size = waypoints.size(); ok(test_lookup(waypoints,3),"waypoint lookup",0); ok(!test_lookup(waypoints,5000),"waypoint bad lookup",0); ok(test_nearest(waypoints),"waypoint nearest",0); ok(test_nearest_landable(waypoints),"waypoint nearest landable",0); ok(test_location(waypoints,true),"waypoint location good",0); ok(test_location(waypoints,false),"waypoint location bad",0); ok(test_range(waypoints,100)==1,"waypoint visit range 100m",0); ok(test_radius(waypoints,100)==1,"waypoint radius 100m",0); ok(test_range(waypoints,500000)== waypoints.size(),"waypoint range 500000m",0); ok(test_radius(waypoints,25000)<= test_range(waypoints,25000),"waypoint radius<range",0); // test clear waypoints.clear(); ok(waypoints.size()==0,"waypoint clear",0); setup_waypoints(waypoints); ok(size == waypoints.size(),"waypoint setup after clear",0); ok(test_copy(waypoints),"waypoint copy",0); ok(test_erase(waypoints,3),"waypoint erase",0); ok(test_replace(waypoints,4),"waypoint replace",0); return exit_status(); }
int main(int argc, char **argv) { krb5_keyblock keyblock; krb5_error_code ret; krb5_context context; krb5_crypto crypto; int i; ret = krb5_init_context(&context); if (ret) errx(1, "krb5_context_init: %d", ret); ret = krb5_generate_random_keyblock(context, ENCTYPE_AES256_CTS_HMAC_SHA1_96, &keyblock); if (ret) krb5_err(context, 1, ret, "krb5_generate_random_keyblock"); ret = krb5_crypto_init(context, &keyblock, 0, &crypto); if (ret) krb5_err(context, 1, ret, "krb5_crypto_init"); test_special(context, crypto, 1, 60); test_special(context, crypto, 0, 60); for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { test_range(&tests[i], 1, context, crypto); test_range(&tests[i], 0, context, crypto); } krb5_free_keyblock_contents(context, &keyblock); krb5_crypto_destroy(context, crypto); krb5_free_context(context); return 0; }
// find ranges for retract and repush bool Printlines::find_nextmoves(double minlength, uint startindex, AORange &range, const vector<PLine3> &lines) { if (!find_moverange(minlength, startindex, range.movestart, range.moveend, lines)) return false; uint num_lines = lines.size(); // find previous move if (range.movestart == 0) range.tractstart = 0; else { int i = range.movestart-1; range.tractstart = range.movestart; while ( i >= (int)startindex && ( !(lines[i].is_move() || lines[i].has_absolute_extrusion()) || lines[i].is_command() )) { range.tractstart = i; i--; } } while (range.tractstart < num_lines-1 && lines[range.tractstart].is_command()) range.tractstart++; // find next move after if (range.moveend == num_lines-1) range.pushend = range.moveend; else { uint i = range.moveend+1; range.pushend = range.moveend; while ( i < num_lines && (!(lines[i].is_move() || lines[i].has_absolute_extrusion()) || lines[i].is_command()) ) { range.pushend = i; i++; } } while (range.pushend > 0 && lines[range.pushend].is_command()) range.pushend--; #if AODEBUG test_range(range, lines); #endif // cerr << "found move " << tractstart << "..." <<movestart // << "--"<<moveend<< "..."<< pushend << endl; return true; }
int test_main(int,char *[]) { test_range(); return 0; }
void test_duplicates(unsigned int num) { const struct map_config map_conf = { .size = MAP_DEFAULT_SIZE, .lower_bound = MAP_DEFAULT_LOWER_BOUND, .upper_bound = MAP_DEFAULT_UPPER_BOUND, .static_size = false, .key_compare = &compare_int, .key_hash = &hash_uint, .data_delete = NULL, }; struct map *m; struct random *random; unsigned int i, n, dups1, dups2;; int err; m = map_new(&map_conf); random = random_new(); assert(m); assert(random); dups1 = 0; for(i = 0; i < num; ++i) { n = random_uint(random); if(map_contains(m, (void *)(long) n)) { dups1 += 1; } else { err = map_insert(m, (void *)(long) n, (void *)(long) n); if(err < 0) { fprintf(stderr, "Warning: " "Map unable to insert %u in %uth iteration: %s\n", n, i, strerror(-err)); } } } random_delete(random); map_clear(m); srand(time(NULL)); dups2 = 0; for(i = 0; i < num; ++i) { n = rand(); if(map_contains(m, (void *)(long) n)) { dups2 += 1; } else { err = map_insert(m, (void *)(long) n, (void *)(long) n); if(err < 0) { fprintf(stderr, "Warning: " "Map unable to insert %u in %uth iteration: %s\n", n, i, strerror(-err)); } } } map_delete(m); fprintf(stdout, "random: After %u iterations there are %u (%lf %%) duplicates\n" "rand(): After %u iterations there are %u (%lf %%) duplicates\n", num, dups1, (double) dups1 / num, num, dups2, (double) dups2 / num); } void test_range(unsigned int num) { struct random *rand; unsigned int i, n; rand = random_new(); assert(rand); for(i = 0; i < num; ++i) { n = random_uint_range(rand, 0, 100); assert(n <= 100); n = random_uint_range(rand, 1000, 10000); assert(n >= 1000 && n <= 10000); n = random_uint_range(rand, 99999, 123456); assert(n >= 99999 && n <= 123456); n = random_uint_range(rand, (unsigned int) 1e6 + 1, (unsigned int) 1e8); assert(n >= (unsigned int) 1e6 + 1 && n <= (unsigned int) 1e8); n = random_uint_range(rand, 0, 0); assert(n == 0); n = random_uint_range(rand, 100, 100); assert(n == 100); } random_delete(rand); } int main(int argc, char *argv[]) { unsigned int num; if(argc == 2) num = atoi(argv[1]); else num = 0; test_randomness(); if(num) { test_seeding(num); test_duplicates(num); test_range(num); } fprintf(stdout, "Tests finished\n"); return EXIT_SUCCESS; }
DEF_TEST(ClampRange, reporter) { gReporter = reporter; test_range(0, 0, 20); test_range(0xFFFF, 0, 20); test_range(-ff(2), 0, 20); test_range( ff(2), 0, 20); test_range(-10, 1, 20); test_range(10, -1, 20); test_range(-10, 3, 20); test_range(10, -3, 20); test_range(ff(1), ff(16384), 100); test_range(ff(-1), ff(-16384), 100); test_range(ff(1)/2, ff(16384), 100); test_range(ff(1)/2, ff(-16384), 100); SkRandom rand; // test non-overflow cases for (int i = 0; i < 1000000; i++) { SkFixed fx = rand.nextS() >> 1; SkFixed sx = rand.nextS() >> 1; int count = rand.nextU() % 1000 + 1; SkFixed dx = (sx - fx) / count; test_range(fx, dx, count); } // test overflow cases for (int i = 0; i < 100000; i++) { SkFixed fx = rand.nextS(); SkFixed dx = rand.nextS(); int count = rand.nextU() % 1000 + 1; test_range(fx, dx, count); } }
int do_test(test_entry_t *tp, int invert) { // variables for ranges unsigned long r0, b0; // range before both xor ranges unsigned long r1, b1; // range unique to first test (start) unsigned long r2, b2; // range where tests overlap unsigned long r3, b3; // range unique to first test (end) unsigned long r4, b4; // range after both xor ranges int result; // sanity check test ranges specified in test case assert(tp->a_start <= tp->b_start); assert(tp->a_start + tp->a_bytes >= tp->b_start + tp->b_bytes); assert(tp->a_start + tp->a_bytes <= SIZE_IN_BYTES); assert(tp->b_start + tp->b_bytes <= SIZE_IN_BYTES); // check invert variable assert(invert == 0 || invert == 1); invert ^= 1; // lets us eliminate logical not later // clear destination array init_dest(); printf("Test: %s\n", tp->desc); // calculate the bounds of the five ranges r0 = 0; b0 = tp->a_start; r1 = tp->a_start; b1 = tp->b_start - r1; r2 = tp->b_start; b2 = tp->b_bytes; r3 = tp->b_start + tp->b_bytes; b3 = tp->a_start + tp->a_bytes - r3; r4 = tp->a_start + tp->a_bytes; b4 = SIZE_IN_BYTES - r4; // do the xors xor_range(tp->test_a, tp->a_start, tp->a_bytes); xor_range(tp->test_b, tp->b_start, tp->b_bytes); // do the checks result = test_range(IS_ZERO, r0, b0); if (result ^ invert) { printf("%s: leading range [%ld,+%ld] was not zero\n", tp->desc,r0,b0); return 0; // false value => failure } result = test_range(tp->check_a, r1, b1); if (result ^ invert) { printf("%s: leading 'a' range failed %s check\n", tp->desc, check_name[tp->check_a]); return 0; } result = test_range(tp->check_b, r2, b2); if (result ^ invert) { printf("%s: overlapping range failed %s check\n", tp->desc, check_name[tp->check_b]); return 0; } result = test_range(tp->check_c, r3, b3); if (result ^ invert) { printf("%s: trailing 'a' range failed %s check\n", tp->desc, check_name[tp->check_c]); return 0; } result = test_range(IS_ZERO, r4, b4); if (result ^ invert) { printf("%s: trailing range [%ld,+%ld] was not zero\n", tp->desc,r4,b4); return 0; } return 1; }
int main() { test_range(); return boost::report_errors(); }
// test_harness returns the number of tests passed int test_harness(void) { int passed = 0; test_entry_t *tp = tests; int is_required, invert, result; int rand_trials = 10000; unsigned long start,bytes; // do all the individual tests from the list while(tp->test_a != END_OF_TESTS) { is_required = 0; invert = 0; // check whether description starts with '*' or '!' while ((tp->desc)[0] == '*' || (tp->desc)[0] == '!') { if ((tp->desc)[0] == '*') { is_required = 1; } if ((tp->desc)[0] == '!') { invert ^= 1; } ++(tp->desc); } result = do_test(tp,invert); if (result) { ++passed; } else { if (is_required) { printf("Failed required test: aborting remaining tests\n"); return passed; } } ++tp; } // do random test: first xor with bytewise, then do same xor with // aligned_word_xor and check that dest array is zero after each // pair. srand(1); printf("Doing %d random XOR trials\n", rand_trials); init_dest(); while(rand_trials--) { start = rand() % SIZE_IN_BYTES; bytes = rand() % (SIZE_IN_BYTES - start); assert(start + bytes <= SIZE_IN_BYTES); bytewise_xor(&dst[start],&src[start],bytes); aligned_word_xor(&dst[start],&src[start],bytes); result = test_range(IS_ZERO,0,SIZE_IN_BYTES); if (!result) { printf("Failed random trials\n"); break; } } if (rand_trials <= 0) { printf("Passed random trials\n"); ++passed; } return passed; }