mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-04 22:49:32 +03:00
Move test macros/helpers to a separate header
This commit is contained in:
parent
6ead2840ec
commit
d7105c20a9
2 changed files with 51 additions and 32 deletions
|
@ -23,7 +23,6 @@ we therefore test the API over various inputs. Please add more tests :-)
|
||||||
[1] https://github.com/daanx/mimalloc-bench
|
[1] https://github.com/daanx/mimalloc-bench
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -36,33 +35,7 @@ we therefore test the API over various inputs. Please add more tests :-)
|
||||||
#include "mimalloc.h"
|
#include "mimalloc.h"
|
||||||
// #include "mimalloc-internal.h"
|
// #include "mimalloc-internal.h"
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
#include "testhelper.h"
|
||||||
// Test macros: CHECK(name,predicate) and CHECK_BODY(name,body)
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
static int ok = 0;
|
|
||||||
static int failed = 0;
|
|
||||||
|
|
||||||
#define CHECK_BODY(name,body) \
|
|
||||||
do { \
|
|
||||||
fprintf(stderr,"test: %s... ", name ); \
|
|
||||||
bool result = true; \
|
|
||||||
do { body } while(false); \
|
|
||||||
if (!(result)) { \
|
|
||||||
failed++; \
|
|
||||||
fprintf(stderr, \
|
|
||||||
"\n FAILED: %s:%d:\n %s\n", \
|
|
||||||
__FILE__, \
|
|
||||||
__LINE__, \
|
|
||||||
#body); \
|
|
||||||
/* exit(1); */ \
|
|
||||||
} \
|
|
||||||
else { \
|
|
||||||
ok++; \
|
|
||||||
fprintf(stderr,"ok.\n"); \
|
|
||||||
} \
|
|
||||||
} while (false)
|
|
||||||
|
|
||||||
#define CHECK(name,expr) CHECK_BODY(name,{ result = (expr); })
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Test functions
|
// Test functions
|
||||||
|
@ -219,10 +192,7 @@ int main(void) {
|
||||||
// ---------------------------------------------------
|
// ---------------------------------------------------
|
||||||
// Done
|
// Done
|
||||||
// ---------------------------------------------------[]
|
// ---------------------------------------------------[]
|
||||||
fprintf(stderr,"\n\n---------------------------------------------\n"
|
return print_test_summary();
|
||||||
"succeeded: %i\n"
|
|
||||||
"failed : %i\n\n", ok, failed);
|
|
||||||
return failed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------
|
// ---------------------------------------------------
|
||||||
|
|
49
test/testhelper.h
Normal file
49
test/testhelper.h
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
Copyright (c) 2018-2020, Microsoft Research, Daan Leijen
|
||||||
|
This is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the MIT license. A copy of the license can be found in the file
|
||||||
|
"LICENSE" at the root of this distribution.
|
||||||
|
-----------------------------------------------------------------------------*/
|
||||||
|
#ifndef TESTHELPER_H_
|
||||||
|
#define TESTHELPER_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Test macros: CHECK(name,predicate) and CHECK_BODY(name,body)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
static int ok = 0;
|
||||||
|
static int failed = 0;
|
||||||
|
|
||||||
|
#define CHECK_BODY(name,body) \
|
||||||
|
do { \
|
||||||
|
fprintf(stderr,"test: %s... ", name ); \
|
||||||
|
bool result = true; \
|
||||||
|
do { body } while(false); \
|
||||||
|
if (!(result)) { \
|
||||||
|
failed++; \
|
||||||
|
fprintf(stderr, \
|
||||||
|
"\n FAILED: %s:%d:\n %s\n", \
|
||||||
|
__FILE__, \
|
||||||
|
__LINE__, \
|
||||||
|
#body); \
|
||||||
|
/* exit(1); */ \
|
||||||
|
} \
|
||||||
|
else { \
|
||||||
|
ok++; \
|
||||||
|
fprintf(stderr,"ok.\n"); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
#define CHECK(name,expr) CHECK_BODY(name,{ result = (expr); })
|
||||||
|
|
||||||
|
// Print summary of test. Return value can be directly use as a return value for main().
|
||||||
|
static inline int print_test_summary(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\n\n---------------------------------------------\n"
|
||||||
|
"succeeded: %i\n"
|
||||||
|
"failed : %i\n\n", ok, failed);
|
||||||
|
return failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TESTHELPER_H_
|
Loading…
Add table
Reference in a new issue