From d5caa00161453eb0cd61e3641d4e6783fb385319 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 5 May 2011 14:51:01 +0300 Subject: [PATCH 1/3] Improved 'make test-unit' time slightly storage/maria/unittest/ma_test_loghandler-t.c: Don't sync during test storage/maria/unittest/ma_test_loghandler_multigroup-t.c: Don't sync during test storage/maria/unittest/ma_test_loghandler_multithread-t.c: Don't sync during test unittest/mysys/bitmap-t.c: Don't test all bit combinations (not needed) unittest/mysys/thr_template.c: Remove sleep as old bug should be fixed nowadays unittest/mysys/waiting_threads-t.c: Only run test with --big unittest/mytap/tap.c: Print total time at end of test. unittest/unit.pl: Use TAP::Harness instead of Test::Harness (recommended according to manual) Add times to tests. --- storage/maria/unittest/ma_test_loghandler-t.c | 2 + .../ma_test_loghandler_multigroup-t.c | 2 + .../ma_test_loghandler_multithread-t.c | 2 + unittest/mysys/bitmap-t.c | 10 ++- unittest/mysys/thr_template.c | 4 +- unittest/mysys/waiting_threads-t.c | 5 ++ unittest/mytap/tap.c | 84 ++++++++++++++++++- unittest/unit.pl | 15 +++- 8 files changed, 115 insertions(+), 9 deletions(-) diff --git a/storage/maria/unittest/ma_test_loghandler-t.c b/storage/maria/unittest/ma_test_loghandler-t.c index ffac9b04839..53459a5239d 100644 --- a/storage/maria/unittest/ma_test_loghandler-t.c +++ b/storage/maria/unittest/ma_test_loghandler-t.c @@ -173,6 +173,8 @@ int main(int argc __attribute__((unused)), char *argv[]) maria_data_root= (char *)"."; if (maria_log_remove()) exit(1); + /* We don't need to do physical syncs in this test */ + my_disable_sync= 1; for (i= 0; i < (LONG_BUFFER_SIZE + LSN_STORE_SIZE * 2 + 2); i+= 2) { diff --git a/storage/maria/unittest/ma_test_loghandler_multigroup-t.c b/storage/maria/unittest/ma_test_loghandler_multigroup-t.c index 7ba7ce3176d..aab94ff10c7 100644 --- a/storage/maria/unittest/ma_test_loghandler_multigroup-t.c +++ b/storage/maria/unittest/ma_test_loghandler_multigroup-t.c @@ -247,6 +247,8 @@ int main(int argc __attribute__((unused)), char *argv[]) load_defaults("my", load_default_groups, &argc, &argv); default_argv= argv; get_options(&argc, &argv); + /* We don't need to do physical syncs in this test */ + my_disable_sync= 1; if (maria_log_remove()) exit(1); diff --git a/storage/maria/unittest/ma_test_loghandler_multithread-t.c b/storage/maria/unittest/ma_test_loghandler_multithread-t.c index dbf47ad2ee1..e46fe047a97 100644 --- a/storage/maria/unittest/ma_test_loghandler_multithread-t.c +++ b/storage/maria/unittest/ma_test_loghandler_multithread-t.c @@ -271,6 +271,8 @@ int main(int argc __attribute__((unused)), plan(WRITERS + FLUSHERS + ITERATIONS * WRITERS * 3 + FLUSH_ITERATIONS * FLUSHERS ); + /* We don't need to do physical syncs in this test */ + my_disable_sync= 1; bzero(&pagecache, sizeof(pagecache)); maria_data_root= (char *)"."; diff --git a/unittest/mysys/bitmap-t.c b/unittest/mysys/bitmap-t.c index 9fca9f8ef20..2065e10b53f 100644 --- a/unittest/mysys/bitmap-t.c +++ b/unittest/mysys/bitmap-t.c @@ -526,8 +526,14 @@ int main() int const max_size = MAX_TESTED_BITMAP_SIZE; MY_INIT("bitmap-t"); - plan(max_size - min_size); - for (i= min_size; i < max_size; i++) + plan((max_size - min_size)/7+1); + + /* + It's ok to do steps in 7, as i module 64 will go trough all values 1..63. + Any errors in the code should manifest as we are working with integers + of size 16, 32, or 64 bits... + */ + for (i= min_size; i < max_size; i+=7) ok(do_test(i) == 0, "bitmap size %d", i); return exit_status(); } diff --git a/unittest/mysys/thr_template.c b/unittest/mysys/thr_template.c index 1ac03e474fd..e6af1fb12e2 100644 --- a/unittest/mysys/thr_template.c +++ b/unittest/mysys/thr_template.c @@ -82,7 +82,9 @@ int main(int argc __attribute__((unused)), char **argv) workaround until we know why it crashes randomly on some machine (BUG#22320). */ - sleep(2); +#ifdef NOT_USED + sleep(1); +#endif pthread_mutex_destroy(&mutex); pthread_cond_destroy(&cond); pthread_attr_destroy(&thr_attr); diff --git a/unittest/mysys/waiting_threads-t.c b/unittest/mysys/waiting_threads-t.c index e32a83ef172..7bb5b2038fb 100644 --- a/unittest/mysys/waiting_threads-t.c +++ b/unittest/mysys/waiting_threads-t.c @@ -181,6 +181,11 @@ void do_one_test() void do_tests() { DBUG_ENTER("do_tests"); + if (skip_big_tests) + { + skip(1, "Big test skipped"); + return; + } plan(14); compile_time_assert(THREADS >= 4); diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index 1792c82519b..4bb501e54dc 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -1,4 +1,5 @@ -/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. + Copyright (c) 2011, 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 @@ -27,6 +28,10 @@ #include #include +static ulong start_timer(void); +static void end_timer(ulong start_time,char *buff); +static void nice_time(double sec,char *buff,my_bool part_second); + /* Visual Studio 2003 does not know vsnprintf but knows _vsnprintf. We don't put this #define in config-win.h because we prefer @@ -185,6 +190,7 @@ static signal_entry install_signal[]= { }; int skip_big_tests= 1; +ulong start_time; void plan(int count) @@ -192,6 +198,8 @@ plan(int count) char *config= getenv("MYTAP_CONFIG"); size_t i; + start_time= start_timer(); + if (config) skip_big_tests= strcmp(config, "big"); @@ -289,6 +297,7 @@ skip(int how_many, char const *fmt, ...) } } + void todo_start(char const *message, ...) { @@ -304,7 +313,10 @@ todo_end() *g_test.todo = '\0'; } -int exit_status() { +int exit_status() +{ + char buff[60]; + /* If there were no plan, we write one last instead. */ @@ -323,10 +335,78 @@ int exit_status() { diag("Failed %d tests!", g_test.failed); return EXIT_FAILURE; } + end_timer(start_time, buff); + printf("Test took %s\n", buff); + fflush(stdout); return EXIT_SUCCESS; } +#if defined(__WIN__) || defined(__NETWARE__) +#include +#else +#include +#ifdef _SC_CLK_TCK // For mit-pthreads +#undef CLOCKS_PER_SEC +#define CLOCKS_PER_SEC (sysconf(_SC_CLK_TCK)) +#endif +#endif + +static ulong start_timer(void) +{ +#if defined(__WIN__) || defined(__NETWARE__) + return clock(); +#else + struct tms tms_tmp; + return times(&tms_tmp); +#endif +} + + +/** + Write as many as 52+1 bytes to buff, in the form of a legible + duration of time. + + len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds") -> 52 +*/ + +static void nice_time(double sec,char *buff, my_bool part_second) +{ + ulong tmp; + if (sec >= 3600.0*24) + { + tmp=(ulong) floor(sec/(3600.0*24)); + sec-=3600.0*24*tmp; + buff+= my_sprintf(buff, (buff, "%ld %s", tmp, + tmp > 1 ? " days " : " day ")); + } + if (sec >= 3600.0) + { + tmp=(ulong) floor(sec/3600.0); + sec-=3600.0*tmp; + buff+= my_sprintf(buff, (buff, "%ld %s", tmp, + tmp > 1 ? " hours " : " hour ")); + } + if (sec >= 60.0) + { + tmp=(ulong) floor(sec/60.0); + sec-=60.0*tmp; + buff+= my_sprintf(buff, (buff, "%ld min ", tmp)); + } + if (part_second) + sprintf(buff,"%.2f sec",sec); + else + sprintf(buff,"%d sec",(int) sec); +} + + +static void end_timer(ulong start_time,char *buff) +{ + nice_time((double) (start_timer() - start_time) / + CLOCKS_PER_SEC,buff,1); +} + + /** @mainpage Testing C and C++ using MyTAP diff --git a/unittest/unit.pl b/unittest/unit.pl index be6424ec798..23ec954f720 100644 --- a/unittest/unit.pl +++ b/unittest/unit.pl @@ -14,7 +14,7 @@ # 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 TAP::Harness; use File::Find; use Getopt::Long; @@ -37,10 +37,11 @@ unit - Run unit tests in directory =cut my $big= $ENV{'MYTAP_CONFIG'} eq 'big'; +my $verbose= 0; my $result = GetOptions ( "big!" => \$big, - "verbose!" => \$Test::Harness::verbose, + "verbose!" => \$verbose, ); $ENV{'MYTAP_CONFIG'} = $big ? 'big' : ''; @@ -102,8 +103,14 @@ 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; + + my %args = ( + verbosity => $verbose, + timer => 1, + exec => [ "/bin/sh", "-c" ], + ); + my $harness= TAP::Harness->new( \%args ); + $harness->runtests(@files); } } From 5cf6ccd29eb9fbdb1993810424cc48ece8e2ac81 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 5 May 2011 23:28:42 +0300 Subject: [PATCH 2/3] Speed up pbxt.range test a bit --- mysql-test/suite/pbxt/r/range.result | 2 ++ mysql-test/suite/pbxt/t/range.test | 3 +++ 2 files changed, 5 insertions(+) diff --git a/mysql-test/suite/pbxt/r/range.result b/mysql-test/suite/pbxt/r/range.result index a8e97d1c725..fb7ce4b4049 100644 --- a/mysql-test/suite/pbxt/r/range.result +++ b/mysql-test/suite/pbxt/r/range.result @@ -362,6 +362,7 @@ name char(1) not null, uid int not null, primary key (id), index uid_index (uid)); +begin; insert into t1(id, uid, name) values(1, 0, ' '); insert into t1(uid, name) values(0, ' '); insert into t2(uid, name) select uid, name from t1; @@ -410,6 +411,7 @@ insert into t2(uid, name) values insert into t1(uid, name) select uid, name from t2 order by uid; delete from t2; insert into t2(id, uid, name) select id, uid, name from t1; +commit; select count(*) from t1; count(*) 1026 diff --git a/mysql-test/suite/pbxt/t/range.test b/mysql-test/suite/pbxt/t/range.test index 8d02089ee1b..0c0349c49c9 100644 --- a/mysql-test/suite/pbxt/t/range.test +++ b/mysql-test/suite/pbxt/t/range.test @@ -322,6 +322,7 @@ create table t2 ( primary key (id), index uid_index (uid)); +begin; insert into t1(id, uid, name) values(1, 0, ' '); insert into t1(uid, name) values(0, ' '); @@ -375,6 +376,8 @@ insert into t1(uid, name) select uid, name from t2 order by uid; delete from t2; insert into t2(id, uid, name) select id, uid, name from t1; +commit; + select count(*) from t1; select count(*) from t2; From 6b8788e425f649bcdb0f882c81b081795005fbe7 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 6 May 2011 14:01:51 +0300 Subject: [PATCH 3/3] Reverted unittest/unit.pl back to Test::Harness as some of our build machines didn't support the new recommended TAP::Harness module unittest/mytap/tap.c: Fixed output for some tests that didn't call plan() --- unittest/mytap/tap.c | 11 +++++++---- unittest/unit.pl | 17 +++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index 4bb501e54dc..e0e42c6eb5e 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -190,7 +190,7 @@ static signal_entry install_signal[]= { }; int skip_big_tests= 1; -ulong start_time; +ulong start_time= 0; void plan(int count) @@ -335,9 +335,12 @@ int exit_status() diag("Failed %d tests!", g_test.failed); return EXIT_FAILURE; } - end_timer(start_time, buff); - printf("Test took %s\n", buff); - fflush(stdout); + if (start_time) + { + end_timer(start_time, buff); + printf("Test took %s\n", buff); + fflush(stdout); + } return EXIT_SUCCESS; } diff --git a/unittest/unit.pl b/unittest/unit.pl index 23ec954f720..9900f47f374 100644 --- a/unittest/unit.pl +++ b/unittest/unit.pl @@ -14,7 +14,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -use TAP::Harness; +use Test::Harness; use File::Find; use Getopt::Long; @@ -37,11 +37,10 @@ unit - Run unit tests in directory =cut my $big= $ENV{'MYTAP_CONFIG'} eq 'big'; -my $verbose= 0; my $result = GetOptions ( "big!" => \$big, - "verbose!" => \$verbose, + "verbose!" => \$Test::Harness::verbose, ); $ENV{'MYTAP_CONFIG'} = $big ? 'big' : ''; @@ -103,14 +102,8 @@ sub run_cmd (@) { if (@files > 0) { # Removing the first './' from the file names foreach (@files) { s!^\./!! } - - my %args = ( - verbosity => $verbose, - timer => 1, - exec => [ "/bin/sh", "-c" ], - ); - my $harness= TAP::Harness->new( \%args ); - $harness->runtests(@files); + $ENV{'HARNESS_PERL_SWITCHES'} .= ' -e "exec @ARGV"'; + $Test::Harness::Timer = 1; + runtests @files; } } -