int main( int argc , char ** argv) { lsf_driver_type * driver = lsf_driver_alloc(); test_option( driver , LSF_BSUB_CMD , "Xbsub"); test_option( driver , LSF_BJOBS_CMD , "Xbsub"); test_option( driver , LSF_BKILL_CMD , "Xbsub"); test_option( driver , LSF_RSH_CMD , "RSH"); test_option( driver , LSF_LOGIN_SHELL , "shell"); test_option( driver , LSF_BSUB_CMD , "bsub"); printf("Options OK\n"); test_server( driver , NULL , LSF_SUBMIT_INTERNAL ); test_server( driver , "LoCaL" , LSF_SUBMIT_LOCAL_SHELL ); test_server( driver , "LOCAL" , LSF_SUBMIT_LOCAL_SHELL ); test_server( driver , "XLOCAL" , LSF_SUBMIT_REMOTE_SHELL ); test_server( driver , NULL , LSF_SUBMIT_INTERNAL ); test_server( driver , "be-grid01" , LSF_SUBMIT_REMOTE_SHELL ); printf("Servers OK\n"); test_status( JOB_STAT_PEND , JOB_QUEUE_PENDING ); test_status( JOB_STAT_PSUSP , JOB_QUEUE_RUNNING ); test_status( JOB_STAT_USUSP , JOB_QUEUE_RUNNING ); test_status( JOB_STAT_SSUSP , JOB_QUEUE_RUNNING ); test_status( JOB_STAT_RUN , JOB_QUEUE_RUNNING ); test_status( JOB_STAT_NULL , JOB_QUEUE_NOT_ACTIVE ); test_status( JOB_STAT_DONE , JOB_QUEUE_DONE ); test_status( JOB_STAT_EXIT , JOB_QUEUE_EXIT ); test_status( JOB_STAT_UNKWN , JOB_QUEUE_EXIT ); test_status( 192 , JOB_QUEUE_DONE ); printf("Status OK \n"); exit(0); }
static void test_pack_unpack() { test_status("Testing binary_seq_pack() / binary_seq_unpack()"); uint8_t packed[TLEN]; Nucleotide bases0[TLEN], bases1[TLEN]; char str[8*TLEN+1]; size_t i, t, len; // Run NTESTS // randomize bases0, pack into packed, unpack into bases1 // compare bases0 vs bases1 for(t = 0; t < NTESTS; t++) { len = rand() % (TLEN/2+1); rand_nucs(bases0, len); memset(packed, 0, TLEN); binary_seq_pack(packed, bases0, len); binary_seq_unpack(packed, bases1, len); for(i = 0; i < len && bases0[i] == bases1[i]; i++); // print output if input != output if(i != len) { bitarr_tostr(packed, (len*2+7)/8, str); printf("bases0: "); print_nucs(bases0, len); printf("\n"); printf("bases1: "); print_nucs(bases1, len); printf("\n"); printf("packed: %s\n", str); } TASSERT(i == len); } }
static void test_binary_seq_str() { test_status("Testing binary_seq_[to|from]_str()"); _binary_seq_str_test(""); _binary_seq_str_test("A"); _binary_seq_str_test("C"); _binary_seq_str_test("G"); _binary_seq_str_test("T"); _binary_seq_str_test("AAAAAA"); _binary_seq_str_test("TATACATA"); _binary_seq_str_test("AGACAATCAGAG"); _binary_seq_str_test("TTTTTTTTTTTTTTTT"); // random tests char str[TLEN]; size_t i, nbases; for(i = 0; i < NTESTS; i++) { nbases = rand() & (TLEN-1); rand_bases(str, nbases); str[nbases] = '\0'; _binary_seq_str_test(str); } }
static void test_binary_seq_rev_cmp() { test_status("binary_seq_reverse_complement() binary_seq_to_str()"); uint8_t data[TLEN], tmp[TLEN]; char str[4*TLEN+1], rev[4*TLEN+1], restore[4*TLEN+1]; size_t i, j, k, nbases; for(i = 0; i < NTESTS; i++) { // Get random sequence, mask top byte, convert to string rand_bytes(data, TLEN); nbases = rand() & (4*TLEN-1); binary_seq_to_str(data, nbases, str); // Reverse complement, convert to string memcpy(tmp, data, TLEN); binary_seq_reverse_complement(tmp, nbases); binary_seq_to_str(tmp, nbases, rev); // Check strings match for(j = 0, k = nbases-1; j < nbases; j++, k--) TASSERT(str[j] == dna_char_complement(rev[k])); // Reverse complement again, check we get back same binary_seq+string binary_seq_reverse_complement(tmp, nbases); binary_seq_to_str(tmp, nbases, restore); TASSERT(memcmp(data, tmp, TLEN) == 0); TASSERT(strncmp(str, restore, nbases) == 0); } }
static void test_strnstr() { test_status("Testing strnstr"); const char a[] = ""; TASSERT(ctx_strnstr(a,a,0) == a); TASSERT(ctx_strnstr(a,"",0) == a); TASSERT(ctx_strnstr(a,"x",0) == NULL); const char b[] = "abc"; TASSERT(ctx_strnstr(b,"",0) == b); TASSERT(ctx_strnstr(b,"",1000) == b); TASSERT(ctx_strnstr(b,"x",10000) == NULL); TASSERT(ctx_strnstr(b,"a",0) == NULL); TASSERT(ctx_strnstr(b,"a",1) == b); TASSERT(ctx_strnstr(b,"a",2) == b); TASSERT(ctx_strnstr(b,"a",3) == b); TASSERT(ctx_strnstr(b,"a",10000) == b); TASSERT(ctx_strnstr(b,"b",0) == NULL); TASSERT(ctx_strnstr(b,"b",1) == NULL); TASSERT(ctx_strnstr(b,"b",2) == b+1); TASSERT(ctx_strnstr(b,"b",3) == b+1); TASSERT(ctx_strnstr(b,"b",1000) == b+1); const char c[] = "asdfasdfasdf asdfasdf asdf asdf xyz asdf asdf xyz"; TASSERT(ctx_strnstr(c,"xyza",100) == NULL); TASSERT(ctx_strnstr(c,"xyz",30) == NULL); TASSERT(ctx_strnstr(c,"xyz",34) == NULL); TASSERT(ctx_strnstr(c,"xyz",35) == strstr(c,"xyz")); TASSERT(ctx_strnstr(c,"xyz",36) == strstr(c,"xyz")); TASSERT(ctx_strnstr(c,"xyz",1000000) == strstr(c,"xyz")); }
static void _test_add_paths() { test_status("Testing adding paths in generate_paths.c and gpath_fetch()"); // Construct 1 colour graph with kmer-size=11 dBGraph graph; size_t kmer_size = 11, ncols = 1; db_graph_alloc(&graph, kmer_size, ncols, ncols, 1024, DBG_ALLOC_EDGES | DBG_ALLOC_COVGS | DBG_ALLOC_BKTLOCKS | DBG_ALLOC_NODE_IN_COL); // Create a path store that tracks path counts gpath_store_alloc(&graph.gpstore, graph.num_of_cols, graph.ht.capacity, 0, ONE_MEGABYTE, true, false); // Create path hash table for fast lookup gpath_hash_alloc(&graph.gphash, &graph.gpstore, ONE_MEGABYTE); build_graph_from_str_mt(&graph, 0, seq0, strlen(seq0)); build_graph_from_str_mt(&graph, 0, seq1, strlen(seq1)); build_graph_from_str_mt(&graph, 0, seq2, strlen(seq2)); build_graph_from_str_mt(&graph, 0, seq3, strlen(seq3)); // Set up alignment correction params CorrectAlnParam params = {.ctpcol = 0, .ctxcol = 0, .frag_len_min = 0, .frag_len_max = 0, .one_way_gap_traverse = true, .use_end_check = true, .max_context = 10, .gap_variance = 0.1, .gap_wiggle = 5}; all_tests_add_paths(&graph, seq0, params, 5, 5); // path lens: 3+3+2+2+2 all_tests_add_paths(&graph, seq1, params, 5, 2); // path lens: 3+3+2+2+2 all_tests_add_paths(&graph, seq2, params, 3, 2); // path lens: 1+1+1 all_tests_add_paths(&graph, seq3, params, 2, 1); // path lens: 1+1 // Test path store gpath_checks_all_paths(&graph, 1); // use one thread // Test path content _check_node_paths(kmerA, kmerApaths, NPATHS_A, 0, &graph); _check_node_paths(kmerB, kmerBpaths, NPATHS_B, 0, &graph); _check_node_paths(kmerAB, kmerABpaths, NPATHS_AB, 0, &graph); _check_node_paths(kmerC, kmerCpaths, NPATHS_C, 0, &graph); _check_node_paths(kmerG, kmerGpaths, NPATHS_G, 0, &graph); _check_node_paths(kmerF, kmerFpaths, NPATHS_F, 0, &graph); _check_node_paths(kmerE, kmerEpaths, NPATHS_E, 0, &graph); _check_node_paths(kmerD, kmerDpaths, NPATHS_D, 0, &graph); _check_node_paths(kmerDEF,kmerDEFpaths,NPATHS_DEF,0, &graph); _check_node_paths(kmerDE, kmerDEpaths, NPATHS_DE, 0, &graph); db_graph_dealloc(&graph); } void test_paths() { _test_add_paths(); }
static void test_util_calc_N50() { test_status("Testing calc_N50()"); size_t arr[] = {1,2,3,4,5,6,7,8,9,10}; TASSERT(calc_N50(arr, 3, 6) == 3); TASSERT(calc_N50(arr, 4, 10) == 3); TASSERT(calc_N50(arr, 10, 55) == 8); }
static void test_pack_cpy_unpack() { test_status("Testing pack()+cpy()+unpack()"); _test_pack_cpy_unpack_shifts("CTA", 3); _test_pack_cpy_unpack_shifts("C", 1); _test_pack_cpy_unpack_shifts("CAGACAG", 7); }
static void test_util_rev_nibble_lookup() { test_status("Testing rev_nibble_lookup()"); size_t i; for(i = 0; i < 16; i++) { TASSERT(rev_nibble_lookup(i) == rev_nibble(i)); TASSERT(rev_nibble_lookup(rev_nibble_lookup(i)) == i); } }
static void test_util_calc_GCD() { test_status("Testing get_GCD()"); TASSERT(calc_GCD(0,0) == 0); TASSERT(calc_GCD(10,0) == 10); TASSERT(calc_GCD(0,10) == 10); TASSERT(calc_GCD(2,2) == 2); TASSERT(calc_GCD(1,1) == 1); TASSERT(calc_GCD(1,2) == 1); TASSERT(calc_GCD(1,100) == 1); TASSERT(calc_GCD(2,4) == 2); TASSERT(calc_GCD(7,5) == 1); TASSERT(calc_GCD(18,6) == 6); TASSERT(calc_GCD(3,6) == 3); TASSERT(calc_GCD(100,120) == 20); TASSERT(calc_GCD(100,125) == 25); }
static void pull_out_supernodes(const char **seq, const char **ans, size_t n, const dBGraph *graph) { dBNodeBuffer nbuf; db_node_buf_alloc(&nbuf, 1024); // 1. Check pulling out supernodes works for iterating over the graph uint64_t *visited; visited = ctx_calloc(roundup_bits2words64(graph->ht.capacity), 8); HASH_ITERATE(&graph->ht, supernode_from_kmer, &nbuf, visited, graph, ans, n); ctx_free(visited); // 2. Check pulling out supernodes works when we iterate over inputs size_t i, j, len; dBNode node; char tmpstr[SNODEBUF]; for(i = 0; i < n; i++) { len = strlen(seq[i]); for(j = 0; j+graph->kmer_size <= len; j++) { // Find node node = db_graph_find_str(graph, seq[i]+j); TASSERT(node.key != HASH_NOT_FOUND); // Fetch supernode db_node_buf_reset(&nbuf); supernode_find(node.key, &nbuf, graph); supernode_normalise(nbuf.b, nbuf.len, graph); // Compare TASSERT(nbuf.len < SNODEBUF); db_nodes_to_str(nbuf.b, nbuf.len, graph, tmpstr); if(strcmp(tmpstr, ans[i]) != 0) { test_status("Got: %s from ans[i]:%s\n", tmpstr, ans[i]); } TASSERT(strcmp(tmpstr, ans[i]) == 0); } } db_node_buf_dealloc(&nbuf); }
int main() { char** args; args = (char**)malloc(sizeof(char**) * SERV_ARGS); for(int i = 0; i < SERV_ARGS; i++) { args[i] = (char*)malloc(ARG_LEN); } snprintf(args[0], ARG_LEN, "%d", 1); snprintf(args[1], ARG_LEN, "%d", 1); run_server(args, 2); for(int i = 0; i < SERV_ARGS; i++) { free(args[i]); } free(args); // Wait for server to start (what a great solution!) // FIXME no sleep here sleep(1); test_status(); assert(server_pid > 0); kill(server_pid, SIGTERM); return 0; }
void test_supernode() { test_status("testing supernode_find()..."); // Construct 1 colour graph with kmer-size=11 dBGraph graph; size_t kmer_size = 19, ncols = 1; db_graph_alloc(&graph, kmer_size, ncols, ncols, 1024, DBG_ALLOC_EDGES | DBG_ALLOC_COVGS | DBG_ALLOC_BKTLOCKS); #define NSEQ 7 const char *seq[NSEQ] = {"AGAGAGAGAGAGAGAGAGAGAGAG", "AAAAAAAAAAAAAAAAAAAAAAAAAA", "ATATATATATATATATATATATATATAT", "CGTTCGCGCATGGCCCACG", "GAACCAATCGGTCGACTGT", "CCCCGCAAAGTCCACTTAGTGTAAGGTACAAATTCTGCAGAGTTGCTGGATCAGCGATAC", "TCAATCCGATAGCAACCCGGTCCAA""TCAATCCGATAGCAACCCGGTCCAA"}; const char *ans[NSEQ] = {"AGAGAGAGAGAGAGAGAGAG", // key AGAGAGAGAGAGAGAGAGA < CTCTCTCTCTCTCTCTCTC "AAAAAAAAAAAAAAAAAAA", "ATATATATATATATATATA", "CGTGGGCCATGCGCGAACG", "ACAGTCGACCGATTGGTTC", "CCCCGCAAAGTCCACTTAGTGTAAGGTACAAATTCTGCAGAGTTGCTGGATCAGCGATAC", "AACCCGGTCCAATCAATCCGATAGCAACCCGGTCCAATCAATC"}; // Load all seq into colour 0 size_t i; for(i = 0; i < NSEQ; i++) build_graph_from_str_mt(&graph, 0, seq[i], strlen(seq[i]), false); pull_out_supernodes(seq, ans, NSEQ, &graph); db_graph_dealloc(&graph); }
static void test_util_bytes_to_str() { test_status("Testing bytes_to_str()"); char str[100]; // Excess decimal points are trimmed off // 14.0MB -> 14MB TASSERT2(strcmp(bytes_to_str(14688256,1,str),"14MB") == 0, "Got: %s", str); // 1.9GB -> 1.9GB TASSERT2(strcmp(bytes_to_str(2040110000,1,str),"1.9GB") == 0, "Got: %s", str); // 1.99GB -> 2GB TASSERT2(strcmp(bytes_to_str(2140110000,1,str),"2GB") == 0, "Got: %s", str); // 1500KB -> 1.4MB TASSERT2(strcmp(bytes_to_str(1500000,1,str),"1.4MB") == 0, "Got: %s", str); // 0.5GB -> 512MB TASSERT2(strcmp(bytes_to_str(536900000,1,str),"512MB") == 0, "Got: %s", str); // 1 -> 1B TASSERT2(strcmp(bytes_to_str(1,1,str),"1B") == 0, "Got: %s", str); // 1023 -> 1023B TASSERT2(strcmp(bytes_to_str(1023,1,str),"1,023B") == 0, "Got: %s", str); }
int main() { begin_test_data(expected_t) test_data( "nothing to skip!", 0, test_pair(1,1), PDS_OK ), test_data( "\t \r\n end", 8, test_pair(1,2), PDS_OK ), test_data( "/**/ end", 5, test_pair(1,1), PDS_OK ), test_data( "/* a\tlonger\tcomment */\t\r\n\r\nend", 27, test_pair(1,3), PDS_OK ), test_data(" \t/*line 1 */\n \t\t/*line 2*/\n \t\t\t/*line 3*/\nend", 44, test_pair(1,4), PDS_OK ), test_data( " /* /* nested comment */", 5, test_pair(0,1), PDS_INVALID_VALUE ), test_data( " /* muti-line \n comment */", 15, test_pair(0,1), PDS_INVALID_VALUE ), end_test_data() PDS_parser parser; memset(&parser, 0, sizeof(PDS_parser)); PDS_set_error_callback(&parser.callbacks, dummy_error); size_t i; test_foreach(i) { parser.line_num = 1; parser.first = test_str(i); parser.current = parser.first; parser.last = parser.first + strlen(parser.first) - 1; parser.status = PDS_OK; int ret; ret = PDS_skip_whitespaces(&parser); check(test_status(i) == parser.status); check(test_end(i) == parser.current); check(test_expected(i).ret == ret); check(test_expected(i).line == parser.line_num); } return EXIT_SUCCESS; }
static void test_binary_seq_cpy() { test_status("Testing shift copy"); uint8_t d0[10] = {0,0,0,0,0,0,0,0,0,0}; uint8_t out[100]; size_t i, j, shift, len; size_t t; // Shifting an array of zeros results in zeros // surrounding array should remain all ones memset(out, 0xff, 100); for(shift = 0; shift < 4; shift++) { binary_seq_cpy_fast(out+1, d0, shift, 15); // first 4 bytes TASSERT(out[0]==0xff); for(i = 1; i < 5; i++) TASSERT(out[i]==0); for(i = 5; i < 100; i++) TASSERT(out[i]==0xff); } // Random testing uint8_t in[TLEN], slow[TLEN], med[TLEN], fast[TLEN]; char tmp1[TLEN*8+1], tmp2[TLEN*8+1]; for(t = 0; t < NTESTS; t++) { memset(slow, 0xff, TLEN); memset(med, 0xff, TLEN); memset(fast, 0xff, TLEN); rand_bytes(in, TLEN); len = rand() % (TLEN/2+1); shift = rand() % 4; // printf("len: %zu shift: %zu\n", len, shift); binary_seq_cpy_slow(slow, in, shift, len); binary_seq_cpy_med(med, in, shift, len); binary_seq_cpy_fast(fast, in, shift, len); if(len > shift) { // Check with string method to be extra safe bitarr_tostr(in, TLEN, tmp1); bitarr_tostr(slow, TLEN, tmp2); for(i = 8*TLEN-1; i != 8*TLEN-(len-shift)*2; i--) TASSERT(tmp1[i-shift*2] == tmp2[i]); } // Check all results match for(i = 0; i < TLEN && slow[i] == med[i]; i++); for(j = 0; j < TLEN && med[j] == fast[j]; j++); // Print output if arrays don't match if(i < TLEN || j < TLEN) { printf("len: %zu shift: %zu\n", len, shift); bitarr_tostr(in, TLEN, tmp1); printf("in: %s\n", tmp1); bitarr_tostr(slow, TLEN, tmp1); printf("slw: %s\n", tmp1); bitarr_tostr(med, TLEN, tmp1); printf("med: %s\n", tmp1); bitarr_tostr(fast, TLEN, tmp1); printf("fst: %s\n", tmp1); printf("\n"); } TASSERT(i == TLEN); TASSERT(j == TLEN); } }
test_data("failure = {{1,2,3,4,5,6}}\r\n", 0, &set[1], PDS_INVALID_VALUE), end_test_data() PDS_parser parser; memset(&parser, 0, sizeof(PDS_parser)); PDS_set_error_callback(&parser.callbacks, dummy_error); PDS_set_set_callbacks(&parser.callbacks, set_begin_callback, set_end_callback); PDS_set_scalar_callback(&parser.callbacks, set_element_callback); size_t i; test_foreach(i) { state_t state = { .index = 0, .expected = test_expected(i) }; parser.line_num = 1; parser.first = test_str(i); parser.last = parser.first + strlen(parser.first) - 1; parser.current = parser.first; parser.status = PDS_OK; parser.user_data = &state; int ret = PDS_parse_statement(&parser); check(test_status(i) == parser.status); if(ret) { check(test_end(i) == parser.current); } } return EXIT_SUCCESS; }
void main_menu (void) { unsigned long choice; mloop: if (THREAD_KILL) return; printf ("\t Main Menu\n"); loop: printf ("\n"); printf ("\t 1. Test/Primenet\n"); printf ("\t 2. Test/Worker threads\n"); printf ("\t 3. Test/Status\n"); if (WORKER_THREADS_ACTIVE && active_workers_count () < WORKER_THREADS_ACTIVE) printf ("\t 4. Test/Continue or Stop\n"); else if (!WORKER_THREADS_ACTIVE || WORKER_THREADS_STOPPING) printf ("\t 4. Test/Continue\n"); else printf ("\t 4. Test/Stop\n"); printf ("\t 5. Test/Exit\n"); printf ("\t 6. Advanced/Test\n"); printf ("\t 7. Advanced/Time\n"); printf ("\t 8. Advanced/P-1\n"); printf ("\t 9. Advanced/ECM\n"); printf ("\t10. Advanced/Manual Communication\n"); printf ("\t11. Advanced/Unreserve Exponent\n"); printf ("\t12. Advanced/Quit Gimps\n"); printf ("\t13. Options/CPU\n"); printf ("\t14. Options/Preferences\n"); printf ("\t15. Options/Torture Test\n"); printf ("\t16. Options/Benchmark\n"); printf ("\t17. Help/About\n"); printf ("\t18. Help/About PrimeNet Server\n"); printf ("Your choice: "); choice = get_number (0); if (choice <= 0 || choice >= 19) { printf ("\t Invalid choice\n"); goto loop; } /* Display the main menu and switch off the users choice */ printf ("\n"); switch (choice) { /* Test/Primenet dialog */ case 1: test_primenet (); break; /* Test/User Information dialog */ case 2: test_worker_threads (); break; /* Test/Status message */ case 3: test_status (); askOK (); break; /* Test/Continue or Stop or Test/Continue or Test/Stop */ case 4: if (WORKER_THREADS_ACTIVE && active_workers_count () < WORKER_THREADS_ACTIVE) test_continue_or_stop (); else if (NUM_WORKER_THREADS > 1 && active_workers_count () < WORKER_THREADS_ACTIVE - 1) test_continue (); else if (!WORKER_THREADS_ACTIVE || WORKER_THREADS_STOPPING) { while (WORKER_THREADS_STOPPING) Sleep (50); linuxContinue ("Another mprime is running.\n", ALL_WORKERS, FALSE); } else if (active_workers_count () > 1) test_stop (); else stop_workers_for_escape (); break; /* Test/Exit */ case 5: { int counter = 0; if (WORKER_THREADS_ACTIVE && !WORKER_THREADS_STOPPING) stop_workers_for_escape (); while (WORKER_THREADS_STOPPING) { if (counter++ % 100 == 0) printf ("Waiting for worker threads to stop.\n"); Sleep (50); } } return; /* Advanced/Test dialog */ case 6: advanced_test (); break; /* Advanced/Time dialog */ case 7: advanced_time (); break; /* Advanced/P-1 dialog */ case 8: advanced_pminus1 (); break; /* Advanced/ECM dialog */ case 9: advanced_ecm (); break; /* Advanced/Manual Communication dialog */ case 10: advanced_manualcomm (); break; /* Advanced/Unreserve exponent dialog */ case 11: advanced_unreserve (); break; /* Advanced/Quit Gimps dialog */ case 12: advanced_quit (); break; /* Options/CPU dialog */ case 13: options_cpu (); break; /* Options/Preferences dialog */ case 14: options_preferences (); break; /* Options/Torture Test */ case 15: torture (); askOK (); break; /* Options/Benchmark Test */ case 16: LaunchBench (); askOK (); break; /* Help/About */ case 17: help_about (); break; /* Help/About PrimeNet Server */ case 18: help_about_server (); break; } goto mloop; }
int main ( int argc, char *argv[]) { char buf[256]; int named_ini_files = -1; int contact_server = 0; int torture_test = 0; int i, nice_level; char *p; /* catch termination signals */ (void)signal(SIGTERM, sigterm_handler); (void)signal(SIGINT, sigterm_handler); /* No buffering of output */ setvbuf (stdout, NULL, _IONBF, 0); /* Change to the executable's directory */ /* NOTE: This only changes the working directory if the user typed */ /* in a full path to the executable (as opposed to finding it on the PATH) */ strcpy (buf, argv[0]); p = strrchr (buf, '/'); if (p != NULL) { *p = 0; (void) _chdir (buf); } /* Initialize gwnum call back routines. Using callback routines lets the */ /* gwnum library have a nice clean interface for users that do not need */ /* additional functionality that only prime95 uses. */ StopCheckRoutine = stopCheck; OutputBothRoutine = OutputBoth; /* Process command line switches */ for (i = 1; i < argc; i++) { p = argv[i]; if (*p++ != '-') break; switch (*p++) { /* Accept a -A switch indicating an alternate set of INI files */ /* are to be used. */ case 'A': case 'a': named_ini_files = 0; while (isspace (*p)) p++; while (isdigit (*p)) { named_ini_files = named_ini_files * 10 + (*p - '0'); p++; } break; /* -C - contact the server now, then exit */ case 'C': case 'c': contact_server = 1; VERBOSE = TRUE; NO_GUI = FALSE; break; /* -D - debug */ case 'D': case 'd': VERBOSE = TRUE; NO_GUI = FALSE; break; /* -H - help */ case 'H': case 'h': case '?': goto usage; /* -M - Menu */ case 'M': case 'm': MENUING = 1; NO_GUI = FALSE; break; /* -S - status */ case 'S': case 's': MENUING = 2; NO_GUI = FALSE; break; /* -T - Torture test */ case 'T': case 't': torture_test = TRUE; break; /* -V - version number */ case 'V': case 'v': printf ("Mersenne Prime Test Program, Version %s.%d\n", VERSION, PORT); return (0); /* -W - use a different working directory */ case 'W': case 'w': (void) _chdir (p); break; /* Otherwise unknown switch */ default: printf ("Invalid switch\n"); goto usage; } } /* Determine the names of the INI files, read them, do other initialization. */ /* Skip the comm code initialization if we are just displaying the status */ /* or running a torture test */ nameAndReadIniFiles (named_ini_files); if (MENUING != 2 && !torture_test) initCommCode (); /* If not running a torture test, set the program to nice priority. */ /* Technically, this is not necessary since worker threads are set to */ /* the lowest possible priority. However, sysadmins might be alarmed */ /* to see a CPU intensive program not running at nice priority when */ /* executing a ps command. */ #if defined (__linux__) || defined (__APPLE__) || defined (__FreeBSD__) /* Linux/FreeBSD ranges from -20 to +19, lower values give more favorable scheduling */ nice_level = IniGetInt (INI_FILE, "Nice", 10); if (!torture_test && nice_level) { setpriority (PRIO_PROCESS, 0, nice_level); } #endif /* If running the torture test, do so now. */ if (torture_test) { int num_threads; VERBOSE = TRUE; NO_GUI = FALSE; num_threads = IniGetInt (INI_FILE, "TortureThreads", NUM_CPUS * CPU_HYPERTHREADS); LaunchTortureTest (num_threads, TRUE); } /* If this is a stress tester, then turn on menuing. */ else if (IniGetInt (INI_FILE, "StressTester", 99) == 1) { MENUING = 1; VERBOSE = TRUE; NO_GUI = FALSE; main_menu (); } /* On first run, get user id before contacting server */ /* for a work assignment. To make first time user more comfortable, we will */ /* display data to the screen, rather than running silently. */ else if (IniGetInt (INI_FILE, "StressTester", 99) == 99) { VERBOSE = TRUE; NO_GUI = FALSE; test_welcome (); } /* If we are to contact the server, do so now. This option lets the */ /* user create a batch file that contacts the server at regular intervals */ /* or when the ISP is contacted, etc. */ else if (contact_server) { do_manual_comm_now (); while (COMMUNICATION_THREAD) Sleep (50); } /* Bring up the main menu */ else if (MENUING == 1) main_menu (); else if (MENUING == 2) test_status(); /* Continue testing, return when worker threads exit. */ else { linuxContinue ("Another mprime is already running!\n", ALL_WORKERS, TRUE); } /* Write the worktodo file in case the WELL_BEHAVED_WORK flag caused us */ /* to delay writing the file. */ writeWorkToDoFile (TRUE); /* All done */ return (0); /* Invalid args message */ usage: printf ("Usage: mprime [-cdhmstv] [-aN] [-wDIR]\n"); printf ("-c\tContact the PrimeNet server, then exit.\n"); printf ("-d\tPrint detailed information to stdout.\n"); printf ("-h\tPrint this.\n"); printf ("-m\tMenu to configure mprime.\n"); printf ("-s\tDisplay status.\n"); printf ("-t\tRun the torture test.\n"); printf ("-v\tPrint the version number.\n"); printf ("-aN\tUse an alternate set of INI and output files (obsolete).\n"); printf ("-wDIR\tRun from a different working directory.\n"); printf ("\n"); return (1); }
/** @SYMTestCaseID SYSLIB-STDLIB-CT-1042 @SYMTestCaseDesc Tests for the ESTW32 facilities for accessing Win32 stdin/stdout/stderr @SYMTestPriority High @SYMTestActions Open RWin32Stream::stdin,stdout,stderr and test writing to these streams. Check for KErrNone flag @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ void DoTest() { RWin32Stream::StartServer(); RWin32Stream stdin; RWin32Stream stdout; RWin32Stream stderr; TRequestStatus status; TInt err; err=stdin.Open(Kstdin); test(err,KErrNone); err=stdout.Open(Kstdout); test(err,KErrNone); err=stderr.Open(Kstderr); test(err,KErrNone); TBuf8<80> outbuf; // stderr outbuf=_L8("Writing to stderr\n"); stderr.Write(status,outbuf); User::WaitForRequest(status); test_status(status,KErrNone); outbuf=_L8("1234XXX89"); stderr.Write(status,outbuf,4); User::WaitForRequest(status); test_status(status,KErrNone); // stdout outbuf=_L8("Writing to stdout\n"); stdout.Write(status,outbuf); User::WaitForRequest(status); test_status(status,KErrNone); outbuf=_L8("1234XXX89"); stdout.Write(status,outbuf,4); User::WaitForRequest(status); test_status(status,KErrNone); FOREVER { stdin.Read(status,outbuf); User::WaitForRequest(status); TRequestStatus outStatus; TBuf8<80> commentary; commentary.Format(_L8("\nread %d, status %d\n"), outbuf.Length(), status.Int()); stderr.Write(outStatus,commentary); User::WaitForRequest(outStatus); test_status(outStatus,KErrNone); if (status.Int()==KErrEof) break; stdout.Write(outStatus,outbuf); User::WaitForRequest(outStatus); test_status(outStatus,KErrNone); } outbuf=_L8("Stdin closed\n"); stderr.Write(status,outbuf); User::WaitForRequest(status); test_status(status,KErrNone); }
void test_graph_crawler() { test_status("Testing graph crawler..."); // Construct 1 colour graph with kmer-size=11 dBGraph graph; const size_t kmer_size = 11, ncols = 3; db_graph_alloc(&graph, kmer_size, ncols, 1, 2048, DBG_ALLOC_EDGES | DBG_ALLOC_NODE_IN_COL | DBG_ALLOC_BKTLOCKS); char graphseq[3][77] = // < X X X............... {"GTTCCAGAGCGGAGGTCTCCCAACAACATGGTATAAGTTGTCTAGCCCCGGTTCGCGCGGGTACTTCTTACAGCGC", "GTTCCAGAGCGGAGGTCTCCCAACAACTTGGTATAAGTTGTCTAGTCCCGGTTCGCGCGGCATTTCAGCATTGTTA", "GTTCCAGAGCGCGACAGAGTGCATATCACGCTAAGCACAGCCCTCTTCTATCTGCTTTTAAATGGATCAATAATCG"}; build_graph_from_str_mt(&graph, 0, graphseq[0], strlen(graphseq[0])); build_graph_from_str_mt(&graph, 1, graphseq[1], strlen(graphseq[1])); build_graph_from_str_mt(&graph, 2, graphseq[2], strlen(graphseq[2])); // Crawl graph GraphCrawler crawler; graph_crawler_alloc(&crawler, &graph); dBNode node = db_graph_find_str(&graph, graphseq[0]); dBNode next_node = db_graph_find_str(&graph, graphseq[0]+1); TASSERT(node.key != HASH_NOT_FOUND); TASSERT(next_node.key != HASH_NOT_FOUND); BinaryKmer bkey = db_node_get_bkmer(&graph, node.key); Edges edges = db_node_get_edges(&graph, node.key, 0); dBNode next_nodes[4]; Nucleotide next_nucs[4]; size_t i, p, num_next, next_idx; num_next = db_graph_next_nodes(&graph, bkey, node.orient, edges, next_nodes, next_nucs); next_idx = 0; while(next_idx < num_next && !db_nodes_are_equal(next_nodes[next_idx],next_node)) next_idx++; TASSERT(next_idx < num_next && db_nodes_are_equal(next_nodes[next_idx],next_node)); // Crawl in all colours graph_crawler_fetch(&crawler, node, next_nodes, next_idx, num_next, NULL, graph.num_of_cols, NULL, NULL, NULL); TASSERT2(crawler.num_paths == 2, "crawler.num_paths: %u", crawler.num_paths); // Fetch paths dBNodeBuffer nbuf; db_node_buf_alloc(&nbuf, 16); StrBuf sbuf; strbuf_alloc(&sbuf, 128); for(p = 0; p < crawler.num_paths; p++) { db_node_buf_reset(&nbuf); graph_crawler_get_path_nodes(&crawler, p, &nbuf); strbuf_ensure_capacity(&sbuf, nbuf.len+graph.kmer_size); sbuf.end = db_nodes_to_str(nbuf.b, nbuf.len, &graph, sbuf.b); for(i = 0; i < 3 && strcmp(graphseq[i]+1,sbuf.b) != 0; i++) {} TASSERT2(i < 3, "seq: %s", sbuf.b); TASSERT2(sbuf.end == 75, "sbuf.end: %zu", sbuf.end); TASSERT2(nbuf.len == 65, "nbuf.len: %zu", nbuf.len); } strbuf_dealloc(&sbuf); db_node_buf_dealloc(&nbuf); graph_crawler_dealloc(&crawler); db_graph_dealloc(&graph); }
int main(int argc, char **argv) { cortex_init(); cmd_init(argc, argv); ctx_msg_out = NULL; ctx_tst_out = stdout; test_status("Tests running k=%i..%i...", get_min_kmer_size(), get_max_kmer_size()); test_status("[version] "VERSION_STATUS_STR"\n"); // Binary Kmer tests should work for all values of MAXK test_bkmer_functions(); test_hash_table(); #if MAX_KMER_SIZE == 31 // not kmer dependent test_util(); test_dna_functions(); test_binary_seq_functions(); // only written in k=31 test_db_node(); test_build_graph(); test_supernode(); test_subgraph(); test_cleaning(); test_paths(); // test_path_sets(); // TODO: replace with test_path_subset() test_graph_walker(); test_corrected_aln(); test_repeat_walker(); test_graph_crawler(); test_bubble_caller(); test_kmer_occur(); test_infer_edges_tests(); #endif cmd_destroy(); // Check we free'd all our memory size_t still_alloced = alloc_get_num_allocs() - alloc_get_num_frees(); TASSERT2(still_alloced == 0, "%zu not free'd", still_alloced); // Finished char num_test_str[100], num_passed_str[100]; size_t tests_num_passed = tests_num_run - tests_num_failed; ulong_to_str(tests_num_run, num_test_str); ulong_to_str(tests_num_passed, num_passed_str); test_status("Tests passed: %s / %s (%.1f%%)", num_passed_str, num_test_str, (100.0*tests_num_passed)/tests_num_run); if(tests_num_failed) test_status("%zu tests failed", tests_num_failed); else test_status("All tests passed."); cortex_destroy(); // Return 1 if any tests failed, 0 on success return tests_num_failed ? 1 : 0; }
static void test_repeat_loop() { TASSERT(sizeof(FollowPath) == 20); // Construct 1 colour graph with kmer-size=11 dBGraph graph; size_t kmer_size = 11, ncols = 1; // Set up alignment correction params CorrectAlnParam params = {.ctpcol = 0, .ctxcol = 0, .ins_gap_min = 0, .ins_gap_max = 0, .one_way_gap_traverse = true, .use_end_check = true, .max_context = 10, .gap_variance = 0.1, .gap_wiggle = 5}; // Sequence with repeat char seq[] = "ATTTGGAACTCCGGA" "GATAGGGCCAGT" "GATAGGGCCAGT" "GATAGGGCCAGT" "GATAGGGCCAGT" "GATAGGGCCAGT" "GATAGGGCCAGT" "GATAGGGCCAGT" "GATAGGGCCAGT" "GATAGGGCCAGT" "GATAGGGCCAGT" "GATAGGGCCAGT" "CGTCAGGAGCTAACT"; char p0[] = "ATTTGGAACTCCGGA""GATAGGGCCAGT""GATAGGGCCAGT"; char p1[] = "GATAGGGCCAGT""GATAGGGCCAGT""CGTCAGGAGCTAACT"; // Allocate graph, but don't add any sequence _construct_graph_with_paths(&graph, kmer_size, ncols, NULL, 0, params); GenPathWorker *gen_path_wrkr = gen_paths_workers_alloc(1, &graph, NULL); GraphWalker gwlk; RepeatWalker rptwlk; graph_walker_alloc(&gwlk); rpt_walker_alloc(&rptwlk, graph.ht.capacity, 12); dBNodeBuffer nbuf; db_node_buf_alloc(&nbuf, 1024); // Construct graph but no paths build_graph_from_str_mt(&graph, 0, seq, strlen(seq)); TASSERT2(graph.ht.num_kmers == 15+12+15, "%zu", (size_t)graph.ht.num_kmers); // Find first node in sequence dBNode node0 = db_graph_find_str(&graph, seq); TASSERT(node0.key != HASH_NOT_FOUND); // 1) With no paths char ans0[] = "ATTTGGAACTCCGGA""GATAGGGCCAGT"; test_walk(&gwlk, &rptwlk, node0, &nbuf, &graph, 15+2, ans0); // 2) Add small paths - produces collapsed down seq with two copy repeat gen_paths_from_str_mt(gen_path_wrkr, p0, params); gen_paths_from_str_mt(gen_path_wrkr, p1, params); char ans1[] = "ATTTGGAACTCCGGA""GATAGGGCCAGT""GATAGGGCCAGT""CGTCAGGAGCTAACT"; test_walk(&gwlk, &rptwlk, node0, &nbuf, &graph, 15+12+12+5, ans1); // 3) Add long paths gen_paths_from_str_mt(gen_path_wrkr, seq, params); test_walk(&gwlk, &rptwlk, node0, &nbuf, &graph, strlen(seq)+1-kmer_size, seq); graph_walker_dealloc(&gwlk); rpt_walker_dealloc(&rptwlk); db_node_buf_dealloc(&nbuf); gen_paths_workers_dealloc(gen_path_wrkr, 1); db_graph_dealloc(&graph); } void test_repeat_walker() { test_status("Testing repeat_walker.h"); test_repeat_loop(); }
// Load each sequence into a separate colour static void test_bubbles(dBGraph *graph, const char **seqs, size_t nseqs, const char *flank5p, const char *flank3p, const char **alleles, size_t nalleles) { db_graph_reset(graph); TASSERT(graph->num_of_cols >= nseqs); size_t i; for(i = 0; i < nseqs; i++) build_graph_from_str_mt(graph, i, seqs[i], strlen(seqs[i]), false); graph->num_of_cols_used = MAX2(graph->num_of_cols_used, 1); StrBuf sbuf; dBNodeBuffer nbuf; strbuf_alloc(&sbuf, 128); db_node_buf_alloc(&nbuf, 128); BubbleCallingPrefs prefs = {.max_allele_len = 100, .max_flank_len = 100, .haploid_cols = NULL, .nhaploid_cols = 0, .remove_serial_bubbles = true}; BubbleCaller *caller = bubble_callers_new(1, &prefs, NULL, graph); _call_bubble(caller, flank5p, flank3p, alleles, nalleles, &nbuf, &sbuf); strbuf_dealloc(&sbuf); db_node_buf_dealloc(&nbuf); bubble_callers_destroy(caller, 1); } void test_bubble_caller() { test_status("Testing bubble calling..."); // Construct 1 colour graph with kmer-size=11 dBGraph graph; const size_t kmer_size = 11, ncols = 3; // Create graph db_graph_alloc(&graph, kmer_size, ncols, 1, 2000, DBG_ALLOC_EDGES | DBG_ALLOC_NODE_IN_COL | DBG_ALLOC_BKTLOCKS); // mutations: x const char *seqs0[] = {"AGGGATAAAACTCTGTACTGGATCTCCCT", "AGGGATAAAACTCTcTACTGGATCTCCCT"}; const char flank5p0[] = "AGGGATAAAACTCT"; const char flank3p0[] = "TACTGGATCTCCCT"; const char *alleles0[] = {"ATAAAACTCTGTACTGGATCT", "ATAAAACTCTcTACTGGATCT"}; test_bubbles(&graph, seqs0, 2, flank5p0, flank3p0, alleles0, 2); // mutations: x y const char *seqs1[] = {"CCCGTAGGTAAGGGCGTTAGTGCAAGGCCACATTGGGACACGAGTTGATA", "CCCGTAGGTAAGtGCGTTAGTGCAAGGCCACATTGGGACACGAGTTGATA", "CCCGTAGGTAAGGGCGTTAGTGCAAGGCCACtTTGGGACACGAGTTGATA"}; // forwards const char flank5p1a[] = "CCCGTAGGTAAG"; const char flank3p1a[] = "GCGTTAGTGCAAGGCCAC"; const char *alleles1a[] = {"CGTAGGTAAGGGCGTTAGTGC", "CGTAGGTAAGtGCGTTAGTGC"}; const char flank5p1b[] = "GCGTTAGTGCAAGGCCAC"; const char flank3p1b[] = "TTGGGACACGAGTTGATA"; const char *alleles1b[] = {"GCAAGGCCACATTGGGACACG", "GCAAGGCCACtTTGGGACACG"}; test_bubbles(&graph, seqs1, 3, flank5p1a, flank3p1a, alleles1a, 2); test_bubbles(&graph, seqs1, 3, flank5p1b, flank3p1b, alleles1b, 2); // reverse // mutations: y x // TATCAACTCGTGTCCCAATGTGGCCTTGCACTAACGCCCTTACCTACGGG // TATCAACTCGTGTCCCAATGTGGCCTTGCACTAACGCaCTTACCTACGGG // TATCAACTCGTGTCCCAAaGTGGCCTTGCACTAACGCCCTTACCTACGGG // const char flank5p1c[] = "GTGGCCTTGCACTAACGC"; const char flank3p1c[] = "CTTACCTACGGG"; const char *alleles1c[] = {"GCACTAACGCCCTTACCTACG", "GCACTAACGCaCTTACCTACG"}; const char flank5p1d[] = "TATCAACTCGTGTCCCAA"; const char flank3p1d[] = "GTGGCCTTGCACTAACGC"; const char *alleles1d[] = {"CGTGTCCCAATGTGGCCTTGC", "CGTGTCCCAAaGTGGCCTTGC"}; test_bubbles(&graph, seqs1, 3, flank5p1c, flank3p1c, alleles1c, 2); test_bubbles(&graph, seqs1, 3, flank5p1d, flank3p1d, alleles1d, 2); db_graph_dealloc(&graph); }
void test_kmer_occur() { test_status("Testing KOGraph..."); test_kmer_occur_filter(); }