1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

5.5-merge

This commit is contained in:
Sergei Golubchik
2011-07-02 22:08:51 +02:00
3220 changed files with 94894 additions and 422456 deletions

View File

@ -1,27 +0,0 @@
# Copyright (C) 2006 MySQL 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
SUBDIRS = mytap . mysys examples strings
EXTRA_DIST = unit.pl
CLEANFILES = unit
unittests = mytap mysys strings @mysql_se_unittest_dirs@ @mysql_pg_unittest_dirs@ ../dbug
test:
perl unit.pl run $(unittests)
test-verbose:
HARNESS_VERBOSE=1 perl unit.pl run $(unittests)

View File

@ -1,24 +0,0 @@
# Copyright (C) 2006 MySQL 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
AM_CPPFLAGS = -I$(srcdir) -I$(top_builddir)/include \
-I$(top_srcdir)/unittest/mytap -I$(top_srcdir)/include
AM_LDFLAGS = -L$(top_builddir)/unittest/mytap
LDADD = -lmytap
# We omit core-t here, since it will always fail.
noinst_PROGRAMS = simple-t skip-t todo-t skip_all-t no_plan-t

View File

@ -18,11 +18,11 @@
int main() {
plan(4);
ok(1, NULL);
ok(1, NULL);
ok1(1);
ok1(1);
SKIP_BLOCK_IF(1, 2, "Example of skipping a few test points in a test") {
ok(1, NULL);
ok(1, NULL);
ok1(1);
ok1(1);
}
return exit_status();
}

View File

@ -31,9 +31,9 @@ int main() {
if (!has_feature())
skip_all("Example of skipping an entire test");
plan(4);
ok(1, NULL);
ok(1, NULL);
ok(1, NULL);
ok(1, NULL);
ok1(1);
ok1(1);
ok1(1);
ok1(1);
return exit_status();
}

View File

@ -21,15 +21,15 @@
int main()
{
plan(4);
ok(1, NULL);
ok(1, NULL);
ok1(1);
ok1(1);
/*
Tests in the todo region is expected to fail. If they don't,
something is strange.
*/
todo_start("Need to fix these");
ok(0, NULL);
ok(0, NULL);
ok1(0);
ok1(0);
todo_end();
return exit_status();
}

View File

@ -22,7 +22,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
MACRO (MY_ADD_TEST name)
ADD_EXECUTABLE(${name}-t ${name}-t.c)
TARGET_LINK_LIBRARIES(${name}-t mytap mysys)
TARGET_LINK_LIBRARIES(${name}-t mytap mysys strings)
ADD_TEST(${name} ${name}-t)
ENDMACRO()

View File

@ -1,37 +0,0 @@
# Copyright (C) 2009 Sun Microsystems, Inc.
#
# 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-1301 USA
INCLUDES = @ZLIB_INCLUDES@ -I$(top_builddir)/include \
-I$(top_srcdir)/include -I$(top_srcdir)/unittest/mytap
noinst_HEADERS = thr_template.c
noinst_HEADERS = thr_template.c
LDADD = $(top_builddir)/unittest/mytap/libmytap.a \
$(top_builddir)/mysys/libmysys.a \
$(top_builddir)/dbug/libdbug.a \
$(top_builddir)/strings/libmystrings.a
noinst_PROGRAMS = bitmap-t base64-t lf-t my_rdtsc-t my_vsnprintf-t my_malloc-t
if NEED_THREAD
# my_atomic-t is used to check thread functions, so it is safe to
# ignore the file in non-threaded builds.
# In fact, it will not compile without thread support.
noinst_PROGRAMS += my_atomic-t waiting_threads-t
endif
EXTRA_DIST = CMakeLists.txt

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2006 MySQL AB
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
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
@ -24,6 +24,8 @@
#include <tap.h>
#include <m_string.h>
#define MAX_TESTED_BITMAP_SIZE 1024
uint get_rand_bit(uint bitsize)
{
return (rand() % bitsize);
@ -75,12 +77,6 @@ error2:
return TRUE;
}
my_bool test_operators(MY_BITMAP *map __attribute__((unused)),
uint bitsize __attribute__((unused)))
{
return FALSE;
}
my_bool test_get_all_bits(MY_BITMAP *map, uint bitsize)
{
uint i;
@ -129,8 +125,8 @@ my_bool test_compare_operators(MY_BITMAP *map, uint bitsize)
uint no_loops= bitsize > 128 ? 128 : bitsize;
MY_BITMAP map2_obj, map3_obj;
MY_BITMAP *map2= &map2_obj, *map3= &map3_obj;
uint32 map2buf[1024];
uint32 map3buf[1024];
uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
uint32 map3buf[MAX_TESTED_BITMAP_SIZE];
bitmap_init(&map2_obj, map2buf, bitsize, FALSE);
bitmap_init(&map3_obj, map3buf, bitsize, FALSE);
bitmap_clear_all(map2);
@ -257,8 +253,21 @@ error2:
my_bool test_get_first_bit(MY_BITMAP *map, uint bitsize)
{
uint i, test_bit;
uint i, test_bit= 0;
uint no_loops= bitsize > 128 ? 128 : bitsize;
bitmap_set_all(map);
for (i=0; i < bitsize; i++)
bitmap_clear_bit(map, i);
if (bitmap_get_first_set(map) != MY_BIT_NONE)
goto error1;
bitmap_clear_all(map);
for (i=0; i < bitsize; i++)
bitmap_set_bit(map, i);
if (bitmap_get_first(map) != MY_BIT_NONE)
goto error2;
bitmap_clear_all(map);
for (i=0; i < no_loops; i++)
{
test_bit=get_rand_bit(bitsize);
@ -321,6 +330,24 @@ my_bool test_prefix(MY_BITMAP *map, uint bitsize)
goto error3;
bitmap_clear_all(map);
}
for (i=0; i < bitsize; i++)
{
if (bitmap_is_prefix(map, i + 1))
goto error4;
bitmap_set_bit(map, i);
if (!bitmap_is_prefix(map, i + 1))
goto error5;
test_bit=get_rand_bit(bitsize);
bitmap_set_bit(map, test_bit);
if (test_bit <= i && !bitmap_is_prefix(map, i + 1))
goto error5;
else if (test_bit > i)
{
if (bitmap_is_prefix(map, i + 1))
goto error4;
bitmap_clear_bit(map, test_bit);
}
}
return FALSE;
error1:
diag("prefix1 error bitsize = %u, prefix_size = %u", bitsize,test_bit);
@ -331,13 +358,127 @@ error2:
error3:
diag("prefix3 error bitsize = %u, prefix_size = %u", bitsize,test_bit);
return TRUE;
error4:
diag("prefix4 error bitsize = %u, i = %u", bitsize,i);
return TRUE;
error5:
diag("prefix5 error bitsize = %u, i = %u", bitsize,i);
return TRUE;
}
my_bool test_compare(MY_BITMAP *map, uint bitsize)
{
MY_BITMAP map2;
uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
uint i, test_bit;
uint no_loops= bitsize > 128 ? 128 : bitsize;
if (bitmap_init(&map2, map2buf, bitsize, FALSE))
{
diag("init error for bitsize %d", bitsize);
return TRUE;
}
/* Test all 4 possible combinations of set/unset bits. */
for (i=0; i < no_loops; i++)
{
test_bit=get_rand_bit(bitsize);
bitmap_clear_bit(map, test_bit);
bitmap_clear_bit(&map2, test_bit);
if (!bitmap_is_subset(map, &map2))
goto error_is_subset;
bitmap_set_bit(map, test_bit);
if (bitmap_is_subset(map, &map2))
goto error_is_subset;
bitmap_set_bit(&map2, test_bit);
if (!bitmap_is_subset(map, &map2))
goto error_is_subset;
bitmap_clear_bit(map, test_bit);
if (!bitmap_is_subset(map, &map2))
goto error_is_subset;
/* Note that test_bit is not cleared i map2. */
}
bitmap_clear_all(map);
bitmap_clear_all(&map2);
/* Test all 4 possible combinations of set/unset bits. */
for (i=0; i < no_loops; i++)
{
test_bit=get_rand_bit(bitsize);
if (bitmap_is_overlapping(map, &map2))
goto error_is_overlapping;
bitmap_set_bit(map, test_bit);
if (bitmap_is_overlapping(map, &map2))
goto error_is_overlapping;
bitmap_set_bit(&map2, test_bit);
if (!bitmap_is_overlapping(map, &map2))
goto error_is_overlapping;
bitmap_clear_bit(map, test_bit);
if (bitmap_is_overlapping(map, &map2))
goto error_is_overlapping;
bitmap_clear_bit(&map2, test_bit);
/* Note that test_bit is not cleared i map2. */
}
return FALSE;
error_is_subset:
diag("is_subset error bitsize = %u", bitsize);
return TRUE;
error_is_overlapping:
diag("is_overlapping error bitsize = %u", bitsize);
return TRUE;
}
my_bool test_intersect(MY_BITMAP *map, uint bitsize)
{
uint bitsize2 = 1 + get_rand_bit(MAX_TESTED_BITMAP_SIZE - 1);
MY_BITMAP map2;
uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
uint i, test_bit1, test_bit2, test_bit3;
if (bitmap_init(&map2, map2buf, bitsize2, FALSE))
{
diag("init error for bitsize %d", bitsize2);
return TRUE;
}
test_bit1= get_rand_bit(bitsize);
test_bit2= get_rand_bit(bitsize);
bitmap_set_bit(map, test_bit1);
bitmap_set_bit(map, test_bit2);
test_bit3= get_rand_bit(bitsize2);
bitmap_set_bit(&map2, test_bit3);
if (test_bit2 < bitsize2)
bitmap_set_bit(&map2, test_bit2);
bitmap_intersect(map, &map2);
if (test_bit2 < bitsize2)
{
if (!bitmap_is_set(map, test_bit2))
goto error;
bitmap_clear_bit(map, test_bit2);
}
if (test_bit1 == test_bit3)
{
if (!bitmap_is_set(map, test_bit1))
goto error;
bitmap_clear_bit(map, test_bit1);
}
if (!bitmap_is_clear_all(map))
goto error;
bitmap_set_all(map);
bitmap_set_all(&map2);
for (i=0; i < bitsize2; i++)
bitmap_clear_bit(&map2, i);
bitmap_intersect(map, &map2);
if (!bitmap_is_clear_all(map))
goto error;
return FALSE;
error:
diag("intersect error bitsize = %u, bit1 = %u, bit2 = %u, bit3 = %u",
bitsize, test_bit1, test_bit2, test_bit3);
return TRUE;
}
my_bool do_test(uint bitsize)
{
MY_BITMAP map;
uint32 buf[1024];
uint32 buf[MAX_TESTED_BITMAP_SIZE];
if (bitmap_init(&map, buf, bitsize, FALSE))
{
diag("init error for bitsize %d", bitsize);
@ -349,9 +490,6 @@ my_bool do_test(uint bitsize)
if (test_flip_bit(&map,bitsize))
goto error;
bitmap_clear_all(&map);
if (test_operators(&map,bitsize))
goto error;
bitmap_clear_all(&map);
if (test_get_all_bits(&map, bitsize))
goto error;
bitmap_clear_all(&map);
@ -366,8 +504,15 @@ my_bool do_test(uint bitsize)
bitmap_clear_all(&map);
if (test_get_next_bit(&map,bitsize))
goto error;
bitmap_clear_all(&map);
if (test_prefix(&map,bitsize))
goto error;
bitmap_clear_all(&map);
if (test_compare(&map,bitsize))
goto error;
bitmap_clear_all(&map);
if (test_intersect(&map,bitsize))
goto error;
return FALSE;
error:
return TRUE;
@ -377,7 +522,7 @@ int main()
{
int i;
int const min_size = 1;
int const max_size = 1024;
int const max_size = MAX_TESTED_BITMAP_SIZE;
MY_INIT("bitmap-t");
plan(max_size - min_size);

View File

@ -27,6 +27,8 @@ int32 inserts= 0, N;
LF_ALLOCATOR lf_allocator;
LF_HASH lf_hash;
int with_my_thread_init=0;
/*
pin allocator - alloc and release an element in a loop
*/
@ -36,7 +38,8 @@ pthread_handler_t test_lf_pinbox(void *arg)
int32 x= 0;
LF_PINS *pins;
my_thread_init();
if (with_my_thread_init)
my_thread_init();
pins= lf_pinbox_get_pins(&lf_allocator.pinbox);
@ -49,7 +52,10 @@ pthread_handler_t test_lf_pinbox(void *arg)
pthread_mutex_lock(&mutex);
if (!--running_threads) pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
my_thread_end();
if (with_my_thread_init)
my_thread_end();
return 0;
}
@ -68,7 +74,8 @@ pthread_handler_t test_lf_alloc(void *arg)
int32 x,y= 0;
LF_PINS *pins;
my_thread_init();
if (with_my_thread_init)
my_thread_init();
pins= lf_alloc_get_pins(&lf_allocator);
@ -101,7 +108,9 @@ pthread_handler_t test_lf_alloc(void *arg)
}
if (!--running_threads) pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
my_thread_end();
if (with_my_thread_init)
my_thread_end();
return 0;
}
@ -112,7 +121,8 @@ pthread_handler_t test_lf_hash(void *arg)
int32 x,y,z,sum= 0, ins= 0;
LF_PINS *pins;
my_thread_init();
if (with_my_thread_init)
my_thread_init();
pins= lf_hash_get_pins(&lf_hash);
@ -152,14 +162,15 @@ pthread_handler_t test_lf_hash(void *arg)
}
if (!--running_threads) pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
my_thread_end();
if (with_my_thread_init)
my_thread_end();
return 0;
}
void do_tests()
{
plan(4);
plan(7);
lf_alloc_init(&lf_allocator, sizeof(TLA), offsetof(TLA, not_used));
lf_hash_init(&lf_hash, sizeof(int), LF_HASH_UNIQUE, 0, sizeof(int), 0,
@ -168,9 +179,15 @@ void do_tests()
bad= my_atomic_initialize();
ok(!bad, "my_atomic_initialize() returned %d", bad);
test_concurrently("lf_pinbox", test_lf_pinbox, N= THREADS, CYCLES);
test_concurrently("lf_alloc", test_lf_alloc, N= THREADS, CYCLES);
test_concurrently("lf_hash", test_lf_hash, N= THREADS, CYCLES/10);
with_my_thread_init= 1;
test_concurrently("lf_pinbox (with my_thread_init)", test_lf_pinbox, N= THREADS, CYCLES);
test_concurrently("lf_alloc (with my_thread_init)", test_lf_alloc, N= THREADS, CYCLES);
test_concurrently("lf_hash (with my_thread_init)", test_lf_hash, N= THREADS, CYCLES/10);
with_my_thread_init= 0;
test_concurrently("lf_pinbox (without my_thread_init)", test_lf_pinbox, N= THREADS, CYCLES);
test_concurrently("lf_alloc (without my_thread_init)", test_lf_alloc, N= THREADS, CYCLES);
test_concurrently("lf_hash (without my_thread_init)", test_lf_hash, N= THREADS, CYCLES/10);
lf_hash_destroy(&lf_hash);
lf_alloc_destroy(&lf_allocator);

View File

@ -110,8 +110,11 @@ int main(void)
test1("Positional arguments octal: <7777>",
"Positional arguments octal: <%1$o>", 07777);
/* Can't use int arguments, as they may be different size from pointers */
test1("Padding and %p <0x12> <0x034> <0x0000ab> < 0xcd>",
"Padding and %%p <%04p> <%05p> <%08p> <%8p>", 0x12, 0x34, 0xab, 0xcd);
"Padding and %%p <%04p> <%05p> <%08p> <%8p>",
(void*) 0x12, (void*) 0x34, (void*) 0xab, (void*) 0xcd);
test1("F with a width (ignored) and precision: <12.34568>",
"F with a width (ignored) and precision: <%10.5f>", 12.3456789);

View File

@ -1,25 +0,0 @@
# Copyright (C) 2006 MySQL 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
AM_CPPFLAGS = -I$(top_srcdir)/include
noinst_LIBRARIES = libmytap.a
noinst_HEADERS = tap.h
libmytap_a_SOURCES = tap.c
EXTRA_DIST = CMakeLists.txt
SUBDIRS = . t

View File

@ -1,22 +0,0 @@
# Copyright (C) 2006 MySQL 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
AM_CPPFLAGS = -I$(srcdir) -I$(top_builddir)/include -I$(srcdir)/.. -I$(top_srcdir)/include
AM_LDFLAGS = -L$(top_builddir)/unittest/mytap
LDADD = -lmytap
noinst_PROGRAMS = basic-t

View File

@ -22,7 +22,7 @@ int main() {
plan(5);
ok(1 == 1, "testing basic functions");
ok(2 == 2, " ");
ok(3 == 3, NULL);
ok1(3 == 3);
if (1 == 1)
skip(2, "Sensa fragoli");
else {

View File

@ -244,6 +244,23 @@ ok(int pass, char const *fmt, ...)
emit_endl();
}
void
ok1(int const pass)
{
va_list ap;
memset(&ap, 0, sizeof(ap));
if (!pass && *g_test.todo == '\0')
++g_test.failed;
vemit_tap(pass, NULL, ap);
if (*g_test.todo != '\0')
emit_dir("todo", g_test.todo);
emit_endl();
}
void
skip(int how_many, char const *fmt, ...)

View File

@ -121,14 +121,25 @@ void plan(int count);
@endcode
@param pass Zero if the test failed, non-zero if it passed.
@param fmt Format string in printf() format. NULL is allowed, in
which case nothing is printed.
@param fmt Format string in printf() format. NULL is not allowed,
use ok1() in this case.
*/
void ok(int pass, char const *fmt, ...)
__attribute__((format(printf,2,3)));
/**
Report test result as a TAP line.
Same as ok() but does not take a message to be printed.
@param pass Zero if the test failed, non-zero if it passed.
*/
void ok1(int const pass);
/**
Skip a determined number of tests.

View File

@ -1,27 +0,0 @@
# Copyright 2000, 2010, Oracle and/or its affiliates. All rights reserved.
#
# 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-1301 USA
AM_CPPFLAGS = @ZLIB_INCLUDES@ -I$(top_builddir)/include
AM_CPPFLAGS += -I$(top_srcdir)/include -I$(top_srcdir)/unittest/mytap
LDADD = $(top_builddir)/unittest/mytap/libmytap.a \
$(top_builddir)/mysys/libmysys.a \
$(top_builddir)/dbug/libdbug.a \
$(top_builddir)/strings/libmystrings.a
noinst_PROGRAMS = strings-t
# Don't update the files from bitkeeper
%::SCCS/s.%

View File

@ -14,7 +14,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
use Test::Harness;
use File::Find;
use Getopt::Long;
@ -38,9 +37,10 @@ unit - Run unit tests in directory
my $big= $ENV{'MYTAP_CONFIG'} eq 'big';
my $opt_verbose;
my $result = GetOptions (
"big!" => \$big,
"verbose!" => \$Test::Harness::verbose,
"verbose!" => \$opt_verbose,
);
$ENV{'MYTAP_CONFIG'} = $big ? 'big' : '';
@ -60,6 +60,19 @@ Run all unit tests in the current directory and all subdirectories.
=cut
BEGIN {
# Test::Harness have been extensively rewritten in newer perl
# versions and is now just a backward compatibility wrapper
# (with a bug causing the HARNESS_PERL_SWITCHES to be mangled)
# Prefer to use TAP::Harness directly if available
if (eval "use TAP::Harness; 1") {
eval 'sub NEW_HARNESS { 1 }';
warn "using TAP::Harness";
} else {
eval "use Test::Harness; 1" or die "couldn't find Test::Harness!";
eval 'sub NEW_HARNESS { 0 }';
}
}
sub _find_test_files (@) {
my @dirs = @_;
@ -102,8 +115,19 @@ sub run_cmd (@) {
if (@files > 0) {
# Removing the first './' from the file names
foreach (@files) { s!^\./!! }
$ENV{'HARNESS_PERL_SWITCHES'} .= ' -e "exec @ARGV"';
runtests @files;
if (NEW_HARNESS())
{
my %args = ( exec => [ ], verbosity => $opt_verbose );
my $harness = TAP::Harness->new( \%args );
$harness->runtests(@files);
}
else
{
$ENV{'HARNESS_VERBOSE'} = $opt_verbose;
$ENV{'HARNESS_PERL_SWITCHES'} .= ' -e "exec @ARGV"';
runtests(@files);
}
}
}