Few things --- there are:
- Fix bug within index allocator - Removed obsolete locking stuff from allocator - Stupid test addedmaster 0.2.4
parent
459ca367a3
commit
bb6a20313b
@ -0,0 +1 @@
|
||||
idxatest
|
@ -0,0 +1,19 @@
|
||||
## AUTOMAKE_OPTIONS = foreign
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
|
||||
-DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
|
||||
-DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \
|
||||
-DCNFPATH=\""$(prefix)/etc"\" \
|
||||
-I$(top_srcdir)/include
|
||||
|
||||
AM_CFLAGS = -Wall -g
|
||||
|
||||
# where to find libsxmp
|
||||
libtdata = $(top_builddir)/lib/.libs/libtdata.la
|
||||
|
||||
bin_PROGRAMS = idxatest
|
||||
|
||||
idxatest_SOURCES = idxa.c
|
||||
idxatest_LDADD = $(libtdata) -lpthread
|
||||
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License.
|
||||
*
|
||||
* This library 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* (c) Copyright 2014 Alexander Vdolainen <avdolainen@zoho.com>
|
||||
*
|
||||
* Index allocator tests
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <tdata/bitwise.h>
|
||||
#include <tdata/idx_allocator.h>
|
||||
|
||||
#define IDXMAX 131072
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
idx_allocator_t idxa;
|
||||
ulong_t r = 0, i = 0;
|
||||
|
||||
memset(&idxa, 0, sizeof(idxa));
|
||||
|
||||
if((r = idx_allocator_init(&idxa, IDXMAX, 0))) {
|
||||
fprintf(stderr, "%d:(%s): IDX init failed with %lu\n", __LINE__,
|
||||
__FUNCTION__, r);
|
||||
goto __finiv;
|
||||
}
|
||||
|
||||
/* one thread */
|
||||
/* (1) use the half of pool and free it */
|
||||
for(i = 0; i < IDXMAX/2; i++) {
|
||||
r = idx_allocate(&idxa);
|
||||
if(r != i) {
|
||||
fprintf(stderr, "%d:(%s):error: expected %lu instead of %lu\n",
|
||||
__LINE__, __FUNCTION__, i, r);
|
||||
r = -1;
|
||||
goto __finiv1;
|
||||
}
|
||||
}
|
||||
|
||||
/* (2) use all pool and free the second part */
|
||||
for(i = IDXMAX/2; i < IDXMAX; i++) {
|
||||
r = idx_allocate(&idxa);
|
||||
if(r != i) {
|
||||
fprintf(stderr, "%d:(%s):error: expected %lu instead of %lu\n",
|
||||
__LINE__, __FUNCTION__, i, r);
|
||||
r = -1;
|
||||
goto __finiv1;
|
||||
}
|
||||
}
|
||||
/* (3) fill second part and free all and try to allocate 1/4 */
|
||||
/* (4) free all */
|
||||
|
||||
__finiv1:
|
||||
|
||||
idx_allocator_destroy(&idxa);
|
||||
|
||||
__finiv:
|
||||
return r;
|
||||
}
|
Loading…
Reference in New Issue