summaryrefslogtreecommitdiffstats
path: root/storage/innobase/unittest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 18:00:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 18:00:34 +0000
commit3f619478f796eddbba6e39502fe941b285dd97b1 (patch)
treee2c7b5777f728320e5b5542b6213fd3591ba51e2 /storage/innobase/unittest
parentInitial commit. (diff)
downloadmariadb-3f619478f796eddbba6e39502fe941b285dd97b1.tar.xz
mariadb-3f619478f796eddbba6e39502fe941b285dd97b1.zip
Adding upstream version 1:10.11.6.upstream/1%10.11.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/innobase/unittest')
-rw-r--r--storage/innobase/unittest/CMakeLists.txt34
-rw-r--r--storage/innobase/unittest/innodb_fts-t.cc52
-rw-r--r--storage/innobase/unittest/innodb_sync-t.cc185
3 files changed, 271 insertions, 0 deletions
diff --git a/storage/innobase/unittest/CMakeLists.txt b/storage/innobase/unittest/CMakeLists.txt
new file mode 100644
index 00000000..7dd7c111
--- /dev/null
+++ b/storage/innobase/unittest/CMakeLists.txt
@@ -0,0 +1,34 @@
+# Copyright (c) 2021, MariaDB Corporation.
+#
+# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/unittest/mytap
+ ${CMAKE_SOURCE_DIR}/storage/innobase/include
+ ${CMAKE_SOURCE_DIR}/tpool)
+ADD_EXECUTABLE(innodb_fts-t innodb_fts-t.cc)
+TARGET_LINK_LIBRARIES(innodb_fts-t mysys mytap)
+ADD_DEPENDENCIES(innodb_fts-t GenError)
+MY_ADD_TEST(innodb_fts)
+# See explanation in innobase/CmakeLists.txt
+IF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64|powerpc64|s390x")
+ ADD_COMPILE_FLAGS(
+ ../sync/srw_lock.cc
+ COMPILE_FLAGS "-mhtm"
+ )
+ENDIF()
+ADD_EXECUTABLE(innodb_sync-t innodb_sync-t.cc ../sync/srw_lock.cc)
+TARGET_LINK_LIBRARIES(innodb_sync-t mysys mytap)
+ADD_DEPENDENCIES(innodb_sync-t GenError)
+MY_ADD_TEST(innodb_sync)
diff --git a/storage/innobase/unittest/innodb_fts-t.cc b/storage/innobase/unittest/innodb_fts-t.cc
new file mode 100644
index 00000000..72a4ca3a
--- /dev/null
+++ b/storage/innobase/unittest/innodb_fts-t.cc
@@ -0,0 +1,52 @@
+#include "tap.h"
+#include "fts0fts.h"
+#include "fts0vlc.h"
+
+struct fts_encode_info
+{
+ const byte buf[10];
+ size_t len;
+ doc_id_t val;
+};
+
+/* Contains fts encoding min & max value for each length bytes */
+static const fts_encode_info fts_info[]=
+{
+ {{0x80}, 1, 0},
+ {{0xFF}, 1, (1 << 7) - 1},
+ {{0x01, 0x80}, 2, 1 << 7},
+ {{0x7F, 0XFF}, 2, (1 << 14) - 1},
+ {{0x01, 0x00, 0x80}, 3, 1 << 14},
+ {{0x7F, 0X7F, 0XFF}, 3, (1 << 21) - 1},
+ {{0x01, 0x00, 0x00, 0x80}, 4, 1 << 21},
+ {{0x7F, 0X7F, 0X7F, 0xFF}, 4, (1 << 28) - 1},
+ {{0x01, 0x00, 0x00, 0x00, 0x80}, 5, 1 << 28},
+ {{0x7F, 0X7F, 0X7F, 0x7F, 0xFF}, 5, (1ULL << 35) - 1},
+ {{0x01, 0x00, 0x00, 0x00, 0x00, 0x80}, 6, 1ULL << 35},
+ {{0x7F, 0X7F, 0X7F, 0x7F, 0x7F, 0xFF}, 6, (1ULL << 42) - 1},
+ {{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80}, 7, 1ULL << 42},
+ {{0x7F, 0X7F, 0X7F, 0x7F, 0x7F, 0x7F, 0XFF}, 7, (1ULL << 49) - 1},
+ {{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80}, 8, 1ULL << 49},
+ {{0x7F, 0X7F, 0X7F, 0x7F, 0x7F, 0x7F, 0X7F, 0XFF}, 8, (1ULL << 56) -1},
+ {{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80}, 9, 1ULL << 56},
+ {{0x7F, 0X7F, 0X7F, 0x7F, 0x7F, 0x7F, 0X7F, 0x7F, 0XFF}, 9, (1ULL << 63) -1},
+ {{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80}, 10, 1ULL << 63},
+ {{0x01, 0X7F, 0X7F, 0x7F, 0x7F, 0x7F, 0X7F, 0x7F, 0x7F, 0xFF}, 10, ~0ULL}
+};
+
+int main(int, char**)
+{
+ for (int i= array_elements(fts_info); i--;)
+ {
+ byte buf[10];
+ const byte* fts_buf= buf;
+ size_t len= fts_encode_int(fts_info[i].val, buf) - &buf[0];
+ if (fts_info[i].len == len &&
+ !memcmp(&fts_info[i].buf, buf, len) &&
+ fts_decode_vlc(&fts_buf) == fts_info[i].val &&
+ fts_buf == &buf[len])
+ ok(true, "FTS Encoded for %zu bytes", fts_info[i].len);
+ else
+ ok(false, "FTS Encoded for %zu bytes", fts_info[i].len);
+ }
+}
diff --git a/storage/innobase/unittest/innodb_sync-t.cc b/storage/innobase/unittest/innodb_sync-t.cc
new file mode 100644
index 00000000..d0289086
--- /dev/null
+++ b/storage/innobase/unittest/innodb_sync-t.cc
@@ -0,0 +1,185 @@
+/* Copyright (c) 2021, MariaDB Corporation.
+
+ 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
+
+#include <thread>
+#include "tap.h"
+#include "my_sys.h"
+#include "sux_lock.h"
+
+static std::atomic<bool> critical;
+
+ulong srv_n_spin_wait_rounds= 30;
+uint srv_spin_wait_delay= 4;
+
+constexpr unsigned N_THREADS= 30;
+constexpr unsigned N_ROUNDS= 100;
+constexpr unsigned M_ROUNDS= 100;
+
+static srw_mutex m;
+
+static void test_srw_mutex()
+{
+ for (auto i= N_ROUNDS * M_ROUNDS; i--; )
+ {
+ m.wr_lock();
+ assert(!critical);
+ critical= true;
+ critical= false;
+ m.wr_unlock();
+ }
+}
+
+static srw_lock_low l;
+
+static void test_srw_lock()
+{
+ for (auto i= N_ROUNDS; i--; )
+ {
+ l.wr_lock();
+ assert(!critical);
+ critical= true;
+ critical= false;
+ l.wr_unlock();
+
+ for (auto j= M_ROUNDS; j--; )
+ {
+ l.rd_lock();
+ assert(!critical);
+ l.rd_unlock();
+ }
+ }
+}
+
+static ssux_lock_impl<false> ssux;
+
+static void test_ssux_lock()
+{
+ for (auto i= N_ROUNDS; i--; )
+ {
+ ssux.wr_lock();
+ assert(!critical);
+ critical= true;
+ critical= false;
+ ssux.wr_unlock();
+
+ for (auto j= M_ROUNDS; j--; )
+ {
+ ssux.rd_lock();
+ assert(!critical);
+ ssux.rd_unlock();
+ }
+
+ for (auto j= M_ROUNDS; j--; )
+ {
+ ssux.u_lock();
+ assert(!critical);
+ ssux.u_wr_upgrade();
+ assert(!critical);
+ critical= true;
+ critical= false;
+ ssux.wr_u_downgrade();
+ ssux.u_unlock();
+ }
+ }
+}
+
+static sux_lock<ssux_lock_impl<true>> sux;
+
+static void test_sux_lock()
+{
+ for (auto i= N_ROUNDS; i--; )
+ {
+ sux.x_lock();
+ assert(!critical);
+ critical= true;
+ for (auto j= M_ROUNDS; j--; )
+ sux.x_lock();
+ critical= false;
+ for (auto j= M_ROUNDS + 1; j--; )
+ sux.x_unlock();
+
+ for (auto j= M_ROUNDS; j--; )
+ {
+ sux.s_lock();
+ assert(!critical);
+ sux.s_unlock();
+ }
+
+ for (auto j= M_ROUNDS / 2; j--; )
+ {
+ sux.u_lock();
+ assert(!critical);
+ sux.u_lock();
+ sux.u_x_upgrade();
+ assert(!critical);
+ critical= true;
+ sux.x_unlock();
+ critical= false;
+ sux.x_u_downgrade();
+ sux.u_unlock();
+ }
+ }
+}
+
+int main(int argc __attribute__((unused)), char **argv)
+{
+ std::thread t[N_THREADS];
+
+ MY_INIT(argv[0]);
+
+ plan(4);
+
+ m.init();
+ for (auto i= N_THREADS; i--; )
+ t[i]= std::thread(test_srw_mutex);
+
+ for (auto i= N_THREADS; i--; )
+ t[i].join();
+
+ m.destroy();
+ ok(true, "srw_mutex");
+
+ l.init();
+
+ for (auto i= N_THREADS; i--; )
+ t[i]= std::thread(test_srw_lock);
+
+ for (auto i= N_THREADS; i--; )
+ t[i].join();
+
+ ok(true, "srw_lock");
+
+ l.destroy();
+
+ ssux.init();
+ for (auto i= N_THREADS; i--; )
+ t[i]= std::thread(test_ssux_lock);
+
+ for (auto i= N_THREADS; i--; )
+ t[i].join();
+
+ ok(true, "ssux_lock");
+ ssux.destroy();
+
+ sux.init();
+ for (auto i= N_THREADS; i--; )
+ t[i]= std::thread(test_sux_lock);
+
+ for (auto i= N_THREADS; i--; )
+ t[i].join();
+
+ ok(true, "sux_lock");
+ sux.free();
+}