Build the fixture file and stamp a generation, the way a publish does. */
| 66 | |
| 67 | /* Build the fixture file and stamp a generation, the way a publish does. */ |
| 68 | static bool gmt_fixture_build(gmt_fixture_t *f) { |
| 69 | char *tmp = th_mktempdir("cbm_graph_mem"); |
| 70 | if (!tmp) { |
| 71 | return false; |
| 72 | } |
| 73 | snprintf(f->dir, sizeof(f->dir), "%s", tmp); |
| 74 | snprintf(f->db, sizeof(f->db), "%s/graph.db", f->dir); |
| 75 | cbm_store_t *s = cbm_store_open_path(f->db); |
| 76 | if (!s || cbm_store_upsert_project(s, "p", "/p") != CBM_STORE_OK || |
| 77 | cbm_store_upsert_project(s, "q", "/q") != CBM_STORE_OK) { |
| 78 | cbm_store_close(s); |
| 79 | return false; |
| 80 | } |
| 81 | for (int i = 0; i < GMT_NODES; i++) { |
| 82 | char name[16]; |
| 83 | /* Every fifth node shares one name: search's (name, id) order has ties. */ |
| 84 | snprintf(name, sizeof(name), (i % 5 == 4) ? "dup" : "n%02d", i); |
| 85 | f->ids[i] = gmt_node(s, "p", i, name); |
| 86 | } |
| 87 | f->other_id = gmt_node(s, "q", 99, "other"); |
| 88 | const int64_t *id = f->ids; |
| 89 | /* chain with a cycle back to the start (0 at hop 3), a self-loop, a diamond */ |
| 90 | gmt_edge(s, id[0], id[1], "CALLS", NULL); |
| 91 | gmt_edge(s, id[1], id[2], "CALLS", NULL); |
| 92 | gmt_edge(s, id[2], id[0], "CALLS", NULL); |
| 93 | gmt_edge(s, id[2], id[3], "CALLS", NULL); |
| 94 | gmt_edge(s, id[5], id[5], "CALLS", NULL); |
| 95 | gmt_edge(s, id[0], id[6], "CALLS", NULL); |
| 96 | gmt_edge(s, id[0], id[7], "CALLS", NULL); |
| 97 | gmt_edge(s, id[6], id[8], "CALLS", NULL); |
| 98 | gmt_edge(s, id[7], id[8], "CALLS", NULL); |
| 99 | /* two IMPORTS rows for one (source, target): distinct local names */ |
| 100 | gmt_edge(s, id[3], id[4], "IMPORTS", "{\"local_name\":\"a\"}"); |
| 101 | gmt_edge(s, id[3], id[4], "IMPORTS", "{\"local_name\":\"b\"}"); |
| 102 | /* a cross-project hop: BFS does not filter by project */ |
| 103 | gmt_edge(s, id[8], f->other_id, "CALLS", NULL); |
| 104 | gmt_edge(s, f->other_id, id[9], "CALLS", NULL); |
| 105 | /* a hub for the degree filters */ |
| 106 | for (int i = 10; i < 30; i++) { |
| 107 | gmt_edge(s, id[i], id[1], (i % 2) ? "CALLS" : "USAGE", NULL); |
| 108 | } |
| 109 | /* seeded random edges over the first 34 nodes; 34..39 stay edgeless */ |
| 110 | uint32_t state = GMT_SEED; |
| 111 | for (int k = 0; k < GMT_RANDOM_EDGES; k++) { |
| 112 | int a = (int)(gmt_next(&state) % 34U); |
| 113 | int b = (int)(gmt_next(&state) % 34U); |
| 114 | const char *type = gmt_types[gmt_next(&state) % 4U]; |
| 115 | gmt_edge(s, id[a], id[b], type, "{\"w\":1}"); |
| 116 | } |
| 117 | /* Stamp and seal, as a publish does: a sealed rollback-journal file is |
| 118 | * the only kind of DB the layer serves. */ |
| 119 | bool ok = cbm_store_generation_advance(s) == CBM_STORE_OK && |
| 120 | cbm_store_prepare_for_publish(s) == CBM_STORE_OK; |
| 121 | cbm_store_close(s); |
| 122 | return ok; |
| 123 | } |
| 124 | |
| 125 | static bool gmt_reseal(const gmt_fixture_t *f) { |
no test coverage detected