"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "t/threads_t.c" between
libmaxminddb-1.5.0.tar.gz and libmaxminddb-1.5.2.tar.gz

About: libmaxminddb is a library that provides functions for working with MaxMind DB files (free GeoLite 2 or commercial GeoIP2).

threads_t.c  (libmaxminddb-1.5.0):threads_t.c  (libmaxminddb-1.5.2)
skipping to change at line 20 skipping to change at line 20
typedef struct test_result { typedef struct test_result {
const char *ip_looked_up; const char *ip_looked_up;
int lookup_string_gai_error; int lookup_string_gai_error;
int lookup_string_mmdb_error; int lookup_string_mmdb_error;
int found_entry; int found_entry;
int get_value_status; int get_value_status;
int data_type_ok; int data_type_ok;
char *data_value; char *data_value;
} test_result_s; } test_result_s;
void test_one_ip(MMDB_s *mmdb, const char *ip, test_result_s *test_result) void test_one_ip(MMDB_s *mmdb, const char *ip, test_result_s *test_result) {
{
test_result->ip_looked_up = ip; test_result->ip_looked_up = ip;
int gai_error = 0; int gai_error = 0;
int mmdb_error = 0; int mmdb_error = 0;
MMDB_lookup_result_s result = MMDB_lookup_result_s result =
MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error); MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
test_result->lookup_string_gai_error = gai_error; test_result->lookup_string_gai_error = gai_error;
if (gai_error) { if (gai_error) {
skipping to change at line 63 skipping to change at line 62
test_result->data_type_ok = data.type == MMDB_DATA_TYPE_UTF8_STRING; test_result->data_type_ok = data.type == MMDB_DATA_TYPE_UTF8_STRING;
if (!test_result->data_type_ok) { if (!test_result->data_type_ok) {
return; return;
} }
test_result->data_value = mmdb_strndup(data.utf8_string, data.data_size); test_result->data_value = mmdb_strndup(data.utf8_string, data.data_size);
return; return;
} }
void *run_one_thread(void *arg) void *run_one_thread(void *arg) {
{
thread_arg_s *thread_arg = (thread_arg_s *)arg; thread_arg_s *thread_arg = (thread_arg_s *)arg;
MMDB_s *mmdb = thread_arg->mmdb; MMDB_s *mmdb = thread_arg->mmdb;
const char *ip = thread_arg->ip_to_lookup; const char *ip = thread_arg->ip_to_lookup;
test_result_s *result = malloc(sizeof(test_result_s)); test_result_s *result = malloc(sizeof(test_result_s));
if (!result) {
BAIL_OUT("could not allocate memory");
}
test_one_ip(mmdb, ip, result); test_one_ip(mmdb, ip, result);
pthread_exit((void *)result); pthread_exit((void *)result);
} }
void process_result(test_result_s *result, const char *expect, void process_result(test_result_s *result,
const char *mode_desc) const char *expect,
{ const char *mode_desc) {
int is_ok; int is_ok;
is_ok = is_ok = ok(!result->lookup_string_gai_error,
ok(!result->lookup_string_gai_error, "no getaddrinfo error for %s - %s", "no getaddrinfo error for %s - %s",
result->ip_looked_up, mode_desc); result->ip_looked_up,
mode_desc);
if (!is_ok) { if (!is_ok) {
return; return;
} }
is_ok = ok(!result->lookup_string_mmdb_error, "no mmdb error for %s - %s", is_ok = ok(!result->lookup_string_mmdb_error,
result->ip_looked_up, mode_desc); "no mmdb error for %s - %s",
result->ip_looked_up,
mode_desc);
if (!is_ok) { if (!is_ok) {
return; return;
} }
is_ok = ok(result->found_entry, "got a result for %s in the database - %s", is_ok = ok(result->found_entry,
result->ip_looked_up, mode_desc); "got a result for %s in the database - %s",
result->ip_looked_up,
mode_desc);
if (!is_ok) { if (!is_ok) {
return; return;
} }
is_ok = is_ok = ok(!result->get_value_status,
ok(!result->get_value_status, "no error from MMDB_get_value for %s - %s",
"no error from MMDB_get_value for %s - %s", result->ip_looked_up,
result->ip_looked_up, mode_desc);
mode_desc);
if (!is_ok) { if (!is_ok) {
return; return;
} }
is_ok = ok(result->data_type_ok, is_ok = ok(result->data_type_ok,
"MMDB_get_value found a utf8_string at 'ip' key for %s - %s", "MMDB_get_value found a utf8_string at 'ip' key for %s - %s",
result->ip_looked_up, mode_desc); result->ip_looked_up,
mode_desc);
if (!is_ok) { if (!is_ok) {
return; return;
} }
is(result->data_value, expect, is(result->data_value,
expect,
"found expected result for 'ip' key for %s - %s", "found expected result for 'ip' key for %s - %s",
result->ip_looked_up, mode_desc); result->ip_looked_up,
mode_desc);
} }
void run_ipX_tests(MMDB_s *mmdb, const char *pairs[][2], int pairs_rows, void run_ipX_tests(MMDB_s *mmdb,
int mode, const char *mode_desc) const char *pairs[][2],
{ int pairs_rows,
int mode,
const char *mode_desc) {
pthread_t threads[pairs_rows]; pthread_t threads[pairs_rows];
struct thread_arg thread_args[pairs_rows]; struct thread_arg thread_args[pairs_rows];
for (int i = 0; i < pairs_rows; i += 1) { for (int i = 0; i < pairs_rows; i += 1) {
thread_args[i].thread_id = i; thread_args[i].thread_id = i;
thread_args[i].mmdb = mmdb; thread_args[i].mmdb = mmdb;
thread_args[i].ip_to_lookup = pairs[i][0]; thread_args[i].ip_to_lookup = pairs[i][0];
int error = pthread_create(&threads[i], NULL, run_one_thread, int error =
&thread_args[i]); pthread_create(&threads[i], NULL, run_one_thread, &thread_args[i]);
if (error) { if (error) {
BAIL_OUT("pthread_create failed"); BAIL_OUT("pthread_create failed");
} }
} }
for (int i = 0; i < pairs_rows; i += 1) { for (int i = 0; i < pairs_rows; i += 1) {
void *thread_return; void *thread_return;
int error = pthread_join(threads[i], &thread_return); int error = pthread_join(threads[i], &thread_return);
if (error) { if (error) {
BAIL_OUT("pthread_join failed"); BAIL_OUT("pthread_join failed");
skipping to change at line 156 skipping to change at line 166
if (NULL != test_result) { if (NULL != test_result) {
process_result(test_result, pairs[i][1], mode_desc); process_result(test_result, pairs[i][1], mode_desc);
if (test_result->data_type_ok) { if (test_result->data_type_ok) {
free(test_result->data_value); free(test_result->data_value);
} }
free(test_result); free(test_result);
} }
} }
} }
void run_tests(int mode, const char *mode_desc) void run_tests(int mode, const char *mode_desc) {
{
const char *filename = "MaxMind-DB-test-mixed-32.mmdb"; const char *filename = "MaxMind-DB-test-mixed-32.mmdb";
const char *path = test_database_path(filename); const char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc); MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path); free((void *)path);
const char *pairs[18][2] = { const char *pairs[18][2] = {
{ "1.1.1.1", "::1.1.1.1" }, {"1.1.1.1", "::1.1.1.1"},
{ "1.1.1.2", "::1.1.1.2" }, {"1.1.1.2", "::1.1.1.2"},
{ "1.1.1.3", "::1.1.1.2" }, {"1.1.1.3", "::1.1.1.2"},
{ "1.1.1.7", "::1.1.1.4" }, {"1.1.1.7", "::1.1.1.4"},
{ "1.1.1.9", "::1.1.1.8" }, {"1.1.1.9", "::1.1.1.8"},
{ "1.1.1.15", "::1.1.1.8" }, {"1.1.1.15", "::1.1.1.8"},
{ "1.1.1.17", "::1.1.1.16" }, {"1.1.1.17", "::1.1.1.16"},
{ "1.1.1.31", "::1.1.1.16" }, {"1.1.1.31", "::1.1.1.16"},
{ "1.1.1.32", "::1.1.1.32" }, {"1.1.1.32", "::1.1.1.32"},
{ "::1:ffff:ffff", "::1:ffff:ffff" }, {"::1:ffff:ffff", "::1:ffff:ffff"},
{ "::2:0:0", "::2:0:0" }, {"::2:0:0", "::2:0:0"},
{ "::2:0:1a", "::2:0:0" }, {"::2:0:1a", "::2:0:0"},
{ "::2:0:40", "::2:0:40" }, {"::2:0:40", "::2:0:40"},
{ "::2:0:4f", "::2:0:40" }, {"::2:0:4f", "::2:0:40"},
{ "::2:0:50", "::2:0:50" }, {"::2:0:50", "::2:0:50"},
{ "::2:0:52", "::2:0:50" }, {"::2:0:52", "::2:0:50"},
{ "::2:0:58", "::2:0:58" }, {"::2:0:58", "::2:0:58"},
{ "::2:0:59", "::2:0:58" }, {"::2:0:59", "::2:0:58"},
}; };
run_ipX_tests(mmdb, pairs, 18, mode, mode_desc); run_ipX_tests(mmdb, pairs, 18, mode, mode_desc);
MMDB_close(mmdb); MMDB_close(mmdb);
free(mmdb); free(mmdb);
} }
int main(void) int main(void) {
{
plan(NO_PLAN); plan(NO_PLAN);
for_all_modes(&run_tests); for_all_modes(&run_tests);
done_testing(); done_testing();
pthread_exit(NULL); pthread_exit(NULL);
} }
 End of changes. 16 change blocks. 
49 lines changed or deleted 57 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)