diff options
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/my_decimal/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittest/mysys/CMakeLists.txt | 3 | ||||
-rw-r--r-- | unittest/mysys/base64-t.c | 2 | ||||
-rw-r--r-- | unittest/mysys/bitmap-t.c | 10 | ||||
-rw-r--r-- | unittest/mysys/ma_dyncol-t.c | 219 | ||||
-rw-r--r-- | unittest/mysys/my_vsnprintf-t.c | 115 | ||||
-rw-r--r-- | unittest/sql/CMakeLists.txt | 3 | ||||
-rw-r--r-- | unittest/sql/explain_filename-t.cc | 4 | ||||
-rw-r--r-- | unittest/sql/my_apc-t.cc | 229 |
9 files changed, 433 insertions, 154 deletions
diff --git a/unittest/my_decimal/CMakeLists.txt b/unittest/my_decimal/CMakeLists.txt index 0a38a18b7ba..85d203e8f47 100644 --- a/unittest/my_decimal/CMakeLists.txt +++ b/unittest/my_decimal/CMakeLists.txt @@ -20,4 +20,4 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/unittest/mytap) # -MY_ADD_TESTS(my_decimal EXT "cc" LINK_LIBRARIES mysys) +MY_ADD_TESTS(my_decimal EXT "cc" LINK_LIBRARIES strings dbug) diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt index effdd9bea1c..8c09a466451 100644 --- a/unittest/mysys/CMakeLists.txt +++ b/unittest/mysys/CMakeLists.txt @@ -16,6 +16,9 @@ MY_ADD_TESTS(bitmap base64 my_vsnprintf my_atomic my_rdtsc lf my_malloc LINK_LIBRARIES mysys) +MY_ADD_TESTS(ma_dyncol + LINK_LIBRARIES mysqlclient) + IF(WIN32) MY_ADD_TESTS(my_delete LINK_LIBRARIES mysys) ENDIF() diff --git a/unittest/mysys/base64-t.c b/unittest/mysys/base64-t.c index ed19c4de851..1cf54f9b673 100644 --- a/unittest/mysys/base64-t.c +++ b/unittest/mysys/base64-t.c @@ -60,7 +60,7 @@ main(int argc __attribute__((unused)),char *argv[]) /* Decode */ dst= (char *) malloc(base64_needed_decoded_length(strlen(str))); - dst_len= base64_decode(str, strlen(str), dst, NULL); + dst_len= base64_decode(str, strlen(str), dst, NULL, 0); ok(dst_len == src_len, "Comparing lengths"); cmp= memcmp(src, dst, src_len); diff --git a/unittest/mysys/bitmap-t.c b/unittest/mysys/bitmap-t.c index 0666f4eaa15..c4588779c9b 100644 --- a/unittest/mysys/bitmap-t.c +++ b/unittest/mysys/bitmap-t.c @@ -129,8 +129,8 @@ my_bool test_compare_operators(MY_BITMAP *map, uint bitsize) MY_BITMAP *map2= &map2_obj, *map3= &map3_obj; my_bitmap_map map2buf[MAX_TESTED_BITMAP_SIZE]; my_bitmap_map map3buf[MAX_TESTED_BITMAP_SIZE]; - bitmap_init(&map2_obj, map2buf, bitsize, FALSE); - bitmap_init(&map3_obj, map3buf, bitsize, FALSE); + my_bitmap_init(&map2_obj, map2buf, bitsize, FALSE); + my_bitmap_init(&map3_obj, map3buf, bitsize, FALSE); bitmap_clear_all(map2); bitmap_clear_all(map3); for (i=0; i < no_loops; i++) @@ -374,7 +374,7 @@ my_bool test_compare(MY_BITMAP *map, uint bitsize) uint32 map2buf[MAX_TESTED_BITMAP_SIZE]; uint i, test_bit; uint no_loops= bitsize > 128 ? 128 : bitsize; - if (bitmap_init(&map2, map2buf, bitsize, FALSE)) + if (my_bitmap_init(&map2, map2buf, bitsize, FALSE)) { diag("init error for bitsize %d", bitsize); return TRUE; @@ -433,7 +433,7 @@ my_bool test_intersect(MY_BITMAP *map, uint bitsize) MY_BITMAP map2; uint32 map2buf[MAX_TESTED_BITMAP_SIZE]; uint i, test_bit1, test_bit2, test_bit3; - if (bitmap_init(&map2, map2buf, bitsize2, FALSE)) + if (my_bitmap_init(&map2, map2buf, bitsize2, FALSE)) { diag("init error for bitsize %d", bitsize2); return TRUE; @@ -481,7 +481,7 @@ my_bool do_test(uint bitsize) { MY_BITMAP map; my_bitmap_map buf[MAX_TESTED_BITMAP_SIZE]; - if (bitmap_init(&map, buf, bitsize, FALSE)) + if (my_bitmap_init(&map, buf, bitsize, FALSE)) { diag("init error for bitsize %d", bitsize); goto error; diff --git a/unittest/mysys/ma_dyncol-t.c b/unittest/mysys/ma_dyncol-t.c index 4a9b687bc08..51e84bc4e40 100644 --- a/unittest/mysys/ma_dyncol-t.c +++ b/unittest/mysys/ma_dyncol-t.c @@ -35,96 +35,100 @@ void test_value_single_null() { int rc= FALSE; + uint ids[1]= {1}; DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_NULL; - dynamic_column_value_init(&res); + mariadb_dyncol_value_init(&res); /* create column */ - if (dynamic_column_create(&str, 1, &val)) + if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ - if (dynamic_column_get(&str, 1, &res)) + if (mariadb_dyncol_get_num(&str, 1, &res)) goto err; rc= (res.type == DYN_COL_NULL); err: ok(rc, "%s", "NULL"); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } void test_value_single_uint(ulonglong num, const char *name) { int rc= FALSE; + uint ids[1]= {1}; DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_UINT; val.x.ulong_value= num; - dynamic_column_value_init(&res); + mariadb_dyncol_value_init(&res); /* create column */ - if (dynamic_column_create(&str, 1, &val)) + if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ - if (dynamic_column_get(&str, 1, &res)) + if (mariadb_dyncol_get_num(&str, 1, &res)) goto err; rc= (res.type == DYN_COL_UINT) && (res.x.ulong_value == num); num= res.x.ulong_value; err: ok(rc, "%s - %llu", name, num); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } void test_value_single_sint(longlong num, const char *name) { int rc= FALSE; + uint ids[1]= {1}; DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_INT; val.x.long_value= num; - dynamic_column_value_init(&res); + mariadb_dyncol_value_init(&res); /* create column */ - if (dynamic_column_create(&str, 1, &val)) + if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ - if (dynamic_column_get(&str, 1, &res)) + if (mariadb_dyncol_get_num(&str, 1, &res)) goto err; rc= (res.type == DYN_COL_INT) && (res.x.long_value == num); num= res.x.ulong_value; err: ok(rc, "%s - %lld", name, num); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } void test_value_single_double(double num, const char *name) { int rc= FALSE; + uint ids[1]= {1}; DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_DOUBLE; val.x.double_value= num; - dynamic_column_value_init(&res); + mariadb_dyncol_value_init(&res); /* create column */ - if (dynamic_column_create(&str, 1, &val)) + if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ - if (dynamic_column_get(&str, 1, &res)) + if (mariadb_dyncol_get_num(&str, 1, &res)) goto err; rc= (res.type == DYN_COL_DOUBLE) && (res.x.double_value == num); num= res.x.ulong_value; err: ok(rc, "%s - %lf", name, num); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } void test_value_single_decimal(const char *num) @@ -133,21 +137,22 @@ void test_value_single_decimal(const char *num) char buff[80]; int rc= FALSE; int length= 80; + uint ids[1]= {1}; DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; /* init values */ - dynamic_column_prepare_decimal(&val); // special procedure for decimal!!! + mariadb_dyncol_prepare_decimal(&val); // special procedure for decimal!!! if (string2decimal(num, &val.x.decimal.value, &end) != E_DEC_OK) goto err; - dynamic_column_value_init(&res); + mariadb_dyncol_value_init(&res); /* create column */ - if (dynamic_column_create(&str, 1, &val)) + if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ - if (dynamic_column_get(&str, 1, &res)) + if (mariadb_dyncol_get_num(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_DECIMAL) && (decimal_cmp(&res.x.decimal.value, &val.x.decimal.value) == 0)); @@ -155,7 +160,7 @@ void test_value_single_decimal(const char *num) err: ok(rc, "%s - %s", num, buff); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } static CHARSET_INFO *charset_list[]= @@ -206,6 +211,7 @@ void test_value_single_string(const char *string, size_t len, CHARSET_INFO *cs) { int rc= FALSE; + uint ids[1]= {1}; DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; @@ -214,14 +220,14 @@ void test_value_single_string(const char *string, size_t len, val.x.string.value.str= (char*)string; val.x.string.value.length= len; val.x.string.charset= cs; - dynamic_column_value_init(&res); + mariadb_dyncol_value_init(&res); /* create column */ - if (dynamic_column_create(&str, 1, &val)) + if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ - if (dynamic_column_get(&str, 1, &res)) + if (mariadb_dyncol_get_num(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_STRING) && (res.x.string.value.length == len) && @@ -233,12 +239,13 @@ err: (uint)res.x.string.charset->number, res.x.string.charset->name); /* cleanup */ val.x.string.value.str= NULL; // we did not allocated it - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } void test_value_single_date(uint year, uint month, uint day, const char *name) { int rc= FALSE; + uint ids[1]= {1}; DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; /* init values */ @@ -247,13 +254,13 @@ void test_value_single_date(uint year, uint month, uint day, const char *name) val.x.time_value.year= year; val.x.time_value.month= month; val.x.time_value.day= day; - dynamic_column_value_init(&res); + mariadb_dyncol_value_init(&res); /* create column */ - if (dynamic_column_create(&str, 1, &val)) + if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ - if (dynamic_column_get(&str, 1, &res)) + if (mariadb_dyncol_get_num(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_DATE) && (res.x.time_value.time_type == MYSQL_TIMESTAMP_DATE) && @@ -263,13 +270,14 @@ void test_value_single_date(uint year, uint month, uint day, const char *name) err: ok(rc, "%s - %04u-%02u-%02u", name, year, month, day); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } void test_value_single_time(uint neg, uint hour, uint minute, uint second, uint mic, const char *name) { int rc= FALSE; + uint ids[1]= {1}; DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; /* init values */ @@ -280,13 +288,13 @@ void test_value_single_time(uint neg, uint hour, uint minute, uint second, val.x.time_value.minute= minute; val.x.time_value.second= second; val.x.time_value.second_part= mic; - dynamic_column_value_init(&res); + mariadb_dyncol_value_init(&res); /* create column */ - if (dynamic_column_create(&str, 1, &val)) + if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ - if (dynamic_column_get(&str, 1, &res)) + if (mariadb_dyncol_get_num(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_TIME) && (res.x.time_value.time_type == MYSQL_TIMESTAMP_TIME) && @@ -299,7 +307,7 @@ err: ok(rc, "%s - %c%02u:%02u:%02u.%06u", name, (neg ? '-' : '+'), hour, minute, second, mic); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } @@ -308,6 +316,7 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day, uint mic, const char *name) { int rc= FALSE; + uint ids[1]= {1}; DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; /* init values */ @@ -321,13 +330,13 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day, val.x.time_value.minute= minute; val.x.time_value.second= second; val.x.time_value.second_part= mic; - dynamic_column_value_init(&res); + mariadb_dyncol_value_init(&res); /* create column */ - if (dynamic_column_create(&str, 1, &val)) + if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ - if (dynamic_column_get(&str, 1, &res)) + if (mariadb_dyncol_get_num(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_DATETIME) && (res.x.time_value.time_type == MYSQL_TIMESTAMP_DATETIME) && @@ -343,7 +352,7 @@ err: ok(rc, "%s - %c %04u-%02u-%02u %02u:%02u:%02u.%06u", name, (neg ? '-' : '+'), year, month, day, hour, minute, second, mic); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } @@ -373,7 +382,7 @@ void test_value_multi(ulonglong num0, val[1].x.long_value= num1; val[2].type= DYN_COL_DOUBLE; val[2].x.double_value= num2; - dynamic_column_prepare_decimal(val + 3); // special procedure for decimal!!! + mariadb_dyncol_prepare_decimal(val + 3); // special procedure for decimal!!! if (string2decimal(num3, &val[3].x.decimal.value, &end3) != E_DEC_OK) goto err; val[4].type= DYN_COL_STRING; @@ -404,14 +413,14 @@ void test_value_multi(ulonglong num0, val[7].x.time_value.second_part= mic7; val[8].type= DYN_COL_NULL; for (i= 0; i < 9; i++) - dynamic_column_value_init(res + i); + mariadb_dyncol_value_init(res + i); /* create column */ - if (dynamic_column_create_many(&str, 9, column_numbers, val)) + if (mariadb_dyncol_create_many_num(&str, 9, column_numbers, val, 1)) goto err; dynstr_append(&str, "\1"); str.length--; //check for overflow /* read column */ for (i= 0; i < 9; i++) - if (dynamic_column_get(&str, column_numbers[i], res + i)) + if (mariadb_dyncol_get_num(&str, column_numbers[i], res + i)) goto err; rc= ((res[0].type == DYN_COL_UINT) && (res[0].x.ulong_value == num0) && @@ -452,7 +461,7 @@ err: ok(rc, "%s", name); /* cleanup */ val[4].x.string.value.str= NULL; // we did not allocated it - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } @@ -467,13 +476,13 @@ void test_value_multi_same_num() for (i= 0; i < 5; i++) val[i].type= DYN_COL_NULL; /* create column */ - if (!dynamic_column_create_many(&str, 5, column_numbers, val)) + if (!mariadb_dyncol_create_many_num(&str, 5, column_numbers, val, 1)) goto err; rc= TRUE; err: ok(rc, "%s", "same column numbers check"); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } @@ -487,68 +496,69 @@ void test_update_multi(uint *column_numbers, uint *column_values, val.type= DYN_COL_UINT; val.x.ulong_value= column_values[0]; - if (dynamic_column_create(&str, column_numbers[0], &val)) + if (mariadb_dyncol_create_many_num(&str, 1, column_numbers, &val, 1)) goto err; for (i= 1; i < all; i++) { val.type= (null_values[i] ? DYN_COL_NULL : DYN_COL_UINT); val.x.ulong_value= column_values[i]; - if (dynamic_column_update(&str, column_numbers[i], &val)) + if (mariadb_dyncol_update_many_num(&str, 1, column_numbers +i, &val)) goto err; /* check value(s) */ for (j= i; j >= (i < only_add ? 0 : i); j--) { - if (dynamic_column_get(&str, column_numbers[j], &val)) + if (mariadb_dyncol_get_num(&str, column_numbers[j], &val)) goto err; if (null_values[j]) { if (val.type != DYN_COL_NULL || - dynamic_column_exists(&str, column_numbers[j]) == ER_DYNCOL_YES) + mariadb_dyncol_exists_num(&str, column_numbers[j]) == ER_DYNCOL_YES) goto err; } else { if (val.type != DYN_COL_UINT || val.x.ulong_value != column_values[j] || - dynamic_column_exists(&str, column_numbers[j]) == ER_DYNCOL_NO) + mariadb_dyncol_exists_num(&str, column_numbers[j]) == ER_DYNCOL_NO) goto err; } } if (i < only_add) { - DYNAMIC_ARRAY num; - if (dynamic_column_list(&str, &num)) + uint elements, *num; + if (mariadb_dyncol_list_num(&str, &elements, &num)) + { + my_free(num); goto err; + } /* cross check arrays */ - if ((int)num.elements != i + 1) + if ((int)elements != i + 1) { - delete_dynamic(&num); + my_free(num); goto err; } for(j= 0; j < i + 1; j++) { int k; for(k= 0; - k < i + 1 && column_numbers[j] != - *dynamic_element(&num, k, uint*); + k < i + 1 && column_numbers[j] != num[k]; k++); if (k >= i + 1) { - delete_dynamic(&num); + my_free(num); goto err; } for(k= 0; - k < i + 1 && column_numbers[k] != - *dynamic_element(&num, j, uint*); + k < i + 1 && column_numbers[k] != num[j]; k++); if (k >= i + 1) { - delete_dynamic(&num); + my_free(num); goto err; } } - delete_dynamic(&num); + my_free(num); } } @@ -556,41 +566,72 @@ void test_update_multi(uint *column_numbers, uint *column_values, err: ok(rc, "%s", "add/delete/update"); /* cleanup */ - dynamic_column_column_free(&str); + mariadb_dyncol_free(&str); } void test_empty_string() { DYNAMIC_COLUMN_VALUE val, res; DYNAMIC_COLUMN str; - DYNAMIC_ARRAY array_of_uint; + uint *array_of_uint; + uint number_of_uint; int rc; + uint ids[1]= {1}; + DYNAMIC_COLUMN_VALUE vals[1]; /* empty string */ bzero(&str, sizeof(str)); - rc= dynamic_column_get(&str, 1, &res); + rc= mariadb_dyncol_get_num(&str, 1, &res); ok( (rc == ER_DYNCOL_OK) && (res.type == DYN_COL_NULL), "%s", "empty get"); - rc= dynamic_column_delete(&str, 1); - ok( (rc == ER_DYNCOL_OK), "%s", "empty delete"); + vals[0].type= DYN_COL_NULL; + rc= mariadb_dyncol_update_many_num(&str, 1, ids, vals); + ok( (rc == ER_DYNCOL_OK) && (str.str == 0), "%s", "empty delete"); - rc= dynamic_column_exists(&str, 1); + rc= mariadb_dyncol_exists_num(&str, 1); ok( (rc == ER_DYNCOL_NO), "%s", "empty exists"); - rc= dynamic_column_list(&str, &array_of_uint); - ok( (rc == ER_DYNCOL_OK) && (array_of_uint.elements == 0), + rc= mariadb_dyncol_list_num(&str, &number_of_uint, &array_of_uint); + ok( (rc == ER_DYNCOL_OK) && (number_of_uint == 0) && (str.str == 0), "%s", "empty list"); val.type= DYN_COL_UINT; val.x.ulong_value= 1212; - rc= dynamic_column_update(&str, 1, &val); + rc= mariadb_dyncol_update_many_num(&str, 1, ids, &val); if (rc == ER_DYNCOL_OK) - rc= dynamic_column_get(&str, 1, &res); - ok( (rc == ER_DYNCOL_OK) && + rc= mariadb_dyncol_get_num(&str, 1, &res); + ok( (rc == ER_DYNCOL_OK) && (str.str != 0) && (res.type == DYN_COL_UINT) && (res.x.ulong_value == val.x.ulong_value), "%s", "empty update"); + mariadb_dyncol_free(&str); +} + +static void test_mdev_4994() +{ + DYNAMIC_COLUMN dyncol; + LEX_STRING key= {0,0}; + DYNAMIC_COLUMN_VALUE val; + int rc; + + val.type= DYN_COL_NULL; + + mariadb_dyncol_init(&dyncol); + rc= mariadb_dyncol_create_many_named(&dyncol, 1, &key, &val, 0); /* crash */ + ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4994"); + mariadb_dyncol_free(&dyncol); } +static void test_mdev_4995() +{ + DYNAMIC_COLUMN dyncol; + uint column_count= 5; + int rc; + + mariadb_dyncol_init(&dyncol); + rc= mariadb_dyncol_column_count(&dyncol,&column_count); + + ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4995"); +} void test_update_many(uint *column_numbers, uint *column_values, uint column_count, @@ -633,11 +674,11 @@ void test_update_many(uint *column_numbers, uint *column_values, res[i].type= DYN_COL_UINT; res[i].x.ulong_value= result_values[i]; } - if (dynamic_column_create_many(&str1, column_count, column_numbers, val)) + if (mariadb_dyncol_create_many_num(&str1, column_count, column_numbers, val, 1)) goto err; - if (dynamic_column_update_many(&str1, update_count, update_numbers, upd)) + if (mariadb_dyncol_update_many_num(&str1, update_count, update_numbers, upd)) goto err; - if (dynamic_column_create_many(&str2, result_count, result_numbers, res)) + if (mariadb_dyncol_create_many_num(&str2, result_count, result_numbers, res, 1)) goto err; if (str1.length == str2.length && memcmp(str1.str, str2.str, str1.length) ==0) @@ -646,8 +687,8 @@ void test_update_many(uint *column_numbers, uint *column_values, err: ok(rc, "%s", "update_many"); /* cleanup */ - dynamic_column_column_free(&str1); - dynamic_column_column_free(&str2); + mariadb_dyncol_free(&str1); + mariadb_dyncol_free(&str2); } int main(int argc __attribute__((unused)), char **argv) @@ -656,7 +697,7 @@ int main(int argc __attribute__((unused)), char **argv) char *big_string= (char *)malloc(1024*1024); MY_INIT(argv[0]); - plan(60); + plan(62); if (!big_string) exit(1); @@ -664,21 +705,17 @@ int main(int argc __attribute__((unused)), char **argv) big_string[i]= ('0' + (i % 10)); test_value_single_null(); test_value_single_uint(0, "0"); - test_value_single_uint(ULL(0xffffffffffffffff), "0xffffffffffffffff"); - test_value_single_uint(ULL(0xaaaaaaaaaaaaaaaa), "0xaaaaaaaaaaaaaaaa"); - test_value_single_uint(ULL(0x5555555555555555), "0x5555555555555555"); + test_value_single_uint(0xffffffffffffffffULL, "0xffffffffffffffff"); + test_value_single_uint(0xaaaaaaaaaaaaaaaaULL, "0xaaaaaaaaaaaaaaaa"); + test_value_single_uint(0x5555555555555555ULL, "0x5555555555555555"); test_value_single_uint(27652, "27652"); test_value_single_sint(0, "0"); test_value_single_sint(1, "1"); test_value_single_sint(-1, "-1"); - test_value_single_sint(LL(0x7fffffffffffffff), - "0x7fffffffffffffff"); - test_value_single_sint(LL(0xaaaaaaaaaaaaaaaa), - "0xaaaaaaaaaaaaaaaa"); - test_value_single_sint(LL(0x5555555555555555), - "0x5555555555555555"); - test_value_single_sint(LL(0x8000000000000000), - "0x8000000000000000"); + test_value_single_sint(0x7fffffffffffffffLL, "0x7fffffffffffffff"); + test_value_single_sint(0xaaaaaaaaaaaaaaaaLL, "0xaaaaaaaaaaaaaaaa"); + test_value_single_sint(0x5555555555555555LL, "0x5555555555555555"); + test_value_single_sint(0x8000000000000000LL, "0x8000000000000000"); test_value_single_double(0.0, "0.0"); test_value_single_double(1.0, "1.0"); test_value_single_double(-1.0, "-1.0"); @@ -735,7 +772,7 @@ int main(int argc __attribute__((unused)), char **argv) } { uint column_numbers[]= {10,1,12,37,4,57,6,76,87}; - test_value_multi(ULL(0xffffffffffffffff), LL(0x7fffffffffffffff), + test_value_multi(0xffffffffffffffffULL, 0x7fffffffffffffffLL, 99999999.999e120, "9999999999999999999999999999999", big_string, 1024*1024, charset_list[0], 9999, 12, 31, @@ -791,5 +828,9 @@ int main(int argc __attribute__((unused)), char **argv) update_numbers, update_values, update_nulls, 4, result_numbers, result_values, 3); } + test_mdev_4994(); + test_mdev_4995(); + + my_end(0); return exit_status(); } diff --git a/unittest/mysys/my_vsnprintf-t.c b/unittest/mysys/my_vsnprintf-t.c index 06f6878826a..45df97fbecd 100644 --- a/unittest/mysys/my_vsnprintf-t.c +++ b/unittest/mysys/my_vsnprintf-t.c @@ -19,7 +19,17 @@ char buf[1024]; /* let's hope that's enough */ -void test1(const char *res, const char *fmt, ...) +static void test_w_len(const char *res, size_t buflen, const char *fmt, ...) +{ + va_list args; + size_t len; + va_start(args,fmt); + len= my_vsnprintf(buf, buflen, fmt, args); + va_end(args); + ok(strlen(res) == len && strcmp(buf, res) == 0, "\"%s\"", buf); +} + +static void test1(const char *res, const char *fmt, ...) { va_list args; size_t len; @@ -29,9 +39,29 @@ void test1(const char *res, const char *fmt, ...) ok(strlen(res) == len && strcmp(buf, res) == 0, "\"%s\"", buf); } +static void test_many(const char **res, const char *fmt, ...) +{ + va_list args; + size_t len; + va_start(args,fmt); + len= my_vsnprintf(buf, sizeof(buf)-1, fmt, args); + va_end(args); + + for (; *res ; res++) + { + if (strlen(*res) == len && strcmp(buf, *res) == 0) + { + ok(1, "\"%s\"", buf); + return; + } + } + ok(0, "\"%s\"", buf); +} + + int main(void) { - plan(58); + plan(39); test1("Constant string", "Constant string"); @@ -121,61 +151,32 @@ int main(void) test1("G with a width (ignored) and precision: <12.35>", "G with a width (ignored) and precision: <%10.5g>", 12.3456789); - diag("================================================================"); - - test1("Hello", - "Hello"); - test1("Hello int, 1", - "Hello int, %d", 1); - test1("Hello int, -1", - "Hello int, %d", -1); - test1("Hello int, 1", - "Hello int, %i", 1); - test1("Hello int, -1", - "Hello int, %i", -1); - test1("Hello string 'I am a string'", - "Hello string '%s'", "I am a string"); - test1("Hello hack hack hack hack hack hack hack 1", - "Hello hack hack hack hack hack hack hack %d", 1); - test1("Hello 1 hack 4", - "Hello %d hack %d", 1, 4); - test1("Hello 1 hack hack hack hack hack 4", - "Hello %d hack hack hack hack hack %d", 1, 4); - test1("Hello 'hack' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", - "Hello '%s' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", "hack"); - test1("Hello hhhhhhhhhhhhhh 1 sssssssssssssss", - "Hello hhhhhhhhhhhhhh %d sssssssssssssss", 1); - test1("Hello 1", - "Hello %u", 1); - test1("Hello 4294967295", - "Hello %u", -1); - test1("Hex: 20 ' 41'", - "Hex: %lx '%6lx'", 32, 65); - test1("conn 1 to: '(null)' user: '(null)' host: '(null)' ((null))", - "conn %ld to: '%-.64s' user: '%-.32s' host: '%-.64s' (%-.64s)", - 1L, NULL, NULL, NULL, NULL); - test1("Hello string `I am a string`", - "Hello string %`s", "I am a string"); - test1("Hello TEST", - "Hello %05s", "TEST"); - test1("My `Q` test", - "My %1$`-.1s test", "QQQQ"); - test1("My AAAA test done DDDD", - "My %2$s test done %1$s", "DDDD", "AAAA"); - test1("My DDDD test CCCC, DDD", - "My %1$s test %2$s, %1$-.3s", "DDDD", "CCCC"); - test1("My QQQQ test", - "My %1$`-.4b test", "QQQQ"); - test1("My X test", - "My %1$c test", 'X'); - test1("My <0000000010> test1 < a> test2 < A>", - "My <%010d> test1 <%4x> test2 <%4X>", 10, 10, 10); - test1("My <0000000010> test1 < a> test2 < a>", - "My <%1$010d> test1 <%2$4x> test2 <%2$4x>", 10, 10); - test1("My 00010 test", - "My %1$*02$d test", 10, 5); - test1("My `DDDD` test CCCC, `DDD`", - "My %1$`s test %2$s, %1$`-.3s", "DDDD", "CCCC"); + { + /* Test that %M works */ + const char *results[]= + { + "Error 1 \"Operation not permitted\"", /* Linux */ + "Error 1 \"Not owner\"", /* Solaris */ + NullS + }; + test_many(results, "Error %M", 1); + } + + test1("M with 0 error code: 0 \"Internal error/check (Not system error)\"", + "M with 0 error code: %M", 0); + + test1("M with positional: 0 \"Internal error/check (Not system error)\"", + "M with positional: %1$M", 0); + + test1("M with width: 0 \"Internal error/ch", + "M with width: %.20M", 0); + test1("M with width positional: 0 \"Internal error/ch", + "M with width positional: %2$.*1$M", 20, 0); + + test_w_len("M small buf: 0 \"In", + 19, "M small buf: %M", 0); + test_w_len("M small buf positional: 0 \"In", + 30, "M small buf positional: %1$M", 0); return exit_status(); } diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index f80f2a5ae70..7cc05e8cea2 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -13,6 +13,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +MY_ADD_TESTS(my_apc LINK_LIBRARIES mysys EXT cc) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/unittest/mytap @@ -27,3 +29,4 @@ ENDIF() TARGET_LINK_LIBRARIES(explain_filename-t sql mytap) ADD_TEST(explain_filename explain_filename-t) + diff --git a/unittest/sql/explain_filename-t.cc b/unittest/sql/explain_filename-t.cc index 4f09f65f0a7..69ce51c0446 100644 --- a/unittest/sql/explain_filename-t.cc +++ b/unittest/sql/explain_filename-t.cc @@ -61,8 +61,9 @@ void test_1(const char *in, const char *exp, enum_explain_filename_mode mode) ok( (pass && length) , "(%d): %s => %s\n", mode, in, out); } -int main() +int main(int argc __attribute__((unused)),char *argv[]) { + MY_INIT(argv[0]); setup(); plan(22); @@ -158,6 +159,7 @@ int main() "\"test\".\"t@0023#\"", EXPLAIN_PARTITIONS_AS_COMMENT); + my_end(0); return exit_status(); } diff --git a/unittest/sql/my_apc-t.cc b/unittest/sql/my_apc-t.cc new file mode 100644 index 00000000000..80bbc6b6e56 --- /dev/null +++ b/unittest/sql/my_apc-t.cc @@ -0,0 +1,229 @@ +/* + Copyright (c) 2012, Monty Program Ab + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* + This file does standalone APC system tests. +*/ +#include <my_global.h> +#include <my_pthread.h> +#include <my_sys.h> + +#include <stdio.h> + +#include <tap.h> + +/* + A fake THD with enter_cond/exit_cond and some other members. +*/ +PSI_stage_info stage_show_explain; +class THD +{ + mysql_mutex_t* thd_mutex; +public: + bool killed; + + THD() : killed(FALSE) {} + inline const char* ENTER_COND(mysql_cond_t *cond, mysql_mutex_t* mutex, + PSI_stage_info*, PSI_stage_info*) + { + mysql_mutex_assert_owner(mutex); + thd_mutex= mutex; + return NULL; + } + inline void EXIT_COND(PSI_stage_info*) + { + mysql_mutex_unlock(thd_mutex); + } +}; + +#include "../sql/my_apc.h" + +#define MY_APC_STANDALONE 1 +#include "../sql/my_apc.cc" + +volatile bool started= FALSE; +volatile bool service_should_exit= FALSE; +volatile bool requestors_should_exit=FALSE; + +/* Counters for APC calls */ +int apcs_served= 0; +int apcs_missed=0; +int apcs_timed_out=0; +mysql_mutex_t apc_counters_mutex; + +inline void increment_counter(int *var) +{ + mysql_mutex_lock(&apc_counters_mutex); + *var= *var+1; + mysql_mutex_unlock(&apc_counters_mutex); +} + +volatile bool have_errors= false; + +Apc_target apc_target; +mysql_mutex_t target_mutex; + +int int_rand(int size) +{ + return (int) (0.5 + ((double)rand() / RAND_MAX) * size); +} + +/* + APC target thread (the one that will serve the APC requests). We will have + one target. +*/ +void *test_apc_service_thread(void *ptr) +{ + my_thread_init(); + mysql_mutex_init(0, &target_mutex, MY_MUTEX_INIT_FAST); + apc_target.init(&target_mutex); + apc_target.enable(); + started= TRUE; + diag("test_apc_service_thread started"); + while (!service_should_exit) + { + //apc_target.disable(); + my_sleep(10000); + //apc_target.enable(); + for (int i = 0; i < 10 && !service_should_exit; i++) + { + apc_target.process_apc_requests(); + my_sleep(int_rand(30)); + } + } + apc_target.disable(); + apc_target.destroy(); + mysql_mutex_destroy(&target_mutex); + my_thread_end(); + pthread_exit(0); + return NULL; +} + + +/* + One APC request (to write 'value' into *where_to) +*/ +class Apc_order : public Apc_target::Apc_call +{ +public: + int value; // The value + int *where_to; // Where to write it + Apc_order(int a, int *b) : value(a), where_to(b) {} + + void call_in_target_thread() + { + my_sleep(int_rand(1000)); + *where_to = value; + increment_counter(&apcs_served); + } +}; + + +/* + APC requestor thread. It makes APC requests, and checks if they were actually + executed. +*/ +void *test_apc_requestor_thread(void *ptr) +{ + my_thread_init(); + diag("test_apc_requestor_thread started"); + THD my_thd; + + while (!requestors_should_exit) + { + int dst_value= 0; + int src_value= int_rand(4*1000*100); + /* Create an APC to do "dst_value= src_value" assignment */ + Apc_order apc_order(src_value, &dst_value); + bool timed_out; + + mysql_mutex_lock(&target_mutex); + bool res= apc_target.make_apc_call(&my_thd, &apc_order, 60, &timed_out); + if (res) + { + if (timed_out) + increment_counter(&apcs_timed_out); + else + increment_counter(&apcs_missed); + + if (dst_value != 0) + { + diag("APC was done even though return value says it wasnt!"); + have_errors= true; + } + } + else + { + if (dst_value != src_value) + { + diag("APC was not done even though return value says it was!"); + have_errors= true; + } + } + //my_sleep(300); + } + diag("test_apc_requestor_thread exiting"); + my_thread_end(); + return NULL; +} + +/* Number of APC requestor threads */ +const int N_THREADS=23; + + +int main(int args, char **argv) +{ + pthread_t service_thr; + pthread_t request_thr[N_THREADS]; + int i; + + my_thread_global_init(); + + mysql_mutex_init(0, &apc_counters_mutex, MY_MUTEX_INIT_FAST); + + plan(1); + diag("Testing APC delivery and execution"); + + pthread_create(&service_thr, NULL, test_apc_service_thread, (void*)NULL); + while (!started) + my_sleep(1000); + for (i = 0; i < N_THREADS; i++) + pthread_create(&request_thr[i], NULL, test_apc_requestor_thread, (void*)NULL); + + for (i = 0; i < 15; i++) + { + my_sleep(500*1000); + diag("%d APCs served %d missed", apcs_served, apcs_missed); + } + diag("Shutting down requestors"); + requestors_should_exit= TRUE; + for (i = 0; i < N_THREADS; i++) + pthread_join(request_thr[i], NULL); + + diag("Shutting down service"); + service_should_exit= TRUE; + pthread_join(service_thr, NULL); + + mysql_mutex_destroy(&apc_counters_mutex); + + diag("Done"); + my_thread_end(); + my_thread_global_end(); + + ok1(!have_errors); + return exit_status(); +} + |