Commit 5409997d authored by serg@serg.mylan's avatar serg@serg.mylan

unittest:

  rename *.t* to *-t* to be automake-friendly
  simplify Makefiles
test_atomic.c:
  move to unittest, add GPL comment, fix warnings, convert to tap framework.
configure:
  remove custom tests for available types, use AC_CHECK_TYPE instead
x86-gcc.h:
  fix gcc -ansi errors while maintaining readability
ignore:
  added *-t
parent 2b9b8446
......@@ -1772,3 +1772,4 @@ zlib/*.ds?
zlib/*.vcproj
libmysqld/event_scheduler.cc
mysys/test_atomic
*-t
......@@ -155,84 +155,6 @@ fi
])
#---START: Used in for client configure
AC_DEFUN([MYSQL_CHECK_ULONG],
[AC_MSG_CHECKING(for type ulong)
AC_CACHE_VAL(ac_cv_ulong,
[AC_TRY_RUN([#include <stdio.h>
#include <sys/types.h>
main()
{
ulong foo;
foo++;
exit(0);
}], ac_cv_ulong=yes, ac_cv_ulong=no, ac_cv_ulong=no)])
AC_MSG_RESULT($ac_cv_ulong)
if test "$ac_cv_ulong" = "yes"
then
AC_DEFINE([HAVE_ULONG], [1], [system headers define ulong])
fi
])
AC_DEFUN([MYSQL_CHECK_UCHAR],
[AC_MSG_CHECKING(for type uchar)
AC_CACHE_VAL(ac_cv_uchar,
[AC_TRY_RUN([#include <stdio.h>
#include <sys/types.h>
main()
{
uchar foo;
foo++;
exit(0);
}], ac_cv_uchar=yes, ac_cv_uchar=no, ac_cv_uchar=no)])
AC_MSG_RESULT($ac_cv_uchar)
if test "$ac_cv_uchar" = "yes"
then
AC_DEFINE([HAVE_UCHAR], [1], [system headers define uchar])
fi
])
AC_DEFUN([MYSQL_CHECK_UINT],
[AC_MSG_CHECKING(for type uint)
AC_CACHE_VAL(ac_cv_uint,
[AC_TRY_RUN([#include <stdio.h>
#include <sys/types.h>
main()
{
uint foo;
foo++;
exit(0);
}], ac_cv_uint=yes, ac_cv_uint=no, ac_cv_uint=no)])
AC_MSG_RESULT($ac_cv_uint)
if test "$ac_cv_uint" = "yes"
then
AC_DEFINE([HAVE_UINT], [1], [system headers define uint])
fi
])
AC_DEFUN([MYSQL_CHECK_IN_ADDR_T],
[AC_MSG_CHECKING(for type in_addr_t)
AC_CACHE_VAL(ac_cv_in_addr_t,
[AC_TRY_RUN([#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char **argv)
{
in_addr_t foo;
exit(0);
}], ac_cv_in_addr_t=yes, ac_cv_in_addr_t=no, ac_cv_in_addr_t=no)])
AC_MSG_RESULT($ac_cv_in_addr_t)
if test "$ac_cv_in_addr_t" = "yes"
then
AC_DEFINE([HAVE_IN_ADDR_T], [1], [system headers define in_addr_t])
fi
])
AC_DEFUN([MYSQL_PTHREAD_YIELD],
[AC_CACHE_CHECK([if pthread_yield takes zero arguments], ac_cv_pthread_yield_zero_arg,
[AC_TRY_LINK([#define _GNU_SOURCE
......@@ -272,25 +194,6 @@ fi
#---END:
AC_DEFUN([MYSQL_CHECK_FP_EXCEPT],
[AC_MSG_CHECKING(for type fp_except)
AC_CACHE_VAL(ac_cv_fp_except,
[AC_TRY_RUN([#include <stdio.h>
#include <sys/types.h>
#include <ieeefp.h>
main()
{
fp_except foo;
foo++;
exit(0);
}], ac_cv_fp_except=yes, ac_cv_fp_except=no, ac_cv_fp_except=no)])
AC_MSG_RESULT($ac_cv_fp_except)
if test "$ac_cv_fp_except" = "yes"
then
AC_DEFINE([HAVE_FP_EXCEPT], [1], [fp_except from ieeefp.h])
fi
])
# From fileutils-3.14/aclocal.m4
# @defmac AC_PROG_CC_STDC
......
......@@ -829,38 +829,20 @@ fi
# Later in this script LIBS will be augmented with a threads library.
NON_THREADED_LIBS="$LIBS"
AC_MSG_CHECKING([for int8])
case $SYSTEM_TYPE in
*netware)
AC_MSG_RESULT([no])
;;
*)
AC_TRY_RUN([
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif
#ifdef HAVE_SYS_TYPES_H
AC_CHECK_TYPES([int8, uint8, int16, uint16, int32, uint32, int64, uint64,
uchar, uint, ulong],[],[], [
#include <sys/types.h>
#endif
int main()
{
int8 i;
return 0;
}
],
[AC_DEFINE([HAVE_INT_8_16_32], [1],
[whether int8, int16 and int32 types exist])
AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])]
)
;;
esac
])
AC_CHECK_TYPES([in_addr_t], [], [], [
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
])
AC_CHECK_TYPES([fp_except], [], [], [
#include <sys/types.h>
#include <ieeefp.h>
])
#
# Some system specific hacks
......@@ -1734,16 +1716,6 @@ MYSQL_FUNC_ALLOCA
MYSQL_TIMESPEC_TS
# Do we have the tzname variable
MYSQL_TZNAME
# Do the system files define ulong
MYSQL_CHECK_ULONG
# Do the system files define uchar
MYSQL_CHECK_UCHAR
# Do the system files define uint
MYSQL_CHECK_UINT
# Check for fp_except in ieeefp.h
MYSQL_CHECK_FP_EXCEPT
# Check for IN_ADDR_T
MYSQL_CHECK_IN_ADDR_T
# Do the c++ compiler have a bool type
MYSQL_CXX_BOOL
# Check some common bugs with gcc 2.8.# on sparc
......
......@@ -19,6 +19,9 @@
cmpxchg8b, if necessary
*/
/* fix -ansi errors while maintaining readability */
#define asm __asm__
#define make_atomic_add_body8 \
asm volatile (LOCK "xadd %0, %1;" : "+r" (v) , "+m" (a->val))
#define make_atomic_swap_body8 \
......
......@@ -864,26 +864,36 @@ typedef void *gptr; /* Generic pointer */
#else
typedef char *gptr; /* Generic pointer */
#endif
#ifndef HAVE_INT_8_16_32
typedef signed char int8; /* Signed integer >= 8 bits */
typedef short int16; /* Signed integer >= 16 bits */
#endif
#ifndef HAVE_UCHAR
typedef unsigned char uchar; /* Short for unsigned char */
#endif
typedef unsigned char uint8; /* Short for unsigned integer >= 8 bits */
typedef unsigned short uint16; /* Short for unsigned integer >= 16 bits */
#ifndef HAVE_INT8
typedef signed char int8; /* Signed integer >= 8 bits */
#endif
#ifndef HAVE_UINT8
typedef unsigned char uint8; /* Unsigned integer >= 8 bits */
#endif
#ifndef HAVE_INT16
typedef short int16;
#endif
#ifndef HAVE_UINT16
typedef unsigned short uint16;
#endif
#if SIZEOF_INT == 4
#ifndef HAVE_INT_8_16_32
typedef int int32;
#ifndef HAVE_INT32
typedef int int32;
#endif
#ifndef HAVE_UINT32
typedef unsigned int uint32;
#endif
typedef unsigned int uint32; /* Short for unsigned integer >= 32 bits */
#elif SIZEOF_LONG == 4
#ifndef HAVE_INT_8_16_32
typedef long int32;
#ifndef HAVE_INT32
typedef long int32;
#endif
#ifndef HAVE_UINT32
typedef unsigned long uint32;
#endif
typedef unsigned long uint32; /* Short for unsigned integer >= 32 bits */
#else
#error "Neither int or long is of 4 bytes width"
#endif
......@@ -900,8 +910,12 @@ typedef unsigned long ulonglong; /* ulong or unsigned long long */
typedef long longlong;
#endif
#endif
#ifndef HAVE_INT64
typedef longlong int64;
#endif
#ifndef HAVE_UINT64
typedef ulonglong uint64;
#endif
#if defined(NO_CLIENT_LONG_LONG)
typedef unsigned long my_ulonglong;
......
......@@ -821,8 +821,9 @@ extern ulong crc32(ulong crc, const uchar *buf, uint len);
extern uint my_set_max_open_files(uint files);
void my_free_open_file_info(void);
ulonglong my_getsystime(void);
my_bool my_gethwaddr(uchar *to);
extern ulonglong my_getsystime(void);
extern my_bool my_gethwaddr(uchar *to);
extern int my_getncpus();
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
......
......@@ -63,7 +63,6 @@ libmysys_a_LIBADD = @THREAD_LOBJECTS@
# testhash_DEPENDENCIES= $(LIBRARIES)
# test_charset_DEPENDENCIES= $(LIBRARIES)
# charset2html_DEPENDENCIES= $(LIBRARIES)
noinst_PROGRAMS= test_atomic$(EXEEXT)
DEFS = -DDEFAULT_BASEDIR=\"$(prefix)\" \
-DDATADIR="\"$(MYSQLDATAdir)\"" \
-DDEFAULT_CHARSET_HOME="\"$(MYSQLBASEdir)\"" \
......
SUBDIRS = mytap . mysys examples
noinst_SCRIPTS = unit
#EXTRA_DIST = unit.pl
EXTRA_DIST = unit.pl
unittests = mytap mysys
DISTCLEANFILES = unit
unittests = mysys examples
.PHONY: all mytap mysys examples test
test: unit all
@./unit run $(unittests)
mytap:
cd mytap && $(MAKE)
mysys:
cd mysys && $(MAKE)
examples:
cd examples && $(MAKE)
test: unit
./unit run $(unittests)
unit: $(srcdir)/unit.pl
cp $(srcdir)/unit.pl $@
chmod +x $@
chmod 700 $@
......@@ -7,14 +7,14 @@ will be added over time.
mytap Source for the MyTAP library
mysys Tests for mysys components
bitmap.t.c Unit test for MY_BITMAP
base64.t.c Unit test for base64 encoding functions
bitmap-t.c Unit test for MY_BITMAP
base64-t.c Unit test for base64 encoding functions
examples Example unit tests
simple.t.c Example of a standard TAP unit test
skip.t.c Example where some test points are skipped
skip_all.t.c Example of a test where the entire test is skipped
todo.t.c Example where test contain test points that are TODO
no_plan.t.c Example of a test with no plan (avoid this)
simple-t.c Example of a standard TAP unit test
skip-t.c Example where some test points are skipped
skip_all-t.c Example of a test where the entire test is skipped
todo-t.c Example where test contain test points that are TODO
no_plan-t.c Example of a test with no plan (avoid this)
Executing unit tests
......@@ -28,9 +28,12 @@ To make and execute all unit tests in the directory:
Adding unit tests
-----------------
Add a file with a name of the format "foo.t.c" to the appropriate
Add a file with a name of the format "foo-t.c" to the appropriate
directory and add the following to the Makefile.am in that directory
(where ... denotes stuff already there):
noinst_PROGRAMS = ... foo.t
foo_t_c_SOURCES = foo.t.c
noinst_PROGRAMS = ... foo-t
Note, it's important to have "-t" at the end of the filename, otherwise the
test won't be executed by 'make test' !
......@@ -5,14 +5,5 @@ AM_LDFLAGS = -L$(top_builddir)/unittest/mytap
LDADD = -lmytap
noinst_PROGRAMS = simple.t skip.t todo.t skip_all.t no_plan.t
noinst_PROGRAMS = simple-t skip-t todo-t skip_all-t no_plan-t
simple_t_SOURCES = simple.t.c
skip_t_SOURCES = skip.t.c
todo_t_SOURCES = todo.t.c
skip_all_t_SOURCES = skip_all.t.c
no_plan_t_SOURCES = no_plan.t.c
......@@ -7,9 +7,5 @@ AM_LDFLAGS += -L$(top_builddir)/strings -L$(top_builddir)/dbug
LDADD = -lmytap -lmysys -ldbug -lmystrings
noinst_PROGRAMS = bitmap.t base64.t
bitmap_t_SOURCES = bitmap.t.c
base64_t_SOURCES = base64.t.c
noinst_PROGRAMS = bitmap-t base64-t my_atomic-t
/* 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; either version 2 of the License, or
(at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <tap.h>
#include <my_global.h>
#include <my_sys.h>
#include <my_atomic.h>
......@@ -25,6 +43,7 @@ pthread_handler_t test_atomic_add_handler(void *arg)
N--;
if (!N) pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
return 0;
}
/*
......@@ -54,6 +73,7 @@ pthread_handler_t test_atomic_swap_handler(void *arg)
N--;
if (!N) pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
return 0;
}
/*
......@@ -75,6 +95,7 @@ pthread_handler_t test_atomic_cas_handler(void *arg)
N--;
if (!N) pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
return 0;
}
void test_atomic(const char *test, pthread_handler handler, int n, int m)
......@@ -86,7 +107,7 @@ void test_atomic(const char *test, pthread_handler handler, int n, int m)
my_atomic_store32(&b32, 0, &rwl);
my_atomic_store32(&c32, 0, &rwl);
printf("Testing %s with %d threads, %d iterations... ", test, n, m);
diag("Testing %s with %d threads, %d iterations... ", test, n, m);
for (N=n ; n ; n--)
pthread_create(&t, &thr_attr, handler, &m);
......@@ -95,24 +116,19 @@ void test_atomic(const char *test, pthread_handler handler, int n, int m)
pthread_cond_wait(&cond, &mutex);
pthread_mutex_unlock(&mutex);
now=my_getsystime()-now;
printf("got %lu in %g secs\n", my_atomic_load32(&a32, &rwl),
((double)now)/1e7);
ok(my_atomic_load32(&a32, &rwl) == 0,
"tested %s in %g secs", test, ((double)now)/1e7);
}
int main()
{
int err;
#ifdef _IONBF
setvbuf(stdout, 0, _IONBF, 0);
#endif
printf("N CPUs: %d\n", my_getncpus());
diag("N CPUs: %d", my_getncpus());
err= my_atomic_initialize();
if ((err= my_atomic_initialize()))
{
printf("my_atomic_initialize() failed. Error=%d\n", err);
return 1;
}
plan(4);
ok(err == 0, "my_atomic_initialize() returned %d", err);
pthread_attr_init(&thr_attr);
pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
......@@ -128,6 +144,6 @@ int main()
pthread_cond_destroy(&cond);
pthread_attr_destroy(&thr_attr);
my_atomic_rwlock_destroy(&rwl);
return 0;
return exit_status();
}
......@@ -5,8 +5,5 @@ AM_LDFLAGS = -L$(top_builddir)/unittest/mytap
LDADD = -lmytap
noinst_PROGRAMS = basic.t
noinst_PROGRAMS = basic-t
basic_t_SOURCES = basic.t.c
all: $(noinst_PROGRAMS)
......@@ -59,7 +59,7 @@ sub _find_test_files (@) {
my @files;
find sub {
$File::Find::prune = 1 if /^SCCS$/;
push(@files, $File::Find::name) if -x _ && /\.t\z/;
push(@files, $File::Find::name) if -x _ && /-t\z/;
}, @dirs;
return @files;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment