// ensure that the response comes from dest->src int assert_eth_header(const u_char *bytes, unsigned short vlan, unsigned short protocol) { struct ether_header eh; memcpy(&eh, bytes, sizeof eh); // check macs if (memcmp(eh.ether_shost, DEFAULT_DST_MAC, ETH_ALEN)) { test_log("Wrong source MAC in packet"); return 1; } if (memcmp(eh.ether_dhost, DEFAULT_SRC_MAC, ETH_ALEN)) { test_log("Wrong destination MAC in packet"); return 1; } if (config.vlan) { if (eh.ether_type != htons(ETH_P_8021Q) || *(uint16_t*)(bytes + ETH_HLEN) != htons(vlan) || *(uint16_t*)(bytes + ETH_HLEN + 2) != htons(protocol)) { test_log("Wrong protocol number in packet"); return 1; } } else if (eh.ether_type != htons(protocol)) { test_log("Wrong protocol number in packet"); return 1; } return 0; }
void run_test(int (*test_item)(void), const char *test_name) { test_log("test #%04d: %s", ++current_test, test_name); test_sanitize(); if (test_item() != 0) { test_log("test result: FAILED"); bin2hex(test_result_buffer, test_result_len); tests_not_ok++; } else { test_log("test result: PASS"); tests_ok++; } }
int test_udp_cisco_init(void) { u_char bytes[ETH_FRAME_LEN],*ptr; struct udphdr uh; struct timespec ts; memset(bytes, 0, ETH_FRAME_LEN); build_eth_header(DEFAULT_DST_MAC, DEFAULT_SRC_MAC, 42, ETH_P_IP, bytes); build_ip_header(*DEFAULT_SRC_IP, *DEFAULT_DST_IP, 32, 17, bytes); ptr = bytes + ip_start + sizeof(struct ip); uh.source = htons(4242); uh.dest = htons(1967); // packet has 8 bytes of data and 24 bytes of payload uh.len = htons(32); uh.check = 0; // put it in place memcpy(ptr, &uh, sizeof(uh)); ptr += sizeof(uh); // put in the actual data *(ptr) = 0x01; memcpy(ptr+0x10, DEFAULT_DST_IP, 4); *((unsigned short*)(ptr+0x14)) = htons(50505); // actual testing port // then calculate checksum tcp4_checksum((u_char*)DEFAULT_SRC_IP, (u_char*)DEFAULT_DST_IP, 0x11, bytes+UDP_START, 32, (unsigned short*)(bytes+UDP_START+0x06)); // and that's it. do_pak_handler(bytes, 66 + eth_o_vlan); // did we get anything? if (test_result_len != 66 + eth_o_vlan) { test_log("result is not %u bytes long as expected, was %lu", 70, test_result_len); return 1; } if (assert_ip(test_result_buffer, *DEFAULT_DST_IP, *DEFAULT_SRC_IP, 32, 17)) return 1; // checksum check tcp4_checksum((u_char*)DEFAULT_SRC_IP, (u_char*)DEFAULT_DST_IP, 0x11, test_result_buffer+UDP_START, 32, (unsigned short*)(test_result_buffer+UDP_START+0x06)); if (*((unsigned short*)(test_result_buffer+UDP_START+0x06)) != 0x0) { test_log("invalid TCP checksum, ended up with %02x", (unsigned short*)(test_result_buffer+UDP_START+0x06)); return 1; } // check that something nice was sent. if (*(test_result_buffer + UDP_DATA + 0x03) != 0x08 || memcmp(test_result_buffer + UDP_DATA + 0x04, "\0\0\0\0\0\0\0\0", 8)) { test_log("invalid response - check your code"); return 1; } return 0; }
static void test_all_log() { test_log(zero, nan, "0"); test_log(cent, dec64_new(-4605170185988091, -16), "0.01"); test_log(half, dec64_new(-6931471805599453, -16), "1/2"); test_log(one, zero, "1"); test_log(half_pi, dec64_new(4515827052894549, -16), "pi/2"); test_log(two, dec64_new(6931471805599453, -16), "2"); test_log(e, one, "e"); test_log(pi, dec64_new(11447298858494002, -16), "pi"); test_log(ten, dec64_new(23025850929940457, -16), "10"); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Tests the basic features of Virtual File Drivers * * Return: Success: 0 * Failure: 1 * * Programmer: Raymond Lu * Tuesday, Sept 24, 2002 * *------------------------------------------------------------------------- */ int main(void) { int nerrors = 0; h5_reset(); printf("Testing basic Virtual File Driver functionality.\n"); nerrors += test_sec2() < 0 ? 1 : 0; nerrors += test_core() < 0 ? 1 : 0; nerrors += test_family() < 0 ? 1 : 0; nerrors += test_family_compat() < 0 ? 1 : 0; nerrors += test_multi() < 0 ? 1 : 0; nerrors += test_multi_compat() < 0 ? 1 : 0; nerrors += test_direct() < 0 ? 1 : 0; nerrors += test_log() < 0 ? 1 : 0; nerrors += test_stdio() < 0 ? 1 : 0; nerrors += test_windows() < 0 ? 1 : 0; if(nerrors) { printf("***** %d Virtual File Driver TEST%s FAILED! *****\n", nerrors, nerrors > 1 ? "S" : ""); return 1; } printf("All Virtual File Driver tests passed.\n"); return 0; }
int main(int argc, char *argv[]) { ULONG res = 0; MathIeeeSingTransBase = (BaseType *)OpenLibrary("mathieeesingtrans.library", 34); if(MathIeeeSingTransBase) { PutStr("ok!\n"); test_const(); test_acos(); test_asin(); test_atan(); test_cos(); test_cosh(); test_exp(); test_fieee(); test_log(); test_log10(); test_pow(); test_sin(); test_sincos(); test_sinh(); test_sqrt(); test_tan(); test_tanh(); test_tieee(); CloseLibrary((struct Library *)MathIeeeSingTransBase); } else { PutStr("No mathieeesingtrans.library!\n"); res = 1; } return res; }
int test_mf(void) { u_char bytes[ETH_FRAME_LEN]; struct icmphdr ih; build_eth_header(DEFAULT_DST_MAC, DEFAULT_SRC_MAC, 42, ETH_P_IP, bytes); // add IP header. build_ip_header(*DEFAULT_SRC_IP, *DEFAULT_DST_IP, 64, 1, bytes); *(uint16_t*)(bytes + IP_O_FRAG_OFF) = 0x20; // MF ih.type = 8; ih.code = 0; ih.checksum = 0; ih.un.echo.id = 0x4343; ih.un.echo.sequence = 0x4242; // copy into place memcpy(bytes + ICMP_START, &ih, sizeof(ih)); // add some payload memcpy(bytes + ICMP_DATA, "\xbd\x3b\x78\xf8\xbc\x28\x41\x0f\xf7\xcd\x55\x91\xce\xa8\xe7\xac\xb3\xfe\x56\xd0\x6c\xa2\x1d\x41\xc9\x15\x8e\x74\xa0\x09\x4d\x2a\xe8\xd9\x76\xd9\x0c\x10\xb9\x65\x42\x11\xc9\x58\xbe\xce\x90\x89\x67\xaa\x56\xfa\xb7\x5e\xc0\xd0", 56); // checksum ip_checksum(bytes + ICMP_START, sizeof(ih) + 56, (uint16_t*)(bytes + ICMP_START + 2)); // let's see what we get do_pak_handler(bytes, 100 + 2*config.vlan); if (test_result_len) { test_log("did not expect reply"); return 1; } return 0; }
int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for C_INTRINSICS. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 April 2011 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "C_INTRINSICS:\n" ); printf ( " Test the C intrinsic library.\n" ); test_abs ( ); test_acos ( ); test_asin ( ); test_atan ( ); test_atan2 ( ); test_ceil ( ); test_cos ( ); test_cosh ( ); test_exp ( ); test_fabs ( ); test_floor ( ); test_fmod ( ); test_frexp ( ); test_ldexp ( ); test_log ( ); test_log10 ( ); test_modf ( ); test_pow ( ); test_sin ( ); test_sinh ( ); test_sqrt ( ); test_tan ( ); test_tanh ( ); /* Terminate. */ printf ( "\n" ); printf ( "C_INTRINSICS:\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; }
int main (int argc, char **argv) { test_log (); return 0; }
int main(int argc, char **argv) { int ret = 0; ret |= test_hash(); ret |= test_log(); ret |= test_math(); return ret; }
int main(int argc, char *argv[]) { logInit(); //set_log_syslog(1); test_log(); return 1; }
int main() { int Error(0); Error += test_log(); Error += test_rotation(); Error += test_quat_fastMix(); Error += test_quat_shortMix(); return Error; }
int main() { MemPool *pool = mem_pool_create(640); //640M configure_handler_t *config_handler = load_configure_file(pool, "test.conf"); test_log(pool, config_handler); configure_handler_destroy(pool, config_handler); mem_pool_destroy(pool); return 0; }
int test_arp_not_for_me(void) { u_char bytes[ETH_FRAME_LEN]; build_arp_pak(DEFAULT_SRC_MAC, DEFAULT_SRC_MAC, ARPOP_REQUEST, *DEFAULT_SRC_IP, *DEFAULT_SRC_IP, bytes); do_pak_handler(bytes, 64); if (test_result_len > 0 ) { test_log("did not expect reply"); return 1; } return 0; }
static void check3 (char *s, unsigned long prec, mpfr_rnd_t rnd) { mpfr_t x, y; mpfr_init2 (x, prec); mpfr_init2 (y, prec); mpfr_set_str (x, s, 10, rnd); test_log (y, x, rnd); mpfr_out_str (stdout, 10, 0, y, rnd); puts (""); mpfr_clear (x); mpfr_clear (y); }
int assert_arp(u_char *bytes) { struct arphdr ah; if (assert_eth_header(bytes, 42, ETH_P_ARP)) return 1; memcpy(&ah, bytes + ip_start, sizeof ah); if (ah.ar_hrd != htons(ARPHRD_ETHER)) { test_log("invalid hwaddr in response"); return 1; } if (ah.ar_pro != htons(ETH_P_IP)) { test_log("invalid protocol in response"); return 1; } if (ah.ar_hln != ETH_ALEN) { test_log("invalid hwaddr length in response"); return 1; } if (ah.ar_pln != 4) { test_log("invalid protocol length in response"); return 1; } if (ah.ar_op != htons(ARPOP_REPLY)) { test_log("response is not reply"); return 1; } // make sure it was intended for us. if (memcmp(bytes + ip_start + sizeof(ah), DEFAULT_DST_MAC, ETH_ALEN)) { test_log("wrong source mac in reply"); return 1; } if (memcmp(bytes + ip_start + sizeof(ah) + ETH_ALEN, DEFAULT_DST_IP, 4)) { test_log("wrong source ip in reply"); return 1; } if (memcmp(bytes + ip_start + sizeof(ah) + ETH_ALEN + 4, DEFAULT_SRC_MAC, ETH_ALEN)) { test_log("wrong destination mac in reply"); return 1; } if (memcmp(bytes + ip_start + sizeof(ah) + ETH_ALEN*2 + 4, DEFAULT_SRC_IP, 4)) { test_log("wrong destination ip in reply, %08x != %08x", *(uint32_t*)(bytes + ip_start + sizeof(ah) + ETH_ALEN*2 + 4), *DEFAULT_SRC_IP); return 1; } return 0; }
int main() { int Error(0); Error += test_pow(); Error += test_exp(); Error += test_log(); Error += test_exp2(); Error += test_log2(); Error += test_sqrt(); Error += test_inversesqrt(); return Error; }
int test_broadcast_arp(void) { u_char bytes[ETH_FRAME_LEN]; build_arp_pak((u_char*)"\xff\xff\xff\xff\xff\xff", DEFAULT_SRC_MAC, ARPOP_REQUEST, *DEFAULT_DST_IP, *DEFAULT_SRC_IP, bytes); do_pak_handler(bytes, 64); if (test_result_len != 64) { test_log("result is not 64 bytes long as expected, was %lu", test_result_len); return 1; } return assert_arp(test_result_buffer); }
//-------------------------------------------------------------------------------------- int main(int, char**) { /*test_process(); stop(); test_threads(); stop(); test_bitset(); stop(); test_list(); stop(); test_shared_ptr(); stop(); test_file(); stop(); test_ini_file(); stop(); test_string(); stop(); test_string_buffer(); stop(); test_vector(); stop(); test_map(); stop(); test_set(); stop(); test_heap(); stop(); test_graph(); stop();*/ test_log(); stop(); return 0; }
int test_invalid_arp(void) { u_char bytes[ETH_FRAME_LEN]; build_arp_pak(DEFAULT_DST_MAC, DEFAULT_SRC_MAC, ARPOP_REQUEST, *DEFAULT_DST_IP, *DEFAULT_SRC_IP, bytes); // do some slight corruption bytes[ip_start] = 0x5; do_pak_handler(bytes, 64); if (test_result_len > 0 ) { test_log("did not expect reply"); return 1; } return 0; }
int assert_ip(u_char *bytes, uint32_t srcip, uint32_t dstip, unsigned short data_len, unsigned short proto) { struct iphdr iph; if (assert_eth_header(bytes, 42, ETH_P_IP)) return 1; memcpy(&iph, bytes + ip_start, sizeof iph); // checksum test ip_checksum((const unsigned char*)&iph, sizeof(iph), &iph.check); if (iph.check != 0) { test_log("ip checksum did not validate"); return 1; } // check corrct protocol and such if (iph.version != 4) { test_log("wrong ip version"); return 1; } if (iph.ihl != 5) { test_log("ip header len != 5"); return 1; } if (iph.tot_len != htons(data_len + sizeof(iph))) { test_log("total length wasn't as expected: wanted %u, got %u", data_len + sizeof(iph), ntohs(iph.tot_len)); return 1; } if (iph.id != 0x4545) { test_log("IPID wrong"); return 1; } if (iph.protocol != proto) { test_log("unexpected protocol: wanted %u, got %u", proto, iph.protocol); return 1; } if (iph.saddr != srcip) { test_log("invalid source ip"); return 1; } if (iph.daddr != dstip) { test_log("invalid destination ip"); return 1; } return 0; }
char *client_library_load(const char *name) { char *newname; int errcode; check_for_fork(); if (!use_ldcs || ldcsid == -1) { return (char *) name; } if (!(opts & OPT_RELOCSO)) { return (char *) name; } /* Don't relocate a new copy of libc, it's always already loaded into the process. */ find_libc_name(); if (libc_name && strcmp(name, libc_name) == 0) { debug_printf("la_objsearch not redirecting libc %s\n", name); test_log(name); return (char *) name; } sync_cwd(); get_relocated_file(ldcsid, name, &newname, &errcode); if(!newname) { newname = concatStrings(NOT_FOUND_PREFIX, name); } else { patch_on_load_success(newname, name); } debug_printf("la_objsearch redirecting %s to %s\n", name, newname); test_log(newname); return newname; }
static void check3 (double d, unsigned long prec, mp_rnd_t rnd) { mpfr_t x, y; mpfr_init2 (x, prec); mpfr_init2 (y, prec); mpfr_set_d (x, d, rnd); test_log (y, x, rnd); mpfr_out_str (stdout, 10, 0, y, rnd); puts (""); mpfr_print_binary (y); puts (""); mpfr_clear (x); mpfr_clear (y); }
static int ikgt_systl_debug(struct ctl_table *ctl, int write, void __user *buffer, size_t *count, loff_t *ppos) { unsigned long val; int len, rc; char buf[32]; if (!*count || (*ppos && !write)) { *count = 0; return 0; } if (!write) { len = snprintf(buf, sizeof(buf), "%d\n", ikgt_agent_debug); rc = copy_to_user(buffer, buf, sizeof(buf)); if (rc != 0) return -EFAULT; } else { len = *count; rc = kstrtoul_from_user(buffer, len, 0, &val); if (rc) return rc; ikgt_agent_debug = val; switch (val) { case 1000: test_log(); break; case 1001: test_hypercall(); break; default: ikgt_debug(val); break; } } *count = len; *ppos += len; return 0; }
IMPLEMENT int Jdb_bp::test_log_only() { Space *t = Jdb::get_thread(0)->space(); Mword dr6 = read_debug_register(6, t); if (dr6 & 0x0000000f) { test_log(dr6); write_debug_register(6, dr6, t); if (!(dr6 & 0x0000e00f)) // don't enter jdb, breakpoints only logged return 1; } // enter jdb return 0; }
int test_checksum_tcp(void) { struct udphdr uh; u_char data[64]; uh.source = htons(7); uh.dest = htons(7); uh.len = 64; uh.check = 0xb423; memcpy(data, &uh, sizeof uh); memcpy(data+sizeof(uh), "\xbd\x3b\x78\xf8\xbc\x28\x41\x0f\xf7\xcd\x55\x91\xce\xa8\xe7\xac\xb3\xfe\x56\xd0\x6c\xa2\x1d\x41\xc9\x15\x8e\x74\xa0\x09\x4d\x2a\xe8\xd9\x76\xd9\x0c\x10\xb9\x65\x42\x11\xc9\x58\xbe\xce\x90\x89\x67\xaa\x56\xfa\xb7\x5e\xc0\xd0", 56); // just some random data to make things interesting tcp4_checksum((u_char*)DEFAULT_SRC_IP, (u_char*)DEFAULT_DST_IP, 0x11, data, 64, &uh.check); if (uh.check != 0) { test_log("Checksum wrong: (0 != %04x)", uh.check); } return uh.check; }
int get_stat_result(int fd, const char *path, int is_lstat, int *exists, struct stat *buf) { int result; char buffer[MAX_PATH_LEN+1]; char cache_name[MAX_PATH_LEN+3]; char *newpath; int use_cache = (opts & OPT_SHMCACHE) && (shm_cachesize > 0); int found_file = 0; if (use_cache) { debug_printf2("Looking up %sstat for %s in shared cache\n", is_lstat ? "l" : "", path); get_cache_name(path, is_lstat ? "**" : "*", cache_name); cache_name[sizeof(cache_name)-1] = '\0'; found_file = fetch_from_cache(cache_name, &newpath); } if (!found_file) { result = send_stat_request(fd, (char *) path, is_lstat, buffer); if (result == -1) { *exists = 0; return -1; } newpath = buffer[0] != '\0' ? buffer : NULL; if (use_cache) shmcache_update(cache_name, newpath); } if (newpath == NULL) { *exists = 0; return 0; } *exists = 1; test_log(newpath); result = read_stat(newpath, buf); if (result == -1) { err_printf("Failed to read stat info for %s from %s\n", path, newpath); *exists = 0; return -1; } return 0; }
static void check2 (const char *as, mp_rnd_t rnd_mode, const char *res1s) { mpfr_t ta, tres; mpfr_inits2 (53, ta, tres, (mpfr_ptr) 0); mpfr_set_str1 (ta, as); test_log (tres, ta, rnd_mode); if (mpfr_cmp_str1 (tres, res1s)) { printf ("mpfr_log failed for a=%s, rnd_mode=%s\n", as, mpfr_print_rnd_mode (rnd_mode)); printf ("correct result is %s\n mpfr_log gives ", res1s); mpfr_out_str(stdout, 10, 0, tres, GMP_RNDN); exit (1); } mpfr_clears (ta, tres, (mpfr_ptr) 0); }
/** @return 0 if only breakpoints were logged and jdb should not be entered */ IMPLEMENT int Jdb_bp::test_log_only() { Mword dr6 = read_debug_register(6); if (dr6 & Val_test) { dr7 = read_debug_register(7); // disable breakpoints -- we might trigger a r/w breakpoint again write_debug_register(7, dr7 & Val_enter); test_log(dr6); write_debug_register(6, dr6); write_debug_register(7, dr7); if (!(dr6 & Val_test_other)) // don't enter jdb, breakpoints only logged return 1; } // enter jdb return 0; }
int test_checksum_ip(void) { struct iphdr hdr; hdr.version = 4; hdr.ihl = 5; hdr.tos = 0; hdr.tot_len = htons(84); hdr.id = 0x4545; hdr.frag_off = 0; hdr.ttl = 64; hdr.protocol = 1; hdr.check = 0xca60; hdr.saddr = *DEFAULT_DST_IP; hdr.daddr = *DEFAULT_SRC_IP; ip_checksum((const unsigned char*)&hdr, sizeof(hdr), &hdr.check); if (hdr.check != 0) { test_log("Checksum wrong: (0 != %04x)", hdr.check); } return hdr.check; }