diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-01 18:15:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-01 18:15:00 +0000 |
commit | a2a2e32c02643a0cec111511220227703fda1cd5 (patch) | |
tree | 69cc2b631234c2a8e026b9cd4d72676c61c594df /libmariadb/unittest | |
parent | Releasing progress-linux version 1:10.11.8-1~progress7.99u1. (diff) | |
download | mariadb-a2a2e32c02643a0cec111511220227703fda1cd5.tar.xz mariadb-a2a2e32c02643a0cec111511220227703fda1cd5.zip |
Merging upstream version 1:11.4.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libmariadb/unittest')
-rw-r--r-- | libmariadb/unittest/libmariadb/CMakeLists.txt | 4 | ||||
-rw-r--r-- | libmariadb/unittest/libmariadb/bulk1.c | 350 | ||||
-rw-r--r-- | libmariadb/unittest/libmariadb/charset.c | 9 | ||||
-rw-r--r-- | libmariadb/unittest/libmariadb/connection.c | 47 | ||||
-rw-r--r-- | libmariadb/unittest/libmariadb/misc.c | 30 | ||||
-rw-r--r-- | libmariadb/unittest/libmariadb/my_test.h | 24 | ||||
-rw-r--r-- | libmariadb/unittest/libmariadb/ps_bugs.c | 70 | ||||
-rw-r--r-- | libmariadb/unittest/libmariadb/rpl_api.c | 80 |
8 files changed, 601 insertions, 13 deletions
diff --git a/libmariadb/unittest/libmariadb/CMakeLists.txt b/libmariadb/unittest/libmariadb/CMakeLists.txt index 876e5cfc..d5b93716 100644 --- a/libmariadb/unittest/libmariadb/CMakeLists.txt +++ b/libmariadb/unittest/libmariadb/CMakeLists.txt @@ -31,7 +31,9 @@ IF(WITH_DYNCOL) SET(API_TESTS ${API_TESTS} "dyncol") ENDIF() -SET(API_TESTS ${API_TESTS} "async") +IF(NOT WIN32) + SET(API_TESTS ${API_TESTS} "async") +ENDIF() #exclude following tests from ctests, since we need to run them manually with different credentials SET(MANUAL_TESTS "t_conc173" "rpl_api") diff --git a/libmariadb/unittest/libmariadb/bulk1.c b/libmariadb/unittest/libmariadb/bulk1.c index 62267cd7..56ae20d8 100644 --- a/libmariadb/unittest/libmariadb/bulk1.c +++ b/libmariadb/unittest/libmariadb/bulk1.c @@ -21,6 +21,12 @@ static my_bool bulk_enabled= 0; +#define SERVER_SUPPORT_BULK_UNIT_RESULTS(mysql)\ + (!(mysql->server_capabilities & CLIENT_MYSQL) &&\ + (mysql->extension->mariadb_server_capabilities & \ + (MARIADB_CLIENT_BULK_UNIT_RESULTS >> 32))) + + char *rand_str(size_t length) { const char charset[] = "0123456789" "abcdefghijklmnopqrstuvwxyz" @@ -57,11 +63,14 @@ static int bulk1(MYSQL *mysql) MYSQL_RES *res; MYSQL_ROW row; unsigned int intval; + my_bool bool_val; if (!bulk_enabled) return SKIP; rc= mysql_select_db(mysql, "testc"); + mysql_get_option(mysql, MARIADB_OPT_BULK_UNIT_RESULTS, &bool_val); + FAIL_IF(bool_val, "bool_val == true"); rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk1"); check_mysql_rc(rc, mysql); @@ -1067,6 +1076,344 @@ static int test_mdev16593(MYSQL *mysql) return OK; } +static int bulk_with_unit_result_insert(MYSQL *my) +{ + my_bool unique_result= 1; + my_bool bool_val; + MYSQL *mysql; + MYSQL_STMT *stmt; + unsigned int array_size= TEST_ARRAY_SIZE; + int rc, rowcount= 0; + unsigned int i; + char **buffer; + unsigned long *lengths; + MYSQL_BIND bind[1]; + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL_BIND bind_out[2]; + int id, affected_rows = 0; + int expectedId = 1; + unsigned int intval; + + SKIP_MAXSCALE; + if (!SERVER_SUPPORT_BULK_UNIT_RESULTS(my)) + { + diag("Server doesn't support bulk unit results"); + return SKIP; + } + + mysql= mysql_init(NULL); + stmt= mysql_stmt_init(mysql); + mysql_options(mysql, MARIADB_OPT_BULK_UNIT_RESULTS, &unique_result); + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(mysql)); + mysql_get_option(mysql, MARIADB_OPT_BULK_UNIT_RESULTS, &bool_val); + FAIL_UNLESS(bool_val, "bool_val != true"); + + if (!bulk_enabled) + return SKIP; + + rc= mysql_select_db(mysql, "testc"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_with_unit_result_insert"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bulk_with_unit_result_insert (a int NOT NULL AUTO_INCREMENT, b VARCHAR(255), PRIMARY KEY (a)) engine=MyISAM"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO bulk_with_unit_result_insert(b) VALUES (?)")); + check_stmt_rc(rc, stmt); + + /* allocate memory */ + buffer= calloc(TEST_ARRAY_SIZE, sizeof(char *)); + lengths= (unsigned long *)calloc(sizeof(long), TEST_ARRAY_SIZE); + + for (i=0; i < TEST_ARRAY_SIZE; i++) + { + buffer[i]= rand_str(254); + lengths[i]= -1; + } + + memset(bind, 0, sizeof(MYSQL_BIND) * 1); + memset(bind_out, '\0', sizeof(bind_out)); + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer= (void *)buffer; + bind[0].length= (unsigned long *)lengths; + + bind_out[0].buffer_type= MYSQL_TYPE_LONG; + bind_out[0].buffer= (void*) &id; + bind_out[1].buffer_type= MYSQL_TYPE_LONG; + bind_out[1].buffer= (void*) &affected_rows; + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + for (i=0; i < 100; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_result(stmt, bind_out); + check_stmt_rc(rc, stmt); + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + { + rowcount++; + // diag("id:%llu expected %llu", id, expectedId); + FAIL_UNLESS(id == expectedId, "id != expectedId"); + expectedId++; + // diag("affected_rows:%llu", affected_rows); + FAIL_UNLESS(affected_rows == 1, "affected_rows != 1"); + } + // test can be improved depending on auto_increment_increment/auto_increment_offset... + FAIL_IF(rowcount != TEST_ARRAY_SIZE, "rowcount != TEST_ARRAY_SIZE"); + } + + for (i=0; i < array_size; i++) + free(buffer[i]); + + free(buffer); + free(lengths); + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT COUNT(*) FROM bulk_with_unit_result_insert"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + intval= atoi(row[0]); + mysql_free_result(res); + FAIL_IF(intval != array_size * 100, "Expected 102400 rows"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_with_unit_result_insert"); + check_mysql_rc(rc, mysql); + mysql_close(mysql); + check_mysql_rc(rc, my); + return OK; +} + +static int bulk_with_unit_result_delete(MYSQL *my) +{ + my_bool unique_result= 1; + unsigned int array_size= 5; + int rc, rowcount= 0; + unsigned int i, j; + MYSQL_BIND bind[1]; + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL_BIND bind_out[2]; + unsigned int *vals; + int id, affected_rows = 0; + unsigned int intval; + MYSQL *mysql; + MYSQL_STMT *stmt; + + SKIP_MAXSCALE; + if (!SERVER_SUPPORT_BULK_UNIT_RESULTS(my)) + { + diag("Server doesn't support bulk unit results"); + return SKIP; + } + + mysql= mysql_init(NULL); + stmt= mysql_stmt_init(mysql); + mysql_options(mysql, MARIADB_OPT_BULK_UNIT_RESULTS, &unique_result); + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(mysql)); + + if (!bulk_enabled) + return SKIP; + + rc= mysql_select_db(mysql, "testc"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_with_unit_result_delete"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bulk_with_unit_result_delete (a int NOT NULL AUTO_INCREMENT, b VARCHAR(255), PRIMARY KEY (a))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO bulk_with_unit_result_delete(b) with recursive cte (seq) as (select 1 union all select seq+1 from cte where seq < 100) select concat(seq, 'test') from cte"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("DELETE FROM bulk_with_unit_result_delete WHERE a = ?")); + check_stmt_rc(rc, stmt); + + memset(bind_out, '\0', sizeof(bind_out)); + bind_out[0].buffer_type= MYSQL_TYPE_LONG; + bind_out[0].buffer= (void*) &id; + bind_out[1].buffer_type= MYSQL_TYPE_LONG; + bind_out[1].buffer= (void*) &affected_rows; + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + vals= (unsigned int *)calloc(sizeof(int), 5); + memset(bind, 0, sizeof(MYSQL_BIND) * 1); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= vals; + + for (i=0; i < 10; i++) + { + for (j=0; j < 5; j++) + vals[j]= 1 + j * 2 + i * 10; + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_result(stmt, bind_out); + check_stmt_rc(rc, stmt); + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + { + rowcount++; + FAIL_UNLESS(id == 0, "id != 0"); + FAIL_UNLESS(affected_rows == 1, "affected_rows != 1"); + } + // test can be improved depending on auto_increment_increment/auto_increment_offset... + FAIL_UNLESS(rowcount == 5, "rowcount != 5"); + } + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + free(vals); + rc= mysql_query(mysql, "SELECT a FROM bulk_with_unit_result_delete"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + rowcount= 0; + for (i=1; i < 51; i++) + { + row=mysql_fetch_row(res); + intval = atoi(row[0]); + FAIL_UNLESS(intval == i * 2, "intval != i * 2"); + } + mysql_free_result(res); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_with_unit_result_delete"); + check_mysql_rc(rc, mysql); + mysql_close(mysql); + check_mysql_rc(rc, my); + return OK; +} + + +static int bulk_with_unit_result_update(MYSQL *my) +{ + my_bool unique_result= 1; + unsigned int array_size= 5; + int rc, rowcount= 0; + unsigned int i, j; + MYSQL_BIND bind[1]; + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL_BIND bind_out[2]; + unsigned int *vals; + int id, affected_rows = 0; + char str[50]; + MYSQL *mysql; + MYSQL_STMT *stmt; + + SKIP_MAXSCALE; + if (!SERVER_SUPPORT_BULK_UNIT_RESULTS(my)) + { + diag("Server doesn't support bulk unit results"); + return SKIP; + } + + mysql= mysql_init(NULL); + stmt= mysql_stmt_init(mysql); + + mysql_options(mysql, MARIADB_OPT_BULK_UNIT_RESULTS, &unique_result); + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(mysql)); + + if (!bulk_enabled) + return SKIP; + + rc= mysql_select_db(mysql, "testc"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_with_unit_result_update"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bulk_with_unit_result_update (a int NOT NULL AUTO_INCREMENT, b VARCHAR(255), PRIMARY KEY (a))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO bulk_with_unit_result_update(b) with recursive cte (seq) as (select 1 union all select seq+1 from cte where seq < 100) select concat(seq, 'test') from cte"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("UPDATE bulk_with_unit_result_update SET b=CONCAT(b,'added') WHERE a = ?")); + check_stmt_rc(rc, stmt); + + memset(bind_out, '\0', sizeof(bind_out)); + bind_out[0].buffer_type= MYSQL_TYPE_LONG; + bind_out[0].buffer= (void*) &id; + bind_out[1].buffer_type= MYSQL_TYPE_LONG; + bind_out[1].buffer= (void*) &affected_rows; + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + vals= (unsigned int *)calloc(sizeof(int), 5); + memset(bind, 0, sizeof(MYSQL_BIND) * 1); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= vals; + + for (i=0; i < 10; i++) + { + for (j=0; j < 5; j++) + vals[j]= 1 + j * 2 + i * 10; + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_result(stmt, bind_out); + check_stmt_rc(rc, stmt); + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + { + rowcount++; + FAIL_UNLESS(id == 0, "id != 0"); + FAIL_UNLESS(affected_rows == 1, "affected_rows != 1"); + } + // test can be improved depending on auto_increment_increment/auto_increment_offset... + FAIL_UNLESS(rowcount == 5, "rowcount != 5"); + } + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + free(vals); + rc= mysql_query(mysql, "SELECT b FROM bulk_with_unit_result_update"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + rowcount= 0; + for (i=1; i < 101; i++) + { + row=mysql_fetch_row(res); + if (i % 2 == 0) { + sprintf(str, "%dtest", i); + } else { + sprintf(str, "%dtestadded", i); + } + FAIL_IF(strcmp(row[0], str) != 0, "strcmp(row[0], str) != 0"); + } + mysql_free_result(res); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_with_unit_result_update"); + check_mysql_rc(rc, mysql); + mysql_close(mysql); + check_mysql_rc(rc, my); + return OK; +} + struct my_tests_st my_tests[] = { {"check_bulk", check_bulk, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_mdev16593", test_mdev16593, TEST_CONNECTION_NEW, 0, NULL, NULL}, @@ -1083,6 +1430,9 @@ struct my_tests_st my_tests[] = { {"bulk4", bulk4, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"bulk_null", bulk_null, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"bulk_skip_row", bulk_skip_row, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk_with_unit_result_insert", bulk_with_unit_result_insert, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk_with_unit_result_delete", bulk_with_unit_result_delete, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk_with_unit_result_update", bulk_with_unit_result_update, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {NULL, NULL, 0, 0, NULL, NULL} }; diff --git a/libmariadb/unittest/libmariadb/charset.c b/libmariadb/unittest/libmariadb/charset.c index 4d17731f..35ae716f 100644 --- a/libmariadb/unittest/libmariadb/charset.c +++ b/libmariadb/unittest/libmariadb/charset.c @@ -794,6 +794,10 @@ static int test_conc223(MYSQL *mysql) MYSQL_ROW row; int found= 0; int mdev27266= 0; + int unsupported[]= { + 579, /* utf8mb3_general1400_as_ci added in 11.5 */ + 611, /* utf8mb4_general1400_as_ci added in 11.5 */ + 0}; SKIP_MYSQL(mysql); @@ -839,8 +843,11 @@ static int test_conc223(MYSQL *mysql) id= atoi(row[0]); if (!mariadb_get_charset_by_nr(id)) { - diag("%04d %s %s", id, row[1], row[2]); + int j=0; found++; + for (j=0; unsupported[j]; j++) + if (unsupported[j] == id) + found--; } } } diff --git a/libmariadb/unittest/libmariadb/connection.c b/libmariadb/unittest/libmariadb/connection.c index a10e01bd..bd4e0e0a 100644 --- a/libmariadb/unittest/libmariadb/connection.c +++ b/libmariadb/unittest/libmariadb/connection.c @@ -686,6 +686,7 @@ int test_connection_timeout2(MYSQL *unused __attribute__((unused))) unsigned int timeout= 5; time_t start, elapsed; MYSQL *mysql; + my_bool no= 0; SKIP_SKYSQL; SKIP_MAXSCALE; @@ -694,6 +695,7 @@ int test_connection_timeout2(MYSQL *unused __attribute__((unused))) mysql= mysql_init(NULL); mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (unsigned int *)&timeout); mysql_options(mysql, MYSQL_INIT_COMMAND, "set @a:=SLEEP(7)"); + mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &no); start= time(NULL); if (my_test_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_REMEMBER_OPTIONS)) { @@ -1378,7 +1380,6 @@ static int test_conc276(MYSQL *unused __attribute__((unused))) return FAIL; } diag("Cipher in use: %s", mysql_get_ssl_cipher(mysql)); - rc= mariadb_reconnect(mysql); check_mysql_rc(rc, mysql); @@ -2307,6 +2308,49 @@ static int test_conc632(MYSQL *my __attribute__((unused))) return OK; } +static int test_x509(MYSQL *my __attribute__((unused))) +{ + MYSQL *mysql1, *mysql2; + my_bool val= 1; + my_bool verify= 0; + char fp[65]; + MARIADB_X509_INFO *info; + + SKIP_MAXSCALE; + + mysql1= mysql_init(NULL); + mysql2= mysql_init(NULL); + + mysql_options(mysql1, MYSQL_OPT_SSL_ENFORCE, &val); + mysql_options(mysql2, MYSQL_OPT_SSL_ENFORCE, &val); + + mysql_options(mysql1, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify); + if (!(my_test_connect(mysql1, hostname, username, + password, schema, port, + socketname, 0))) + { + diag("connection failed"); + return FAIL; + } + mariadb_get_infov(mysql1, MARIADB_TLS_PEER_CERT_INFO, &info); + memset(fp, 0, 65); + diag("fingerprint: %s", info->fingerprint); + mysql_options(mysql2, MARIADB_OPT_TLS_PEER_FP, info->fingerprint); + if (!(my_test_connect(mysql2, hostname, username, + password, schema, port, + socketname, 0))) + { + diag("connection failed"); + return FAIL; + } + mariadb_get_infov(mysql2, MARIADB_TLS_PEER_CERT_INFO, &info); + FAIL_IF(info->verify_mode != MARIADB_VERIFY_FINGERPRINT, "Fingerprint verification expected"); + + mysql_close(mysql1); + mysql_close(mysql2); + return OK; +} + static int test_conc505(MYSQL *my __attribute__((unused))) { MYSQL *mysql= mysql_init(NULL); @@ -2333,6 +2377,7 @@ static int test_conc505(MYSQL *my __attribute__((unused))) } struct my_tests_st my_tests[] = { + {"test_x509", test_x509, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_conc505", test_conc505, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_conc632", test_conc632, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_status_callback", test_status_callback, TEST_CONNECTION_NONE, 0, NULL, NULL}, diff --git a/libmariadb/unittest/libmariadb/misc.c b/libmariadb/unittest/libmariadb/misc.c index f67d1366..47f2f523 100644 --- a/libmariadb/unittest/libmariadb/misc.c +++ b/libmariadb/unittest/libmariadb/misc.c @@ -1628,7 +1628,37 @@ static int test_ext_field_attr(MYSQL *mysql) return OK; } +static int test_disable_tls1_0(MYSQL *my __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + const char *disabled_version= "TLSv1.0"; + MYSQL_RES *result; + MYSQL_ROW row; + int rc; + + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + mysql_optionsv(mysql, MARIADB_OPT_TLS_VERSION, disabled_version); + + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(mysql)); + + rc= mysql_query(mysql, "SHOW STATUS LIKE 'ssl_version'"); + check_mysql_rc(rc, mysql); + + result = mysql_store_result(mysql); + row= mysql_fetch_row(result); + + FAIL_IF(!strcmp(row[1], "TLSv1.0"), "TLS 1.0 should be disabled!"); + + mysql_free_result(result); + + mysql_close(mysql); + return OK; +} + + struct my_tests_st my_tests[] = { + {"test_disable_tls1_0", test_disable_tls1_0, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_ext_field_attr", test_ext_field_attr, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc533", test_conc533, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_conc458", test_conc458, TEST_CONNECTION_NONE, 0, NULL, NULL}, diff --git a/libmariadb/unittest/libmariadb/my_test.h b/libmariadb/unittest/libmariadb/my_test.h index 9f75d67a..3184b80d 100644 --- a/libmariadb/unittest/libmariadb/my_test.h +++ b/libmariadb/unittest/libmariadb/my_test.h @@ -76,7 +76,7 @@ if (IS_SKYSQL(hostname)) \ #endif #define SKIP_TLS \ -if (force_tls)\ +if (force_tls || fingerprint[0])\ {\ diag("Test doesn't work with TLS");\ return SKIP;\ @@ -224,6 +224,7 @@ MYSQL *my_test_connect(MYSQL *mysql, static const char *schema = 0; static char *hostname = 0; static char *password = 0; +static char fingerprint[65]; static unsigned int port = 0; static unsigned int ssl_port = 0; static char *socketname = 0; @@ -656,7 +657,9 @@ MYSQL *my_test_connect(MYSQL *mysql, unsigned long clientflag) { if (force_tls) - mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &force_tls); + mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &force_tls); + if (fingerprint[0]) + mysql_options(mysql, MARIADB_OPT_SSL_FP, fingerprint); if (!mysql_real_connect(mysql, host, user, passwd, db, port, unix_socket, clientflag)) { diag("error: %s", mysql_error(mysql)); @@ -677,6 +680,8 @@ MYSQL *my_test_connect(MYSQL *mysql, void run_tests(struct my_tests_st *test) { int i, rc, total=0; MYSQL *mysql; + my_bool verify= 0; + MARIADB_X509_INFO *info= NULL; while (test[total].function) total++; @@ -684,13 +689,15 @@ void run_tests(struct my_tests_st *test) { /* display TLS stats */ mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify); mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); if (!mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0)) { + diag("Error: %s", mysql_error(mysql)); BAIL_OUT("Can't establish TLS connection to server."); } - + fingerprint[0]= 0; if (!mysql_query(mysql, "SHOW VARIABLES LIKE '%ssl%'")) { MYSQL_RES *res; @@ -703,8 +710,15 @@ void run_tests(struct my_tests_st *test) { while ((row= mysql_fetch_row(res))) diag("%s: %s", row[0], row[1]); mysql_free_result(res); - diag("Cipher in use: %s", mysql_get_ssl_cipher(mysql)); - diag("--------------------"); + if (mysql_get_ssl_cipher(mysql)) + diag("Cipher in use: %s", mysql_get_ssl_cipher(mysql)); + mariadb_get_infov(mysql, MARIADB_TLS_PEER_CERT_INFO, &info); + if (info) + { + strcpy(fingerprint, info->fingerprint); + diag("Peer certificate fingerprint: %s", fingerprint); + diag("--------------------"); + } } mysql_close(mysql); diff --git a/libmariadb/unittest/libmariadb/ps_bugs.c b/libmariadb/unittest/libmariadb/ps_bugs.c index 72af30b4..7a581ad8 100644 --- a/libmariadb/unittest/libmariadb/ps_bugs.c +++ b/libmariadb/unittest/libmariadb/ps_bugs.c @@ -5741,7 +5741,77 @@ end: return ret; } +static int test_conc667(MYSQL *mysql) +{ + MYSQL_STMT *stmt1, *stmt2; + int rc; + + stmt1= mysql_stmt_init(mysql); + stmt2= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt1, "SELECT 1", -1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_prepare(stmt2, "SELECT 2", -1); + check_stmt_rc(rc, stmt2); + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_free_result(stmt2); + FAIL_IF(!rc || mysql_stmt_errno(stmt2) != CR_STMT_NO_RESULT, + "Expected CR_STMT_NO_RESULT"); + diag("Error (expected) %s", mysql_stmt_error(stmt2)); + + rc= mysql_stmt_reset(stmt2); + FAIL_IF(!rc || mysql_stmt_errno(stmt2) != CR_COMMANDS_OUT_OF_SYNC, + "Expected commands out of sync error"); + + rc= mysql_stmt_fetch(stmt1); + check_stmt_rc(rc, stmt1); + + mysql_stmt_free_result(stmt1); + + rc= mysql_stmt_close(stmt1); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_close(stmt2); + check_stmt_rc(rc, stmt2); + + return OK; +} + +static int test_conc683(MYSQL *mysql) +{ + MYSQL_STMT *stmt1, *stmt2; + int rc; + + stmt1= mysql_stmt_init(mysql); + stmt2= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt1, "SELECT 1 UNION SELECT 2", -1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_prepare(stmt2, "SELECT 1", -1); + check_stmt_rc(rc, stmt2); + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_close(stmt2); + FAIL_IF(!rc || mysql_stmt_errno(stmt2) != CR_COMMANDS_OUT_OF_SYNC, + "Expected commands out of sync error"); + + rc= mysql_stmt_close(stmt1); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_close(stmt2); + check_stmt_rc(rc, stmt2); + + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc683", test_conc683, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc667", test_conc667, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc633", test_conc633, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc623", test_conc623, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc627", test_conc627, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, diff --git a/libmariadb/unittest/libmariadb/rpl_api.c b/libmariadb/unittest/libmariadb/rpl_api.c index f65a2915..b502eec8 100644 --- a/libmariadb/unittest/libmariadb/rpl_api.c +++ b/libmariadb/unittest/libmariadb/rpl_api.c @@ -72,6 +72,7 @@ static int test_rpl_async(MYSQL *my __attribute__((unused))) mysql_query(mysql, "SET @mariadb_slave_capability=4"); mysql_query(mysql, "SET NAMES latin1"); mysql_query(mysql, "SET @slave_gtid_strict_mode=1"); + mysql_query(mysql, "SET @master_heartbeat_period=10"); mysql_query(mysql, "SET @slave_gtid_ignore_duplicates=1"); mysql_query(mysql, "SET NAMES utf8"); mysql_query(mysql, "SET @master_binlog_checksum= @@global.binlog_checksum"); @@ -85,7 +86,7 @@ static int test_rpl_async(MYSQL *my __attribute__((unused))) /* We run rpl_api as very last test, too make sure binary log contains > 10000 events. */ - while((event= mariadb_rpl_fetch(rpl, event)) && events < 10000) + while((event= mariadb_rpl_fetch(rpl, event)) && event->event_type != HEARTBEAT_LOG_EVENT) { events++; } @@ -142,6 +143,7 @@ static int test_rpl_semisync(MYSQL *my __attribute__((unused))) mysql_query(mysql, "SET NAMES latin1"); mysql_query(mysql, "SET @slave_gtid_strict_mode=1"); mysql_query(mysql, "SET @slave_gtid_ignore_duplicates=1"); + mysql_query(mysql, "SET @master_heartbeat_period=10"); mysql_query(mysql, "SET NAMES utf8"); mysql_query(mysql, "SET @master_binlog_checksum= @@global.binlog_checksum"); rpl->server_id= 12; @@ -161,10 +163,7 @@ static int test_rpl_semisync(MYSQL *my __attribute__((unused))) if (mariadb_rpl_open(rpl)) return FAIL; - /* We run rpl_api as very last test, too make sure - binary log contains > 10000 events. - */ - while((event= mariadb_rpl_fetch(rpl, event)) && events < 10000) + while((event= mariadb_rpl_fetch(rpl, event)) && event->event_type != HEARTBEAT_LOG_EVENT) { events++; } @@ -341,7 +340,78 @@ static int test_conc592(MYSQL *my __attribute__((unused))) return OK; } +static int test_conc689(MYSQL *my __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + MYSQL_RES *result; + MYSQL_ROW row; + MARIADB_RPL_EVENT *event= NULL; + MARIADB_RPL *rpl; + int events= 0, rc; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + if (!is_mariadb) + return SKIP; + + if (!my_test_connect(mysql, hostname, username, + password, schema, port, socketname, 0)) + { + diag("Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + + rc= mysql_query(mysql, "SELECT @@log_bin"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + row= mysql_fetch_row(result); + if (!atoi(row[0])) + rc= SKIP; + mysql_free_result(result); + + if (rc == SKIP) + { + diag("binary log disabled -> skip"); + mysql_close(mysql); + return SKIP; + } + + rpl = mariadb_rpl_init(mysql); + + mysql_query(mysql, "SET @mariadb_slave_capability=4"); + mysql_query(mysql, "SET NAMES latin1"); + mysql_query(mysql, "SET @slave_gtid_strict_mode=1"); + mysql_query(mysql, "SET @master_heartbeat_period=10"); + mysql_query(mysql, "SET @slave_gtid_ignore_duplicates=1"); + mysql_query(mysql, "SET NAMES utf8"); + mysql_query(mysql, "SET @master_binlog_checksum= @@global.binlog_checksum"); + rpl->server_id= 12; + rpl->start_position= 4; + rpl->flags= MARIADB_RPL_BINLOG_SEND_ANNOTATE_ROWS; + + if (mariadb_rpl_open(rpl)) + return FAIL; + + /* We run rpl_api as very last test, too make sure + binary log contains > 10000 events. + */ + while((event= mariadb_rpl_fetch(rpl, event)) && event->event_type != HEARTBEAT_LOG_EVENT) + { + events++; + } + FAIL_IF(event->event.heartbeat.filename.length == 0, "Invalid filename"); + mariadb_free_rpl_event(event); + mariadb_rpl_close(rpl); + mysql_close(mysql); + return OK; +} + + struct my_tests_st my_tests[] = { + {"test_conc689", test_conc689, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_conc592", test_conc592, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_rpl_async", test_rpl_async, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_rpl_semisync", test_rpl_semisync, TEST_CONNECTION_NEW, 0, NULL, NULL}, |