Files
MaxScale/server/core/test/testgwbitmask.c
Johan Wikman ed96e2c54a Make GWBITMASK fixed size
Originally GWBITMASK was capable of extending itself dynamically,
a functionality that in practice was never used, and that, in fact,
was broken.

As GWBITMASK is used for a single purpose inside MaxScale, its size
is now fixed at 256 bits, which is sufficient for 256 threads. Its
fixed size removes a few potential error situations that now then
do not need to be dealt with. And in principle is also more
performant.

In a separate change, bitmask_free will be renamed to bitmask_finish,
as contrary to free-functions in general, the function does not free
the argument, but only its data. The implementation will be empty,
but the function left in place for symmetry reasons (alloc/free,
init/finish).
2016-08-18 09:37:03 +03:00

85 lines
2.0 KiB
C

/*
* Copyright (c) 2016 MariaDB Corporation Ab
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
*
* Change Date: 2019-07-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
/**
*
* @verbatim
* Revision History
*
* Date Who Description
* 13-10-2014 Martin Brampton Initial implementation
*
* @endverbatim
*/
// To ensure that ss_info_assert asserts also when builing in non-debug mode.
#if !defined(SS_DEBUG)
#define SS_DEBUG
#endif
#if defined(NDEBUG)
#undef NDEBUG
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gwbitmask.h>
#include <skygw_debug.h>
/**
* test1 Create a bitmap and mess around with it
*
*/
static int
test1()
{
static GWBITMASK bitmask, another;
int i;
/* Hint tests */
ss_dfprintf(stderr,
"testgwbitmask : Initialise a bitmask");
bitmask_init(&bitmask);
for (i = 0; i < MXS_BITMASK_LENGTH; i++)
{
ss_info_dassert(0 == bitmask_isset(&bitmask, i), "All bits should initially be zero");
}
ss_info_dassert(0 != bitmask_isallclear(&bitmask), "Should be all clear");
ss_dfprintf(stderr, "\t..done\nSet an arbitrary bit.");
bitmask_set(&bitmask, 17);
bitmask_copy(&another, &bitmask);
ss_info_dassert(0 != bitmask_isset(&another, 17), "Test bit should be set");
ss_dfprintf(stderr, "\t..done\nClear the arbitrary bit.");
bitmask_clear(&bitmask, 17);
ss_info_dassert(0 != bitmask_isallclear(&bitmask), "Should be all clear");
ss_info_dassert(0 == bitmask_isset(&bitmask, 17), "Test bit should be clear");
ss_dfprintf(stderr, "\t..done\nFree the bitmask.");
bitmask_free(&bitmask);
ss_dfprintf(stderr, "\t..done\n");
return 0;
}
int main(int argc, char **argv)
{
int result = 0;
result += test1();
exit(result);
}