1#------------------------------------------------------------------------------ 2# Test mysql_tzinfo_to_sql program against system zoneinfo files. 3# The mysql_tzinfo_to_sql program loads the time zone tables in the mysql 4# database. It is used on systems that have a zoneinfo database (the set of 5# files describing time zones). 6# Examples of such systems are Linux, FreeBSD, Solaris, and Mac OS X. One 7# likely location for these files is the /usr/share/zoneinfo directory 8# (/usr/share/lib/zoneinfo on Solaris). 9# The test is skipped if any of the required zoneinfo files cannot be found. 10# usage: 11# 1] mysql_tzinfo_to_sql tz_dir 12# 2] mysql_tzinfo_to_sql tz_file tz_name 13# 3] mysql_tzinfo_to_sql --leap tz_file 14# Test aims loading zone tables in the mysql with above command. 15# Data is loaded into zone table from test_zone database instead of mysql 16# database. 17#------------------------------------------------------------------------------ 18--source include/not_windows.inc 19--source include/not_embedded.inc 20 21# Escape to perl to locate zoneinfo on this system 22perl; 23my $dir = $ENV{'MYSQLTEST_VARDIR'}; 24open ( OUTPUT, ">$dir/tmp/zoneinfocheck.inc") ; 25@path=(); 26# Check zoneinfo folder in default places 27if(-d "/usr/share/zoneinfo"){ 28 $path[1] = "/usr/share/zoneinfo"; 29}elsif(-d "/usr/share/lib/zoneinfo"){ 30 $path[1] = "/usr/share/lib/zoneinfo"; 31}else{ 32 # check if whereis command knows zoneinfo location 33 system("whereis zoneinfo"); 34 if ($?==0) { 35 @path = split (/\s+/, `whereis zoneinfo`); 36 } 37} 38 39# Check that all requires zoneinfo resources are available 40if (defined($path[1])) { 41 if (-e "$path[1]/Japan") { 42 print OUTPUT "let zoneinfo_japan_path = $path[1]/Japan;\n"; 43 } 44 if (-d "$path[1]/Europe") { 45 print OUTPUT "let zoneinfo_europe_path = $path[1]/Europe;\n"; 46 } 47 if (-e "$path[1]/right/Europe/Moscow") { 48 print OUTPUT "let zoneinfo_leap_moscow_path= $path[1]/right/Europe/Moscow;\n", 49 } 50} 51 52close (OUTPUT); 53EOF 54 55# Load zoneinfo_path variables 56--source $MYSQLTEST_VARDIR/tmp/zoneinfocheck.inc 57 58--remove_file $MYSQLTEST_VARDIR/tmp/zoneinfocheck.inc 59 60# Skip test if any required zoneinfo resources are unavailable 61if (!$zoneinfo_japan_path) { 62 --skip Unable to locate zoneinfo/Japan 63} 64if (!$zoneinfo_europe_path) { 65 --skip Unable to locate zoneinfo/Europe 66} 67 68# Create tables zone tables in test_zone database 69CREATE DATABASE test_zone; 70USE test_zone; 71CREATE TABLE time_zone as SELECT * FROM mysql.time_zone WHERE 1 = 0; 72CREATE TABLE time_zone_leap_second as SELECT * FROM mysql.time_zone_leap_second WHERE 1 = 0; 73CREATE TABLE time_zone_name as SELECT * FROM mysql.time_zone_name WHERE 1 = 0; 74CREATE TABLE time_zone_transition as SELECT * FROM mysql.time_zone_transition WHERE 1 = 0; 75CREATE TABLE time_zone_transition_type as SELECT * FROM mysql.time_zone_transition_type WHERE 1 = 0; 76 77--echo # Load system zone table for Japanese zones. (mysql_tzinfo_to_sql <syszonepath>/Japan test_japan). 78--exec $MYSQL_TZINFO_TO_SQL $zoneinfo_japan_path test_japan >$MYSQLTEST_VARDIR/tmp/loadzonefile.sql 79 80# Disabling query log when sourcing loadzonefile.sql to make test stable 81--disable_query_log 82--source $MYSQLTEST_VARDIR/tmp/loadzonefile.sql 83--enable_query_log 84# Selecting count(*) > 0 to verify that mysql_tzinfo_to_sql produced output, while keeping the test stable 85SELECT (count(*) > 0) FROM time_zone; 86SELECT (count(*) > 0) FROM time_zone_name; 87SELECT (count(*) > 0) FROM time_zone_transition; 88SELECT (count(*) > 0) FROM time_zone_transition_type; 89 90--echo # Load system Moscow zone table with --leap option. (mysql_tzinfo_to_sql --leap <syszonepath>/right/Europe/Moscow) 91# Disabling query log when sourcing loadzonefile.sql to make test stable 92--disable_query_log 93# Not all systems include the <zoneinfo>/right directory 94if ($zoneinfo_leap_moscow_path) { 95 --exec $MYSQL_TZINFO_TO_SQL --leap $zoneinfo_leap_moscow_path >$MYSQLTEST_VARDIR/tmp/loadzonefile.sql 96 --source $MYSQLTEST_VARDIR/tmp/loadzonefile.sql 97 SELECT (count(*) > 1) AS OK FROM time_zone_leap_second; 98} 99if (!$zoneinfo_leap_moscow_path) { 100 # Dummy select to match the result file 101 SELECT (count(*) = 0) AS OK FROM time_zone_leap_second; 102} 103--enable_query_log 104 105--echo # Load system zone table files in Europe folder. (mysql_tzinfo_to_sql <syszonepath>/Europe) 106--exec $MYSQL_TZINFO_TO_SQL $zoneinfo_europe_path >$MYSQLTEST_VARDIR/tmp/loadzonefile.sql 107# Disabling query log when sourcing loadzonefile.sql to make test stable 108--disable_query_log 109--source $MYSQLTEST_VARDIR/tmp/loadzonefile.sql 110--enable_query_log 111# Selecting count(*) > 0 to verify that mysql_tzinfo_to_sql produced output, while keeping the test stable 112SELECT (count(*) > 0) FROM time_zone; 113SELECT (count(*) > 0) FROM time_zone_name; 114SELECT (count(*) > 0) FROM time_zone_transition; 115SELECT (count(*) > 0) FROM time_zone_transition_type; 116 117# Cleanup 118DROP DATABASE test_zone; 119--remove_file $MYSQLTEST_VARDIR/tmp/loadzonefile.sql 120