Update test suite to properly allocation & deallocation
This commit is contained in:
1 parent
50e8d1f469
commit
37b2f4d2ac
29 files changed
+82
-68
No files matched your search
+1
-2
@@ -20,6 +20,7 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "test-obj.h"
|
||||
#include "m-list.h"
|
||||
#include "m-i-list.h"
|
||||
#include "m-array.h"
|
||||
@@ -29,8 +30,6 @@
|
||||
#include "m-tuple.h"
|
||||
#include "m-algo.h"
|
||||
|
||||
#include "test-obj.h"
|
||||
|
||||
typedef struct over_s {
|
||||
unsigned long data;
|
||||
ILIST_INTERFACE(ilist_over, over_s);
|
||||
|
||||
@@ -20,10 +20,9 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-string.h"
|
||||
#include "coverage.h"
|
||||
|
||||
#include "m-bitset.h"
|
||||
|
||||
static void test1(void)
|
||||
|
||||
@@ -20,11 +20,9 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-string.h"
|
||||
#include "m-bptree.h"
|
||||
#include "test-obj.h"
|
||||
#include "coverage.h"
|
||||
|
||||
START_COVERAGE
|
||||
|
||||
@@ -20,9 +20,8 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "m-core.h"
|
||||
#include "test-obj.h"
|
||||
#include "coverage.h"
|
||||
|
||||
#include "m-bstring.h"
|
||||
|
||||
static void test0(void)
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "m-buffer.h"
|
||||
|
||||
#include "test-obj.h"
|
||||
#include "m-buffer.h"
|
||||
#include "coverage.h"
|
||||
|
||||
START_COVERAGE
|
||||
// Define a fixed queue of unsigned int
|
||||
BUFFER_DEF(buffer_uint, unsigned int, 10, BUFFER_QUEUE|BUFFER_BLOCKING)
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "test-obj.h"
|
||||
#include "coverage.h"
|
||||
|
||||
#include "m-array.h"
|
||||
#include "m-bptree.h"
|
||||
@@ -35,6 +34,7 @@
|
||||
#include "m-variant.h"
|
||||
|
||||
#include "m-concurrent.h"
|
||||
#include "coverage.h"
|
||||
|
||||
TUPLE_DEF2(point, (x, int), (y, int))
|
||||
#define M_OPL_point_t() TUPLE_OPLIST(point, M_BASIC_OPLIST, M_BASIC_OPLIST)
|
||||
|
||||
+1
-2
@@ -29,9 +29,8 @@
|
||||
#define M_F(a,b) M_OVERRIDE_F(a,b)
|
||||
#define M_OVERRIDE__method() , _get_method ,
|
||||
#define M_OVERRIDE__method2() , _get_method2
|
||||
#include "m-core.h"
|
||||
|
||||
#include "test-obj.h"
|
||||
#include "m-core.h"
|
||||
|
||||
static bool tmp_init(void) { return true; }
|
||||
static bool tmp_get_method(void) { return true; }
|
||||
|
||||
+3
-4
@@ -21,17 +21,16 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-dict.h"
|
||||
#include "m-array.h"
|
||||
#include "m-string.h"
|
||||
#include "test-obj.h"
|
||||
#include "coverage.h"
|
||||
|
||||
static inline bool oor_equal_p(int k, unsigned char n) { return k == (int)-n-1; }
|
||||
static inline void oor_set(int *k, unsigned char n) { *k = (int)-n-1; }
|
||||
static inline void update_value (int *p, const int p1, const int p2) { *p = p1 + p2; }
|
||||
#include "coverage.h"
|
||||
|
||||
START_COVERAGE
|
||||
DICT_DEF2(dict_str, string_t, STRING_OPLIST, string_t, STRING_OPLIST)
|
||||
DICT_OA_DEF2(dict_oa_int, int, M_OPEXTEND(M_BASIC_OPLIST, OOR_EQUAL(oor_equal_p), OOR_SET(oor_set M_IPTR)), int, M_OPEXTEND(M_BASIC_OPLIST, ADD(update_value M_IPTR)))
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-string.h"
|
||||
#include "m-funcobj.h"
|
||||
|
||||
@@ -21,14 +21,12 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include "coverage.h"
|
||||
|
||||
#include "test-obj.h"
|
||||
#include "m-string.h"
|
||||
#include "m-array.h"
|
||||
#include "m-list.h"
|
||||
#include "m-generic.h"
|
||||
#include "coverage.h"
|
||||
|
||||
// Generic is not supported if not C11
|
||||
// TCC has some issues in the preprocessing.
|
||||
|
||||
@@ -20,12 +20,11 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-thread.h"
|
||||
#include "m-atomic.h"
|
||||
#include "m-core.h"
|
||||
#include "coverage.h"
|
||||
|
||||
#include "m-genint.h"
|
||||
|
||||
#define MAX_N 256
|
||||
|
||||
+2
-3
@@ -22,9 +22,9 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "test-obj.h"
|
||||
#include "m-i-list.h"
|
||||
#include "coverage.h"
|
||||
|
||||
typedef struct test_s {
|
||||
int n;
|
||||
@@ -37,7 +37,6 @@ static inline bool test_equal_p(const test_t *i1, const test_t *i2)
|
||||
return i1->n == i2->n;
|
||||
}
|
||||
|
||||
#include "coverage.h"
|
||||
START_COVERAGE
|
||||
ILIST_DEF(ilist_tname, test_t, M_OPEXTEND(M_POD_OPLIST, EQUAL(API_6(test_equal_p))))
|
||||
END_COVERAGE
|
||||
|
||||
@@ -20,11 +20,8 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "test-obj.h"
|
||||
|
||||
#include "m-i-shared.h"
|
||||
|
||||
#include "m-thread.h"
|
||||
#include "coverage.h"
|
||||
|
||||
|
||||
+1
-2
@@ -20,12 +20,11 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-string.h"
|
||||
#include "m-list.h"
|
||||
|
||||
#include "coverage.h"
|
||||
|
||||
START_COVERAGE
|
||||
LIST_DEF(list_uint, unsigned int)
|
||||
LIST_DEF(list_mpz, testobj_t, TESTOBJ_OPLIST)
|
||||
|
||||
@@ -21,12 +21,10 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "test-obj.h"
|
||||
#include "m-mempool.h"
|
||||
|
||||
#include "coverage.h"
|
||||
|
||||
START_COVERAGE
|
||||
MEMPOOL_DEF(mempool_uint, unsigned int)
|
||||
END_COVERAGE
|
||||
|
||||
@@ -20,13 +20,11 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-string.h"
|
||||
#include "m-prioqueue.h"
|
||||
|
||||
#include "coverage.h"
|
||||
|
||||
START_COVERAGE
|
||||
PRIOQUEUE_DEF(int_pqueue, int)
|
||||
END_COVERAGE
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-string.h"
|
||||
#include "m-rbtree.h"
|
||||
#include "coverage.h"
|
||||
|
||||
static bool uint_in_str(unsigned int *u, FILE *f)
|
||||
{
|
||||
@@ -49,7 +49,6 @@ static void uint_get_str(string_t str, unsigned int u, bool append)
|
||||
(append ? string_cat_printf : string_printf) (str, "%u", u);
|
||||
}
|
||||
|
||||
#include "coverage.h"
|
||||
START_COVERAGE
|
||||
RBTREE_DEF(rbtree_uint, unsigned int, M_OPEXTEND(M_BASIC_OPLIST, IN_STR(uint_in_str M_IPTR), OUT_STR(uint_out_str), GET_STR(uint_get_str), PARSE_STR(uint_parse_str M_IPTR)) )
|
||||
END_COVERAGE
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "test-obj.h"
|
||||
#include "m-tuple.h"
|
||||
#include "m-array.h"
|
||||
#include "m-variant.h"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "test-obj.h"
|
||||
#include "m-tuple.h"
|
||||
#include "m-array.h"
|
||||
#include "m-variant.h"
|
||||
|
||||
@@ -20,10 +20,8 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "test-obj.h"
|
||||
#include "m-shared-ptr.h"
|
||||
|
||||
#include "m-string.h"
|
||||
#include "m-array.h"
|
||||
#include "m-bptree.h"
|
||||
@@ -34,7 +32,6 @@
|
||||
#include "m-rbtree.h"
|
||||
#include "m-tuple.h"
|
||||
#include "m-variant.h"
|
||||
|
||||
#include "coverage.h"
|
||||
|
||||
// TEST WITH INT
|
||||
|
||||
@@ -20,12 +20,10 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "test-obj.h"
|
||||
|
||||
#include "m-shared.h"
|
||||
|
||||
#include "coverage.h"
|
||||
|
||||
START_COVERAGE
|
||||
SHARED_PTR_DEF(shared_int, int)
|
||||
SHARED_RESOURCE_DEF(shared_ressource, testobj_t, TESTOBJ_OPLIST)
|
||||
|
||||
@@ -21,10 +21,8 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "test-obj.h"
|
||||
|
||||
#include "m-snapshot.h"
|
||||
#include "m-thread.h"
|
||||
|
||||
#include "coverage.h"
|
||||
|
||||
// Long Structure with a simple CRC to check for proper passing
|
||||
|
||||
@@ -22,9 +22,8 @@
|
||||
*/
|
||||
|
||||
#define M_USE_ADDITIONAL_CHECKS 1
|
||||
#include "m-core.h"
|
||||
#include "test-obj.h"
|
||||
#include "coverage.h"
|
||||
|
||||
#include "m-string.h"
|
||||
|
||||
BOUNDED_STRING_DEF(string16, 16)
|
||||
@@ -609,16 +608,18 @@ static void test0(void)
|
||||
assert (string_equal_str_p(s1, "QWERTYQWERTY"));
|
||||
|
||||
string_clear (s2);
|
||||
size_t cap = string_capacity(s1);
|
||||
char *s = string_clear_get_str (s1);
|
||||
assert(strcmp(s, "QWERTYQWERTY") == 0);
|
||||
free(s);
|
||||
overloaded_free(1, s, cap <= sizeof (m_str1ng_heap_ct) - 1 ? strlen(s)+1 : cap );
|
||||
|
||||
string_t s3;
|
||||
string_init(s3);
|
||||
string_cat_str(s3, "ABC");
|
||||
cap = string_capacity(s3);
|
||||
s = string_clear_get_str(s3);
|
||||
assert(strcmp(s, "ABC") == 0);
|
||||
free(s);
|
||||
overloaded_free(1, s, cap <= sizeof (m_str1ng_heap_ct) - 1 ? strlen(s)+1 : cap );
|
||||
|
||||
string_init_set_str(s1, "RESTART");
|
||||
assert (string_equal_str_p(s1, "RESTART"));
|
||||
|
||||
+1
-4
@@ -20,11 +20,8 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "m-tree.h"
|
||||
|
||||
#include "test-obj.h"
|
||||
#include "m-tree.h"
|
||||
#include "m-string.h"
|
||||
#include "coverage.h"
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ static bool test_final_in_progress;
|
||||
|
||||
#include "test-obj.h"
|
||||
#include "coverage.h"
|
||||
|
||||
#include "m-try.h"
|
||||
|
||||
M_TRY_DEF_ONCE()
|
||||
|
||||
+1
-3
@@ -20,13 +20,11 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-string.h"
|
||||
|
||||
#include "m-tuple.h"
|
||||
|
||||
#include "coverage.h"
|
||||
|
||||
START_COVERAGE
|
||||
TUPLE_DEF2(pair,
|
||||
(key, string_t, (INIT(string_init), INIT_SET(string_init_set), SET(string_set), CLEAR(string_clear))),
|
||||
|
||||
@@ -20,13 +20,11 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "test-obj.h"
|
||||
#include "m-string.h"
|
||||
|
||||
#include "m-variant.h"
|
||||
|
||||
#include "coverage.h"
|
||||
|
||||
START_COVERAGE
|
||||
VARIANT_DEF2(pair,
|
||||
(key, int, M_BASIC_OPLIST),
|
||||
|
||||
@@ -20,9 +20,8 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "m-core.h"
|
||||
#include "test-obj.h"
|
||||
#include "coverage.h"
|
||||
|
||||
#include "m-worker.h"
|
||||
|
||||
/* Compute Fibonacci number using thread systems. */
|
||||
|
||||
@@ -25,6 +25,52 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// First overwrite memory handling function so that we can check if everything is ok
|
||||
#ifdef M_MEMORY_REALLOC
|
||||
# error ERROR: Do not include M*LIB headers before this header.
|
||||
#endif
|
||||
|
||||
static size_t amount_allocated = 0;
|
||||
|
||||
static inline void *overloaded_realloc(size_t st, void *ptr, size_t o, size_t n)
|
||||
{
|
||||
size_t *p = (size_t *) ptr;
|
||||
if (p != NULL) {
|
||||
p -= 2;
|
||||
assert(p[0] == st);
|
||||
assert(p[1] == o);
|
||||
amount_allocated -= st * o;
|
||||
}
|
||||
p = (size_t *) realloc(p, 2*sizeof(size_t) + st * n);
|
||||
assert(p != NULL);
|
||||
p[0] = st;
|
||||
p[1] = n;
|
||||
amount_allocated += st * n;
|
||||
return (void*) (&p[2]);
|
||||
}
|
||||
|
||||
static inline void overloaded_free(size_t st, void *ptr, size_t n)
|
||||
{
|
||||
size_t *p = (size_t *) ptr;
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
p -= 2;
|
||||
assert(p[0] == st);
|
||||
assert(p[1] == n);
|
||||
amount_allocated -= st * n;
|
||||
free(p);
|
||||
}
|
||||
|
||||
#define M_MEMORY_REALLOC(type, ptr, o, n) (type *) overloaded_realloc(sizeof(type), ptr, o, n)
|
||||
#define M_MEMORY_FREE(type, ptr, o) overloaded_free(sizeof(type), ptr, o)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "m-string.h"
|
||||
|
||||
@@ -45,6 +91,8 @@ static inline void testobj_final_check(void)
|
||||
{
|
||||
// All created testobj shall have been cleared at the end.
|
||||
assert(testobj_init_counter == 0);
|
||||
// All memory allocations shall be cleared
|
||||
assert(amount_allocated == 0);
|
||||
}
|
||||
|
||||
static inline void testobj_init(testobj_t z)
|
||||
|
||||
Reference in new issue
Block a user